質問編集履歴

1

文章を修正

2021/11/11 01:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,11 +2,125 @@
2
2
 
3
3
 
4
4
 
5
-
6
-
7
-
8
-
9
- 参考サイト: [https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping](https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping)
5
+ 参考サイトのwhile分のループですがこれはカスタムフレームバッファを利用していない場合のコードなのですがRenderScene()のコードが二つありますがこれはどっちにレンダリングするコードを書けばいいのでしょうか?またこれはカスタムフレームバッファを利用していないコードですがカスタムフレームバッファを利用する場合はどこに書けばいいのでしょうか?
6
+
7
+
8
+
9
+
10
+
11
+ 参考サイト: [https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/3.1.3.shadow_mapping/shadow_mapping.cpp
12
+
13
+ ](https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/3.1.3.shadow_mapping/shadow_mapping.cpp)
14
+
15
+
16
+
17
+ ##### 参考サイトのwhile文内部のコード
18
+
19
+ ```
20
+
21
+ glm::mat4 lightProjection, lightView;
22
+
23
+ glm::mat4 lightSpaceMatrix;
24
+
25
+ float near_plane = 1.0f, far_plane = 7.5f;
26
+
27
+ //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
28
+
29
+ lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
30
+
31
+ lightView = glm::lookAt(lightPos, glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
32
+
33
+ lightSpaceMatrix = lightProjection * lightView;
34
+
35
+ // render scene from light's point of view
36
+
37
+ simpleDepthShader.use();
38
+
39
+ simpleDepthShader.setMat4("lightSpaceMatrix", lightSpaceMatrix);
40
+
41
+
42
+
43
+ glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
44
+
45
+ glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
46
+
47
+ glClear(GL_DEPTH_BUFFER_BIT);
48
+
49
+ glActiveTexture(GL_TEXTURE0);
50
+
51
+ glBindTexture(GL_TEXTURE_2D, woodTexture);
52
+
53
+ //////////////////////////////////////////////////////////////////////////
54
+
55
+ renderScene(simpleDepthShader);
56
+
57
+ //////////////////////////////////////////////////////////////////////////
58
+
59
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
60
+
61
+
62
+
63
+ // reset viewport
64
+
65
+ glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
66
+
67
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
68
+
69
+
70
+
71
+ // 2. render scene as normal using the generated depth/shadow map
72
+
73
+ // --------------------------------------------------------------
74
+
75
+ glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
76
+
77
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78
+
79
+ shader.use();
80
+
81
+ glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
82
+
83
+ glm::mat4 view = camera.GetViewMatrix();
84
+
85
+ shader.setMat4("projection", projection);
86
+
87
+ shader.setMat4("view", view);
88
+
89
+ // set light uniforms
90
+
91
+ shader.setVec3("viewPos", camera.Position);
92
+
93
+ shader.setVec3("lightPos", lightPos);
94
+
95
+ shader.setMat4("lightSpaceMatrix", lightSpaceMatrix);
96
+
97
+ glActiveTexture(GL_TEXTURE0);
98
+
99
+ glBindTexture(GL_TEXTURE_2D, woodTexture);
100
+
101
+ glActiveTexture(GL_TEXTURE1);
102
+
103
+ glBindTexture(GL_TEXTURE_2D, depthMap);
104
+
105
+ ////////////////////////////////////////////////////////////////
106
+
107
+ renderScene(shader);
108
+
109
+ ////////////////////////////////////////////////////////////////
110
+
111
+ ```
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ ##### Camera.cpp
10
124
 
11
125
 
12
126