我在跳棋板的GLSL中做了一些简单的阴影:
f(P) = [ floor(Px)+floor(Py)+floor(Pz) ] mod 2
除了我看到物体的内部但我只想看到正面的事实之外,它似乎运作良好。 任何想法如何解决这一问题?谢谢!
茶壶(glutSolidTeapot()):
立方体(glutSolidCube):
顶点着色器文件是:
varying float x,y,z;
void main(){
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
x = gl_Position.x;
y = gl_Position.y;
z = gl_Position.z;
}
片段着色器文件是:
varying float x,y,z;
void main(){
float _x=x;
float _y=y;
float _z=z;
_x=floor(_x);
_y=floor(_y);
_z=floor(_z);
float sum = (_x+_y+_z);
sum = mod(sum,2.0);
gl_FragColor = vec4(sum,sum,sum,1.0);
}
答案 0 :(得分:5)
着色器不是问题 - 面部剔除是。
你应该禁用面部剔除(不建议这样做,因为它因性能原因而不好):
glDisable(GL_CULL_FACE);
或使用glCullFace
和glFrontFace
来设置剔除模式,即:
glEnable(GL_CULL_FACE); // enables face culling
glCullFace(GL_BACK); // tells OpenGL to cull back faces (the sane default setting)
glFrontFace(GL_CW); // tells OpenGL which faces are considered 'front' (use GL_CW or GL_CCW)
glFrontFace的参数取决于应用程序约定,即矩阵旋向性。