View Full Version : Shadow and shaders
03-31-2005, 03:52 AM
I have some objects on a plane and i use shadow mapping, all goes right. But when i draw an object with a shader, that object casts shadow but does not receive (as normal). To make my object receive shadow do i have to change shader code (inserting test with shadow map)? Is this way correct? If yes, do i have to change all shaders that i want to receive shadow? For example i have a wood, marble and stone shaders, if i want draw objects with and without shadow mapping i must have two version of every shader, is this correct?
03-31-2005, 05:48 AM
This is an uberlight type of question.
First, yes you must insert the shader code to do a shadow test, such as testing against a depth texture with a shadow2D( sampler2DShadow, texCoord.stp );
Second, your choice if you want to do two versions of each shader or not.
You could certainly have something like:
uniform bool shadowMe;
uniform sampler2DShadow shadowMap;
uniform sampler2D baseMap;
varying vec3 P_light;
varying vec2 TC;
void main( void )
if ( shadowMe )
percentLight = shadow2D( shadowMap, P_Light );
percentLight = 1.0;
vec4 baseColor = texture2D( baseMap, TC );
baseColor.rgb *= percentLight;
gl_FragColor = baseColor;
}Or you could write two different shaders.
The tradeoff is the cost to manage and switch between shaders versus the cost of the conditional per fragment.
Both costs are implementation dependent. The balance point between them also shifts depending on the size of the objects (in pixels) you are shading and how frequently you switch between shadowed/not shadowed shaders.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.