summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-07-21 02:33:24 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-10 18:14:46 +0100
commitf737aada2b7164683303beb3bb490c30a4949fb0 (patch)
treed188ee31247b2f3f38021d1cc9a8e558c5a8b15f /gfx/gl
parentUse mesh extents for shadow stencil extents (diff)
downloadilt-f737aada2b7164683303beb3bb490c30a4949fb0.tar.bz2
ilt-f737aada2b7164683303beb3bb490c30a4949fb0.tar.xz
ilt-f737aada2b7164683303beb3bb490c30a4949fb0.zip
Use texture alpha in shadow stencil
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shaders/shadowStencil.fs16
-rw-r--r--gfx/gl/shaders/shadowStencil.vs7
-rw-r--r--gfx/gl/shadowStenciller.cpp8
-rw-r--r--gfx/gl/shadowStenciller.h4
4 files changed, 31 insertions, 4 deletions
diff --git a/gfx/gl/shaders/shadowStencil.fs b/gfx/gl/shaders/shadowStencil.fs
index e69de29..f149c23 100644
--- a/gfx/gl/shaders/shadowStencil.fs
+++ b/gfx/gl/shaders/shadowStencil.fs
@@ -0,0 +1,16 @@
+#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
+
+layout(binding = 0) uniform sampler2D textureAlbedo;
+
+include(`materialInterface.glsl')
+include(`materialCommon.glsl')
+
+void
+main()
+{
+ if (getTextureColour(Material, TexCoords).a < 0.5) {
+ discard;
+ }
+ gl_FragDepth = gl_FragCoord.z;
+}
diff --git a/gfx/gl/shaders/shadowStencil.vs b/gfx/gl/shaders/shadowStencil.vs
index 4f4c250..45a0867 100644
--- a/gfx/gl/shaders/shadowStencil.vs
+++ b/gfx/gl/shaders/shadowStencil.vs
@@ -1,11 +1,18 @@
#version 330 core
#extension GL_ARB_shading_language_420pack : enable
+layout(binding = 1) uniform usampler2DRect materialData;
+
include(`meshIn.glsl')
+include(`materialInterface.glsl')
+include(`getMaterialDetail.glsl')
uniform mat4 viewProjection;
void
main()
{
+ TexCoords = texCoord;
+ Material = getMaterialDetail(material);
+
gl_Position = viewProjection * vec4(position, 1);
}
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp
index e20eda1..2ba519f 100644
--- a/gfx/gl/shadowStenciller.cpp
+++ b/gfx/gl/shadowStenciller.cpp
@@ -1,6 +1,7 @@
#include "shadowStenciller.h"
#include "config/types.h"
#include "gfx/gl/program.h"
+#include "gfx/gl/shaders/fs-shadowStencil.h"
#include "gfx/gl/shaders/vs-shadowStencil.h"
#include "gfx/models/mesh.h"
#include "glArrays.h"
@@ -8,7 +9,7 @@
#include "maths.h"
#include <stdexcept>
-ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs}
+ShadowStenciller::ShadowStenciller() : shadowCaster {shadowStencil_vs, shadowStencil_fs}
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDrawBuffer(GL_NONE);
@@ -32,13 +33,16 @@ ShadowStenciller::createStencilTexture(GLsizei width, GLsizei height)
}
void
-ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh) const
+ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh, const Texture::AnyPtr texture) const
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, stencil, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw std::runtime_error("Stencil framebuffer not complete!");
}
+ if (texture) {
+ texture->bind();
+ }
glUseProgram(shadowCaster);
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 256, 256);
diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h
index 5a22a7e..bf6d204 100644
--- a/gfx/gl/shadowStenciller.h
+++ b/gfx/gl/shadowStenciller.h
@@ -1,8 +1,8 @@
#pragma once
-#include "config/types.h"
#include "gfx/gl/program.h"
#include "gfx/models/mesh.h"
+#include "gfx/models/texture.h"
#include "glArrays.h"
class ShadowStenciller {
@@ -11,7 +11,7 @@ public:
[[nodiscard]]
static glTexture createStencilTexture(GLsizei width, GLsizei height);
- void renderStencil(const glTexture &, const MeshBase &) const;
+ void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const;
private:
glFrameBuffer fbo;