Compare commits

...

4 Commits

Author SHA1 Message Date
Tleety b81f2b3240 WIP Bloom 2016-02-10 15:00:12 +01:00
Tleety 03d77beff9 MipMapping all textures 2016-02-10 10:46:27 +01:00
Tleety 64e7bb1e94 Good looking blur, need some fixes, but framerates takes a huge hit. 2016-02-09 16:19:17 +01:00
Tleety a33cd42ca3 WIP 2016-02-08 17:53:31 +01:00
12 changed files with 362 additions and 53 deletions
+1 -1
Submodule assets updated: c4898d8281...cfeeb1f880
+12 -2
View File
@@ -8,6 +8,7 @@
#include "ShaderProgram.h"
//#include "Util/UnorderedMapVec2.h"
#include "Texture.h"
#include "imgui/imgui.h"
class DrawBloomPass
{
@@ -26,27 +27,36 @@ public:
//Getters
//Return the blurred result of the texture that was sent into draw
GLuint GaussianTexture() const { return m_GaussianTexture_vert; }
GLuint GaussianTexture() const { return m_FinalBlurTexture; }
private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
void BlurOneMipMapLevel(GLuint* texture, GLint iterations, GLint mipMapLevel);
Texture* m_WhiteTexture;
Model* m_ScreenQuad;
const IRenderer* m_Renderer;
//const LightCullingPass* m_LightCullingPass
GLuint m_iterations = 9;
//GLuint m_iterations = 5;
GLint m_DebugTextureToDraw = 0;
GLint m_Iterations = 3;
float m_ScreenSizes[10];
GLuint m_FinalBlurTexture;
GLuint m_GaussianTexture_horiz;
GLuint m_GaussianTexture_vert;
FrameBuffer m_GaussianFrameBuffer_horiz;
FrameBuffer m_GaussianFrameBuffer_vert;
FrameBuffer m_BlurredFinalTexture;
ShaderProgram* m_GaussianProgram_horiz;
ShaderProgram* m_GaussianProgram_vert;
ShaderProgram* m_GaussianProgram_both;
ShaderProgram* m_CombineProgram;
};
+118 -24
View File
@@ -40,7 +40,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="9161.41992" Z="0"/>
<Orientation X="0" Y="9161.42871" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -105,7 +105,7 @@
</c:RaptorCopter>
<c:Transform>
<Position X="2.1529963" Y="6.59221172" Z="0.169116676"/>
<Orientation X="4.16300011" Y="17199.7988" Z="0"/>
<Orientation X="4.16300011" Y="17199.8086" Z="0"/>
</c:Transform>
</Components>
<Children/>
@@ -188,7 +188,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="2918.14136" Z="0"/>
<Orientation X="0" Y="2918.146" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -237,7 +237,7 @@
<Axis X="1" Y="1" Z="1"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="15792.2051" Y="15792.2051" Z="15792.2051"/>
<Orientation X="15792.2139" Y="15792.2139" Z="15792.2139"/>
</c:Transform>
</Components>
<Children>
@@ -301,7 +301,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="15589.2383" Z="0"/>
<Orientation X="0" Y="15589.2471" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -333,7 +333,7 @@
<Axis X="0.699999988" Y="1" Z="0.300000012"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="11456.2695" Y="16313.6973" Z="4881.66504"/>
<Orientation X="11456.2764" Y="16313.7061" Z="4881.66797"/>
</c:Transform>
</Components>
<Children>
@@ -683,7 +683,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -730,7 +730,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -790,7 +790,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -837,7 +837,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -883,7 +883,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -930,7 +930,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -977,7 +977,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1217.61243" Z="0"/>
<Orientation X="0" Y="1217.61707" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1390,7 +1390,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1750.85376" Z="0"/>
<Orientation X="0" Y="1750.8584" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1399,7 +1399,7 @@
<c:ExplosionEffect>
<ColorByDistance>true</ColorByDistance>
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
<TimeSinceDeath>1.3671759474185377</TimeSinceDeath>
<TimeSinceDeath>1.3764088929643181</TimeSinceDeath>
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
<Randomness>true</Randomness>
@@ -1446,7 +1446,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1750.85376" Z="0"/>
<Orientation X="0" Y="1750.8584" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1455,7 +1455,7 @@
<c:ExplosionEffect>
<Velocity X="0.5" Y="1" Z="0"/>
<ExplosionOrigin X="0" Y="0.900000036" Z="0"/>
<TimeSinceDeath>0.31711568080172703</TimeSinceDeath>
<TimeSinceDeath>0.3263486263475075</TimeSinceDeath>
</c:ExplosionEffect>
<c:Model>
<Resource>Models/Assault.mesh</Resource>
@@ -1498,7 +1498,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="1750.85376" Z="0"/>
<Orientation X="0" Y="1750.8584" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1513,7 +1513,7 @@
<ColorByDistance>true</ColorByDistance>
<Velocity X="0.300000012" Y="2" Z="0"/>
<ExplosionOrigin X="0" Y="1.30000007" Z="-0.200000003"/>
<TimeSinceDeath>0.31711568080172703</TimeSinceDeath>
<TimeSinceDeath>0.3263486263475075</TimeSinceDeath>
<EndColor A="0" B="0.333333343" G="0.933333337" R="3.92156863"/>
<Randomness>true</Randomness>
</c:ExplosionEffect>
@@ -1558,7 +1558,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="857.983765" Z="0"/>
<Orientation X="0" Y="857.988403" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1568,7 +1568,7 @@
<ColorByDistance>true</ColorByDistance>
<Velocity X="0" Y="0.699999988" Z="0"/>
<ExplosionOrigin X="0" Y="-1.10000002" Z="0"/>
<TimeSinceDeath>0.95047462600732735</TimeSinceDeath>
<TimeSinceDeath>0.95970757155310782</TimeSinceDeath>
<ExplosionDuration>10</ExplosionDuration>
<EndColor A="1" B="0" G="0" R="1"/>
<RandomnessScalar>3</RandomnessScalar>
@@ -1616,7 +1616,7 @@
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:Transform>
<Orientation X="0" Y="456.13559" Z="0"/>
<Orientation X="0" Y="456.140198" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -1626,7 +1626,7 @@
<ColorByDistance>true</ColorByDistance>
<Velocity X="6" Y="0.100000001" Z="0"/>
<ExplosionOrigin X="0" Y="-10" Z="0"/>
<TimeSinceDeath>1.350502887383392</TimeSinceDeath>
<TimeSinceDeath>1.3597358329291724</TimeSinceDeath>
<ExponentialAccelaration>true</ExponentialAccelaration>
<ExplosionDuration>5</ExplosionDuration>
<Randomness>true</Randomness>
@@ -1807,7 +1807,7 @@
<c:ExplosionEffect>
<ColorByDistance>true</ColorByDistance>
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
<TimeSinceDeath>1.3671759474185377</TimeSinceDeath>
<TimeSinceDeath>1.3764088929643181</TimeSinceDeath>
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
<Randomness>true</Randomness>
@@ -1943,6 +1943,100 @@
</Entity>
</Children>
</Entity>
<Entity name="FontTestOrigin">
<Components>
<c:Transform>
<Position X="-9.54515171" Y="0" Z="-32.3266869"/>
</c:Transform>
</Components>
<Children>
<Entity name="BackGround">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="0.117647059" G="0.117647059" R="0.117647059"/>
</c:Model>
<c:Transform>
<Position X="0" Y="5.89724827" Z="-0.562690914"/>
<Scale X="28.9000015" Y="62.8000031" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="DroidSans">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="2" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Xirod">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/xirod.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="3" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="NulshockBd">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/nulshock bd.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="4" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="KenneyFutureSquare">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/Kenney Future Square.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="5" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="KenneyFutureNarrow">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/Kenney Future Narrow.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="6" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="KenneySpace">
<Components>
<c:Text>
<Content>Tawqesmr *^~ 1345790</Content>
<Resource>Fonts/Kenney Space.ttf,64</Resource>
</c:Text>
<c:Transform>
<Position X="0" Y="7" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+36
View File
@@ -0,0 +1,36 @@
#version 430
#extension GL_EXT_gpu_shader4 : enable
uniform int MipMapLevel;
uniform bool Horizontal;
uniform vec2 ScreenSize[5];
layout (binding = 0) uniform sampler2D Texture;
in VertexData{
vec2 TextureCoordinate;
}Input;
out vec4 fragmentColor;
uniform float offset[3] = float[]( 0.0, 1.3846153846, 3.2307692308 );
uniform float weight[5] = float[]( 0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162 );
void main()
{
//vec2 tex_offset = 1.0 / textureSize2D(Texture, 0);
vec3 result = textureLod(Texture, vec2(gl_FragCoord)/ScreenSize[0], MipMapLevel ).rgb * weight[0];
if(Horizontal) {
for( int i = 1; i<3; i++) {
result += textureLod( Texture, Input.TextureCoordinate + vec2(offset[i], 0.0), MipMapLevel ).rgb * weight[i];
result += textureLod( Texture, Input.TextureCoordinate - vec2(offset[i], 0.0), MipMapLevel ).rgb * weight[i];
}
} else {
for( int i = 1; i<3; i++) {
result += textureLod( Texture, Input.TextureCoordinate + vec2(0.0, offset[i]), MipMapLevel ).rgb * weight[i];
result += textureLod( Texture, Input.TextureCoordinate - vec2(0.0, offset[i]), MipMapLevel ).rgb * weight[i];
}
}
fragmentColor = vec4(result, 1.0);
}
+13
View File
@@ -0,0 +1,13 @@
#version 430
layout (location = 0) in vec3 Position;
out VertexData{
vec2 TextureCoordinate;
}Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.TextureCoordinate = (vec2(Position) + 1) / 2;
}
+7 -3
View File
@@ -1,6 +1,7 @@
#version 430
#extension GL_EXT_gpu_shader4 : enable
uniform int MipMapLevel;
layout (binding = 0) uniform sampler2D Texture;
in VertexData{
@@ -14,11 +15,14 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01
void main()
{
vec2 tex_offset = 1.0 / textureSize2D(Texture, 0);
vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
vec3 result = textureLod(Texture, Input.TextureCoordinate, MipMapLevel).rgb * weight[0];
//vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
for(int i = 1; i < 5; ++i) {
result += texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
result += texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
result += textureLod(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0), MipMapLevel).rgb * weight[i];
result += textureLod(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0), MipMapLevel).rgb * weight[i];
//result += texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
//result += texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
}
fragmentColor = vec4(result, 1.0);
}
+7 -3
View File
@@ -1,6 +1,7 @@
#version 430
#extension GL_EXT_gpu_shader4 : enable
uniform int MipMapLevel;
layout (binding = 0) uniform sampler2D Texture;
in VertexData{
@@ -14,11 +15,14 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01
void main()
{
vec2 tex_offset = 1.0 / textureSize2D(Texture, 0);
vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
//vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0];
vec3 result = textureLod(Texture, Input.TextureCoordinate, MipMapLevel).rgb * weight[0];
for(int i = 1; i < 5; ++i) {
result += texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
result += texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
result += textureLod(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i), MipMapLevel).rgb * weight[i];
result += textureLod(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i), MipMapLevel).rgb * weight[i];
//result += texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
//result += texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
}
fragmentColor = vec4(result, 1.0);
}
@@ -0,0 +1,21 @@
#version 430
layout (binding = 0) uniform sampler2D Texture0;
layout (binding = 1) uniform sampler2D Texture1;
in VertexData{
vec2 TextureCoordinate;
}Input;
out vec4 fragmentColor;
void main()
{
vec4 texel0 = texture(Texture0, Input.TextureCoordinate);
vec4 texel1 = texture(Texture1, Input.TextureCoordinate);
fragmentColor = texel0 + texel1;
//fragmentColor = vec4(1,0.5,0.7,1);
}
@@ -0,0 +1,13 @@
#version 430
layout (location = 0) in vec3 Position;
out VertexData{
vec2 TextureCoordinate;
}Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.TextureCoordinate = (vec2(Position) + 1) / 2;
}
+105 -13
View File
@@ -6,6 +6,18 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer)
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
m_ScreenSizes[0] = 1920.f;
m_ScreenSizes[1] = 1053.f;
m_ScreenSizes[2] = 959.f;
m_ScreenSizes[3] = 525.f;
m_ScreenSizes[4] = 479.f;
m_ScreenSizes[5] = 262.f;
m_ScreenSizes[6] = 239.f;
m_ScreenSizes[7] = 130.f;
m_ScreenSizes[8] = 119.f;
m_ScreenSizes[9] = 64.f;
InitializeTextures();
InitializeBuffers();
InitializeShaderPrograms();
@@ -18,31 +30,51 @@ void DrawBloomPass::InitializeTextures()
void DrawBloomPass::InitializeShaderPrograms()
{
m_GaussianProgram_horiz = ResourceManager::Load<ShaderProgram>("##GaussianProgramHoriz");
m_GaussianProgram_horiz = ResourceManager::Load<ShaderProgram>("#GaussianProgramHoriz");
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_horiz.vert.glsl")));
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl")));
m_GaussianProgram_horiz->Compile();
m_GaussianProgram_horiz->Link();
m_GaussianProgram_vert = ResourceManager::Load<ShaderProgram>("##GaussianProgramVert");
m_GaussianProgram_vert = ResourceManager::Load<ShaderProgram>("#GaussianProgramVert");
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_vert.vert.glsl")));
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_vert.frag.glsl")));
m_GaussianProgram_vert->Compile();
m_GaussianProgram_vert->Link();
m_GaussianProgram_both = ResourceManager::Load<ShaderProgram>("#GaussianProgramBoth");
m_GaussianProgram_both->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_both.vert.glsl")));
m_GaussianProgram_both->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_both.frag.glsl")));
m_GaussianProgram_both->Compile();
m_GaussianProgram_both->Link();
m_CombineProgram = ResourceManager::Load<ShaderProgram>("#CombineProgram");
m_CombineProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/TextureCombine.vert.glsl")));
m_CombineProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/TextureCombine.frag.glsl")));
m_CombineProgram->Compile();
m_CombineProgram->Link();
//Fixa nya combine shadern
}
void DrawBloomPass::InitializeBuffers()
{
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
m_GaussianFrameBuffer_horiz.Generate();
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_HALF_FLOAT);
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
m_GaussianFrameBuffer_vert.Generate();
GenerateTexture(&m_FinalBlurTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_BlurredFinalTexture.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_FinalBlurTexture, GL_COLOR_ATTACHMENT0)));
m_BlurredFinalTexture.Generate();
}
@@ -60,65 +92,123 @@ void DrawBloomPass::ClearBuffer()
void DrawBloomPass::Draw(GLuint texture)
{
GLERROR("DrawBloomPass::Draw: Pre");
ImGui::Combo("DebugBloom", &m_DebugTextureToDraw, "ALL\0First\0SEcond\0Third\0Fourth\0Fifth");
ImGui::SliderInt("Iterations", &m_Iterations, 0, 10);
if (m_DebugTextureToDraw == 1)
BlurOneMipMapLevel(&texture, m_Iterations, 1);
else if (m_DebugTextureToDraw == 2)
BlurOneMipMapLevel(&texture, m_Iterations, 2);
else if (m_DebugTextureToDraw == 3)
BlurOneMipMapLevel(&texture, m_Iterations, 3);
else if (m_DebugTextureToDraw == 4)
BlurOneMipMapLevel(&texture, m_Iterations, 4);
else if (m_DebugTextureToDraw == 0) {
BlurOneMipMapLevel(&texture, m_Iterations, 1);
BlurOneMipMapLevel(&texture, m_Iterations, 2);
BlurOneMipMapLevel(&texture, m_Iterations, 3);
BlurOneMipMapLevel(&texture, m_Iterations, 4);
}
}
void DrawBloomPass::BlurOneMipMapLevel(GLuint* texture, GLint iterations, GLint mipMapLevel)
{
GLERROR("PRE");
//new code
DrawBloomPassState state;
//Loop through and blur texture at mipmap level
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle();
//Horizontal pass, first use the given texture then save it to the horizontal framebuffer.
//First horiz pass
m_GaussianFrameBuffer_horiz.Bind();
m_GaussianProgram_horiz->Bind();
GLERROR("Bind");
glUniform1i(glGetUniformLocation(shaderHandle_horiz, "MipMapLevel"), mipMapLevel);
//glUniform2fv(glGetUniformLocation(m_GaussianProgram_both->GetHandle(), "ScreenSize"), 5, m_ScreenSizes);
//glUniform1i(glGetUniformLocation(m_GaussianProgram_both->GetHandle(), "Horizontal"), true);
GLERROR("1");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
GLERROR("2");
//Iterate some times to make it more gaussian.
for (int i = 1; i < m_iterations; i++) {
//Loop through vert, then horiz and save to respective textures X number of times.
for (int i = 1; i < iterations; i++) {
//Vertical pass
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
//glUniform1i(glGetUniformLocation(m_GaussianProgram_both->GetHandle(), "Horizontal"), false);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
GLERROR("3");
//horizontal pass
m_GaussianFrameBuffer_horiz.Bind();
m_GaussianProgram_horiz->Bind();
//glUniform1i(glGetUniformLocation(m_GaussianProgram_both->GetHandle(), "Horizontal"), true);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
GLERROR("4");
}
//final vertical gaussian after the iterations are done
//the final vertical iteration.
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
//glUniform1i(glGetUniformLocation(m_GaussianProgram_both->GetHandle(), "Horizontal"), false);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
GLERROR("5");
GLERROR("DrawBloomPass::Draw: END");
//Combine the the new blurred texture into the final texture
m_BlurredFinalTexture.Bind();
m_CombineProgram->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_FinalBlurTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].EndIndex - m_ScreenQuad->MaterialGroups()[0].StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].StartIndex);
GLERROR("END");
}
void DrawBloomPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
@@ -132,3 +222,5 @@ void DrawBloomPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum fil
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
GLERROR("Texture initialization failed");
}
+26 -6
View File
@@ -28,8 +28,8 @@ void DrawFinalPass::InitializeFrameBuffers()
GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGBA, GL_UNSIGNED_INT, 4);
//GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT);
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
@@ -207,15 +207,32 @@ void DrawFinalPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum fil
void DrawFinalPass::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const
{
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGBA, GL_UNSIGNED_INT, 4);
//glGenTextures(1, texture);
//glBindTexture(GL_TEXTURE_2D, *texture);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, dimensions.x, dimensions.y, GL_UNSIGNED_BYTE, NULL);
//glGenerateMipmap(GL_TEXTURE_2D);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture);
glGenerateMipmap(GL_TEXTURE_2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //TODO: THIS SHIS IS BROKEN WHY YOU NO LINEAR MIPMAP? SHITTY FUCK
glGenerateMipmap(GL_TEXTURE_2D);
GLERROR("MipMap Texture initialization failed");
//glGenTextures(1, texture);
//glBindTexture(GL_TEXTURE_2D, *texture);
//glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
//glTexImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture);
//glGenerateMipmap(GL_TEXTURE_2D);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
GLERROR("MipMap Texture initialization failed");
}
@@ -307,6 +324,9 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_BloomTexture);
glGenerateMipmap(GL_TEXTURE_2D);
}
+3 -1
View File
@@ -29,10 +29,12 @@ Texture::Texture(std::string path)
glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//glTexStorage2D(GL_TEXTURE_2D, 4, GL_RGBA8, image.Width, image.Height);
glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, image.Data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLERROR("Texture load");
}