2016-06-11 18 views
1

Androidでopengles 2.0ビュー用のシェーダを作成しようとしています。 私のシェーダは次のとおりです。GLSL 2.0 Shaderが異なるデバイスに異なる光を与える

頂点シェーダ:

uniform mat4 u_MVPMatrix;  // A constant representing the combined model/view/projection matrix. 
uniform mat4 u_MVMatrix;  // A constant representing the combined model/view matrix.    

attribute vec4 a_Position;  // Per-vertex position information we will pass in.        
attribute vec3 a_Normal;  // Per-vertex normal information we will pass in.  
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.  

varying vec3 v_Position;  // This will be passed into the fragment shader.        
varying vec3 v_Normal;   // This will be passed into the fragment shader. 
varying vec2 v_TexCoordinate; // This will be passed into the fragment shader.    

// The entry point for our vertex shader. 
void main()              
{               
    // Transform the vertex into eye space.  
    v_Position = vec3(u_MVMatrix * a_Position); 

    // Pass through the texture coordinate. 
    v_TexCoordinate = a_TexCoordinate;          

    // Transform the normal's orientation into eye space. 
    v_Normal = normalize(vec3(u_MVMatrix * vec4(a_Normal, 0.0))); 

    // gl_Position is a special variable used to store the final position. 
    // Multiply the vertex by the matrix to get the final point in normalized screen coordinates. 
    gl_Position = (u_MVPMatrix * a_Position); 
} 

フラグメントシェーダ:

precision highp float;   // Set the default precision to medium. We don't need as high of a 
           // precision in the fragment shader. 
uniform vec3 u_LightPos1;   // The position of the light in eye space. 
uniform vec3 u_LightDir1;   // The position of the light in eye space. 
float l_spotCutOff=45.0; 
uniform sampler2D u_Texture; // The input texture. 

varying vec3 v_Position;  // Interpolated position for this fragment. 
varying vec3 v_Normal;   // Interpolated normal for this fragment. 
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. 
float cutoff = 0.1; 
// The entry point for our fragment shader. 
void main()       
{        

    // Get a lighting direction vector from the light to the vertex. 
    vec3 lightVector1 = normalize(u_LightPos1 - v_Position); 

     // Will be used for attenuation. 
     float distance1 = length(u_LightPos1 - v_Position); 

    float diffuse=0.0; 

     // Calculate the dot product of the light vector and vertex normal. If the normal and light vector are 
     // pointing in the same direction then it will get max illumination. 
    float diffuse1 = max(dot(v_Normal, lightVector1), 0.1); 
     // Add attenuation. 
    diffuse1 = diffuse1 * (1.0/(1.0+(0.25*distance1))); 

    // Add ambient lighting 
    diffuse = diffuse1+0.2; 
    // Multiply the color by the diffuse illumination level and texture value to get final output color. 
    vec4 color = (texture2D(u_Texture, v_TexCoordinate)); 
    color.rgb *= (diffuse); 
    if(color.a < cutoff) 
     discard; 

    gl_FragColor = color; 


    }                   

今シェーダが完璧に働いているが、その別のデバイスに異なる動作を:

デバイス1: (モトーxプレイ)

1

デバイス2:(サムスンS7) 2

誰でも助けることができますか?

+0

を使用して、両方のデバイスの機能を確認して良いです。 –

+0

私はhighpの代わりにmediumpを使用しましたが、ライトインテンシティを変更しましたが、それと同じ効果 – sabby

答えて

0

問題はテクスチャ形式/タイプで使用している可能性があります。すべてのデバイスがすべてのテクスチャ形式をサポートするわけではありません。 たとえば、出力カラーが負の値を持ち、デバイスのテクスチャフォーマットがそれらをサポートしていない場合、出力カラーは0にクランプされ、異なる結果が得られます。 `highp float`は、すべてのデバイスで利用できない、それは差分の源となり得る

GLES20.glGetString(GLES20.GL_EXTENSIONS)); 
関連する問題