Skip to content

Commit 1c48cc8

Browse files
committed
more ssao tweaks; fix shadowmaps changing resolution
1 parent 30d967f commit 1c48cc8

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

data/cage/shaders/effects/ssaoGenerate.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ vec3 ndcToView(vec2 p, float d)
2929
// all view-space
3030
vec3 reconstructNormal(vec3 position)
3131
{
32-
return normalize(cross(dFdx(position), dFdy(position)));
32+
return normalize(cross(dFdxFine(position), dFdyFine(position)));
3333
}
3434

3535
mat3 makeTbn(vec3 myNormal)
@@ -82,7 +82,7 @@ void main()
8282
{
8383
vec3 samplePos = ndcToView(rayNdc.xy, sampleDepth); // view-space sample position
8484
float diff = length(rayPos - samplePos);
85-
occ += smoothstep(1, 0, diff / raysLength);
85+
occ += smoothstep(1, 0, saturate(diff / raysLength));
8686
}
8787
total += 1;
8888
}

data/cage/shaders/effects/ssaoParams.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ layout(std140, binding = CAGE_SHADER_UNIBLOCK_CUSTOMDATA) uniform Ssao
33
{
44
mat4 proj;
55
mat4 projInv;
6-
vec4 params; // strength, threshold, power, raysLength
6+
vec4 params; // strength, bias, power, raysLength
77
ivec4 iparams; // sampleCount, hashSeed
88
};

data/cage/shaders/effects/ssaoResolve.glsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ out float outAo;
1414
void main()
1515
{
1616
float ao = texelFetch(texAo, ivec2(gl_FragCoord.xy), 0).x;
17-
if (ao < params[1])
18-
ao = 0;
19-
ao = pow(max(ao, 0), params[2]) * params[0];
17+
ao = pow(max(ao - params[1], 0), params[2]) * params[0];
2018
outAo = clamp(1 - ao, 0, 1);
2119
}

sources/include/cage-engine/screenSpaceEffectsProperties.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace cage
88
struct CAGE_ENGINE_API ScreenSpaceAmbientOcclusion
99
{
1010
Real raysLength = 0.1; // world-space
11-
Real threshold = 0.03;
11+
Real bias = 0.03;
1212
Real power = 1.2;
1313
Real strength = 3;
14-
// ao = pow(ao - threshold, power) * strength
14+
// ao = pow(ao - bias, power) * strength
1515
uint32 samplesCount = 32;
1616
uint32 blurPasses = 3;
1717
};

sources/libengine/graphics/renderPipeline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ namespace cage
15951595
{
15961596
Holder<ProvisionalTexture> tex;
15971597
{
1598-
const String name = Stringizer() + this->name + "_shadowmap_" + e->id() + "_cascades_" + resolution;
1598+
const String name = Stringizer() + this->name + "_shadowmap_" + e->id() + "_cascades_" + sc.resolution;
15991599
tex = provisionalGraphics->texture(name, GL_TEXTURE_2D_ARRAY,
16001600
[resolution = sc.resolution](Texture *t)
16011601
{
@@ -1628,7 +1628,7 @@ namespace cage
16281628
auto data = createShadowmapPipeline(e, lc, sc);
16291629
data->initializeShadowmapSingle();
16301630
{
1631-
const String name = Stringizer() + data->name + "_" + resolution;
1631+
const String name = Stringizer() + this->name + "_shadowmap_" + e->id() + "_" + sc.resolution;
16321632
data->shadowmap->shadowTexture = provisionalGraphics->texture(name, data->shadowmap->lightComponent.lightType == LightTypeEnum::Point ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D_ARRAY,
16331633
[resolution = data->resolution, internalFormat = data->shadowmap->lightComponent.lightType == LightTypeEnum::Point ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT24](Texture *t)
16341634
{

sources/libengine/graphics/screenSpaceEffects.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ namespace cage
8484
{
8585
Mat4 proj;
8686
Mat4 projInv;
87-
Vec4 params; // strength, threshold, power, raysLength
87+
Vec4 params; // strength, bias, power, raysLength
8888
Vec4i iparams; // sampleCount, hashSeed
8989
} s;
9090
s.proj = config.proj;
9191
s.projInv = inverse(config.proj);
92-
s.params = Vec4(config.strength, config.threshold, config.power, config.raysLength);
92+
s.params = Vec4(config.strength, config.bias, config.power, config.raysLength);
9393
s.iparams[0] = config.samplesCount;
9494
s.iparams[1] = hash(config.frameIndex);
9595
q->universalUniformStruct(s, CAGE_SHADER_UNIBLOCK_CUSTOMDATA);

0 commit comments

Comments
 (0)