SuzanneIsland: An island of Real-time rendering effects!
lightbeams_effect.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <iostream>
6 
7 #include <GL/glew.h>
8 #include <glm/glm.hpp>
9 #include <glm/gtc/type_ptr.hpp>
10 
11 #include "../shader.h"
12 #include "../texture.hpp"
13 
14 
25 
48 {
49 
50 private:
51 
52  int windowWidth, windowHeight;
53 
54  int numSamples = 100; // fixed number of samples between fragment and sun (higher means better quality).
55  float sampleDensityBias = 0.85f; // if 1 we reach sun in numSamples. if < 1 sampling will be denser but end before reaching the sun
56  float sampleWeight = 5.00f; // intensity contribution of each sample (higher means brighter)
57  float decayFactor = 0.98f; // how contribution decays with distance to fragment (lower means shorter light beams)
58  float exposure = 0.0035f; // total intensity contribution (higher means brighter)
59 
60  GLuint fboOccludedSky, occludedSkyColorTexture, occludedSkyDepthBuffer;
61 
62  Shader *lightbeamsShader = nullptr;
63 
64 public:
65 
66  LightbeamsEffect(int windowWidth, int windowHeight);
68 
69  inline void bindOcclusionFrameBuffer() { bindFrameBuffer(fboOccludedSky, windowWidth, windowHeight); }
70 
71  void bindFrameBuffer(GLuint frameBuffer, int width, int height);
72  void bindDefaultFrameBuffer();
73 
74  Shader *setupLightbeamsShader(const glm::vec3 &sunWorldPos, const glm::mat4 &viewProjMat);
75 
76 
77 private:
78 
81  glm::vec2 worldToRelativeScreenSpace(const glm::vec3 &worldPos, const glm::mat4 &viewProjMat);
82 
84  GLuint createFrameBuffer();
85 
87  GLuint createColorTextureAttachment(int width, int height);
88 
91  GLuint createDepthTextureAttachment(int width, int height);
92 
96  GLuint createDepthRenderbufferAttachment(int width, int height);
97 
98 };
99 
100 
Shader class.
Definition: shader.h:15
LightbeamsEffect Based on Kenny Mitchell "Volumetric Light Scattering as a Post-Process" http://http...
Definition: lightbeams_effect.h:47
LightbeamsEffect(int windowWidth, int windowHeight)
Definition: lightbeams_effect.cpp:3