realbasic-games
[Top] [All Lists]

Re: OBJ and 3DS support for vertex colors

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: OBJ and 3DS support for vertex colors
From: Lo Saeteurn <realbasic at miensoftware dot com>
Date: Mon, 15 Aug 2005 21:51:13 -0700
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <8DF2BB08-78E5-4A06-B484-895B5868CC47 at miensoftware dot com> <98D5C6A8-4D28-4AAC-9D45-664AA46DD36E at chaoticbox dot com> <D962D06D-00DB-4899-A24F-5553090F959B at miensoftware dot com> <CAE9040D-2C53-47E2-81EC-3B54FA9F6C50 at chaoticbox dot com> <C67E7CE8-E64B-4C39-A825-14CD0A88C271 at miensoftware dot com> <75099C14-B525-45F5-B96A-6FF18C435514 at chaoticbox dot com>
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>

<Prev in Thread] Current Thread [Next in Thread>