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 PCSS with WebGL1 #5403

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/scene/shader-lib/chunks/lit/frag/shadowPCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ export default /* glsl */`
uniform float pcssDiskSamples[PCSS_SAMPLE_COUNT];
uniform float pcssSphereSamples[PCSS_SAMPLE_COUNT];

vec2 vogelDisk(int sampleIndex, float count, float phi) {
vec2 vogelDisk(int sampleIndex, float count, float phi, float r) {
const float GoldenAngle = 2.4;
float r = pcssDiskSamples[sampleIndex];

float theta = float(sampleIndex) * GoldenAngle + phi;

float sine = sin(theta);
float cosine = cos(theta);
return vec2(r * cosine, r * sine);
}

vec3 vogelSphere(int sampleIndex, float count, float phi) {
vec3 vogelSphere(int sampleIndex, float count, float phi, float r) {
const float GoldenAngle = 2.4;
float r = pcssSphereSamples[sampleIndex];

float theta = float(sampleIndex) * GoldenAngle + phi;

float weight = float(sampleIndex) / count;
Expand Down Expand Up @@ -87,7 +83,8 @@ float PCSS(TEXTURE_ACCEPT(shadowMap), vec3 shadowCoords, vec4 cameraParams, floa
vec2 samplePoints[PCSS_SAMPLE_COUNT];
float noise = gradientNoise( gl_FragCoord.xy ) * 2.0 * PI;
for (int i = 0; i < PCSS_SAMPLE_COUNT; i++) {
samplePoints[i] = vogelDisk(i, float(PCSS_SAMPLE_COUNT), noise);
float pcssPresample = pcssDiskSamples[i];
samplePoints[i] = vogelDisk(i, float(PCSS_SAMPLE_COUNT), noise, pcssPresample);
}

// Calculate the ratio of FOV between 45.0 degrees (tan(45) == 1) and the FOV of the camera
Expand Down Expand Up @@ -144,7 +141,8 @@ float PCSSCube(samplerCube shadowMap, vec4 shadowParams, vec3 shadowCoords, vec4
vec3 samplePoints[PCSS_SAMPLE_COUNT];
float noise = gradientNoise( gl_FragCoord.xy ) * 2.0 * PI;
for (int i = 0; i < PCSS_SAMPLE_COUNT; i++) {
samplePoints[i] = vogelSphere(i, float(PCSS_SAMPLE_COUNT), noise);
float r = pcssSphereSamples[i];
samplePoints[i] = vogelSphere(i, float(PCSS_SAMPLE_COUNT), noise, r);
}

float receiverDepth = length(lightDir) * shadowParams.w + shadowParams.z;
Expand Down