Shader system approach
I arrived at the point that creating a good shader system in my engine is unevitable.
After quite some thinking i found/ thought of a few approaches.
Today
- defined an effect id to each mesh instance
- all effects include exactly the same lighting equations
(quite flexible though, including up to 3 drectional and 16 point lights in one pass, depending on sm2.0 or 3.0, read from my own scene file format)
- i'm also at the point of creating a grid for spatial culling (sort of quadtree in my scenegraph).
That way i only pass pont lights to the effect/shader if they have effect within the 'active node'/ frustum.
- my rendering function using scenegraph, now loops through: effects, materials, meshes, meshinstances
The decision on my shader system probably will affect this.
- i'm aware of deferred renderg but first want to 'master' this without
Scenario 1:
- separate lighting from other effects and create 1 generic and flexible lighting shader
(few variants based on input in my scene file format and the available shader model).
This effect includes materials, ambient lighting, directional lighting, point lights, transformations, single texturemapping, an opaque and a blended technique
- additional effects which can be used on mesh instance level, read from scene file format
Scenario 2:
- same as 1 but additional effects are on material level (might be to complex because a material isn't that big a part of the effect
Scenario 3:
- keep it as is today
- create my own engine's semantics list and do lighting through all the different effects if semantics exist
Scenario 4:
Other solutions?
This all basically comes down to the question, is it performance wise vs flexibility, worthwhile to go through the whole visible scene with more then one effect? (for meshinstances or materials that need something else then the lighting of the scene)
All advice is really appreciated.
Which one sounds best to you? Any of your approaches sound like they will work, so it is just a matter of what you want your engine to be able to do. I put a premium on flexibility, with performance and usability coming next (in a tie). But it sounds like you want to build the system for a specific lighting scheme, so flexibility probably isn't that important for your stated requirements.
Hi Jason, thank for the reply.
Personally I'd say scenario one achieves all I need;
- have a generic lighting scheme/ shader which does all 'the basics' including lighting/ single texturing/ material etc..
This way when implementing 'nicer'/'better' lighting I don't need to change a lot of effects/shaders.
- for the lower number of mesh instances I can then use another effect for 'special effects'
The only thing I'm not sure of, is if this approach wil 'kill' performance, by executing multiple effect files on specific meshinstances during rendering.
Unfortunately there is no good answer to that question. No matter how you architect your engine, there is always the possibility that a particular scene can wipe out performance - even the big boys like iD and Unreal and Crytek all have their limitations. That was why I was emphasizing the 'is it what you want' part of the question, since you will probably implement this and later on discover that there are some improvements or updates that you want to make.
I have been adding to my engine for well over 10 years now, with no end in sight :)