2

So I've got these two images- one of a shadow map of the objects that block light, and another of the light.

Shadow Map-

Shadow Map

Light-

light

This is what I want my final result to be-

Lighting shadows

My question is, what is the best way to achieve this final result? My prior implementation involved sending wall data to the shader so the light could calculate whether or not it was intersecting a wall, but I figure there's a more optimized approach to take here. Would anyone be able to guide me in the right direction?

  • My approach to this would probably be to only send the geometry that's at least partially lit to the shader and the simply use the light as a mask (i.e multiply the output color by the lightmask (assuming you're light levels are between 0 and 1, zero being not lit, 1 being fully lit)), but I'm sure there's a fancier (read: more complex shader) way to do this – MindSwipe Oct 28 '21 at 08:30

1 Answers1

0

Load your ShadowMap as a Texture passed to the shader and multiply the final color by the sampled pixel.

float4 PSBasicPixelLightingTx(PSInput pin) : SV_Target0
{
    float4 color = SAMPLE_TEXTURE(Texture, pin.TexCoord); // Light Texture
    
    // add whatever lighting here
    
    color.rgb *= SAMPLE_TEXTURE(ShadowTexture, pin.TexCoord); // Shadow
    
    return color;
}