Renderqueue / shader system design question

Started by
5 comments, last by cozzie 10 years, 2 months ago
Hi,
Say you have the following contents in a 3d scene/ level:

- x meshes
- y mesh instances of x
- z renderables, being submeshes of x/y
- a unique materials
- shared over the x meshes and used by the z renderables
- of a materials, b of them have alpha maps/ need blending

- I have a different shader / set of states for the materials with/ without alpha maps.

My questions:
- how would you sort out not blended and blended, by material or by renderable?
(by material would mean lots of complexity and switching vertex/indexbuffers a lot for meshes that have both rederables opaque and blended)
- with todays hardware, would you have 2 different shaders or simply set renderstates when you encounter the materials with alpha map and branch in the shader, to only use alphamap if some parameter per material says yes or no? (difficult to tell unless I add some custom vaue, not in my current X file meshes, exprted from max
- or even a step further, just don't distinguish and keep blending enabled always and only use the alpha map if its set as texture in the stage (downside would be that I have to find a way to sort renderables back to front which use materials with alpha map/blending)
- probably it's a good idea to sort the materials to all opaque first and then the ones with blending/ alpha map

Any input is appreciated

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

Draw opaque from close to far to maximize use of the depth buffer's quad tree optimizations since the pixels are the bottleneck unless you have thousands of tiny items.

Take a copy of the depth buffer if you want to support deep particles.

Then draw alpha filtered from far to close with depth writing disabled to show each layer.

Thanks. How would you sort then, based on materials or based on renderables?
My idea now is:

- 2 arrays with material id's, one opaque and one blended
- for each opaque material sort all renderables front to back and draw
- for each blended material sort all renderables back to front and draw
- find an efficient way of doing this without having to switch meshes/ buffers more then needed

If I do this I can switch between the 2 shaders after opaque is finished and set the corresponding states. Only thing I have to figure out is which material is blended/ uses an alphamap (from the source, export from max). Maybe I can abuse a specific emissive color to mark blended = yes and then in the blended/ alphamap shader, don't use emissive in the lighting calculations? This might be a bit tricky, but no high risk.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I only sort by instances since anything advanced will just move the bottleneck to the CPU.

I use one opaque/alpha flag for the whole model and design with separate instances. This is not a problem since it is mostly particles and breakable windows that use alpha filtering.

I once tried removing the code that changed textures and the framerate did not change at all.

Ok clear. That's what I do today but with one downside:

1. I design a scene in 3ds max, containing for example 80 subobjects/ objects
2. Within them 5 of them are blended/ useapha blended textures
3. I know have to make several exports of the scene to distinguish the subobjects that need to be marked as blended

I could solve this by making/ using another mesh format, but I think this will not solve it. Now I think of it, I could simply export the whole scene twice, one for opaque and one for blended. I can use max group filters to hide one of the 2 groups easily and not include them in the export. Then my renderqueue sorts all submeshes like it does today, per mesh. For blended I already sort back to front, I can add front to back for the opaque renderables. That way a specific material is not perse opaque or blended, but only if the object/ renderable that uses the material, is.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Try to normalize your collection of istances to the first normal form without sub objects so that they can be easily sorted as one list. Design many models in separate files and place them in a level editor to allow dynamic physics, multiple detail levels and easy reuse of models between games.

Thanks dawoodoz. Ideally I think your right. Up till know I didn't find the motivation to build a 3d level editor, where 3ds max fills in around half of what I need. I'll think about it.
Till know it's always pencil and paper, excel and notepad :)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement