Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Shader system approach

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 cozzie   Members   -  Reputation: 2699


Posted 20 February 2013 - 03:22 PM

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.

- 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.


#2 Jason Z   Crossbones+   -  Reputation: 6062


Posted 20 February 2013 - 07:51 PM

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.

#3 cozzie   Members   -  Reputation: 2699


Posted 21 February 2013 - 05:19 AM

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.

#4 Jason Z   Crossbones+   -  Reputation: 6062


Posted 21 February 2013 - 05:52 AM

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 :)

#5 cozzie   Members   -  Reputation: 2699


Posted 21 February 2013 - 06:30 AM

Thanks, this really helps. I have to let go that I want to achieve the 'ultimate' situation (at once).

For now I'll go for scenario 1 because that achieves what I need now with high flexibility and 'relatively low' performance impact.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.