You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

4 years ago
4 years ago
4 years ago
  1. #include "scene.h"
  2. #include "utils.h"
  3. #include "model.h"
  4. #include "framebufferobject.h"
  5. #include "fullscreenquad.h"
  6. glm::mat4 viewMatrix, projectionMatrix;
  7. glm::vec3 cameraPos(4.0f, 3.0f, 4.0f);
  8. Model model;
  9. FrameBufferObject *fbo;
  10. FullScreenQuad *fsq;
  11. void Init()
  12. {
  13. model.Init("Res/Cube.obj");
  14. model.mShader->Init("Res/spot_light.vs", "Res/spot_light.fs");
  15. model.SetPosition(0.0f, 0.0f, 0.0f);
  16. //���û���������
  17. model.SetAmbientMaterial(0.1f, 0.1f, 0.1f, 1.0f);
  18. model.mShader->SetVec4("U_AmbientLight", 0.1f, 0.1f, 0.1f, 1.0f);
  19. //���û���������
  20. model.mShader->SetVec4("U_LightPos", 0.0f, 1.8f, 0.0f, 0.0f);
  21. model.SetDiffuseMaterial(0.4f, 0.4f, 0.4f, 1.0f);
  22. model.mShader->SetVec4("U_DiffuseLight", 0.8f, 0.8f, 0.8f, 1.0f);
  23. //���ø߹�����
  24. model.SetSpecularMaterial(1.0f, 1.0f, 1.0f, 1.0f);
  25. model.mShader->SetVec4("U_SpecularLight", 1.0f, 1.0f, 1.0f, 1.0f);
  26. //���þ۹��Ʋ���
  27. model.mShader->SetVec4("U_LightDirection", 0.0f, -1.0f, 0.0f, 15.0f);//15.0��cutoff
  28. model.mShader->SetVec4("U_LightOption", 32.0f, 2.0f, 0.0f, 0.0f);
  29. viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  30. fsq = new FullScreenQuad();
  31. fsq->Init();
  32. fsq->mShader->Init("Res/fullscreenquad.vs", "Res/fullscreenquad.fs");
  33. }
  34. void SetViewPortSize(float width, float height)
  35. {
  36. projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f);
  37. fbo = new FrameBufferObject();
  38. fbo->AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, (int)width, (int)height);
  39. fbo->AttachDepthBuffer("depth", (int)width, (int)height);
  40. fbo->Finish();
  41. fbo->Bind();
  42. glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
  43. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  44. model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z);
  45. fbo->Unbind();
  46. }
  47. void Draw()
  48. {
  49. glClearColor(0.0f,0.0f,0.0f,1.0f);
  50. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  51. fsq->mShader->SetTexture("U_Texture", fbo->GetBuffer("color"));
  52. fsq->Draw();
  53. }