Skip to content

Commit

Permalink
vsm fog optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Oct 5, 2024
1 parent 0c229cf commit 65315a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 9 additions & 9 deletions shader/sky/fog.frag
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ layout(binding = 4) uniform utexture3D pageTbl;
layout(binding = 5) uniform texture2D pageData;
#endif

const float dFogMin = 0;
//const float dFogMax = 1;
const float dFogMax = 0.9999;

#if defined(GL_COMPUTE_SHADER)
uvec2 invocationID = gl_GlobalInvocationID.xy;
#endif
Expand Down Expand Up @@ -175,10 +179,8 @@ vec4 fog(vec2 uv, float z) {
const int steps = 32;
const float noise = interleavedGradientNoise()/steps;

const float dMin = 0;
const float dMax = 0.9999;
const vec3 pos0 = project(scene.viewProjectLwcInv, vec3(inPos,dMin));
const vec3 pos1 = project(scene.viewProjectLwcInv, vec3(inPos,dMax));
const vec3 pos0 = project(scene.viewProjectLwcInv, vec3(inPos,dFogMin));
const vec3 pos1 = project(scene.viewProjectLwcInv, vec3(inPos,dFogMax));
const vec3 posz = project(scene.viewProjectLwcInv, vec3(inPos,z));

#if defined(VIRTUAL_SHADOW) || defined(VIRTUAL_SHADOW_MARK)
Expand Down Expand Up @@ -262,11 +264,9 @@ const vec3 debugColors[MAX_DEBUG_COLORS] = {
};

vec4 fog(vec2 uv, float z) {
float dMin = 0;
float dMax = 0.9999;
float dZ = linearDepth( z, scene.clipInfo);
float d0 = linearDepth(dMin, scene.clipInfo);
float d1 = linearDepth(dMax, scene.clipInfo);
float dZ = linearDepth( z, scene.clipInfo);
float d0 = linearDepth(dFogMin, scene.clipInfo);
float d1 = linearDepth(dFogMax, scene.clipInfo);
float d = (dZ-d0)/(d1-d0);
// return vec4(debugColors[min(int(d*textureSize(fogLut,0).z), textureSize(fogLut,0).z-1)%MAX_DEBUG_COLORS], 0);
return textureLod(fogLut, vec3(uv,d), 0);
Expand Down
10 changes: 7 additions & 3 deletions shader/virtual_shadow/vsm_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ bool vsmPageClip(ivec2 fragCoord, const uint page) {
}

int vsmCalcMipIndex(in vec2 shPos) {
#if 1
float d = max(abs(shPos.x), abs(shPos.y));
uint id = uint(d);
return findMSB(id)+1;
#else
float x = ceil(log2(max(abs(shPos.x), 1)));
float y = ceil(log2(max(abs(shPos.y), 1)));
return int(max(x,y));
#endif
}

int vsmCalcMipIndex(in vec2 shPos, int minMip) {
float x = ceil(log2(max(abs(shPos.x), 1)));
float y = ceil(log2(max(abs(shPos.y), 1)));
return max(minMip, int(max(x,y)));
return max(vsmCalcMipIndex(shPos), minMip);
}

uint pageIdHash7(ivec3 src) {
Expand Down

0 comments on commit 65315a2

Please sign in to comment.