Skip to content

Commit

Permalink
Use model-space bpcem
Browse files Browse the repository at this point in the history
  • Loading branch information
gecko0307 committed Dec 24, 2024
1 parent dce2bd9 commit 817273d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ uniform float fogStart;
uniform float fogEnd;

uniform bool useBoxProjection;
uniform vec3 boxSize;
uniform vec3 boxPosition;

#include <unproject.glsl>
#include <gamma.glsl>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/dagon/render/deferred/shaders/probe.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 817273d

Please sign in to comment.