View Full Version : ARB_fragment_program view vector

burnettryan

04-14-2005, 08:15 AM

Does anyone know how to get/calculate the view vector in ARB_fragment_program? I am trying to implement phong with a fragment program. So I need to get/calculate the view vector in order to computer the specular component.

Or does any know how to implement phong in ARB_fragment_program?

Java Cool Dude

04-14-2005, 08:52 AM

Multiplying the inverse modelview matrix by {0.0,0.0,0.0,1.0} will give you the camera position.

You can pass your vertex position to the fragment processor through the vertex program and the rest is basic math :)

burnettryan

04-14-2005, 08:56 AM

Thx for the help.

You can pass your vertex position to the fragment processor through the vertex program How do I do this?

Java Cool Dude

04-14-2005, 09:00 AM

Use one of the spare texcoord?

I usually use the 4th (texcoord[3]) since I reserve the first through the 3rd are for texture coordinates, binomals and tangent components...

NitroGL

04-14-2005, 09:13 AM

This is what I use for my view direction:

SUB result.texcoord[1], mvit[3], vertex.position;That's in the vertex program, then I normalize it in the fragment program (mvit is the inverse transpose of the modelview matrix BTW).

dorbie

04-14-2005, 09:25 AM

Vertices are in EYE space after transformation through the modelview matrix it should be clear that the vertex coordinate for any vertex location expressed as a vector is the view vector (you may have to normalize or negate depending on your math).

object_space_vertex * modelview_matrix = eye_space_vertex = unnormalized_view_vector

Now if you have the object space view vector going in from the application you'd want to transform through inverse modelview (just because it's a vector) but that would be an expensive contortion for no reason.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.