Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ao distance value usage #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ao/AOEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { TRAAEffect } from "../traa/TRAAEffect"
const defaultAOOptions = {
resolutionScale: 1,
spp: 8,
distance: 2,
distancePower: 1,
power: 2,
bias: 40,
Expand Down Expand Up @@ -79,6 +78,7 @@ class AOEffect extends Effect {

case "distance":
this.aoPass.fullscreenMaterial.uniforms.aoDistance.value = value
this.poissionDenoisePass.fullscreenMaterial.uniforms["distance"].value = Math.max(value, 0.0001)
break

case "resolutionScale":
Expand Down
2 changes: 1 addition & 1 deletion src/hbao/shader/hbao.frag
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ float getOcclusion(const vec3 cameraPosition, const vec3 worldPos, const vec3 wo
float deltaDepth = depth - sampleDepth;

// distance based bias
float d = distance(sampleWorldPos, cameraPosition);
float d = distance(sampleWorldPos, cameraPosition) / aoDistance;
deltaDepth *= 0.001 * d * d;

float th = thickness * 0.01;
Expand Down
5 changes: 4 additions & 1 deletion src/poissionDenoise/PoissionDenoisePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultPoissonBlurOptions = {
depthPhi: 2,
normalPhi: 3.25,
samples: 16,
distance: 2,
normalTexture: null
}

Expand All @@ -51,6 +52,7 @@ export class PoissionDenoisePass extends Pass {
lumaPhi: { value: 5.0 },
depthPhi: { value: 5.0 },
normalPhi: { value: 5.0 },
distance: { value: 1.0 },
resolution: { value: new Vector2() },
blueNoiseTexture: { value: null },
index: { value: 0 },
Expand All @@ -74,7 +76,8 @@ export class PoissionDenoisePass extends Pass {
uniforms["cameraMatrixWorld"].value = camera.matrixWorld
uniforms["depthPhi"].value = options.depthPhi
uniforms["normalPhi"].value = options.normalPhi

uniforms["distance"].value = options.distance

if (options.normalTexture) {
uniforms["normalTexture"] = { value : options.normalTexture }
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/poissionDenoise/shader/poissionDenoise.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ uniform sampler2D blueNoiseTexture;
uniform vec2 blueNoiseRepeat;
uniform int index;
uniform vec2 resolution;
uniform float distance;

#include <common>
#include <sampleBlueNoise>
Expand Down Expand Up @@ -105,7 +106,7 @@ void main() {
#endif
float lumaSimilarity = max(1.0 - lumaDiff / lumaPhi, 0.0);

float depthDiff = 1. - distToPlane(worldPos, worldPosSample, normal);
float depthDiff = 1. - (distToPlane(worldPos, worldPosSample, normal) / distance);
float depthSimilarity = max(depthDiff / depthPhi, 0.);

float w = lumaSimilarity * depthSimilarity * normalSimilarity;
Expand Down
2 changes: 1 addition & 1 deletion src/ssao/shader/ssao.frag
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void main() {
float distSample = linearize_depth(sampleDepth, cameraNear, cameraFar);
float distWorld = linearize_depth(offset.z, cameraNear, cameraFar);

float rangeCheck = smoothstep(0.0, 1.0, aoDistance / (aoDistance * abs(distSample - distWorld)));
float rangeCheck = smoothstep(0.0, 1.0, aoDistance / abs(distSample - distWorld));
rangeCheck = pow(rangeCheck, distancePower);
float weight = dot(sampleDirection, normal);

Expand Down