Horde3D

Next-Generation Graphics Engine
It is currently 25.04.2024, 00:11

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 15.11.2010, 17:38 
Offline

Joined: 16.05.2009, 12:43
Posts: 207
I need the view space angle between the normal and my eye->model vector.

Here's how I'm doing it:

vec4 v;
v.xyz = viewer;
v.w = 0;
eyepos = gl_ModelViewMatrix * v;
rlpos = gl_ModelViewMatrix * gl_Vertex;
norm = gl_NormalMatrix * gl_Normal;

so eyepos should be the camera position
rlpos should be the new position of the suface
norm should be the normal of that position

I subtract eyepos from pos to get the surface->camera direction, normalize it, then dot it with the normal.

Only, it looks quite different to the same thing in rendermonkey. In that it does mostly what I want (creates a rim light), but doesnt seem to be view independant (like the view direction isnt being updated).

Anyone see anything wrong here? is viewer actually the camera position in world space or am I reading it wrong?


Top
 Profile  
Reply with quote  
PostPosted: 15.11.2010, 22:28 
Offline

Joined: 16.05.2009, 12:43
Posts: 207
that norm line is wrong. Wrong cut and paste. That actually barfs the engine when running a shader with it enabled. But it does the same thing (takes the normal and multiplies by the model view transform in a different form).

It looks like the viewer uniform doesnt seem to hold what I expect.

Is there a way to get the POSITION of the camera in a shader? (in view space) so I can dot it with the view space normal?


Top
 Profile  
Reply with quote  
PostPosted: 14.12.2010, 08:27 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
IIRC, the 'viewer' variable holds the position of the camera in world space.
You can multiply a vertex-position with 'worldMat' to convert it to world space, then perform a subtraction and normalize to get the viewer-direction in world-space.
You can then multiply the normal with 'worldNormalMat' to get the world space normal, and perform the dot product to get the angular difference.


In view space, the position of the camera should be (0,0,0) -- view space is relative to the camera.
So alternatively, if you want to work in view-space instead of world-space, just normalise the view-space vertex-position to get the direction from the camera to the vert.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group