GLSL - 多边形的正面与背面
我在棋盘的 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);
}
I made some simple shading in GLSL of a checkers board:
f(P) = [ floor(Px)+floor(Py)+floor(Pz) ] mod 2
It seems to work well except the fact that i see the interior of the objects but i want to see only the front face.
Any ideas how to fix this? Thanks!
Teapot (glutSolidTeapot()):
Cube (glutSolidCube):
The vertex shader file is:
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;
}
And the fragment shader file is:
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
着色器不是问题 - 面部剔除才是问题。
您应该禁用面部剔除(不建议这样做,因为它出于性能原因而不好):
glFrontFace 来设置剔除模式,即:
或者使用
glCullFace
和glFrontFace 取决于应用程序约定,即矩阵旋向性。
The shaders are not the problem - the face culling is.
You should either disable the face culling (which is not recommended, since it's bad for performance reasons):
or use
glCullFace
andglFrontFace
to set the culling mode, i.e.:The argument to glFrontFace depends on application conventions, i.e. the matrix handedness.