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


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:


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.


Image included?

Does the image appear now?

The holes are there because you call discard. What exactly were you expecting to happen?

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!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.