質問編集履歴

9

文章を修正

2021/12/17 07:23

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- opengl 2D 正射形行列でbloomを実装したい。
1
+ opengl bloomの描画手順が正いのか知りたい。
test CHANGED
@@ -1,593 +1,603 @@
1
- 提示コードですが正射形行列を使って2Dでフォンシェーディングを行いその後bloomをのですが正射形で実装しましたがライティングされません`Draw_setBloom()`関数部ですが`.frag`シェーダー何が間違えてのでしょうか
1
+ 提示コードですがbloom効果実装したいのですが画面に何も表示されず困っていbloomの描画手順ですが以下説明で正しいのでしょうか
2
-
3
-
4
-
2
+
5
- ##### 調査したこと、調べたこと
3
+ ##### 描画手順
6
-
7
- 描画は正射形行列です。
4
+
8
-
9
- カメラの初期座標は0,0,10です。向きは-1です。
10
-
11
- スプライトの座標は0,0です。
12
-
13
- スプライトの頂点の法線向きはすべて0,0,1 です。
14
-
15
- シェーダーでは二次元の座標を渡して三次元目は-1にしています。
16
-
17
- 全てのシェーダーに頂点情報を設定
18
-
19
- 他の物が影響している可能性があるためループ部を短縮化
20
-
21
- ダー書き写しライト描画のfor文を消して一つのライトに変更
5
+ 1,シーを描画して一つは普通描画結果で、二つ目は輝度を取得するカーバッファを作る
6
+
22
-
7
+ 2,bloomブラーを付ける
8
+
23
- Draw_setBloom()関数でシ描画してカラーバッファを作成して輝度のカラーバッファ作成
9
+ 3,ブラーを付けたカラーバッファを最後に描画するカラーバッファにつける。
24
-
25
- Draw_setBlur()関数でbloomを描画
26
-
27
- Draw_Final()関数でカラーバッファを描画
28
-
29
-
30
-
31
-
32
-
33
- Github: [https://github.com/Shigurechan/AAEditor](https://github.com/Shigurechan/AAEditor)
34
-
35
-
36
10
 
37
11
 
38
12
 
39
13
  参考サイト: [https://learnopengl.com/Advanced-Lighting/Bloom](https://learnopengl.com/Advanced-Lighting/Bloom)
40
14
 
41
- 参考コド: [https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp](https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp)
42
-
43
-
44
-
45
-
46
-
47
- ##### レンダリングループ
15
+ ##### 描画ル
16
+
17
+ ```cpp
18
+
19
+ // ##################################### 初期化 #####################################
20
+
21
+ FrameWork::Camera::Camera()
22
+
23
+ {
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ //カラーバッファ
32
+
33
+ glGenFramebuffers(1, &hdrFBO);
34
+
35
+ glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
36
+
37
+ // create 2 floating point color buffers (1 for normal rendering, other for brightness threshold values)
38
+
39
+ glGenTextures(2, colorBuffers);
40
+
41
+ for (unsigned int i = 0; i < 2; i++)
42
+
43
+ {
44
+
45
+ glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
46
+
47
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, GL_RGBA, GL_FLOAT, NULL);
48
+
49
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
50
+
51
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
52
+
53
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
54
+
55
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
56
+
57
+ // attach texture to framebuffer
58
+
59
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0);
60
+
61
+ }
62
+
63
+
64
+
65
+
66
+
67
+ //描画行列
68
+
69
+ position = glm::vec3(0,0,1); //座標
70
+
71
+ vecLook = glm::vec3(0,0,-1); //向き(視線)
72
+
73
+ view = glm::lookAt(glm::vec3(position.x, position.y, position.z), vecLook, glm::vec3(0, 1, 0)); //ビュー行列
74
+
75
+ projection = glm::perspective(glm::radians(90.0f), 4.0f / 3.0f, 0.1f, 10000.0f); //透視射形行列
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+ sprite.InputTexture(FrameWork::LoadTexture("texture/texture_3.png"));
84
+
85
+
86
+
87
+ glGenFramebuffers(2, pingpongFBO);
88
+
89
+ glGenTextures(2, pingpongColorbuffers);
90
+
91
+ for (unsigned int i = 0; i < 2; i++)
92
+
93
+ {
94
+
95
+ glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]);
96
+
97
+ glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]);
98
+
99
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, GL_RGBA, GL_FLOAT, NULL);
100
+
101
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
102
+
103
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
104
+
105
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
106
+
107
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
108
+
109
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongColorbuffers[i], 0);
110
+
111
+ // also check if framebuffers are complete (no need for depth buffer)
112
+
113
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
114
+
115
+ std::cout << "Framebuffer not complete!" << std::endl;
116
+
117
+ }
118
+
119
+
120
+
121
+
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ void FrameWork::Camera::Renderer()
132
+
133
+ {
134
+
135
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
136
+
137
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
138
+
139
+
140
+
141
+ glEnable(GL_DEPTH_TEST); //深度バッファを有効
142
+
143
+ glDepthFunc(GL_LEQUAL); //深度バッファタイプ
144
+
145
+ glEnable(GL_CULL_FACE); //カリングを有効
146
+
147
+ glCullFace(GL_BACK); //裏面を無効
148
+
149
+
150
+
151
+
152
+
153
+ glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
154
+
155
+ glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
156
+
157
+
158
+
159
+ glClear(GL_DEPTH_BUFFER_BIT);
160
+
161
+
162
+
163
+ //深度バッファレンダリング
164
+
165
+ for(std::vector<std::shared_ptr<Actor>>::iterator itr = actor.begin(); itr != actor.end(); itr++)
166
+
167
+ {
168
+
169
+ (*itr)->Renderer_DepthOnly(getViewProjection());
170
+
171
+ }
172
+
173
+
174
+
175
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
176
+
177
+
178
+
179
+
180
+
181
+ glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y);
182
+
183
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
184
+
185
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
186
+
187
+ glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
188
+
189
+
190
+
191
+
192
+
193
+ // sprite.Draw_setBloom(getViewProjection_2D(), glm::vec2(0, 0), 0, 0.0f, glm::vec2(1.0f, 1.0f), glm::vec2(0, 0), glm::vec2(100, 100));
194
+
195
+
196
+
197
+ sprite.Draw_Light(getViewProjection(), glm::vec2(0, 0), 0, 0.0f, glm::vec2(1.0f, 1.0f), glm::vec2(0, 0), glm::vec2(100, 100));
198
+
199
+
200
+
201
+ sprite.Draw_setBloom(getViewProjection(), glm::vec2(0, 0), 0, 0.0f, glm::vec2(1.0f, 1.0f), glm::vec2(0, 0), glm::vec2(100, 100));
202
+
203
+
204
+
205
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
206
+
207
+
208
+
209
+ sprite.Draw_setBlur(quadVAO,quadVBO, colorBuffers[1],pingpongColorbuffers,pingpongFBO);
210
+
211
+
212
+
213
+
214
+
215
+ //ImGui
216
+
217
+ ImGui::Render();
218
+
219
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
220
+
221
+
222
+
223
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, colorBuffers[0]);
224
+
225
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdrFBO);
226
+
227
+ glBlitFramebuffer(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
228
+
229
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
230
+
231
+ glClear(GL_COLOR_BUFFER_BIT);
232
+
233
+
234
+
235
+ glDisable(GL_DEPTH_TEST);
236
+
237
+
238
+
239
+ sprite.Draw_Final(colorBuffers[0], pingpongColorbuffers);
240
+
241
+
242
+
243
+ shaderFrameBuffer->setEnable();
244
+
245
+ glBindVertexArray(quadVAO);
246
+
247
+ glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
248
+
249
+ glActiveTexture(GL_TEXTURE0);
250
+
251
+ glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
252
+
253
+ glDrawArrays(GL_TRIANGLES, 0, 6);
254
+
255
+ shaderFrameBuffer->setDisable();
256
+
257
+
258
+
259
+ glBindVertexArray(0);
260
+
261
+ glBindTexture(GL_TEXTURE_2D,0);
262
+
263
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
264
+
265
+
266
+
267
+
268
+
269
+ actor.clear();
270
+
271
+ shadowActor.clear();
272
+
273
+
274
+
275
+ }
276
+
277
+
48
278
 
49
279
  ```
50
280
 
51
281
 
52
282
 
283
+
284
+
285
+
286
+
287
+ ##### Sprite
288
+
289
+ ```
290
+
53
- void FrameWork::Camera::Renderer()
291
+ void FrameWork::D2::Sprite::Draw_setBloom(glm::mat4 projection,glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
54
292
 
55
293
  {
56
294
 
57
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
58
-
59
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
60
-
61
-
62
-
63
- glEnable(GL_DEPTH_TEST); //深度バッファを有効
64
-
65
- glDepthFunc(GL_LEQUAL); //深度バッファタイプ
66
-
67
- glEnable(GL_CULL_FACE); //カリングを有効
68
-
69
- glCullFace(GL_BACK); //裏面を無効
70
-
71
-
72
-
73
-
74
-
75
- glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
76
-
77
- glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
78
-
79
-
80
-
81
- glClear(GL_DEPTH_BUFFER_BIT);
82
-
83
-
84
-
85
-
86
-
87
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
88
-
89
-
90
-
91
- glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y);
92
-
93
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
94
-
95
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
96
-
97
- glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
98
-
99
-
100
-
101
- ImGui_ImplOpenGL3_NewFrame();
102
-
103
- ImGui_ImplGlfw_NewFrame();
104
-
105
- ImGui::NewFrame();
106
-
107
-
108
-
109
- sprite.Draw_setBloom(glm::vec2(100,100),0,0.0f,glm::vec2(1.0f,1.0f),glm::vec2(0,0),glm::vec2(100,100));
110
-
111
-
112
-
113
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
114
-
115
-
116
-
117
- sprite.Draw_setBlur(quadVAO,quadVBO, colorBuffers[1],pingpongColorbuffers,pingpongFBO);
118
-
119
-
120
-
121
- glBindFramebuffer(GL_READ_FRAMEBUFFER, colorBuffers[0]);
122
-
123
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdrFBO);
124
-
125
- glBlitFramebuffer(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
126
-
127
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
128
-
129
- glClear(GL_COLOR_BUFFER_BIT);
130
-
131
-
132
-
133
- glDisable(GL_DEPTH_TEST);
134
-
135
-
136
-
137
- sprite.Draw_Final(colorBuffers[0], pingpongColorbuffers);
138
-
139
-
140
-
141
- shaderFrameBuffer->setEnable();
142
-
143
- glBindVertexArray(quadVAO);
144
-
145
- glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
295
+
296
+
297
+ startSize = start; //テクスチャ始点
298
+
299
+ endSize = end; //テクスチャ終点
300
+
301
+
302
+
303
+ setAttribute();
304
+
305
+ setNormal();
306
+
307
+
308
+
309
+ shaderBloom.setEnable();
310
+
311
+ glBindVertexArray(vao);
312
+
313
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
314
+
315
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex->size(), vertex->data());
316
+
317
+
318
+
319
+ setNormal();
320
+
321
+ setAttribute();
322
+
323
+ glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
324
+
325
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
326
+
327
+
328
+
329
+
330
+
331
+ //Transform
332
+
333
+ setPosition(pos); //座標
334
+
335
+ setScale(s + glm::vec2(end - start)); //スケール
336
+
337
+ setRotate(r); //回転
338
+
339
+
340
+
341
+ shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
342
+
343
+ shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
344
+
345
+ shaderBloom.setUniform3f("light.Color",glm::vec3(0,1,0));
346
+
347
+
348
+
349
+ //描画
350
+
351
+ shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
352
+
353
+ shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
354
+
355
+ shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
356
+
357
+ shaderBloom.setUniformMatrix4fv("uViewProjection", projection);
358
+
359
+
360
+
361
+ glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
362
+
363
+
364
+
365
+
366
+
367
+ shaderBloom.setDisable();
368
+
369
+ glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
370
+
371
+ glBindVertexArray(0);
372
+
373
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
374
+
375
+
376
+
377
+
378
+
379
+ }
380
+
381
+
382
+
383
+ void FrameWork::D2::Sprite::Draw_Light(glm::mat4 projection, glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
384
+
385
+ {
386
+
387
+
388
+
389
+ startSize = start; //テクスチャ始点
390
+
391
+ endSize = end; //テクスチャ終点
392
+
393
+
394
+
395
+ setAttribute();
396
+
397
+ setNormal();
398
+
399
+
400
+
401
+ shaderLight.setEnable();
402
+
403
+ glBindVertexArray(vao);
404
+
405
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
406
+
407
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex->size(), vertex->data());
408
+
409
+
410
+
411
+ setNormal();
412
+
413
+ setAttribute();
414
+
415
+ //glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
416
+
417
+ //glActiveTexture(GL_TEXTURE0); //テクスチャ有効
418
+
419
+
420
+
421
+
422
+
423
+ //Transform
424
+
425
+ setPosition(pos); //座標
426
+
427
+ setScale(s + glm::vec2(end - start)); //スケール
428
+
429
+ setRotate(r); //回転
430
+
431
+
432
+
433
+ shaderLight.setUniform3f("lightColor", glm::vec3(0, 1, 0));
434
+
435
+
436
+
437
+ //描画
438
+
439
+ shaderLight.setUniformMatrix4fv("uTranslate", getMatTranslation());
440
+
441
+ shaderLight.setUniformMatrix4fv("uRotate", getMatRotate());
442
+
443
+ shaderLight.setUniformMatrix4fv("uScale", getMatScale());
444
+
445
+ shaderLight.setUniformMatrix4fv("uViewProjection", projection);
446
+
447
+
448
+
449
+ glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
450
+
451
+
452
+
453
+
454
+
455
+ shaderLight.setDisable();
456
+
457
+ //glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
458
+
459
+ glBindVertexArray(0);
460
+
461
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
462
+
463
+
464
+
465
+
466
+
467
+ }
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+ void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
478
+
479
+ {
480
+
481
+ horizontal = true;
482
+
483
+ bool first_iteration = true;
484
+
485
+ unsigned int amount = 10;
486
+
487
+ shaderBloomBlur.setEnable();
488
+
489
+
490
+
491
+ for (unsigned int i = 0; i < amount; i++)
492
+
493
+ {
494
+
495
+ glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
496
+
497
+ shaderBloomBlur.setUniform1i("horizontal", horizontal);
498
+
499
+ glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
500
+
501
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+ glBindVertexArray(quadVAO);
510
+
511
+ glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
512
+
513
+
514
+
515
+ setAttribute(); //頂点属性 設定
516
+
517
+
518
+
519
+
520
+
521
+ //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
522
+
523
+
524
+
525
+ glDrawArrays(GL_TRIANGLES, 0, 6);
526
+
527
+
528
+
529
+ //バインド解除
530
+
531
+ glBindVertexArray(0);
532
+
533
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
534
+
535
+ glBindTexture(GL_TEXTURE_2D, 0);
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+ horizontal = !horizontal;
546
+
547
+ if (first_iteration)
548
+
549
+ first_iteration = false;
550
+
551
+ }
552
+
553
+ shaderBloomBlur.setDisable();
554
+
555
+ }
556
+
557
+
558
+
559
+ void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
560
+
561
+ {
562
+
563
+ shaderBloomFinal.setEnable();
564
+
565
+ glBindVertexArray(vao);
566
+
567
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
568
+
569
+
146
570
 
147
571
  glActiveTexture(GL_TEXTURE0);
148
572
 
149
- glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
573
+ glBindTexture(GL_TEXTURE_2D, frameBuffer);
574
+
575
+ glActiveTexture(GL_TEXTURE1);
576
+
577
+ glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
578
+
579
+ shaderBloomFinal.setUniform1i("bloom", true);
580
+
581
+ shaderBloomFinal.setUniform1f("exposure", 1.0f);
582
+
583
+
150
584
 
151
585
  glDrawArrays(GL_TRIANGLES, 0, 6);
152
586
 
153
- shaderFrameBuffer->setDisable();
154
-
155
587
 
156
588
 
157
589
  glBindVertexArray(0);
158
590
 
159
- glBindTexture(GL_TEXTURE_2D,0);
160
-
161
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
591
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
592
+
593
+
594
+
162
-
595
+ shaderBloomFinal.setDisable();
163
-
164
-
165
-
166
-
167
-
596
+
597
+
168
598
 
169
599
  }
170
600
 
171
601
 
172
602
 
173
-
174
-
175
603
  ```
176
-
177
-
178
-
179
- ##### Sprite
180
-
181
- ```
182
-
183
-
184
-
185
-
186
-
187
- void FrameWork::D2::Sprite::Draw_setBloom(glm::mat4 projection,glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
188
-
189
- {
190
-
191
-
192
-
193
- startSize = start; //テクスチャ始点
194
-
195
- endSize = end; //テクスチャ終点
196
-
197
-
198
-
199
- setAttribute();
200
-
201
- setNormal();
202
-
203
-
204
-
205
- shaderBloom.setEnable();
206
-
207
- glBindVertexArray(vao);
208
-
209
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
210
-
211
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex->size(), vertex->data());
212
-
213
-
214
-
215
- setNormal();
216
-
217
- setAttribute();
218
-
219
- glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
220
-
221
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
222
-
223
-
224
-
225
-
226
-
227
- //Transform
228
-
229
- setPosition(pos); //座標
230
-
231
- setScale(s + glm::vec2(end - start)); //スケール
232
-
233
- setRotate(r); //回転
234
-
235
-
236
-
237
- shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
238
-
239
- shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
240
-
241
- shaderBloom.setUniform3f("light.Color",glm::vec3(0,1,0));
242
-
243
-
244
-
245
- //描画
246
-
247
- shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
248
-
249
- shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
250
-
251
- shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
252
-
253
- shaderBloom.setUniformMatrix4fv("uViewProjection", projection);
254
-
255
-
256
-
257
- glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
258
-
259
-
260
-
261
-
262
-
263
- shaderBloom.setDisable();
264
-
265
- glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
266
-
267
- glBindVertexArray(0);
268
-
269
- glBindBuffer(GL_ARRAY_BUFFER, 0);
270
-
271
-
272
-
273
-
274
-
275
- }
276
-
277
-
278
-
279
- void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
280
-
281
- {
282
-
283
- horizontal = true;
284
-
285
- bool first_iteration = true;
286
-
287
- unsigned int amount = 10;
288
-
289
- shaderBloomBlur.setEnable();
290
-
291
-
292
-
293
- for (unsigned int i = 0; i < amount; i++)
294
-
295
- {
296
-
297
- glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
298
-
299
- shaderBloomBlur.setUniform1i("horizontal", horizontal);
300
-
301
- glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
302
-
303
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
- glBindVertexArray(quadVAO);
312
-
313
- glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
314
-
315
-
316
-
317
- setAttribute(); //頂点属性 設定
318
-
319
-
320
-
321
-
322
-
323
- //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
324
-
325
-
326
-
327
- glDrawArrays(GL_TRIANGLES, 0, 6);
328
-
329
-
330
-
331
- //バインド解除
332
-
333
- glBindVertexArray(0);
334
-
335
- glBindBuffer(GL_ARRAY_BUFFER, 0);
336
-
337
- glBindTexture(GL_TEXTURE_2D, 0);
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
- horizontal = !horizontal;
348
-
349
- if (first_iteration)
350
-
351
- first_iteration = false;
352
-
353
- }
354
-
355
- shaderBloomBlur.setDisable();
356
-
357
- }
358
-
359
-
360
-
361
- void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
362
-
363
- {
364
-
365
- shaderBloomFinal.setEnable();
366
-
367
- glBindVertexArray(vao);
368
-
369
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
370
-
371
-
372
-
373
- glActiveTexture(GL_TEXTURE0);
374
-
375
- glBindTexture(GL_TEXTURE_2D, frameBuffer);
376
-
377
- glActiveTexture(GL_TEXTURE1);
378
-
379
- glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
380
-
381
- shaderBloomFinal.setUniform1i("bloom", true);
382
-
383
- shaderBloomFinal.setUniform1f("exposure", 1.0f);
384
-
385
-
386
-
387
- glDrawArrays(GL_TRIANGLES, 0, 6);
388
-
389
-
390
-
391
- glBindVertexArray(0);
392
-
393
- glBindBuffer(GL_ARRAY_BUFFER, 0);
394
-
395
-
396
-
397
- shaderBloomFinal.setDisable();
398
-
399
-
400
-
401
- }
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
- ```
410
-
411
-
412
-
413
- ##### Bloomシェーダー
414
-
415
- ```vert
416
-
417
- #version 330 core
418
-
419
-
420
-
421
-
422
-
423
- layout(location = 0) in vec2 vertexPosition;
424
-
425
- layout(location = 1) in vec2 vertexUV;
426
-
427
- layout(location = 2) in vec3 vertexNormal;
428
-
429
-
430
-
431
- out VS_OUT {
432
-
433
- vec3 FragPos;
434
-
435
- vec3 Normal;
436
-
437
- vec2 TexCoords;
438
-
439
- } vs_out;
440
-
441
-
442
-
443
- uniform mat4 uTranslate;
444
-
445
- uniform mat4 uRotate;
446
-
447
- uniform mat4 uScale;
448
-
449
- uniform mat4 uViewProjection;
450
-
451
-
452
-
453
- void main()
454
-
455
- {
456
-
457
- mat4 model = uTranslate * uRotate * uScale;
458
-
459
-
460
-
461
- vs_out.FragPos = vec3(model * vec4(vertexPosition,-1.0, 1.0));
462
-
463
- vs_out.TexCoords = vertexUV;
464
-
465
-
466
-
467
- mat3 normalMatrix = transpose(inverse(mat3(model)));
468
-
469
- vs_out.Normal = normalize(normalMatrix * vertexNormal);
470
-
471
-
472
-
473
- //gl_Position = projection * view * model * vec4(aPos, 1.0);
474
-
475
-
476
-
477
- gl_Position = (uViewProjection * model) * vec4(vertexPosition,-1.0, 1.0);
478
-
479
-
480
-
481
- }
482
-
483
- ```
484
-
485
-
486
-
487
- ```frag
488
-
489
- #version 330 core
490
-
491
- layout (location = 0) out vec4 FragColor;
492
-
493
- layout (location = 1) out vec4 BrightColor;
494
-
495
-
496
-
497
- in VS_OUT {
498
-
499
- vec3 FragPos;
500
-
501
- vec3 Normal;
502
-
503
- vec2 TexCoords;
504
-
505
- } fs_in;
506
-
507
-
508
-
509
- struct Light {
510
-
511
- vec3 Position;
512
-
513
- vec3 Color;
514
-
515
- };
516
-
517
-
518
-
519
- uniform Light light;
520
-
521
- uniform sampler2D diffuseTexture;
522
-
523
- uniform vec3 viewPos;
524
-
525
-
526
-
527
- void main()
528
-
529
- {
530
-
531
- vec3 color = texture(diffuseTexture, fs_in.TexCoords).rgb;
532
-
533
- vec3 normal = normalize(fs_in.Normal);
534
-
535
- // ambient
536
-
537
- vec3 ambient = 0.0 * color;
538
-
539
- // lighting
540
-
541
- vec3 lighting = vec3(0.0);
542
-
543
- vec3 viewDir = normalize(viewPos - fs_in.FragPos);
544
-
545
-
546
-
547
- // diffuse
548
-
549
- vec3 lightDir = normalize(light.Position - fs_in.FragPos);
550
-
551
- float diff = max(dot(lightDir, normal), 0.0);
552
-
553
- vec3 result = light.Color * diff * color;
554
-
555
- // attenuation (use quadratic as we have gamma correction)
556
-
557
- float distance = length(fs_in.FragPos - light.Position);
558
-
559
- result *= 1.0 / (distance * distance);
560
-
561
- lighting += result;
562
-
563
-
564
-
565
- result = ambient + lighting;
566
-
567
- // check whether result is higher than some threshold, if so, output as bloom threshold color
568
-
569
- float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
570
-
571
- if(brightness > 1.0)
572
-
573
- {
574
-
575
- BrightColor = vec4(result, 1.0);
576
-
577
- }
578
-
579
- else
580
-
581
- {
582
-
583
- BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
584
-
585
- }
586
-
587
-
588
-
589
- FragColor = vec4(result, 1.0);
590
-
591
- }
592
-
593
- ```

8

タイトルを修正

2021/12/17 07:23

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- opengl 2D 正射形行列でフォンライティングを実装したい。
1
+ opengl 2D 正射形行列でbloomを実装したい。
test CHANGED
File without changes

7

文章を修正

2021/12/16 12:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- ##### 現状
5
+ ##### 調査したこと、調べたこと
6
6
 
7
7
  描画は正射形行列です。
8
8
 

6

文章を修正

2021/12/16 12:14

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,539 +1,593 @@
1
- 提示コードですが正射形行列を使って2Dでフォンシェーディングを行いその後bloomを行いたのですが場合を変更すればのでしょうか
1
+ 提示コードですが正射形行列を使って2Dでフォンシェーディングを行いその後bloomを行いたのですが正射形で実装しましたがライティングされません。`Draw_setBloom()`関数部ですが`.frag`シェーダーの何が間違えてのでしょうか
2
+
3
+
4
+
2
-
5
+ ##### 現状
6
+
7
+ 描画は正射形行列です。
8
+
9
+ カメラの初期座標は0,0,10です。向きは-1です。
10
+
11
+ スプライトの座標は0,0です。
12
+
13
+ スプライトの頂点の法線向きはすべて0,0,1 です。
14
+
15
+ シェーダーでは二次元の座標を渡して三次元目は-1にしています。
16
+
17
+ 全てのシェーダーに頂点情報を設定
18
+
3
- 正射形で実装ましがライティングされません。
19
+ 他の物が影響ている可能性があるめループ部を短縮化
20
+
4
-
21
+ シェーダーを書き写しライト描画のfor文を消して一つのライトに変更
22
+
5
-
23
+ Draw_setBloom()関数でシーンを描画してカラーバッファを作成して輝度のカラーバッファ作成
24
+
25
+ Draw_setBlur()関数でbloomを描画
26
+
27
+ Draw_Final()関数でカラーバッファを描画
28
+
29
+
30
+
31
+
32
+
33
+ Github: [https://github.com/Shigurechan/AAEditor](https://github.com/Shigurechan/AAEditor)
34
+
35
+
36
+
37
+
38
+
39
+ 参考サイト: [https://learnopengl.com/Advanced-Lighting/Bloom](https://learnopengl.com/Advanced-Lighting/Bloom)
40
+
41
+ 参考コード: [https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp](https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp)
42
+
43
+
44
+
45
+
46
+
47
+ ##### レンダリングループ
6
48
 
7
49
  ```
8
50
 
9
- shaderBloom.setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, (float)FrameWork::windowContext->getSize().x, 0.0f, (float)FrameWork::windowContext->getSize().y));
51
+
52
+
53
+ void FrameWork::Camera::Renderer()
54
+
55
+ {
56
+
57
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
58
+
59
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
60
+
61
+
62
+
63
+ glEnable(GL_DEPTH_TEST); //深度バッファを有効
64
+
65
+ glDepthFunc(GL_LEQUAL); //深度バッファタイプ
66
+
67
+ glEnable(GL_CULL_FACE); //カリングを有効
68
+
69
+ glCullFace(GL_BACK); //裏面を無効
70
+
71
+
72
+
73
+
74
+
75
+ glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
76
+
77
+ glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
78
+
79
+
80
+
81
+ glClear(GL_DEPTH_BUFFER_BIT);
82
+
83
+
84
+
85
+
86
+
87
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
88
+
89
+
90
+
91
+ glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y);
92
+
93
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
94
+
95
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
96
+
97
+ glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
98
+
99
+
100
+
101
+ ImGui_ImplOpenGL3_NewFrame();
102
+
103
+ ImGui_ImplGlfw_NewFrame();
104
+
105
+ ImGui::NewFrame();
106
+
107
+
108
+
109
+ sprite.Draw_setBloom(glm::vec2(100,100),0,0.0f,glm::vec2(1.0f,1.0f),glm::vec2(0,0),glm::vec2(100,100));
110
+
111
+
112
+
113
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
114
+
115
+
116
+
117
+ sprite.Draw_setBlur(quadVAO,quadVBO, colorBuffers[1],pingpongColorbuffers,pingpongFBO);
118
+
119
+
120
+
121
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, colorBuffers[0]);
122
+
123
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdrFBO);
124
+
125
+ glBlitFramebuffer(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
126
+
127
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
128
+
129
+ glClear(GL_COLOR_BUFFER_BIT);
130
+
131
+
132
+
133
+ glDisable(GL_DEPTH_TEST);
134
+
135
+
136
+
137
+ sprite.Draw_Final(colorBuffers[0], pingpongColorbuffers);
138
+
139
+
140
+
141
+ shaderFrameBuffer->setEnable();
142
+
143
+ glBindVertexArray(quadVAO);
144
+
145
+ glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
146
+
147
+ glActiveTexture(GL_TEXTURE0);
148
+
149
+ glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
150
+
151
+ glDrawArrays(GL_TRIANGLES, 0, 6);
152
+
153
+ shaderFrameBuffer->setDisable();
154
+
155
+
156
+
157
+ glBindVertexArray(0);
158
+
159
+ glBindTexture(GL_TEXTURE_2D,0);
160
+
161
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ }
170
+
171
+
172
+
173
+
10
174
 
11
175
  ```
12
176
 
13
177
 
14
178
 
15
-
16
-
17
- ##### 現状
18
-
19
- 描画は正射形行列です。
20
-
21
- シェーダーでは二次元の座標を渡して三次元目は-1にしています。
22
-
23
- 他の物が影響している可能性があるためループ部を短縮化
24
-
25
- シェーダーを書き写しライト描画のfor文を消して一つのライトに変更
26
-
27
- Draw_setBloom()関数でシーンを描画してカラーバッファを作成して輝度のカラーバッファ作成
28
-
29
- Draw_setBlur()関数でbloomを描画
30
-
31
- Draw_Final()関数でカラーバッファを描画
32
-
33
-
34
-
35
-
36
-
37
- Github: [https://github.com/Shigurechan/AAEditor](https://github.com/Shigurechan/AAEditor)
38
-
39
-
40
-
41
-
42
-
43
- 参考サイト: [https://learnopengl.com/Advanced-Lighting/Bloom](https://learnopengl.com/Advanced-Lighting/Bloom)
44
-
45
- 参考コード: [https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp](https://learnopengl.com/code_viewer_gh.php?code=src/5.advanced_lighting/7.bloom/bloom.cpp)
46
-
47
-
48
-
49
- ##### 初期化
179
+ ##### Sprite
50
180
 
51
181
  ```
52
182
 
53
183
 
54
184
 
185
+
186
+
55
- // ##################################### 初期化 #####################################
187
+ void FrameWork::D2::Sprite::Draw_setBloom(glm::mat4 projection,glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
56
-
57
- FrameWork::Camera::Camera()
58
188
 
59
189
  {
60
190
 
61
191
 
62
192
 
193
+ startSize = start; //テクスチャ始点
194
+
63
- //カラーバッファ
195
+ endSize = end; //テクスチャ終点
196
+
197
+
198
+
64
-
199
+ setAttribute();
200
+
201
+ setNormal();
202
+
203
+
204
+
205
+ shaderBloom.setEnable();
206
+
65
- glGenFramebuffers(1, &hdrFBO);
207
+ glBindVertexArray(vao);
66
-
208
+
67
- glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
209
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
68
-
210
+
69
- // create 2 floating point color buffers (1 for normal rendering, other for brightness threshold values)
211
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex->size(), vertex->data());
212
+
213
+
214
+
70
-
215
+ setNormal();
216
+
217
+ setAttribute();
218
+
219
+ glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
220
+
221
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
222
+
223
+
224
+
225
+
226
+
227
+ //Transform
228
+
229
+ setPosition(pos); //座標
230
+
231
+ setScale(s + glm::vec2(end - start)); //スケール
232
+
233
+ setRotate(r); //回転
234
+
235
+
236
+
237
+ shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
238
+
239
+ shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
240
+
241
+ shaderBloom.setUniform3f("light.Color",glm::vec3(0,1,0));
242
+
243
+
244
+
245
+ //描画
246
+
247
+ shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
248
+
249
+ shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
250
+
251
+ shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
252
+
253
+ shaderBloom.setUniformMatrix4fv("uViewProjection", projection);
254
+
255
+
256
+
257
+ glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
258
+
259
+
260
+
261
+
262
+
263
+ shaderBloom.setDisable();
264
+
265
+ glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
266
+
267
+ glBindVertexArray(0);
268
+
71
- glGenTextures(2, colorBuffers);
269
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
270
+
271
+
272
+
273
+
274
+
72
-
275
+ }
276
+
277
+
278
+
279
+ void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
280
+
281
+ {
282
+
283
+ horizontal = true;
284
+
285
+ bool first_iteration = true;
286
+
287
+ unsigned int amount = 10;
288
+
289
+ shaderBloomBlur.setEnable();
290
+
291
+
292
+
73
- for (unsigned int i = 0; i < 2; i++)
293
+ for (unsigned int i = 0; i < amount; i++)
74
294
 
75
295
  {
76
296
 
297
+ glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
298
+
299
+ shaderBloomBlur.setUniform1i("horizontal", horizontal);
300
+
301
+ glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
302
+
303
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+ glBindVertexArray(quadVAO);
312
+
313
+ glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
314
+
315
+
316
+
317
+ setAttribute(); //頂点属性 設定
318
+
319
+
320
+
321
+
322
+
323
+ //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
324
+
325
+
326
+
327
+ glDrawArrays(GL_TRIANGLES, 0, 6);
328
+
329
+
330
+
331
+ //バインド解除
332
+
333
+ glBindVertexArray(0);
334
+
335
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
336
+
77
- glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
337
+ glBindTexture(GL_TEXTURE_2D, 0);
78
-
79
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, GL_RGBA, GL_FLOAT, NULL);
338
+
80
-
81
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
339
+
82
-
83
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
340
+
84
-
85
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
341
+
86
-
342
+
343
+
344
+
345
+
346
+
87
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
347
+ horizontal = !horizontal;
348
+
88
-
349
+ if (first_iteration)
350
+
89
- // attach texture to framebuffer
351
+ first_iteration = false;
90
-
91
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0);
92
352
 
93
353
  }
94
354
 
95
-
96
-
97
-
98
-
99
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
100
-
101
-
102
-
103
-
104
-
105
- sprite.InputTexture(FrameWork::LoadTexture("texture/texture_3.png"));
106
-
107
-
108
-
109
- glGenFramebuffers(2, pingpongFBO);
355
+ shaderBloomBlur.setDisable();
110
-
111
- glGenTextures(2, pingpongColorbuffers);
112
-
113
- for (unsigned int i = 0; i < 2; i++)
114
-
115
- {
116
-
117
- glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]);
118
-
119
- glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]);
120
-
121
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, GL_RGBA, GL_FLOAT, NULL);
122
-
123
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
124
-
125
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
126
-
127
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
128
-
129
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
130
-
131
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongColorbuffers[i], 0);
132
-
133
- // also check if framebuffers are complete (no need for depth buffer)
134
-
135
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
136
-
137
- std::cout << "Framebuffer not complete!" << std::endl;
138
-
139
- }
140
-
141
-
142
-
143
-
144
356
 
145
357
  }
146
358
 
359
+
360
+
361
+ void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
362
+
363
+ {
364
+
365
+ shaderBloomFinal.setEnable();
366
+
367
+ glBindVertexArray(vao);
368
+
369
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
370
+
371
+
372
+
373
+ glActiveTexture(GL_TEXTURE0);
374
+
375
+ glBindTexture(GL_TEXTURE_2D, frameBuffer);
376
+
377
+ glActiveTexture(GL_TEXTURE1);
378
+
379
+ glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
380
+
381
+ shaderBloomFinal.setUniform1i("bloom", true);
382
+
383
+ shaderBloomFinal.setUniform1f("exposure", 1.0f);
384
+
385
+
386
+
387
+ glDrawArrays(GL_TRIANGLES, 0, 6);
388
+
389
+
390
+
391
+ glBindVertexArray(0);
392
+
393
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
394
+
395
+
396
+
397
+ shaderBloomFinal.setDisable();
398
+
399
+
400
+
401
+ }
402
+
403
+
404
+
405
+
406
+
407
+
408
+
147
409
  ```
148
410
 
149
411
 
150
412
 
151
- ##### レンリングル
413
+ ##### Bloomシェーダー
414
+
415
+ ```vert
416
+
417
+ #version 330 core
418
+
419
+
420
+
421
+
422
+
423
+ layout(location = 0) in vec2 vertexPosition;
424
+
425
+ layout(location = 1) in vec2 vertexUV;
426
+
427
+ layout(location = 2) in vec3 vertexNormal;
428
+
429
+
430
+
431
+ out VS_OUT {
432
+
433
+ vec3 FragPos;
434
+
435
+ vec3 Normal;
436
+
437
+ vec2 TexCoords;
438
+
439
+ } vs_out;
440
+
441
+
442
+
443
+ uniform mat4 uTranslate;
444
+
445
+ uniform mat4 uRotate;
446
+
447
+ uniform mat4 uScale;
448
+
449
+ uniform mat4 uViewProjection;
450
+
451
+
452
+
453
+ void main()
454
+
455
+ {
456
+
457
+ mat4 model = uTranslate * uRotate * uScale;
458
+
459
+
460
+
461
+ vs_out.FragPos = vec3(model * vec4(vertexPosition,-1.0, 1.0));
462
+
463
+ vs_out.TexCoords = vertexUV;
464
+
465
+
466
+
467
+ mat3 normalMatrix = transpose(inverse(mat3(model)));
468
+
469
+ vs_out.Normal = normalize(normalMatrix * vertexNormal);
470
+
471
+
472
+
473
+ //gl_Position = projection * view * model * vec4(aPos, 1.0);
474
+
475
+
476
+
477
+ gl_Position = (uViewProjection * model) * vec4(vertexPosition,-1.0, 1.0);
478
+
479
+
480
+
481
+ }
152
482
 
153
483
  ```
154
484
 
155
485
 
156
486
 
157
- void FrameWork::Camera::Renderer()
158
-
159
- {
160
-
161
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
162
-
163
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
164
-
165
-
166
-
167
- glEnable(GL_DEPTH_TEST); //深度バッファを有効
168
-
169
- glDepthFunc(GL_LEQUAL); //深度バッファタイプ
170
-
171
- glEnable(GL_CULL_FACE); //カリングを有効
172
-
173
- glCullFace(GL_BACK); //裏面を無効
174
-
175
-
176
-
177
-
178
-
179
- glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
180
-
181
- glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
182
-
183
-
184
-
185
- glClear(GL_DEPTH_BUFFER_BIT);
186
-
187
-
188
-
189
-
190
-
191
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
192
-
193
-
194
-
195
- glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y);
196
-
197
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
198
-
199
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
200
-
201
- glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
202
-
203
-
204
-
205
- ImGui_ImplOpenGL3_NewFrame();
206
-
207
- ImGui_ImplGlfw_NewFrame();
208
-
209
- ImGui::NewFrame();
210
-
211
-
212
-
213
- sprite.Draw_setBloom(glm::vec2(100,100),0,0.0f,glm::vec2(1.0f,1.0f),glm::vec2(0,0),glm::vec2(100,100));
214
-
215
-
216
-
217
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
218
-
219
-
220
-
221
- sprite.Draw_setBlur(quadVAO,quadVBO, colorBuffers[1],pingpongColorbuffers,pingpongFBO);
222
-
223
-
224
-
225
- glBindFramebuffer(GL_READ_FRAMEBUFFER, colorBuffers[0]);
226
-
227
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdrFBO);
228
-
229
- glBlitFramebuffer(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
230
-
231
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
232
-
233
- glClear(GL_COLOR_BUFFER_BIT);
234
-
235
-
236
-
237
- glDisable(GL_DEPTH_TEST);
238
-
239
-
240
-
241
- sprite.Draw_Final(colorBuffers[0], pingpongColorbuffers);
242
-
243
-
244
-
245
- shaderFrameBuffer->setEnable();
246
-
247
- glBindVertexArray(quadVAO);
248
-
249
- glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
250
-
251
- glActiveTexture(GL_TEXTURE0);
252
-
253
- glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
254
-
255
- glDrawArrays(GL_TRIANGLES, 0, 6);
256
-
257
- shaderFrameBuffer->setDisable();
258
-
259
-
260
-
261
- glBindVertexArray(0);
262
-
263
- glBindTexture(GL_TEXTURE_2D,0);
264
-
265
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
266
-
267
-
268
-
269
-
270
-
271
-
487
+ ```frag
488
+
489
+ #version 330 core
490
+
491
+ layout (location = 0) out vec4 FragColor;
492
+
493
+ layout (location = 1) out vec4 BrightColor;
494
+
495
+
496
+
497
+ in VS_OUT {
498
+
499
+ vec3 FragPos;
500
+
501
+ vec3 Normal;
502
+
503
+ vec2 TexCoords;
504
+
505
+ } fs_in;
506
+
507
+
508
+
509
+ struct Light {
510
+
511
+ vec3 Position;
512
+
513
+ vec3 Color;
514
+
515
+ };
516
+
517
+
518
+
519
+ uniform Light light;
520
+
521
+ uniform sampler2D diffuseTexture;
522
+
523
+ uniform vec3 viewPos;
524
+
525
+
526
+
527
+ void main()
528
+
529
+ {
530
+
531
+ vec3 color = texture(diffuseTexture, fs_in.TexCoords).rgb;
532
+
533
+ vec3 normal = normalize(fs_in.Normal);
534
+
535
+ // ambient
536
+
537
+ vec3 ambient = 0.0 * color;
538
+
539
+ // lighting
540
+
541
+ vec3 lighting = vec3(0.0);
542
+
543
+ vec3 viewDir = normalize(viewPos - fs_in.FragPos);
544
+
545
+
546
+
547
+ // diffuse
548
+
549
+ vec3 lightDir = normalize(light.Position - fs_in.FragPos);
550
+
551
+ float diff = max(dot(lightDir, normal), 0.0);
552
+
553
+ vec3 result = light.Color * diff * color;
554
+
555
+ // attenuation (use quadratic as we have gamma correction)
556
+
557
+ float distance = length(fs_in.FragPos - light.Position);
558
+
559
+ result *= 1.0 / (distance * distance);
560
+
561
+ lighting += result;
562
+
563
+
564
+
565
+ result = ambient + lighting;
566
+
567
+ // check whether result is higher than some threshold, if so, output as bloom threshold color
568
+
569
+ float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
570
+
571
+ if(brightness > 1.0)
572
+
573
+ {
574
+
575
+ BrightColor = vec4(result, 1.0);
576
+
577
+ }
578
+
579
+ else
580
+
581
+ {
582
+
583
+ BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
584
+
585
+ }
586
+
587
+
588
+
589
+ FragColor = vec4(result, 1.0);
272
590
 
273
591
  }
274
592
 
275
-
276
-
277
-
278
-
279
593
  ```
280
-
281
-
282
-
283
- ##### Sprite初期化部
284
-
285
- ```
286
-
287
-
288
-
289
- // ##################################### コンストラクタ #####################################
290
-
291
- FrameWork::D2::Sprite::Sprite() : Render()
292
-
293
- {
294
-
295
- shaderBloom.Load("shader/Bloom.vert", "shader/Bloom.frag");
296
-
297
- shaderBloomBlur.Load("shader/Bloom_Blur.vert", "shader/Bloom_Blur.frag");
298
-
299
- shaderBloomFinal.Load("shader/BloomFinal.vert", "shader/BloomFinal.frag");
300
-
301
-
302
-
303
-
304
-
305
- vertex = FrameWork::Camera::getVertexAttribute();
306
-
307
-
308
-
309
- //省略
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
- }
318
-
319
-
320
-
321
- ```
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
- ##### sprite描画
330
-
331
- ```
332
-
333
-
334
-
335
- void FrameWork::D2::Sprite::Draw_setBloom(glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
336
-
337
- {
338
-
339
- shaderBloom.setEnable();
340
-
341
- glBindVertexArray(vao);
342
-
343
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
344
-
345
-
346
-
347
- setNormal();
348
-
349
- setAttribute();
350
-
351
- glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
352
-
353
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
354
-
355
-
356
-
357
-
358
-
359
- //Transform
360
-
361
- setPosition(pos); //座標
362
-
363
- setScale(s + glm::vec2(end - start)); //スケール
364
-
365
- setRotate(r); //回転
366
-
367
-
368
-
369
- shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
370
-
371
- shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
372
-
373
- shaderBloom.setUniform3f("light.Color",glm::vec3(0,255,0));
374
-
375
-
376
-
377
- //描画
378
-
379
- shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
380
-
381
- shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
382
-
383
- shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
384
-
385
- shaderBloom.setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, (float)FrameWork::windowContext->getSize().x, 0.0f, (float)FrameWork::windowContext->getSize().y));
386
-
387
-
388
-
389
- glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
390
-
391
-
392
-
393
-
394
-
395
- shaderBloom.setDisable();
396
-
397
- glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
398
-
399
- glBindVertexArray(0);
400
-
401
- glBindBuffer(GL_ARRAY_BUFFER, 0);
402
-
403
-
404
-
405
-
406
-
407
- }
408
-
409
-
410
-
411
- void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
412
-
413
- {
414
-
415
- horizontal = true;
416
-
417
- bool first_iteration = true;
418
-
419
- unsigned int amount = 10;
420
-
421
- shaderBloomBlur.setEnable();
422
-
423
- for (unsigned int i = 0; i < amount; i++)
424
-
425
- {
426
-
427
- glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
428
-
429
- shaderBloomBlur.setUniform1i("horizontal", horizontal);
430
-
431
- glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
432
-
433
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
- glBindVertexArray(quadVAO);
442
-
443
- glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
444
-
445
- setAttribute(); //頂点属性 設定
446
-
447
-
448
-
449
-
450
-
451
- //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
452
-
453
-
454
-
455
- glDrawArrays(GL_TRIANGLES, 0, 6);
456
-
457
-
458
-
459
- //バインド解除
460
-
461
- glBindVertexArray(0);
462
-
463
- glBindBuffer(GL_ARRAY_BUFFER, 0);
464
-
465
- glBindTexture(GL_TEXTURE_2D, 0);
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
- horizontal = !horizontal;
476
-
477
- if (first_iteration)
478
-
479
- first_iteration = false;
480
-
481
- }
482
-
483
- shaderBloomBlur.setDisable();
484
-
485
- }
486
-
487
-
488
-
489
- void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
490
-
491
- {
492
-
493
- shaderBloomFinal.setEnable();
494
-
495
- glBindVertexArray(vao);
496
-
497
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
498
-
499
-
500
-
501
- glActiveTexture(GL_TEXTURE0);
502
-
503
- glBindTexture(GL_TEXTURE_2D, frameBuffer);
504
-
505
- glActiveTexture(GL_TEXTURE1);
506
-
507
- glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
508
-
509
- shaderBloomFinal.setUniform1i("bloom", true);
510
-
511
- shaderBloomFinal.setUniform1f("exposure", 1.0f);
512
-
513
-
514
-
515
- glDrawArrays(GL_TRIANGLES, 0, 6);
516
-
517
-
518
-
519
- glBindVertexArray(0);
520
-
521
- glBindBuffer(GL_ARRAY_BUFFER, 0);
522
-
523
-
524
-
525
- shaderBloomFinal.setDisable();
526
-
527
-
528
-
529
- }
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
- ```

5

文章とタイトルを修正

2021/12/16 12:03

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- opengl 2D 正射形行列でBloomを実装したい。
1
+ opengl 2D 正射形行列でフォンライティングを実装したい。
test CHANGED
@@ -1,4 +1,16 @@
1
- 提示コードですが画面に何も描画されないのですが何が原因なのでしょうか?正射形行列2Dで行いたのですがその場合何を変更すればいいのでしょうか?
1
+ 提示コードですが正射形行列を使って2Dでフォンシェーディングを行いその後bloomを行いたのですがその場合何を変更すればいいのでしょうか?
2
+
3
+ 正射形で実装しましたがライティングされません。
4
+
5
+
6
+
7
+ ```
8
+
9
+ shaderBloom.setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, (float)FrameWork::windowContext->getSize().x, 0.0f, (float)FrameWork::windowContext->getSize().y));
10
+
11
+ ```
12
+
13
+
2
14
 
3
15
 
4
16
 
@@ -46,12 +58,6 @@
46
58
 
47
59
  {
48
60
 
49
- actor.resize(0);
50
-
51
- shadowActor.resize(0);
52
-
53
- vertex->resize(6); //頂点配列を初期化 2Dスプライト描画用
54
-
55
61
 
56
62
 
57
63
  //カラーバッファ
@@ -262,9 +268,7 @@
262
268
 
263
269
 
264
270
 
265
- actor.clear();
271
+
266
-
267
- shadowActor.clear();
268
272
 
269
273
  }
270
274
 
@@ -302,7 +306,35 @@
302
306
 
303
307
 
304
308
 
305
-
309
+ //省略
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+ }
318
+
319
+
320
+
321
+ ```
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+ ##### sprite描画
330
+
331
+ ```
332
+
333
+
334
+
335
+ void FrameWork::D2::Sprite::Draw_setBloom(glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
336
+
337
+ {
306
338
 
307
339
  shaderBloom.setEnable();
308
340
 
@@ -312,54 +344,58 @@
312
344
 
313
345
 
314
346
 
347
+ setNormal();
348
+
349
+ setAttribute();
350
+
351
+ glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
352
+
353
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
354
+
355
+
356
+
357
+
358
+
359
+ //Transform
360
+
361
+ setPosition(pos); //座標
362
+
363
+ setScale(s + glm::vec2(end - start)); //スケール
364
+
365
+ setRotate(r); //回転
366
+
367
+
368
+
369
+ shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
370
+
371
+ shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
372
+
373
+ shaderBloom.setUniform3f("light.Color",glm::vec3(0,255,0));
374
+
375
+
376
+
315
- //座標
377
+ //描画
316
-
378
+
317
- GLint attrib = shaderBloom.getAttribLocation("vertexPosition");
379
+ shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
318
-
319
- glEnableVertexAttribArray(attrib);
380
+
320
-
321
- glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW);
322
-
323
- glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)0);
324
-
325
- shaderBloom.setBindAttribLocation("vertexPosition");
381
+ shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
326
-
327
-
328
-
329
-
330
-
331
- //UV
382
+
332
-
333
- attrib = shaderBloom.getAttribLocation("vertexUV");
334
-
335
- glEnableVertexAttribArray(attrib);
336
-
337
- glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW);
338
-
339
- glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 2));
340
-
341
- shaderBloom.setBindAttribLocation("vertexUV");
383
+ shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
342
-
343
-
344
-
345
-
346
-
347
- //Normal
384
+
348
-
349
- attrib = shaderBloom.getAttribLocation("vertexNormal");
385
+ shaderBloom.setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, (float)FrameWork::windowContext->getSize().x, 0.0f, (float)FrameWork::windowContext->getSize().y));
350
-
351
- glEnableVertexAttribArray(attrib);
386
+
352
-
387
+
388
+
353
- glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW);
389
+ glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
354
-
355
- glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 4));
390
+
356
-
357
- shaderBloom.setBindAttribLocation("vertexNormal");
391
+
358
392
 
