PDA

View Full Version : Specular light, world, eye space?

PeTeAR
12-10-2011, 05:47 PM
Hello,

Using OpenGL ES 2.0 with shaders.

I just created a light source where the reflection from the light (the specular part) on my flat surface is following me so to speak. Like walking on a wet road with roadlights reflecting on the wet road. Or like a sunset, just that you can get close to the "sun".

Now, in the vertex shader I have implemented this both from a world space point of view and an eye space point of view.

With worldspace I mean that just the various shapes are transformed into their positions in the world. It is in worldspace that I for example decided where the lightsource should be. (-3, 1, 0) and then I created a mesh from (0,0,0) extending in pos x and negative y. Translated the mesh (-3, 0, 0) so that the light is just above the corner of the mesh. The I fly of to the opposite corner (like pos x, neg z) to watch the reflections.

With eye space I mean that I have transformed worldspace to eye space with the View matrix which is my transposed camera matrix. (modelviewmatrix = viewmatrix * modelmatrix).

In worldspace I need to pass in the players position to do the reflection calculations. Other than that it's pretty neat to work in this space. I prefer this way.

However in eye space I can just check against the normalized negative vertex position in eye space. But instead I need to transform the lightposition from worldspace to eye space.

/p

thokra
12-11-2011, 01:57 AM
Mathematically it's not important in which space you do you calculations, as long as your only using entities from the same space.

If there aren't any performance implications when doing your math in a specific space you already gave the answer yourself: It's a matter of preferrence. In many cases I like world space better as well. Just remember the golden rule: Don't throw entities from different spaces together when doing calculations which require them to be in the same space.

PeTeAR
12-11-2011, 06:09 AM
Thanks for the answer, being new to opengl you sometimes wonder if you are doing things right or if there are other and/or better ways. Reading books don't give you all, puzzling together pieces is a process of questioning and trying. Sometimes you just need to verify your findings...and a forum is great for that :-)