I've got a load of source compiled and running with the from source engine I'm learning. Quite a big step for me all those static libraries, dynamincally linked libraries, a tonne of SIMD stuff that had to be commented out because it was in the wrong assembly format for my compiler (Intel whereas CB uses AT&T), pixel shader, vertex shaders etc....
Sure I've come a long way. Shoot I even know how most of it works. I printed off a load of paper copies of the source and I often nip out to local pubs for a coffee whilst having a read!
But I have hit a couple of snags in concept stuff. Mainly about what's really going on between the CPU, the RAM and the GPU and the RAM on the graphics card (not sure of proper terminology for this). That's for another thread though, this one is about shaders and lighting.
I've got the shaders to run and work. Have a look at their code, pretty simple as far as I know in shader talk:
Vertex Shader(vsh): vs.1.1 dcl_position0 v0 dcl_normal0 v3 dcl_texcoord0 v6 m4x4 oPos, v0, c0 mov oD0, c4 mov oT0, v6
The vsh does some stuff with the geometry and then moves the value stored in the constant register c4 into the output register oD0 which is then inputted into the psh. Whenever a function that affects the light is used it gets the value relating to light colour and intensity and loads it into the register c4. SetAmbientLight does this, for example.
Pixel Shader:(psh) ps.1.1 tex t0 mul r0, v0, t0
Here the value in v0 (which I assume is the received light data from the vsh) is multiplied with the texel and the final result stored in the psh output register r0. Ok fine.
BUT (you knew it was coming).....
The scene is blacker than the underside of a witch's boob on a moonless night. If I change the code for the psh to this:
Pixel Shader:(psh) ps.1.1 tex t0 add r0, v0, t0
... then all affected geometry becomes so bright you could hunt rabbits with them on a dark winter's evening.
So, obviously something odd is happening here. The original author's shaders produces scenes that are way too dark. Yet my own alterations produce scenes that are horribly bright, and cause very bad colour mixing between the ambient light and the texel colour. Like if for example I set ambient to 0.5f,0.5f,0.5f middle of teh road grey, then instead of the predominatly green appearance of the demo model (a green tank) showing through more strongly, it just has this awful painted grey appearance to it, rather like someone has just thrown a load of grey paint over it.
What is the proper method here? I just want to be able to nicely mimic with a shader what i've already achieved fine with the fixed function pipeline in the past. But I don't know the proper algorithm for lighting. The one I've made is bright but awful, the one the author made is horribly dark, even with ambient light set to max (1.0f,1.0f,1.0f).
I'd also rather not discuss point and directional lights just yet, although I have got these working well, but again I had to depart from the author's code as it was too dark. Furthermore the extra passes per light make things difficult so if possible I'd rather just talk about getting good ambient light working for now, thanks.
I'd appreciate any replies anyone can take the time to write. Seems to me good lighting it what makes a huge difference to the pleasure the eye feels when playing a game or looking at any rendered scene for that matter.