Skip to main content
gamedev.net
🔒 Locked

Computing Lightmap

Started by magneeto 2 replies 950+ views
Original Post
magneeto
magneeto
hi, i'm trying to get the environment light map from an eye image. i have access to the pixel colors in the eye area and also the normal map. my question is... for each pixel in the eye image how do i compute the incident light direction?
Thr33d
Thr33d
What's an eye image? A digital photograph of someone's eye?

Probably the best way to get it would be to know the surface normal of each image pixel, and know the viewing (normalized) vector for each image pixel.
Then calculate the reflection vector by bouncing the viewing vector off of the surface, and there's your incident light vector.

In order to get the surface normal of each pixel, you either need to have a way to find this either directly or indirectly. If you know the geometry, then you can find the derivative of each point, and do some cross products to find the surface normal, which brings us to the obvious approximation for this case.

Assume the viewing vector is (relatively) parallel (or account for it not being if you like)
Assume the eye's surface can be closely approximated as a sphere.
Estimate the center of the eye.
Estimate the radius - remember they're slightly bigger than just the center->edge visible in the image
Ignore the perturbance of the cornea (making it non-spherical)
Find the incident ray this way.

Math to follow.

-M
Thr33d
Thr33d
R = 2(N•L)N - L
where R is the reflection vector
N is the surface normal
-and-
L is the light (in this case camera) vector

This is how it's done for Phong specularity.
This was taken from this Delphi3d page


If you simplify the approximation, assuming the camera to be a nearly orthographic projection, the camera vector becomes <0,1,0> thus simplifying the equation:
R = 2(N•L)N - L, let L = <0,1,0>
R = 2*N.y*N - <0,1,0>

For a sphere, the surface normal would just be a unit length vector from the origin, therefore:

N.x = x'/radius
N.z = y'/radius
N.y = sqr(1-(N.x^2 + N.y^2))
where x' is the image's x value, relative to the center of the eye, y' is the image's y value, relative to the center of the eye.

This should be enough to get that first approximation :-)

Hope it helps!
-Michael g.
magneeto
magneeto
i've seen something like this

light = ray - normal * (normal dot ray)* 2

it seems like the terms in the right hand side has been swapped. is this ok? the code works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.