GLSL Not Working In App?

Started by
9 comments, last by zaneski13 14 years, 2 months ago
So heres what I've found


this shader works

//VERTconst int NUM_LIGHTS = 2;uniform vec3 LightPosition[NUM_LIGHTS];uniform mat4 CameraViewMatrix; varying vec2 texCoord;varying vec3 vertPos;varying vec3 lightPos[NUM_LIGHTS];void main(void){   texCoord = gl_MultiTexCoord0.xy;      lightPos[0] = (vec4(LightPosition[0],1.0f) * CameraViewMatrix).xyz;   lightPos[1] = (vec4(LightPosition[1],1.0f) * CameraViewMatrix).xyz;   gl_Position = ftransform();   vertPos = (gl_Vertex* gl_ModelViewMatrix).xyz;}//FRAGconst int NUM_LIGHTS = 2;uniform sampler2D diffuseTex;uniform vec4 LightColor[NUM_LIGHTS];uniform float LightRadius[NUM_LIGHTS];varying vec2 texCoord;varying vec3 vertPos;varying vec3 lightPos[NUM_LIGHTS];void main(void){   vec4 diffuseColor = texture2D(diffuseTex, texCoord);      vec4 colorAcum = vec4(0.0f, 0.0f, 0.0f, 1.0f);         float percentLit;	//light 1   percentLit = 1.0f - (distance(lightPos[0], vertPos) / LightRadius[0]);     if ( percentLit < 0.0f )          percentLit = 0.0f;         colorAcum += (vec4(percentLit,percentLit,percentLit,1.0f) * LightColor[0]);	//light 2   percentLit = 1.0f - (distance(lightPos[1], vertPos) / LightRadius[1]);     if ( percentLit < 0.0f )          percentLit = 0.0f;         colorAcum += (vec4(percentLit,percentLit,percentLit,1.0f) * LightColor[1]);   if ( colorAcum.r < 0.3f && colorAcum.g < 0.3f && colorAcum.b < 0.3f )      colorAcum = vec4(0.3f, 0.3f, 0.3f, 1.0f);   gl_FragColor = diffuseColor * colorAcum;}



While this one doesn't


//VERTconst int NUM_LIGHTS = 2;uniform vec3 LightPosition[NUM_LIGHTS];uniform mat4 CameraViewMatrix; varying vec2 texCoord;varying vec3 vertPos;varying vec3 lightPos[NUM_LIGHTS];void main(void){   texCoord = gl_MultiTexCoord0.xy;      for ( int i = 0; i < NUM_LIGHTS; i++ )   {      lightPos = (vec4(LightPosition,1.0f) * CameraViewMatrix).xyz;   }   gl_Position = ftransform();   vertPos = (gl_Vertex* gl_ModelViewMatrix).xyz;}//FRAGconst int NUM_LIGHTS = 2;uniform sampler2D diffuseTex;uniform vec4 LightColor[NUM_LIGHTS];uniform float LightRadius[NUM_LIGHTS];varying vec2 texCoord;varying vec3 vertPos;varying vec3 lightPos[NUM_LIGHTS];void main(void){   vec4 diffuseColor = texture2D(diffuseTex, texCoord);      vec4 colorAcum = vec4(0.0f, 0.0f, 0.0f, 1.0f);         float percentLit;   for ( int i = 0; i < NUM_LIGHTS; i++ )   {       percentLit = 1.0f - (distance(lightPos, vertPos) / LightRadius);        if ( percentLit < 0.0f )           percentLit = 0.0f;            colorAcum += (vec4(percentLit,percentLit,percentLit,1.0f) * LightColor);   }	   if ( colorAcum.r > 1.0f )       colorAcum.r = 1.0f;   if ( colorAcum.g > 1.0f )       colorAcum.g = 1.0f;   if ( colorAcum.b > 1.0f )       colorAcum.b = 1.0f;   if ( colorAcum.a > 1.0f )       colorAcum.a = 1.0f;   if ( colorAcum.r < 0.3f && colorAcum.g < 0.3f && colorAcum.b < 0.3f )      colorAcum = vec4(0.3f, 0.3f, 0.3f, 1.0f);   gl_FragColor = diffuseColor * colorAcum;}



And yet the second one compiles fine in render monkey

This topic is closed to new replies.

Advertisement