How to obtain eyeposition in shaders?

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
lukeNeo

How to obtain eyeposition in shaders?

Post by lukeNeo » 04 Oct 2015, 10:31

Hi to all,
I'm trying to do some porting from GLSL shaders to HLSL in Ventuz. One problem I have is: how can I know my eyeposition (camera position) into the shader code?
For example, even to compute specular lighting effect, I need the eye position to calculate the specular reflection..

I can't find the right constant for "eyeposition" in the documentation:
http://www.ventuz.com/support/help/V4_0 ... hader.html

Anyone can help?
Thank you!

TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

Re: How to obtain eyeposition in shaders?

Post by TVM Cracklings » 05 Oct 2015, 12:55

Method 1: Use viewspace to compute lighting. This would probably make your program run faster as well.

Method 2: The hard way. Getting Camera position through view matrix. Check out this post on SO.

Hope this helps.
-C

TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

Re: How to obtain eyeposition in shaders?

Post by TVM Cracklings » 06 Oct 2015, 08:17

Oh, and you can always pass your camera position in world space as uniform variables if everythings else fails.

Or take a look at the glm::lookAt() function and implement it directly in your shader. This would even save you a camera node. :lol:

Post Reply