From 817273d4f795347a4e045c5e1b1ba36dc30bc929 Mon Sep 17 00:00:00 2001 From: Timur Gafarov Date: Tue, 24 Dec 2024 14:29:14 +0300 Subject: [PATCH] Use model-space bpcem --- .../EnvironmentProbe/EnvironmentProbe.frag.glsl | 17 +++++++++-------- src/dagon/render/deferred/shaders/probe.d | 4 ---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/data/__internal/shaders/EnvironmentProbe/EnvironmentProbe.frag.glsl b/data/__internal/shaders/EnvironmentProbe/EnvironmentProbe.frag.glsl index 6cb2f02..acd70f1 100644 --- a/data/__internal/shaders/EnvironmentProbe/EnvironmentProbe.frag.glsl +++ b/data/__internal/shaders/EnvironmentProbe/EnvironmentProbe.frag.glsl @@ -23,8 +23,6 @@ uniform float fogStart; uniform float fogEnd; uniform bool useBoxProjection; -uniform vec3 boxSize; -uniform vec3 boxPosition; #include #include @@ -68,8 +66,11 @@ subroutine uniform srtAmbient ambient; uniform sampler2D ambientBRDF; uniform bool haveAmbientBRDF; -vec3 bpcm(in vec3 pos, in vec3 v, vec3 boxMax, vec3 boxMin, vec3 boxPos) +// Model-space box projection +vec3 bpcem(in vec3 pos, in vec3 v) { + const vec3 boxMax = vec3(1.0, 1.0, 1.0); + const vec3 boxMin = vec3(-1.0, -1.0, -1.0); vec3 nrdir = v; vec3 rbmax = (boxMax - pos) / nrdir; vec3 rbmin = (boxMin - pos) / nrdir; @@ -79,7 +80,7 @@ vec3 bpcm(in vec3 pos, in vec3 v, vec3 boxMax, vec3 boxMin, vec3 boxPos) rbminmax.z = (nrdir.z > 0.0)? rbmax.z : rbmin.z; float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z); vec3 posOnBox = pos + nrdir * fa; - return posOnBox - boxPos; + return posOnBox; } layout(location = 0) out vec4 fragColor; @@ -119,10 +120,10 @@ void main() if (useBoxProjection) { - vec3 boxMin = boxPosition - boxSize; - vec3 boxMax = boxPosition + boxSize; - //worldN = normalize(bpcm(worldPos, worldN, boxMax, boxMin, boxPosition)); - worldR = normalize(bpcm(worldPos, worldR, boxMax, boxMin, boxPosition)); + vec3 objN = (invModelMatrix * vec4(worldN, 0.0)).xyz; + worldN = normalize(bpcem(objPos, objN)); + vec3 objR = (invModelMatrix * vec4(worldR, 0.0)).xyz; + worldR = normalize(bpcem(objPos, objR)); } vec4 pbr = texture(pbrBuffer, gbufTexCoord); diff --git a/src/dagon/render/deferred/shaders/probe.d b/src/dagon/render/deferred/shaders/probe.d index 247f3c7..c76bb15 100644 --- a/src/dagon/render/deferred/shaders/probe.d +++ b/src/dagon/render/deferred/shaders/probe.d @@ -157,10 +157,6 @@ class EnvironmentProbeShader: Shader setParameter("ambientEnergy", mat.emissionEnergy); - Vector3f boxSize = state.modelMatrix.scaling; - Vector3f boxPosition = state.modelMatrix.translation; - setParameter("boxSize", boxSize); - setParameter("boxPosition", boxPosition); setParameter("useBoxProjection", useBoxProjection); // Texture 6 - occlusion buffer