neuralsandwich / graphics-programming

Repo for graphics programming module
MIT License
2 stars 0 forks source link

Phong shader problem #5

Closed neuralsandwich closed 11 years ago

neuralsandwich commented 11 years ago

Issue with line 20 (commit 5676c216c1f6f3d9da8042d0517cc4b9d6e5d4b4) of phong.vert, which stops the shader from linking.

The overall lighting effect doesn't seem like it is correct either.

This doesn't work

void main()
{
  // Past through position
  vertex_position = (model * position).xyz;

  // Transform position
  gl_Position = MVP * vec4(position, 1.0);

  // Updating normal with normal matrix
  transformed_normal = normal_matrix * normal;

  // Output tex coord
  vertex_tex_coord = tex_coord;

}

This works

void main()
{
  // Past through position
  //vertex_position = (model * position).xyz;

  // Transform position
  gl_Position = MVP * vec4(position, 1.0);

  // Updating normal with normal matrix
  transformed_normal = normal_matrix * normal;

  // Output tex coord
  vertex_tex_coord = tex_coord;

}
7thsanctum commented 11 years ago

You can't multiply a mat4 by a vec3. To get around this you could multiply it by a vec4 instead. do something like

vertex_position = (model * vec4(position,1)).xyz;

neuralsandwich commented 11 years ago

I was thinking that in the workbook by Kevin Chalmers it said to do it. I am still getting used to GLM and OpenGL so I wasn't sure.

I'll try it and see what happens!