Graphics GLSL-多边形的正面与背面
我在跳棋板的GLSL中做了一些简单的着色:Graphics GLSL-多边形的正面与背面,graphics,glsl,Graphics,Glsl,我在跳棋板的GLSL中做了一些简单的着色: f(P) = [ floor(Px)+floor(Py)+floor(Pz) ] mod 2 它似乎工作得很好,除了我能看到物体的内部,但我只想看到正面。 有没有办法解决这个问题?谢谢 茶壶(茶壶()): 立方体(立方体): 顶点着色器文件是: varying float x,y,z; void main(){ gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vert
f(P) = [ floor(Px)+floor(Py)+floor(Pz) ] mod 2
它似乎工作得很好,除了我能看到物体的内部,但我只想看到正面。
有没有办法解决这个问题?谢谢
茶壶(茶壶()):
立方体(立方体):
顶点着色器文件是:
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);
}
片段着色器文件是:
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);
}
着色器不是问题所在-面剔除才是问题所在 您应该禁用面剔除(不建议这样做,因为出于性能原因,这样做不好): 或者使用
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的参数取决于应用程序惯例,即矩阵惯用手。着色器不是问题所在-面剔除是问题所在 您应该禁用面剔除(不建议这样做,因为出于性能原因,这样做不好): 或者使用
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的参数取决于应用惯例,即矩阵利手