359
393
 
360
394
 
361
395
  shaderBloom.setDisable();
362
396
 
397
+ glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
398
+
363
399
  glBindVertexArray(0);
364
400
 
365
401
  glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -368,37 +404,93 @@
368
404
 
369
405
 
370
406
 
371
- //省略
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
407
  }
380
408
 
381
409
 
382
410
 
383
- ```
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
- ##### sprite描画
392
-
393
- ```
394
-
395
-
396
-
397
- void FrameWork::D2::Sprite::Draw_setBloom(glm::vec2 pos, int texNum, float r, glm::vec2 s, glm::vec2 start, glm::vec2 end)
411
+ void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
398
412
 
399
413
  {
400
414
 
415
+ horizontal = true;
416
+
417
+ bool first_iteration = true;
418
+
419
+ unsigned int amount = 10;
420
+
401
- shaderBloom.setEnable();
421
+ shaderBloomBlur.setEnable();
422
+
423
+ for (unsigned int i = 0; i < amount; i++)
424
+
425
+ {
426
+
427
+ glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
428
+
429
+ shaderBloomBlur.setUniform1i("horizontal", horizontal);
430
+
431
+ glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
432
+
433
+ glActiveTexture(GL_TEXTURE0); //テクスチャ有効
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ glBindVertexArray(quadVAO);
442
+
443
+ glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
444
+
445
+ setAttribute(); //頂点属性 設定
446
+
447
+
448
+
449
+
450
+
451
+ //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
452
+
453
+
454
+
455
+ glDrawArrays(GL_TRIANGLES, 0, 6);
456
+
457
+
458
+
459
+ //バインド解除
460
+
461
+ glBindVertexArray(0);
462
+
463
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
464
+
465
+ glBindTexture(GL_TEXTURE_2D, 0);
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+ horizontal = !horizontal;
476
+
477
+ if (first_iteration)
478
+
479
+ first_iteration = false;
480
+
481
+ }
482
+
483
+ shaderBloomBlur.setDisable();
484
+
485
+ }
486
+
487
+
488
+
489
+ void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
490
+
491
+ {
492
+
493
+ shaderBloomFinal.setEnable();
402
494
 
403
495
  glBindVertexArray(vao);
404
496
 
@@ -406,57 +498,23 @@
406
498
 
407
499
 
408
500
 
409
- setNormal();
410
-
411
- setAttribute();
412
-
413
- glBindTexture(GL_TEXTURE_2D, textureID.at(texNum)); //テクスチャバインド
414
-
415
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
501
+ glActiveTexture(GL_TEXTURE0);
416
-
417
-
418
-
419
-
420
-
421
- //Transform
502
+
422
-
423
- setPosition(pos); //座標
503
+ glBindTexture(GL_TEXTURE_2D, frameBuffer);
424
-
425
- setScale(s + glm::vec2(end - start)); //スケール
504
+
426
-
427
- setRotate(r); //回転
505
+ glActiveTexture(GL_TEXTURE1);
428
-
429
-
430
-
431
- shaderBloom.setUniform3f("viewPos", glm::vec3(0, 0, 10));
506
+
432
-
433
- shaderBloom.setUniform3f("light.Position", glm::vec3(0, 0, 1.0f));
434
-
435
- shaderBloom.setUniform3f("light.Color",glm::vec3(0,255,0));
507
+ glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
436
-
437
-
438
-
439
- //描画
508
+
440
-
441
- shaderBloom.setUniformMatrix4fv("uTranslate", getMatTranslation());
442
-
443
- shaderBloom.setUniformMatrix4fv("uRotate", getMatRotate());
444
-
445
- shaderBloom.setUniformMatrix4fv("uScale", getMatScale());
509
+ shaderBloomFinal.setUniform1i("bloom", true);
446
-
510
+
447
- shaderBloom.setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, (float)FrameWork::windowContext->getSize().x, 0.0f, (float)FrameWork::windowContext->getSize().y));
511
+ shaderBloomFinal.setUniform1f("exposure", 1.0f);
448
-
449
-
450
-
512
+
513
+
514
+
451
- glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
515
+ glDrawArrays(GL_TRIANGLES, 0, 6);
452
-
453
-
454
-
455
-
456
-
457
- shaderBloom.setDisable();
516
+
458
-
459
- glBindTexture(GL_TEXTURE_2D, 0); //テクスチャバインド
517
+
460
518
 
