Anyone more then me interested in this?
I am using this code in the grass/tree system. It renders all grass geometry in only one pass. The shaders does lots of non light-related stuff as well (like moving verts around etc.) so I kind of need it.
It works just like regular single-pass but ambient lights does not pollute the list, and there’s a variable so you don’t have to iterate over all four lights inside the shaders (when there are less then four non-ambient lights in the list it’s filled up with empty lights normally to reach 4).
Btw. if you don’t know what this is, or what’s going on, then you probably don’t need this stuff so its no loss.
A minimal matdef:
MaterialDef My MaterialDef {
MaterialParameters {
Int NumLights
}
Technique {
LightMode SinglePass
VertexShader GLSL100: Blablabla.vert
FragmentShader GLSL100: Blablabla.frag
Defines {
NUM_LIGHTS : NumLights
}
}
}
Shader stuff:
...
uniform vec4 g_LightPosition[4];
uniform vec4 g_LightColor[4];
uniform vec4 g_LightDirection[4];
void main() {
for(int i = 0; i < NUM_LIGHTS; i++){
// light stuff
}
...
}
The material class just has to override updateLightListUniforms.
The material class:
http://pastebin.com/7MgBZQde
Its still a work in progress but it looks pretty good so far. Gonna keep an updated version in the forester lib anyways and notify when its changed.