Jump to content


GLSL instruction limitation ?


3 replies to this topic

#1 NDark

    New Member

  • Members
  • Pip
  • 8 posts

Posted 22 April 2008 - 09:01 AM

I write both vertex and fragment shader with GLSL , and I am trying to blend 4 or more textures in one pass which means sampling different textures and summation those colors with some sort of weighting .

I use 3 textures the result is fine . When I use 4 , the program using is fail . At started I think it might be memory , I decrease the variable using , still failed . When I comment the calculation of weighting , 4 texture is OK .



So , I wonder that is there instruction limitation in GLSL , or how small it is ( because I didn't write too large my codes ) ?



My graphic card is GeForce 7600GS , OpenGL2.0 , NVidia driver updated and NVidia OpenGL SDK 10 is installed .

My code is following :
vertex shader :

varying vec3 L0 ;// 4 light position for weighting

varying vec3 L1 ;

varying vec3 L2 ;

varying vec3 L3 ;

varying vec3 N ;// normal


void main(void)

{

	vec3 P = vec3( gl_ModelViewMatrix * gl_Vertex) ;

	L0 = normalize( gl_LightSource[ 0 ].position - P ) ;

	L1 = normalize( gl_LightSource[ 1 ].position - P ) ;

	L2 = normalize( gl_LightSource[ 2 ].position - P ) ;

	L3 = normalize( gl_LightSource[ 3 ].position - P ) ;	

	N = normalize( gl_NormalMatrix * gl_Normal);

	

             // texture matrix for projective texture

	gl_TexCoord[ 0 ] = gl_TextureMatrix[ 0 ] * gl_Vertex ;

	gl_TexCoord[ 1 ] = gl_TextureMatrix[ 1 ] * gl_Vertex ;

	gl_TexCoord[ 2 ] = gl_TextureMatrix[ 2 ] * gl_Vertex ;

	gl_TexCoord[ 3 ] = gl_TextureMatrix[ 3 ] * gl_Vertex ;	

	

	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex ;

}



fragment shader :

varying vec3 L0 ;

varying vec3 L1 ;

varying vec3 L2 ;

varying vec3 L3 ;

varying vec3 N ;

uniform sampler2D Texture0 ;// 4 texture binded with GL_TEXTURE0~4

uniform sampler2D Texture1 ;

uniform sampler2D Texture2 ;

uniform sampler2D Texture3 ;


void main (void)

{

	vec4 texColor = texture2DProj( Texture0 , gl_TexCoord[ 0 ] ) * max( dot( N , L0 ), 0.0 ) ;

	texColor += texture2DProj( Texture1 , gl_TexCoord[ 1 ] ) * max( dot( N , L1 ), 0.0 ) ;

	texColor += texture2DProj( Texture3 , gl_TexCoord[ 2 ] ) * max( dot( N , L2 ), 0.0 ) ;


	texColor += texture2DProj( Texture3 , gl_TexCoord[ 3 ] ) * max( dot( N , L3 ), 0.0 ) ;// If i comment this line , the program works .

	gl_FragColor = min( texColor , 1.0 )  ;	// prevent overflow

}


thanks in advance .


NDark

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 22 April 2008 - 12:12 PM

As far as I remember, GLSL 1.10 has an instruction limit of 1024, but not all implementations adhere to the specifications (just look at the dynamic branching issues)...

There are also some inconsistencies in your code, you could try and fix them and see what happens:

  • In the vertex program you have a 'varying vec3 P', but not in the fragment program
  • When weighting the 3rd texture, you are using L3 instead of L2
  • 'min( texColor , 1.0 )' should probably be 'texColor = min( texColor , 1.0 )'

Btw. I'm pretty sure the hardware automatically clamps the output values of fragment program.
"Stupid bug! You go squish now!!" - Homer Simpson

#3 NDark

    New Member

  • Members
  • Pip
  • 8 posts

Posted 23 April 2008 - 01:33 AM

thank you , Mr. Gorking , I fixed the writed-mistake , and make code more clear.

#4 NDark

    New Member

  • Members
  • Pip
  • 8 posts

Posted 05 May 2008 - 08:39 AM

It's the problem of using too much varying variable in Shader ,
solution link is here :
http://www.opengl.or...7438#Post237438





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users