461
519
  glBindVertexArray(0);
462
520
 
@@ -464,138 +522,18 @@
464
522
 
465
523
 
466
524
 
525
+ shaderBloomFinal.setDisable();
526
+
467
527
 
468
528
 
469
529
  }
470
530
 
471
531
 
472
532
 
473
- void FrameWork::D2::Sprite::Draw_setBlur(const GLuint quadVAO, const GLuint quadVBO,const GLint frameBuffer_Luminance, GLuint pingpongColorbuffers[2], GLuint pingpongFBO[2])
533
+
474
-
475
- {
534
+
476
-
477
- horizontal = true;
535
+
478
-
479
- bool first_iteration = true;
536
+
480
-
481
- unsigned int amount = 10;
537
+
482
-
483
- shaderBloomBlur.setEnable();
538
+
484
-
485
- for (unsigned int i = 0; i < amount; i++)
486
-
487
- {
488
-
489
- glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
490
-
491
- shaderBloomBlur.setUniform1i("horizontal", horizontal);
492
-
493
- glBindTexture(GL_TEXTURE_2D, first_iteration ? frameBuffer_Luminance : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
494
-
495
- glActiveTexture(GL_TEXTURE0); //テクスチャ有効
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
- glBindVertexArray(quadVAO);
504
-
505
- glBindBuffer(GL_ARRAY_BUFFER,quadVBO);
506
-
507
- setAttribute(); //頂点属性 設定
508
-
509
-
510
-
511
-
512
-
513
- //glDrawArrays(GL_TRIANGLES, 0, vertex->size()); //描画
514
-
515
-
516
-
517
- glDrawArrays(GL_TRIANGLES, 0, 6);
518
-
519
-
520
-
521
- //バインド解除
522
-
523
- glBindVertexArray(0);
524
-
525
- glBindBuffer(GL_ARRAY_BUFFER, 0);
526
-
527
- glBindTexture(GL_TEXTURE_2D, 0);
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
- horizontal = !horizontal;
538
-
539
- if (first_iteration)
540
-
541
- first_iteration = false;
542
-
543
- }
544
-
545
- shaderBloomBlur.setDisable();
546
-
547
- }
548
-
549
-
550
-
551
- void FrameWork::D2::Sprite::Draw_Final(GLuint frameBuffer, GLuint pingpongColorbuffers[2])
552
-
553
- {
554
-
555
- shaderBloomFinal.setEnable();
556
-
557
- glBindVertexArray(vao);
558
-
559
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
560
-
561
-
562
-
563
- glActiveTexture(GL_TEXTURE0);
564
-
565
- glBindTexture(GL_TEXTURE_2D, frameBuffer);
566
-
567
- glActiveTexture(GL_TEXTURE1);
568
-
569
- glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[horizontal]);
570
-
571
- shaderBloomFinal.setUniform1i("bloom", true);
572
-
573
- shaderBloomFinal.setUniform1f("exposure", 1.0f);
574
-
575
-
576
-
577
- glDrawArrays(GL_TRIANGLES, 0, 6);
578
-
579
-
580
-
581
- glBindVertexArray(0);
582
-
583
- glBindBuffer(GL_ARRAY_BUFFER, 0);
584
-
585
-
586
-
587
- shaderBloomFinal.setDisable();
588
-
589
-
590
-
591
- }
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
- ```
539
+ ```

