specular

Phong lighting: add specular lighting separately or with ambient and diffuse?

孤街醉人 提交于 2019-12-24 09:50:13
问题 I am trying to implement Phong lighting. In some tutorials specular lighting is added to ambient and diffuse lighting and then total lighting is multiplied by texture color. I also saw a tutorial where specular lighting was added separately after the addition of ambient and diffuse lights was multiplied with texture color. Here is a fragment shader with both options present and with screenshots. #version 330 core out vec4 FragColor; in vec2 TexCoord; in vec3 normals; in vec3 fragPosition; /

OpenGL shimmering pixels artifact

限于喜欢 提交于 2019-12-10 14:18:54
问题 I'm trying to implement ambient occlusion on a voxel-based mesh and get these flickering white pixels at the edges of faces: Here is my fragment shader: #version 120 varying vec4 color; varying vec4 normal; void main(void) { float light = normal.w + max(0.15*dot(normal.xyz, vec3(1,1,1)), 0.0); gl_FragColor = vec4(color.xyz * light, 1.0); } If I remove the light from the gl_FragColor vec4 then the artifact disappears. The light value is calculated from the ambient occlusion value ( normal.w )