Advertisement

Point/Spot light shadows. Improve? Soft shadows?(Unity)

Started by August 28, 2021 05:01 AM
1 comment, last by Zurtan 3 years, 5 months ago

I am trying to add to my game a point light shadow map.

I render depth map of a cube texture, but without the top and bottom since it's not necessary from the perspective of my game.

I was able to cast shadows like that with 4 cameras, each for every side of the cube(without the top and bottom).

Each 90 degrees fov.

I was able to do this, but I want to improve it.

I want soft shadows.

Also, something that is weird, it seems that if the near and far is (0.1, 300) it is somehow more accurate than (0.1, 20), which is kind of weird.

I use 16 UNORM textures for storing the (0..1) normalized depth.

I calculate the depth this way:

In the vertex shader:

o.depth = UnityObjectToClipPos(v.vertex);

In the fragment shader:

                i.depth /= i.depth.w;

               float d = i.depth.z;

               return float4(d, d, d, 1);

I wish to have soft shadows like in Unity's directional soft shadows.

I also did a bit more sampling to try and make the shadows more soft.

This is my result:

 

This is a comparison of point + direcitonal shadows and point alone, to show you the difference between soft shadows.

Here is another thing I did to soften shadows on small creaves:

return depth < sampleDepth ? 1.0-min(max((sampleDepth/depth)-1.0, 0.0)/0.1, 1.0) : 1.0;

This topic is closed to new replies.

Advertisement