4
$\begingroup$

Given a 3D space and a light source, I use ray casting to determine the shadows generated in the scene. If I'm to store the shadow data (boundary of the shadow, object which cast the shadow, etc.) what is an efficient way to go about it?

Edit:

Its basically for an application where I want to be able to move the shadow around manually to see the change in the 3d objects position. Say I apply a force to the shadow of a ball, I can actually see the ball move and also the change in the shadow. So I need to be able to set up colliders for the shadow and hence need a way to be able to store the boundary of the shadow and information about the object that cast it to carry out the actions.

$\endgroup$
  • $\begingroup$ In my understanding, raycasting isnt very good for boundary information. Depthmaps also dont dont benefit from raycasting. Deepshadow maps might benefit from raycasting. Otherwise you would just be better of baking lightning to model uv maps or some kind of voxel tree. Possibly per vertex/face. The question is a bit hard to swallow, could you specify it a bit. Best is not defined, efficient in this case is not terribly defined either $\endgroup$ – joojaa Oct 19 '15 at 6:15
  • $\begingroup$ Are you asking for something geometric such as Franklin Crow's Projected Shadow Volumes? $\endgroup$ – Simon F Oct 19 '15 at 12:19
  • $\begingroup$ Please fill in the "etc" and tell us the purpose of storing the shadow data. $\endgroup$ – Yves Daoust Oct 19 '15 at 21:07
  • $\begingroup$ I apologize for being so vague.. Its basically for an application where I want to be able to move the shadow around manually to see the change in the 3d objects position. Say I apply a force to the shadow of a ball, I can actually see the ball move and also the change in the shadow. So I need to be able to set up colliders for the shadow and hence need a way to be able to store the boundary of the shadow and information about the object that cast it to carry out the actions. $\endgroup$ – ichigo1191 Oct 20 '15 at 1:03
  • $\begingroup$ Can I infer that "etc" is void ? What other information is relevant ? $\endgroup$ – Yves Daoust Oct 20 '15 at 8:49
3
$\begingroup$

If the goal is mouse interactivity, you can do with a simple "shadow buffer", i.e. an image that holds the identity of the occluding object (if any) on every rendered pixel. You will compute this map during the casting process as you shoot the rays to the source.

In case there are several occluding objects, it is up to you to choose which one to consider (or keep a linked list of all occluding objects). If there are several sources, you can keep one map per source.

$\endgroup$
  • $\begingroup$ Why not trace on click? There sa really neat trick if there is less than 32-96 objects. $\endgroup$ – joojaa Oct 20 '15 at 14:48
  • $\begingroup$ @joojaa: no idea what you mean. $\endgroup$ – Yves Daoust Oct 20 '15 at 15:55
  • $\begingroup$ Why make a buffer of rays? If your only interested in one ray, shoot the ray when your needing it. Its fast enough. Why shoot a shadow buffer with rays just use a separate pass and use depth maps + index color. Again you can do this on demand. If you have 3 color channels you can use a bit mask for surfaces hit tahtway you can store ALL objects in pass of ray if you must etc. Too many open variables in question to nake any meaningful impact. $\endgroup$ – joojaa Oct 20 '15 at 16:21
  • $\begingroup$ @joojaa: I guess this comment belongs to the OP. I am answering the question "how to store ?". $\endgroup$ – Yves Daoust Oct 20 '15 at 17:05
0
$\begingroup$

You might want to look into signed distance field textures. They are very efficient and high quality for monochromatic images like shadows. They work by storing a clamped, signed distance from the pixel to the shape. Working this way, the distances play nicely with the bilinear interpolation of texture sampling, so you can have very nice results for very low resolution. You can also give them a soft edge to have a soft shadow look.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.