Skip to content

Commit

Permalink
fix typos and improve comment readability in shadow section
Browse files Browse the repository at this point in the history
  • Loading branch information
jbritain committed Nov 13, 2024
1 parent b5ef12d commit 86b1595
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This tutorial is still being developed. Some statements may be incorrect, and th
:::

## Setting up the file structure
Minecraft shaders require a specific structure of files in the right places to load code. While it's important to understand this structure, to save time, we will be working with the Base 330 pack from shaderLABs. Download it from [here](https://github.com/shaderLABS/Base-330), and extract it into your `shaderpacks` folder. You should have the following structure.
Minecraft shaders require a specific structure of files in the right places to load code. While it's important to understand this structure, to save time, we will be working with the Base 330 pack from shaderLABS. Download it from [here](https://github.com/shaderLABS/Base-330), and extract it into your `shaderpacks` folder. You should have the following structure.

```
.
Expand Down
28 changes: 21 additions & 7 deletions src/content/docs/guides/Beginners/Your First Shader/4_shadows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ We can then add
```glsl
#include /lib/distort.glsl
```
to our `shadow.vsh`. *This should be included before the `main` function, as you cannot define functions within a function. I put mine just before my `out` declarations.
to our `shadow.vsh`. *This should be included before the `main` function, as you cannot define functions within a function.* I put mine just before my `out` declarations.

**We should also move our declaration of `shadowmapresolution` to `distort.glsl`.** This way, we can access this variable anywhere we are sampling the shadow map.
**We should also move our declaration of `shadowMapResolution` to `distort.glsl`.** This way, we can access this variable anywhere we are sampling the shadow map.

:::caution[Warning]
Preprocessor directives *do not have a semicolon on the end*.
Expand Down Expand Up @@ -268,21 +268,35 @@ Let's go back to `composite.fsh` and make a new function called `getShadow`. It
vec3 getShadow(vec3 shadowScreenPos){
float transparentShadow = step(shadowScreenPos.z, texture(shadowtex0, shadowScreenPos.xy).r); // sample the shadow map containing everything
// note that a value of 1.0 means 100% of sunlight is getting through, not that there is 100% shadowing
/*
note that a value of 1.0 means 100% of sunlight is getting through
not that there is 100% shadowing
*/
if(transparentShadow == 1.0){ // since this shadow map contains everything, there is no shadow at all so we return full sunlight
if(transparentShadow == 1.0){
/*
since this shadow map contains everything,
there is no shadow at all, so we return full sunlight
*/
return vec3(1.0);
}
float opaqueShadow = step(shadowScreenPos.z, texture(shadowtex1, shadowScreenPos.xy).r); // sample the shadow map containing only opaque stuff
if(opaqueShadow == 0.0){ // there is a shadow cast by something opaque, so we return no sunlight
if(opaqueShadow == 0.0){
// there is a shadow cast by something opaque, so we return no sunlight
return vec3(0.0);
}
vec4 shadowColor = texture(shadowcolor0, shadowScreenPos.xy); // contains the color and alpha (transparency) of the thing casting a shadow
// contains the color and alpha (transparency) of the thing casting a shadow
vec4 shadowColor = texture(shadowcolor0, shadowScreenPos.xy);
return shadowColor.rgb * (1.0 - shadowColor.a); // we use 1 - the alpha to get how much light is let through and multiply that light by the color of the caster
/*
we use 1 - the alpha to get how much light is let through
and multiply that light by the color of the caster
*/
return shadowColor.rgb * (1.0 - shadowColor.a);
}
```

Expand Down

0 comments on commit 86b1595

Please sign in to comment.