PDA

View Full Version : Stencil Buffer Shadows and Rotation.



MrShoe
10-16-2002, 09:10 PM
Ok, ive made a program with a room and an object and a light rotating around the object and the object casts a shadow on the room, i used the "standard" stencil buffer method for this. It works all well and good if i move the light around, but once i rotate or translate thge object obviously the shadows dont change. I know that i need to change the "relative" position of the light to the object, but i dont seem to be able to figure out how to do this well. Does anyone know a good way?

MickeyMouse
10-17-2002, 02:52 AM
Moving objects by X is same as moving light by -X at some high abstraction level (in your special case).....

So when you apply transformations like these to your object:

transformation_0
transformation_1
...
...
trasnformation_n

...you need to apply these to your light origin

transformation_n
...
...
transformation_1
transformation_0

[This message has been edited by MickeyMouse (edited 10-17-2002).]

MrShoe
10-17-2002, 03:47 PM
So if i just rotate the object on say the x axis, all i need to do i rotate the light on the -y axis by the same amount? but then the shadow FORM will be correct, but it will be cast onto the wrong part of the scene afaik. dunno

MickeyMouse
10-17-2002, 11:13 PM
Here's a little pseudocode example:




matrix = identity()
matrix.rotate(a)
matrix.transform(b)
matrix.scale(c)

matrix_inversed = identity()
matrix_inversed.scale(c)
matrix_inversed.transform(b)
matrix_inversed.rotate(a)

matrix.apply()
light_origin_inv = matrix_inv * light_origin
object.determine_shadow_volume(light_origin_inv)

object.draw()
object.draw_shadow_volume()


Hope this helps

[This message has been edited by MickeyMouse (edited 10-18-2002).]

10-18-2002, 12:42 AM
Originally posted by MrShoe:
So if i just rotate the object on say the x axis, all i need to do i rotate the light on the -y axis by the same amount? but then the shadow FORM will be correct, but it will be cast onto the wrong part of the scene afaik. dunno