Skip to content

Commit

Permalink
Add invert effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Isti01 committed Jul 24, 2022
1 parent c4ce669 commit aa29769
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
12 changes: 12 additions & 0 deletions assets/shaders/invert_effect.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core

uniform sampler2D colorTexture;
uniform float intensity = 2;
uniform float start = 2.0f;

layout(location = 0) out vec4 color;

void main() {
vec4 pixel = texelFetch(colorTexture, ivec2(gl_FragCoord.xy), 0);
color = vec4(vec3(1) - pixel.xyz, pixel.w);
}
7 changes: 7 additions & 0 deletions assets/shaders/invert_effect.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 450 core

layout(location = 0) in vec3 position;

void main() {
gl_Position = vec4(position, 1);
}
4 changes: 2 additions & 2 deletions src/Application/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void Window::beginFrame() {
void Window::resetFrame() {
glViewport(0, 0, windowWidth, windowHeight);
glClearColor(clearColor.x * clearColor.w, clearColor.y * clearColor.w, clearColor.z * clearColor.w, clearColor.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}

void Window::finalizeFrame() {
Expand All @@ -148,7 +148,7 @@ void GLAPIENTRY Window::onOpenGlMessage(GLenum source,
GLsizei,
const GLchar *message,
const void *) {
if (id == 131185 || id == 131218 || id == 131169) {
if (id == 131185 || id == 131218 || id == 131169 || id == 131076 || id == 131204) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Rendering/ColorRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void ColorRenderPass::render() {
void ColorRenderPass::renderTextureWithEffect(const Ref<Texture>& texture, const Ref<const ShaderProgram>& effect) {
ColorRenderPass renderPass(effect);
renderPass.setTexture("colorTexture", texture, 0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
renderPass.render();
}

Expand Down
17 changes: 13 additions & 4 deletions src/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Scene::Scene(const std::string& savePath)
: persistence(std::make_shared<Persistence>(savePath)),
world(std::make_shared<World>(persistence)),
player(world, persistence),
vignetteEffect(AssetManager::instance().loadShaderProgram("assets/shaders/vignette_effect")) {
vignetteEffect(AssetManager::instance().loadShaderProgram("assets/shaders/vignette_effect")),
invertEffect(AssetManager::instance().loadShaderProgram("assets/shaders/invert_effect")) {
onResized(Application::instance().getWindowWidth(), Application::instance().getWindowHeight());
updateMouse();
}
Expand Down Expand Up @@ -51,7 +52,10 @@ void Scene::render() {
}

crosshair.render();
if (enableVignette) {
if (enableInvertEffect) {
invertEffect.render();
}
if (enableVignetteEffect) {
vignetteEffect.getShader()->setFloat("intensity", vignetteIntensity);
vignetteEffect.getShader()->setFloat("start", vignetteStart);
vignetteEffect.render();
Expand Down Expand Up @@ -88,9 +92,14 @@ void Scene::renderMenu() {
ImGui::Spacing();
ImGui::Spacing();

ImGui::Checkbox("Enable vignette effect", &enableVignette);
ImGui::Checkbox("Enable invert effect", &enableInvertEffect);

ImGui::Spacing();
ImGui::Spacing();

ImGui::Checkbox("Enable vignette effect", &enableVignetteEffect);

if (enableVignette) {
if (enableVignetteEffect) {
float invertedIntensity = 4 - vignetteIntensity;
if (ImGui::SliderFloat("Vignette intensity", &invertedIntensity, 1, 3)) {
vignetteIntensity = 4 - invertedIntensity;
Expand Down
4 changes: 3 additions & 1 deletion src/Scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class Scene {
Crosshair crosshair;
BlockOutline outline;
PostProcessEffect vignetteEffect;
PostProcessEffect invertEffect;

bool isMenuOpen = false;
bool showIntermediateTextures = false;
bool enableXRay = false;
bool enableVignette = true;
bool enableVignetteEffect = true;
bool enableInvertEffect = false;
float vignetteIntensity = 2.9;
float vignetteStart = 1.5f;

Expand Down

0 comments on commit aa29769

Please sign in to comment.