What about occluders? How do I calculate if something is blocking
the light?
First you need a method to do a line-triangle collision test (a
Google for "line segment triangle intersection" should turn up a
few algorithms). Then you process each vertex for each light like
so: (psuedo-code)
for each light in world
for each vertex in world.mesh
line = CalculateRay(light, vertex)
addlightcontribution = True
for each triangle in world.mesh
if line.Intersects(triangle) then
addlightcontribution = False
exit
end if
next
if addlightcontribution then
vertex.colour = vertex.colour + CalculateContribution
(light, vertex)
end if
next// Vertex
next// Light
That's the gist of it anyway, you should do a distance test to
ensure a vertex is potentially lit by a light before doing all the
triangle collision tests, and add early rejection tests for vertex
normals that face away from the light, etc.
Thanks for the tip.
Would it be feasible to use the FindPoint method (of RB3D space)
to test whether a light hits a given vertex? I could point the
camera at a vertex and see if the findPoint returns a value
relatively close to the vertex (test only the z difference from
the camera). Of course I would have to ignore all the objects out
of view before doing the findpoint test.
That could work, but requires that you actually draw the scene a
whole bunch of times, and the accuracy would be questionable when
converting from screen coordinates. It'd probably be faster and
safer to just do the math yourself.
Okay I'll do this first since it is easier. My math skills has faded
over the years. If I don't like the results then I'll use the faster
more accurate method.
What if an object has been rotated? Is there an easier way to get a
vertex's actual position?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|