PDA

View Full Version : Quiz: Where do these holes come from? (image included)



kon
08-23-2005, 03:04 PM
Hi,

starting writing a small rendering demo I got some results which I can't explain! Well, I'm rendering six sides of a unit cube (each side from -0.5 to 0.5). The shaders are

char* p3DVolVert =
"void main(void) {"
" gl_Position = ftransform();"
" gl_TexCoord[0] = gl_Vertex;"
"}";

char* p3DVolFrag =
"uniform float numAdds;"
"void main(void) {"
"vec3 texCoord = gl_TexCoord[0].xyz;"
"vec3 vvec = normalize(texCoord);"

"texCoord += numAdds * vvec * -0.25;"

"if(texCoord.z < -1.0) discard;"
"if(texCoord.z > 1.0) discard;"

"if(texCoord.y < -1.0) discard;"
"if(texCoord.y > 1.0) discard;"

"if(texCoord.x < -1.0) discard;"
"if(texCoord.x > 1.0) discard;"

"gl_FragColor = vec4(texCoord+vec3(0.5), 1.0);"
"}";The uniform numAdds is set to 7.0 and the image then looks like this:

http://server2.uploadit.org/files/heliosdev-CubeHoles.JPG

The holes get smaller by decreasing numAdds and disappear (solid cube) when numAdds is 6.0.

I any of the if...discard is omitted, the hole of this plane disappears.
Any explanation is appreciated.

kon

Jan
08-24-2005, 12:48 AM
Image included?

kon
08-24-2005, 03:32 AM
Does the image appear now?

Tom Nuydens
08-24-2005, 08:00 AM
The holes are there because you call discard. What exactly were you expecting to happen?

kon
08-24-2005, 09:32 AM
I was just surprised about the circular shape! But this probably comes out of the normalization of the vvec.
Well, it's actually more a math question than a GLSL one!