Materials / Lighting Types / Shading / Illumination

Hi

I’ve finally decided to mess around with lighting in the game project I have, but I’d like to ask for some advice from the people that have done this already. One of my main issues with reading existing code examples is breaking the light maths down in to its constituent components (examples seem to contain all three together), those being

  • Lighting Types (Point / Spot / Direction etc
  • Shading Types (Flat / Gourard etc
  • Illumination Types (Blinn Phong / Cook Torrance / Lambert / etc)

With the meta data being material information (ambient / diffuse / specular / shininess)

For this post I am not asking for examples of implementing the above, I can read up on that myself. What I would like some help on is working out the generic inputs to those component and the outputs of those components. Once I have this I can create a framework for plugging in the various lighting / shading / illumination types.

This is my current view on things

Light Type : - Inputs : Normals, Normal Matrix, Light Position
Outputs : ??
Shading Type - Inputs : ??
Outputs : ??
Illumination Type - Inputs : Material properties, ??
Outputs : Color

As you can see I don’t really know much ;D I think understanding the complete picture will make implementing the algorithms much easier.

Assuming you’re using OpenGL (You mentioned shading) the way for structuring lighting commonly falls under two methods: deferred shading and forward shading.

See the first answer here:

For forward rendering see: www.opengl-tutorial.org/beginners-tutorials/tutorial-8-basic-shading/
For deferred rendering see: http://www.codinglabs.net/tutorial_simple_def_rendering.aspx

Scene Graphs
As for how to structure it code-wise, people always say that scenegraphs break-down when doing ‘real game dev’ but I disagree! You should implement a scenegraph system in your game but DONT use it as an end all for entity systems. Instead use it as a sort of ‘render graph’, and JBullet for a ‘physics system’, then a real 3D entity system like Ashley for everything else. Every entity has access to the render graph and physics system so they can add / remove however they please but it’s never good practice to require them.

Structuring lights
Finally, you usually organize lights as scenegraph nodes and have their position + direction transformed by their parent’s just like any scenenode would inherit the transform of it’s parent.
There’s many ways of defining an object/models material properties, the material should consist of normal maps, ambient texture maps, specular maps, and many others. Usually it’s best to have each model define them before they’re rendered on their own.

Speeding up small, object lights
If you want to take it a step further you can add functionality where the light only renders it’s children, which is super cool to do if you want some nodes to only render on one object, like lights on a character.

Speeding up shadow maps:
Add two different root nodes, one for dynamic objects and one for the static objects. The dynamic objects are rendered to a low-res shadow map every frame for each light, and the static ones are only rendered every time there’s a change in the configuration of it’s child nodes.

I may have some old code laying around, PM me if you’d like some help with this as I’ve had a little experience with lighting stuffs.

Ecumene

Thanks, there is a lot of good information there. For the scene graph points, I am already using a scene graph for rendering and already have an idea for how to integrate light in to that. What you have said though does provoke some other thoughts which I will take in to consideration when I get to that phase.

You are correct in thinking I am going to use opengl, but my questions are implementation independent. At the moment I am less interested in how to do it, I want to understand what information in required for each component and what information comes out. Example lighting types would require light position and other similar properties depending on the actual type, is the resulting output an intensity value? Its this type of information I would like. I’ve read a fair bit but all the examples I see are complete solutions.