PDA

View Full Version : GLSL / HLSL Lighting Models



technomage
07-03-2007, 11:57 PM
Yet another question for anyone who has working with shaders.

I am implementing normal mapping in my engine, currently I am passing in my Light Position in world coordiantes, most of the shaders i have seen use eye coordinates for calculating the light direction.

mostly this is done via

GLSL


lightDir = (lightPosition - ecPosition).xyz


where ecPosition is the gl_Vertex transformed into eye space.

now, I have tried to transform my lightPosition into eye space by



ecLightPos = lightPosition * gl_ModelViewMatrix;


but this does not produce the result I am expecting, in fact it produces some weird results, the lights seem rotate as well.

I would rather not have to define my lights in eye coordinates in my app, but as an actual location in the world.


I hope this makes sense. Anyone got any tips or examples on this.

Oh as a side note, most of the example shaders don't deal with moving objects, they all seem to assume that an object is at 0,0,0

technomage
10-03-2007, 08:33 PM
Having read my own post it doesn't really make any sense :wink: .

I have been playing with GLSL the last few days and figured out that most of the demos assume the light position is in object space or the light direction is in object space ( depending on your lighting model), so I'm going to re do my shaders to use that same model and do some stuff on the client to transform the light postion into object space.

technomage
11-03-2007, 01:24 PM
Fixed the problem, turns out there was an issue with the way the normals were being passed to the renderer. :)

Some screen shots :)

http://www.infinitespace-online.net/images/screenshots/InfinitEngineOpengl4.png

http://www.infinitespace-online.net/images/screenshots/InfinitEngineOpengl5.png

http://www.infinitespace-online.net/images/screenshots/InfinitEngineOpengl6.png

savage
11-03-2007, 01:38 PM
very noise!

Traveler
11-03-2007, 02:16 PM
I'll second that!

NecroDOME
11-03-2007, 08:02 PM
nice work

WILL
11-03-2007, 10:48 PM
Very nice, Dean. ;)

Can't wait to see how your engine turns out.

Any time-frame for a public alpha/beta?

technomage
11-03-2007, 11:12 PM
not at the moment, since I started writting it, most of the work has been going into the kernel of the engine (window/input support, xml support loading images etc) and the renderer support (OpenGL and DirectX). I have only just got the shader system working, it still needs work on the directX side of things though. But there is no hardware vertex buffer support yet or Framebuffer support, but that is on the way (once I figure it out)

Then I need to add scene management in, then terrain and networking and physics ... the list goes on...and on ....and on :wink:

It's kinda interesting cos I'm learning move about OpenGL and at the same time learning about Direct3D too. :D That reminds me I'd better check it still compiles and runs under linux :)

technomage
11-03-2007, 11:13 PM
Another thing, this project has got me side tracked..... I should be working on my competition entry..shoud'nt I....