NDark
04-22-2008, 02: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
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