Sign in to follow this  

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

This topic is 2051 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:

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

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

FinalColor = Color + DarkSideColor;

[/CODE]

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.

Cheers!

Share this post


Link to post
Share on other sites

This topic is 2051 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this