• 9
• 9
• 10
• 9
• 10

# Eye rendering - parallax correction

This topic is 971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone know where I can find info on how to do parallax correction for the iris/pupil ?

There's really not a lot of information out there on something this specific.

but couldn't quite figure out the UV trick he's using. However I do believe this should also work using a displacement map ?

##### Share on other sites
First, look up the equations for refraction. These will tell you how to compute the refracted light direction based on the surface normal and IOR. If you have a mesh for the cornea that matches the actual dimensions of the human eye, then calculating the refraction is really easy in the pixel shader: your incoming light direction will be the eye->pixel vector, and the normal will be the interpolated surface normal of the mesh. Once you've calculated the refracted view direction, you just need to intersect it with the iris. A simple way to do this is to treat the iris as a flat plane that's 2.18mm from the apex of the cornea. You can then do a simple ray/plane intersection test to find the point on the surface of the iris that you're shading. To get the right UV coordinates to use, you just need a simple way of mapping your iris UV's to your actual positions on the iris (I just used an artist-configurable scale value on the XY coordinates of the iris surface). I would recommend doing all of this in a coordinate space that's local to the eye, since it makes the calculations simpler. For instance, you could have it set up such that the apex of the cornea is at X=Y=Z=0, and the iris is plane perpendicular with the XY plane located 2.8mm from the origin. Edited by MJP

##### Share on other sites

I feel like I'm not quite getting the geometry or math in my head how exactly this works.

Or my asset is not correct for this to work.

Here are a few pictures of how the eyeball looks like:

Front in 3ds max:

Side-view in 3ds max:

UVW Mapping in 3ds max:

And here's one where I output the UVs in the shader for the eyes:

Now going back to the code...

As far as I understand it I start from the vector that points from my camera to the pixel aka the view vector (negated because in the direction towards the pixel). I calculate a refraction ratio for the human cornea aka 1.0 / 1.376. Then I can compute the vector that results from refracting it about the surface normal (per pixel). So far so good. Now it gets more complicated for me.

This is a look from above with the Z coordinate going into the positive Y direction (in this drawing). So being in local space I can say that the parallax depth should be X units along the local Z axis, correct ? So as you said I can now calculate the intersection point where the refracted view vector (Vr) intersects this plane (the iris). However what I'm still not sure about, and again maybe its my assets, but how to get the correct UV coordinates for this.

This is pretty much what I came up but it's obviously incomplete and wrong...

// Calculate physically based refraction
// IOR of cornea = 1.376
float eta = 1.0f / 1.376f;
float3 Vr = refract(-V, N, eta);

// Find intersection between refracted ray and iris plane
float t = -(dot(camera_Position, N) + 10000.0f) / dot(Vr, N);
float3 P = camera_Position + t * Vr;
float3 P_local = mul(float4(P, 1.0f), mat4x4_InverseWorld).xyz;

// Find the texcoord corresponding to the local intersection point
// ???

Edited by lipsryme