4

タイトルを修正

2021/12/16 08:16

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- opengl 正射形行列でBloomが上手く実装出来ない原因が知りたい。
1
+ opengl 2D 正射形行列でBloom実装たい。
test CHANGED
File without changes

3

文章を修正

2021/12/16 08:04

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- opengl Bloomが上手く実装出来ない原因が知りたい。
1
+ opengl 正射形行列でBloomが上手く実装出来ない原因が知りたい。
test CHANGED
@@ -1,4 +1,4 @@
1
- 提示コードですが画面に何も描画されないのですが何が原因なのでしょうか?
1
+ 提示コードですが画面に何も描画されないのですが何が原因なのでしょうか?正射形行列の2Dで行いたのですがその場合何を変更すればいいのでしょうか?
2
2
 
3
3
 
4
4
 

2

文章を修正

2021/12/15 12:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  ##### 現状
6
6
 
7
+ 描画は正射形行列です。
8
+
9
+ シェーダーでは二次元の座標を渡して三次元目は-1にしています。
10
+
7
11
  他の物が影響している可能性があるためループ部を短縮化
8
12
 
9
13
  シェーダーを書き写しライト描画のfor文を消して一つのライトに変更

1

文章を修正

2021/12/15 12:27

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
-
21
+ Github: [https://github.com/Shigurechan/AAEditor](https://github.com/Shigurechan/AAEditor)
22
22
 
23
23
 
24
24
 
@@ -50,16 +50,6 @@
50
50
 
51
51
 
52
52
 
53
- glGenFramebuffers(1, &framebuffer);
54
-
55
- glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
53
  //カラーバッファ
64
54
 
65
55
  glGenFramebuffers(1, &hdrFBO);