Jump to content
  • Advertisement
Sign in to follow this  
#Include Graphics

Soft Shadows

This topic is 1192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone!


I am adding some soft shadows, my idea is lately add them cascades management or even improve them slightly. At this time I have it simple by the way. Here is the depth from light code:

float4 getSVPositionFromLight( float3 wLightPos, float3 wPosition, out float depth )
   float3 dirZ = -normalize(wLightPos);
   float3 up = float3(0,1,0);
   float3 dirX = cross(up, dirZ);
   float3 dirY = cross(dirZ, dirX);

   wPosition -= wLightPos;
   float4 pos;
   pos.x = dot(dirX, wPosition);
   pos.y = dot(dirY, wPosition);
   pos.z = dot(dirZ, wPosition);
   pos.w = 1;
   static const float lightDepth = lightZFar - lightZNear;
   depth =(pos.z - lightZNear)/lightDepth;

   float h = 1/atan(lightViewFovY / 2);
   float w = h * lightAspectRatio;

   float4x4 projMatrix = float4x4( 2/w, 0, 0, 0,
                                   0, 2/h, 0, 0,
                                   0, 0, lightZFar/lightDepth, -lightZNear * lightZFar / lightDepth,
                                   0, 0, 1,0 );
   return mul(projMatrix, pos);

Please ignore other output but the depth because the position is only for test purposes. I have been just doing another things around.


On the check side next to divide the position by w I have this code:

float GetShadow( float4 sLightPos, float depth )
   float depthMap = tex2Dlod(depthMapSampler, float4(sLightPos.xy , 0, 0)).r;
   float shadow = (depth < (depthMap + lightShadowBias));
   return shadow;

It must be missing something because the output isnt what i expected even tweaking around with variables.


Any help should be appreciated because I have been struggling with this for more than a week...


I will also too need some advices to improve it.


those are my depth from light screen and my "shadows":

Edited by #Include Graphics

Share this post

Link to post
Share on other sites

Its natural on me to find the solution just after posting for aid haha, so finally got it, there was a  reamining "op" there that was the transform to texcoords.


Hope at least this two posts help someone or even inspire them on their dark path ^^


I am not really sure which "type of shadows" I have created but It is sure that they are the basics.


I am watching the shadows are very fragile and easy to have artifacts as long as you move you light points. So I imagine it will be difficult to tame them.


Anyway and again if somebody want to share some tips to improve it or just give me some advices for my way of making cascades will be greatly appreciated.


I feel a bit proud of this little thing and will leave a screenshot here, also I know it is a common technique, but I have to say I have never done anything related to shadows before biggrin.png

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!