質問編集履歴
1
文章を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,68 @@
|
|
1
1
|
提示コードですが以下のコメント部のコードが立方体描画のコードなのですがカスタムフレームバッファで深度バッファなどを多数のバッファを色々使ってる場合どこに描画コードを置けばいいのでしょうか?
|
2
2
|
|
3
|
+
参考サイトのwhile分のループですがこれはカスタムフレームバッファを利用していない場合のコードなのですがRenderScene()のコードが二つありますがこれはどっちにレンダリングするコードを書けばいいのでしょうか?またこれはカスタムフレームバッファを利用していないコードですがカスタムフレームバッファを利用する場合はどこに書けばいいのでしょうか?
|
3
4
|
|
4
5
|
|
5
|
-
参考サイト: [https://learnopengl.com/
|
6
|
+
参考サイト: [https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/3.1.3.shadow_mapping/shadow_mapping.cpp
|
7
|
+
](https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/3.1.3.shadow_mapping/shadow_mapping.cpp)
|
6
8
|
|
9
|
+
##### 参考サイトのwhile文内部のコード
|
7
10
|
```
|
11
|
+
glm::mat4 lightProjection, lightView;
|
12
|
+
glm::mat4 lightSpaceMatrix;
|
13
|
+
float near_plane = 1.0f, far_plane = 7.5f;
|
14
|
+
//lightProjection = glm::perspective(glm::radians(45.0f), (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT, near_plane, far_plane); // note that if you use a perspective projection matrix you'll have to change the light position as the current light position isn't enough to reflect the whole scene
|
15
|
+
lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
|
16
|
+
lightView = glm::lookAt(lightPos, glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
|
17
|
+
lightSpaceMatrix = lightProjection * lightView;
|
18
|
+
// render scene from light's point of view
|
19
|
+
simpleDepthShader.use();
|
20
|
+
simpleDepthShader.setMat4("lightSpaceMatrix", lightSpaceMatrix);
|
8
21
|
|
22
|
+
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
23
|
+
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
24
|
+
glClear(GL_DEPTH_BUFFER_BIT);
|
25
|
+
glActiveTexture(GL_TEXTURE0);
|
26
|
+
glBindTexture(GL_TEXTURE_2D, woodTexture);
|
27
|
+
//////////////////////////////////////////////////////////////////////////
|
28
|
+
renderScene(simpleDepthShader);
|
29
|
+
//////////////////////////////////////////////////////////////////////////
|
30
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
31
|
+
|
32
|
+
// reset viewport
|
33
|
+
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
|
34
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
35
|
+
|
36
|
+
// 2. render scene as normal using the generated depth/shadow map
|
37
|
+
// --------------------------------------------------------------
|
38
|
+
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
|
39
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
40
|
+
shader.use();
|
41
|
+
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
42
|
+
glm::mat4 view = camera.GetViewMatrix();
|
43
|
+
shader.setMat4("projection", projection);
|
44
|
+
shader.setMat4("view", view);
|
45
|
+
// set light uniforms
|
46
|
+
shader.setVec3("viewPos", camera.Position);
|
47
|
+
shader.setVec3("lightPos", lightPos);
|
48
|
+
shader.setMat4("lightSpaceMatrix", lightSpaceMatrix);
|
49
|
+
glActiveTexture(GL_TEXTURE0);
|
50
|
+
glBindTexture(GL_TEXTURE_2D, woodTexture);
|
51
|
+
glActiveTexture(GL_TEXTURE1);
|
52
|
+
glBindTexture(GL_TEXTURE_2D, depthMap);
|
53
|
+
////////////////////////////////////////////////////////////////
|
54
|
+
renderScene(shader);
|
55
|
+
////////////////////////////////////////////////////////////////
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
##### Camera.cpp
|
63
|
+
|
64
|
+
```
|
65
|
+
|
9
66
|
void FrameWork::Camera::Renderer()
|
10
67
|
{
|
11
68
|
|