First off, I'm not sure if this is the right place for this question, so if someone could let me know about that...
Anyway, I've just recently been working on a developing a shader. I have some basic things like tonemapping, PCF colored shadows, and emissive objects. However, I'm currently stuck on implementing percentage closer soft shadows (PCSS). I've been looking around online, but I haven't been able to find any helpful documentation for doing this in GLSL (at least not version 1.2). I was wondering if anybody was able to help me with this, or knew where I could find the appropriate information (also, I'm only a beginner with GLSL and shaders in general). I can add source code if necessary.
First off, I'm not sure if this is the right place for this question, so if someone could let me know about that...
Anyway, I've just recently been working on a developing a shader. I have some basic things like tonemapping, PCF colored shadows, and emissive objects. However, I'm currently stuck on implementing percentage closer soft shadows (PCSS). I've been looking around online, but I haven't been able to find any helpful documentation for doing this in GLSL (at least not version 1.2). I was wondering if anybody was able to help me with this, or knew where I could find the appropriate information (also, I'm only a beginner with GLSL and shaders in general). I can add source code if necessary.
Thanks in advance!
This is the code I use for PCSS in my shader pack, however the code generally is similar all around. To roughly describe PCSS, essentially before your PCF code, you want to use a small filter on the area around the central shadow map texel, 3x3 works fine, and you want to get the average depth around that texel (so you want the raw depth, ie `texture2D(shadowtex0, shadowPos.xy + offset).x`). This gets your blocker depth, or the depth of anything casting shadows near the central shadow map texel. Once you've got the blocker depth, calculate the distance between the blocker and your surface using the equation `distance = (surface - blocker) * lightDistance`, where `lightDistance` is a constant that represents the distance of the sun/moon from the surface. Use this distance to influence the radius of your percentage-closer filter, and voila, you should have shadows that soften with distance.
If you ever need help, feel free to hop onto the shaderLABs Discord server. It's a Discord server dedicated to Minecraft shaders, and all relevant shader devs are on there: Sonic Ether, Chocapic, Sildur, Triliton, dotModded, BruceKnowsHow, dethraid, Capt Tatsu, bobcao3, Sergeant Sarcasm, Zombye, and lots more lesser-known devs. I'm jaekmichie97 on there.
Hello!
First off, I'm not sure if this is the right place for this question, so if someone could let me know about that...
Anyway, I've just recently been working on a developing a shader. I have some basic things like tonemapping, PCF colored shadows, and emissive objects. However, I'm currently stuck on implementing percentage closer soft shadows (PCSS). I've been looking around online, but I haven't been able to find any helpful documentation for doing this in GLSL (at least not version 1.2). I was wondering if anybody was able to help me with this, or knew where I could find the appropriate information (also, I'm only a beginner with GLSL and shaders in general). I can add source code if necessary.
Thanks in advance!
This is the code I use for PCSS in my shader pack, however the code generally is similar all around. To roughly describe PCSS, essentially before your PCF code, you want to use a small filter on the area around the central shadow map texel, 3x3 works fine, and you want to get the average depth around that texel (so you want the raw depth, ie `texture2D(shadowtex0, shadowPos.xy + offset).x`). This gets your blocker depth, or the depth of anything casting shadows near the central shadow map texel. Once you've got the blocker depth, calculate the distance between the blocker and your surface using the equation `distance = (surface - blocker) * lightDistance`, where `lightDistance` is a constant that represents the distance of the sun/moon from the surface. Use this distance to influence the radius of your percentage-closer filter, and voila, you should have shadows that soften with distance.
If you ever need help, feel free to hop onto the shaderLABs Discord server. It's a Discord server dedicated to Minecraft shaders, and all relevant shader devs are on there: Sonic Ether, Chocapic, Sildur, Triliton, dotModded, BruceKnowsHow, dethraid, Capt Tatsu, bobcao3, Sergeant Sarcasm, Zombye, and lots more lesser-known devs. I'm jaekmichie97 on there.
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
My Github page.
The entire Minecraft shader development community now has its own Discord server! Feel free to join and chat with all the developers!