Saturday, 10 November 2012

Engines 0.8

So this week I got glsl lighting into the game. It took a while because everything in a glsl shader is relative to eye space (or something like that) and I want the light positions to be global. We exported lights in our scene from Maya so we wanted to be able to use those lights and not have to set their coordinates all over again.

Getting light positions of light entities in Ogre and then sending them to the shader isn't too hard once you know how to do it. Finding out how to do this takes a while though. I did it with this line of code:  "param_named_auto myLightPos light_position 0" when I call the vertex shader in my material file. "param_named_auto" means that you're grabbing a value that Ogre can automatically get for you (here is the list of ALL the variables it can give you http://www.ogre3d.org/docs/manual/manual_23.html#Program-Parameter-Specification ). I'm using "light_position" as the automatically named parameter that I want to get. I assign this value to the variable "myLightPos" in the glsl shader, and then tell it I want the position of light 0 (that's why there's a 0 at the end of that line of code. That's the light number).

I also found out how to pass several textures (a maximum of eight, I believe), to the shader. I did it through the material file.
My texture parameters in the shader are called tex0 and tex1. Then I make Ogre get the textures with "int 0" and "int 1". I think the number corresponds to the order the texture was added in. 

I wanted to get normal mapping to work but that took a bit more work and I'm not done yet. According to Dan, I need go pass in tangents and bitangents to the shader to be able to use the normal map I currently have for my spaceship. 

Apparently that ^ is a tangentspace normal map. That means that it's relative to the texture of the UVs of the object, not the object itself. It also means I need tangents to make it work. I never knew the blue normal maps we see are in fact not relative to the object. Apparently objectspace normal maps should have all sorts of different colours. That's neat. 

No comments:

Post a Comment