Beispiel #1
0
void UberShader::ApplyCamera(const glm::mat4 &projection, const glm::mat4 &view, const glm::mat4 &model) {
  Device *dev = Device::GetInstance();
  RenderState *render_dev = &dev->render_state();
  const Material &material = render_dev->LastMaterial();

  Shader &shader = Load(material.props);

  //world-view-projection
  //world, view, projection 같은것을 등록할수 잇으면 등록하기
  glm::mat4 mvp = glm::mat4(1.0f);
  mvp *= projection;
  mvp *= view;
  mvp *= model;
  shader.SetUniformMatrix(kMVPHandleName, mvp);
  shader.SetUniformMatrix(kModelHandleName, model);
  shader.SetUniformMatrix(kProjectionHandleName, projection);
  shader.SetUniformMatrix(kViewHandleName, view);
  shader.SetUniformMatrix(kModelViewHandleName, view * model);

  //빛 계산에는 normal계산 뒤집는 행렬이 필요하다
  glm::mat4 modelview_mat4(view * model);
  glm::mat4 modelview_mat4_inv = glm::inverse(modelview_mat4);
  glm::mat4 modelview_mat4_inv_transpose = glm::transpose(modelview_mat4_inv);
  shader.SetUniformMatrix(kMVInvTransposeHandleName, modelview_mat4_inv_transpose);

  const glm::vec3 eye = MatrixHelper::ViewPos(view);
  const glm::vec3 up = MatrixHelper::ViewUpVec(view);
  const glm::vec3 dir = MatrixHelper::ViewDirVec(view);
  glm::vec3 view_side = glm::cross(dir, up);

  glm::vec4 view_side_vec(view_side.x, view_side.y, view_side.z, 1.0f);
  shader.SetUniformVector(kViewSideHandleName, view_side);

  glm::vec4 eye_vec(eye.x, eye.y, eye.z, 1.0f);
  shader.SetUniformVector(kViewPositionHandleName, eye_vec);

  glm::vec4 up_vec(up.x, up.y, up.z, 1.0f);
  shader.SetUniformVector(kViewUpHandleName, up_vec);

  glm::vec4 dir_vec(dir.x, dir.y, dir.z, 1.0f);
  shader.SetUniformVector(kViewDirHandleName, dir_vec);
}
Beispiel #2
0
 /// dot product of unit length vector toward camera
 /// and surface normal (ignoring creases):
 double eye_vec_dot_norm() const { return eye_vec() * norm(); }