Skip to content

Commit

Permalink
messing with blur
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Aug 24, 2024
1 parent 1412186 commit ae0aef2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 32 deletions.
27 changes: 15 additions & 12 deletions samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ bool PseutheBackgroundState::simulate(float dt)

void PseutheBackgroundState::render()
{
//m_backgroundBuffer.clear(cro::Colour::Black);
m_gameScene.render();
//m_backgroundBuffer.clear();
//m_gameScene.render();
//m_backgroundBuffer.display();


//m_blurBufferH.clear(cro::Colour::Black);
//m_blurBufferH.clear();
//m_backgroundQuad.draw();
//m_blurBufferH.display();


//m_blurBufferV.clear();
//m_blurQuadH.draw();
//m_blurBufferV.display();

//m_blurQuadV.draw();

m_gameScene.render();
}

//private
Expand All @@ -127,16 +130,16 @@ void PseutheBackgroundState::loadAssets()
m_resources.shaders.loadFromString(ShaderID::BlurH, cro::SimpleDrawable::getDefaultVertexShader(), GaussianFrag, "#define HORIZONTAL\n");
m_resources.shaders.loadFromString(ShaderID::BlurV, cro::SimpleDrawable::getDefaultVertexShader(), GaussianFrag, "#define VERTICAL\n");

m_backgroundBuffer.create(SceneSize.x/2, SceneSize.y/2, false);
m_backgroundBuffer.setSmooth(true);
m_backgroundBuffer.create(SceneSize.x, SceneSize.y, false);
m_backgroundQuad.setTexture(m_backgroundBuffer.getTexture());
m_backgroundQuad.setScale(glm::vec2(2.f));
//m_backgroundQuad.setShader(m_resources.shaders.get(ShaderID::BlurH));
m_backgroundQuad.setShader(m_resources.shaders.get(ShaderID::BlurH));

m_blurBufferH.create(SceneSize.x, SceneSize.y, false);
m_blurQuadH.setTexture(m_blurBufferH.getTexture());
m_blurQuadH.setShader(m_resources.shaders.get(ShaderID::BlurV));


m_blurBufferV.create(SceneSize.x, SceneSize.y, false);
m_blurQuadV.setTexture(m_blurBufferV.getTexture());
}

void PseutheBackgroundState::createScene()
Expand Down Expand Up @@ -260,10 +263,10 @@ void PseutheBackgroundState::createScene()

// auto winSize = glm::vec2(cro::App::getWindow().getSize());
// auto viewScale = winSize.x / SceneSizeFloat.x;
// m_blurQuadH.setScale(glm::vec2(viewScale));
// m_blurQuadV.setScale(glm::vec2(viewScale));

// float offset = (winSize.y - (SceneSize.y * viewScale)) / 2.f;
// m_blurQuadH.setPosition(glm::vec2(0.f, offset));
// m_blurQuadV.setPosition(glm::vec2(0.f, offset));
// };
//cam.resizeCallback(cam);

Expand Down
3 changes: 3 additions & 0 deletions samples/scratchpad/src/pseuthe/PseutheBackgroundState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class PseutheBackgroundState final : public cro::State, public cro::GuiClient
cro::RenderTexture m_blurBufferH;
cro::SimpleQuad m_blurQuadH;

cro::RenderTexture m_blurBufferV;
cro::SimpleQuad m_blurQuadV;

cro::RenderTexture m_backgroundBuffer;
cro::SimpleQuad m_backgroundQuad;

Expand Down
73 changes: 53 additions & 20 deletions samples/scratchpad/src/pseuthe/PseuthePostFX.inl
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,68 @@ static inline const std::string GaussianFrag =
R"(
uniform sampler2D u_texture;
VARYING_IN vec2 v_texCoord;
VARYING_IN vec4 v_colour;
OUTPUT
uniform float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
uniform float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
#if defined(HORIZONTAL)
const float TextureSize = 1920.0; //TODO set this at compile tile from const vals
#define OFFSET vec2(offset[i], 0.0)
const vec2 offset = vec2(1.0/1920.0, 0.0);
#else
const float TextureSize = 1080.0;
#define OFFSET vec2(0.0, offset[i])
const vec2 offset = vec2(0.0,1.0/1080.0);
#endif
void main()
{
vec4 colour = TEXTURE(u_texture, vec2(gl_FragCoord) / TextureSize) * weight[0];
for (int i = 1; i < 3; i++)
{
colour += TEXTURE(u_texture, (vec2(gl_FragCoord) + OFFSET) / TextureSize) * weight[i];
colour += TEXTURE(u_texture, (vec2(gl_FragCoord) - OFFSET) / TextureSize) * weight[i];
}
vec2 texCoords = v_texCoord;
vec4 colour = vec4(0.0);
colour += TEXTURE(u_texture, texCoords - 4.0 * offset) * 0.0162162162;
colour += TEXTURE(u_texture, texCoords - 3.0 * offset) * 0.0540540541;
colour += TEXTURE(u_texture, texCoords - 2.0 * offset) * 0.1216216216;
colour += TEXTURE(u_texture, texCoords - offset) * 0.1945945946;
colour += TEXTURE(u_texture, texCoords) * 0.2270270270;
colour += TEXTURE(u_texture, texCoords + offset) * 0.1945945946;
colour += TEXTURE(u_texture, texCoords + 2.0 * offset) * 0.1216216216;
colour += TEXTURE(u_texture, texCoords + 3.0 * offset) * 0.0540540541;
colour += TEXTURE(u_texture, texCoords + 4.0 * offset) * 0.0162162162;
FRAG_OUT = colour;// * v_colour;
FRAG_OUT.rgb = colour.rgb;
FRAG_OUT.a = 1.0;
})";

FRAG_OUT *= v_colour;
}

)";
//R"(
//uniform sampler2D u_texture;
//
//VARYING_IN vec4 v_colour;
//
//OUTPUT
//
//uniform float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
//uniform float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
//
//#if defined(HORIZONTAL)
//const float TextureSize = 1920.0; //TODO set this at compile tile from const vals
//#define OFFSET vec2(offset[i], 0.0)
//#else
//const float TextureSize = 1080.0;
//#define OFFSET vec2(0.0, offset[i])
//#endif
//
//void main()
//{
// vec4 colour = TEXTURE(u_texture, vec2(gl_FragCoord) / TextureSize) * weight[0];
//
// for (int i = 1; i < 3; i++)
// {
// colour += TEXTURE(u_texture, (vec2(gl_FragCoord) + OFFSET) / TextureSize) * weight[i];
// colour += TEXTURE(u_texture, (vec2(gl_FragCoord) - OFFSET) / TextureSize) * weight[i];
// }
//
// FRAG_OUT.rgb = colour.rgb;
// FRAG_OUT.a = 1.0;
//
// FRAG_OUT *= v_colour;
//}
//
//)";

0 comments on commit ae0aef2

Please sign in to comment.