Jump to content
  • Advertisement
Sign in to follow this  

How to add 2nd Texture only on shadow side of an object? (Earth w/ city lights)

This topic is 2362 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

Is there a way to add a texture to an object so that you can only see it on the shadow side of the object (some kind of inverse lightning)? I've got a sphere with a earth texture on it and a light (sun) rotating around the earth. The lighted side looks fine but the shadow side is just black (or gray shadowed depending on material settings). What i want is to add a 2. texture with earth at night (city lights and so on) which should only be visible on the shadow side and not on the daylight side. I've searched for hours and tried different lightning and blending options but nothing worked. The night texture is either visible everywhere or no where. Any suggestions how to solve this?
Thank you in advance!

p.s. I'm using DirectX9

Share this post

Link to post
Share on other sites
Definetely it is possible.

The easiest way is to use a vertex/pixel shader and calculate the blending for the second texture there.

Ie. for each vertex calculate the blending factor by surface normal and sun direction. You may reverse your sun direction so that vertices on the dark side get positive values and on the light side negative values. Then simply saturate the value and use that as a blending modifier for the second texture which you may then add to the base color.

Something like:

float4 Color = basetexture * saturate(dot(normal, LightDirection));

float4 DarkSideColor = darksidetexture * saturate(dot(normal, -LightDirection));

FinalColor = Color + DarkSideColor;

You may also do this with a fixel function pipeline. Just blend additively and invert your light direction and redraw the mesh with dark side texture.


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!