Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Shader: question on android error — Gideros Forum

Shader: question on android error

piepie Member
edited June 2016 in General questions
Hi, I am getting this error from my shader on android, but on windows player it works perfectly.
FragmentShader:
0:17: P0004: High precision not supported, instead compiling high precision as medium precision
0:13: S0052: Uniform variable with initializer
I took the normalmap shader and added some maths to make lights to falloff with distance:
this is my uniform, since it seems to be the one causing troubles. I just declare it once at the beginning of glsl file.
uniform vec3 Falloff = vec3(0.1,0.2,0);
Any suggestion on what could cause the error?
Thank you :)

Comments

  • Can you share all code of glsl file ?
  • piepie Member
    of course, I had to clean it up a little :)
    uniform lowp sampler2D g_Texture;
    uniform lowp vec4 g_Color;
     
     
     
    #define NUM_LIGHTS	2
    uniform mediump vec4 lightPos[NUM_LIGHTS];
     
    //attenuation coefficients
    uniform vec3 Falloff = vec3(0.1,0.02,0);         
     
     
    varying highp vec2 texCoord;
    varying mediump vec2 position; 
     
     
    void main()
    {
     
     
    	//Common data
    	//Grab the main pixel color from the classic texture
    	lowp vec3 color0 = texture2D(g_Texture, texCoord).rgb;
     
    	//Set the specular (i.e. "shine") color to 30% gray
    	lowp vec3 color1 = vec3(0.3, 0.3, 0.3);
     
    	//Grab the normal vector from the right part of the texture:
    	//-Displace by 0.5 to the right in normalized coordinates (1=full texture width)
    	//-Convert RGB (range 0->1) to XYZ (range -1 -> 1)
    	mediump vec3 normal =  texture2D(g_Texture, texCoord + vec2(0.5, 0.0)).rgb * 2.0 - 1.0;
     
    	lowp vec3 lightContributions=vec3(0,0,0);	
    	int index;
    	for (index = 0; index <= NUM_LIGHTS; index++) // for all light sources 
    	{ 	
    			//Compute light direction, assuming light distance of altitude units. y inverted as in spriteilluminator
    			vec3 LightDirection =	vec3(lightPos[index].x,-lightPos[index].y, 30) - vec3(position.x,-position.y, 0);
     
    			//Determine distance (used for attenuation) BEFORE we normalize our LightDir
    			float D = length(LightDirection);	
     
    			//normalize lightdir
    			mediump vec3 lightDir = normalize(LightDirection); 
     
    			//Compute the light direction as if light was two times further (for specular)
    			mediump vec3 halfdir = normalize(normalize(lightDir) + vec3(0, 0, 1));
     
    			//Compute diffuse factor: normal and lightDir colinear -> 1, perpendicular -> 0
    			lowp float diff = max(0.1, dot(normal, lightDir));
     
    			//Compute specular factor the same way, but with exponential scale
    			mediump float nh = max(0.1, dot(normal, halfdir));
    			mediump float spec = pow(nh, 10.0); 
     
    			//calculate attenuation
    			float Attenuation = 1.0 / ( Falloff.x + (Falloff.y*D) + (Falloff.z*D*D) );
     
     
    			lightContributions=  lightContributions+ (color0 * diff + color1 * spec) *Attenuation;
     
     
    	} 
     
     
     
     
     
     
     
     
    	gl_FragColor = g_Color * vec4(lightContributions.rgb, 1); 
     
    }
    It's the "multi light" shader made by @hgy29, with some small additions from here:
    https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6

    I thought the error was from Falloff = vec3(0.1,0.02,0); but I have the same error using
    Falloff = vec3(0.1,0.2,0);
    Thank you :)

  • mertocanmertocan Member
    Accepted Answer
    Can you try again after replacing highp with mediump ?
  • hgy29hgy29 Maintainer
    Accepted Answer
    @pie,

    You simply can't give a value to a uniform, uniforms take their value from outside the shader (ie C code or lua).
  • piepie Member
    Thank you @hgy29, I missed that :)
    For the records, I was also missing precision declarations on other variables: ie
    mediump float D = length(LightDirection);
Sign In or Register to comment.