Note that there are some explanatory texts on larger screens.

plurals
  1. POGLSL phong shaders, debugging
    primarykey
    data
    text
    <p>I am looking for some help debugging my GLSL phong shading code. Here is my vertex shader:</p> <pre><code>layout(std140) uniform Matrices { mat4 model[1024]; }; layout(location = 0) in vec4 vertexCoord; layout(location = 2) in vec3 vertexNormal; uniform mat4 view; // from lookAt() uniform mat4 projection; // perspective projection out vec3 Position; out vec3 Normal; out vec4 lightPosEye; void main() { mat4 modelView = view * model[gl_InstanceID]; mat3 normalMatrix = mat3(transpose(inverse(modelView))); //mat3 normalMatrix = mat3(modelView); vec4 lightPos = vec4(350, 350, 350, 1); lightPosEye = modelView * lightPos; Position = vec3(modelView * vertexCoord); Normal = normalize(normalMatrix * vertexNormal); gl_Position = projection * vec4(Position, 1.0); } </code></pre> <p>and here is my fragment shader:</p> <pre><code>in vec3 Position; in vec3 Normal; in vec4 lightPosEye; layout(location = 0) out vec4 FragColor; vec3 ads() { vec3 Ka = vec3(0, 0.5, 0); vec3 Kd = vec3(0, 0.5, 0); vec3 Ks = vec3(0, 0.1, 0); vec3 intensity = vec3(0.3, 0.5, 0.0); float shininess = 0.1; vec3 n = normalize(Normal); vec3 s = normalize(vec3(lightPosEye) - Position); vec3 v = normalize(vec3(-Position)); vec3 r = reflect(-s, n); return intensity * (Ka + Kd * max(dot(s, n), 0.0) + Ks * pow(max(dot(r,v), 0.0), shininess)); } void main() { FragColor = vec4(ads(), 1); } </code></pre> <p>Here is a screenshot of the result (I am also rendering the normals with another geometry shader for debugging purposes):</p> <p><img src="https://i.stack.imgur.com/hp1M9.png" alt="rendering result"></p> <p>The artifacts on the cube are wrong, and the "shadows" on the circle also moves a bit when I move the camera around (change the view matrix).</p> <p>Any obvious errors in my GLSL code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload