Problem with glsl and multitextures

Started by
2 comments, last by zoser 15 years, 1 month ago
when i render the map i get strange artifacts and is not Z-fighting http://img19.imageshack.us/my.php?image=ss1bik.jpg Fragment Shader: varying float m_Pos; uniform sampler2D Map0; uniform sampler2D Map1; uniform sampler2D Map2; uniform sampler2D Map3; void main() { vec4 Color; vec4 TexColor2; if ( m_Pos < 2.0f ) { TexColor2 = texture2D( Map1, gl_TexCoord[0].st); }else if( m_Pos < 4.0f ) { TexColor2 = texture2D( Map0, gl_TexCoord[0].st); }else if(m_Pos < 6.0f ){ TexColor2 = texture2D( Map3, gl_TexCoord[0].st ); } gl_FragColor = TexColor2; } Vertex Shader: varying float m_Pos; varying vec2 m_TexCoord; void main() { m_Pos=gl_Vertex.z; gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } the artifacts apears in m_Pos==4 and m_Pos==6 someone knows how to fix it? thanks
Advertisement
What are your textures?
From just looking at the picture it looks like the texture in question has alpha. If that was the case replacing the last line with

gl_FragColor = vec4(TexColor2.rgb, 1.0);

would solve it.

Also, remove the 'f' from the float values. They are not allowed in pure GLSL syntax.

It looks like due to imprecision, the height-value isn't exactly 6.0 for all of those pixels. Some might be 5.99 and some 6.01, causing the flicker.

Instead, try using something like "m_Pos < 5.999".

[edit] Also, if you want to eliminate those branching statements, and get a smooth transition at the same time, then you can do something like this (and this will also solve your flickering bug):
float smoothstep2( float min1, float max1, float min2, float max2, float input ){	return smoothstep(min1, max1, input) * (1 - smoothstep(min2, max2, input));}void main(){	float weight1 = 1-smoothstep ( 2, 4, m_Pos );	float weight2 =   smoothstep2( 2, 4, 4, 6, m_Pos );	float weight3 =   smoothstep ( 6, 7, m_Pos );	vec3 tex1 = texture2D( Map1, gl_TexCoord[0].st ).rgb;	vec3 tex2 = texture2D( Map0, gl_TexCoord[0].st ).rgb;	vec3 tex3 = texture2D( Map3, gl_TexCoord[0].st ).rgb;	gl_FragColor = tex1*weight1 + tex2*weight2 + tex3*weight3;}
Quote:Original post by Hodgman
It looks like due to imprecision, the height-value isn't exactly 6.0 for all of those pixels. Some might be 5.99 and some 6.01, causing the flicker.

Instead, try using something like "m_Pos < 5.999".

[edit] Also, if you want to eliminate those branching statements, and get a smooth transition at the same time, then you can do something like this (and this will also solve your flickering bug):*** Source Snippet Removed ***




it works thanks you !

This topic is closed to new replies.

Advertisement