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

Started by
1 comment, last by kauna 11 years, 11 months ago
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
Advertisement
You could probably do that with a shader but not sure if you can do it without them.

o3o

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.

Cheers!

This topic is closed to new replies.

Advertisement