How to manage effects?

Started by
2 comments, last by RDragon1 14 years, 3 months ago
Hi, I'm relative new in 3D graphics programming and I'm confused how to manage effects. I want to give option to users that will use my api to add their own effects. I mean effect as combination of vertex/geometry/pixel shader and render states. My first (and absolutely wrong I think) idea was that I'd make a lot of "mega-über-shaders" that combine every possible combination of effects. For example "NormallMappingAmbientOcclusionDiffuseAndBumpMapping shader".:-D Of course, it's crap because there are so many possible combinations (and I'm not even talking about limited number of instructions in SM3). Further, users couldn't add their own effects because they'd have to rewrite every possible combination for their new effect. So, it's wrong. So, my second idea that could lead to goal is: One "normal" shader for one effect. In this case, I'd render scene several times with corresponding shaders. However, in this case I'd render scene too many times, wouldn't I? Suppose that I want to render scene that contains transparent and opaque objects with per-pixel lighting(normal mapping), diffuse texture and ambient occlusion. So render path would be something like: 1) render opaque objects with diffuse texture 2) same with transparent objects 3) normal mapping 4) ambient occlusion So I'd render scene four times. It's too many because there could be more effects, isn't it? How to manage this? I'd be very very thankful for your advices. Thank you!
Advertisement
Hi !

My two rules:

- avoid multipass with too many passes
- avoid single-pass too many instruction

But IMHO it all depends on what your engine is supposed to handle (how many dynamic lights? Transparent/Opaque objects? SSAO? Complex Material system?)

reading your post (and supposing you're using a modern/recent GPU) I think that deferred approach maybe the best way to proceed.



Regards,
Mauro


http://www.breakinglass.com

[Edited by - mauro78 on December 27, 2009 5:47:09 AM]
An interesting idea would be to use conditional compiling in your shaders and have a preprocess step in which you compile a specific shader for every user effect.
2+2=5, for big values of 2!
Note that some games do in fact auto-generate hundreds or thousands of shaders with different features enabled - it's not infeasible to take that approach, as long as its sufficiently automated

This topic is closed to new replies.

Advertisement