Sign in to follow this  
McZ

Material/shader question (again)

Recommended Posts

I have written a version of the material shader implementation that dynamicly resolves the shaders using a bit-field to describe the material of the chunk, this way I can build different render path using a few set of shaders.. but my problem is that I can't figure out a way to setup a multipass render-chain.. for example shadowing if I havn't understand it wrong shadowing works something like this ( well I'm certain there exist different ways ) Pass 1 - render shadow volumes to stencil Pass 2 - render diffuse and specular lights to un-shadowed areas (using stencil test) Pass 3 - render textures and blend them with the previous pass in my engine the above would resolve a ShadowShader, LightingShader and a TextureShader.. when they are resolved I query them for the passes they need, the problem is that I can't figure out a way to know that the Lighting shader is supposed to go in pass 2 and texture shader in pass 3 when they normaly will go in pass 1 when there are no shadowing

Share this post


Link to post
Share on other sites
Quote:
Original post by McZ
I have written a version of the material shader implementation that dynamicly resolves the shaders using a bit-field to describe the material of the chunk, this way I can build different render path using a few set of shaders..

but my problem is that I can't figure out a way to setup a multipass render-chain.. for example shadowing

if I havn't understand it wrong shadowing works something like this ( well I'm certain there exist different ways )

Pass 1 - render shadow volumes to stencil
Pass 2 - render diffuse and specular lights to un-shadowed areas (using stencil test)
Pass 3 - render textures and blend them with the previous pass


in my engine the above would resolve a ShadowShader, LightingShader and a TextureShader.. when they are resolved I query them for the passes they need, the problem is that I can't figure out a way to know that the Lighting shader is supposed to go in pass 2 and texture shader in pass 3 when they normaly will go in pass 1 when there are no shadowing



I have a system that is loosely based on that thread, some parts are quite different (what defines effects and SPGCs etc) but the dynamically linking and multipasses are very similar. Each of my shader classes has a function 'GetShaderPass' which would return 'RPASS_MAIN, RPASS_PREPROCESS, RPASS_RECURSEREFLECT, etc' then using that the shaders are ran in the correct passes (in the correct order).

Even if i dont have any preprocess shaders active the pass is still there (in the queue, just a list), divided up the same way as Yann described. What goes into those lists is resolved by the scenegraph (visible stuff and shaders used to render them).

So when it comes time to render i do (there are more passes), btw just as in Yanns thread :D

RenderPass(RPASS_PREPROCESS);
RenderPAss(RPASS_RECURSE_...);
RenderPass(RPASS_MAIN);
RenderPass(RPASS_POSTPROCESS);
...


As for the other problem that you may be experiencing about if two bounced passes are both to be done in the main pass then which goes first. Well in my case i just assume that if an effect requires a bounce to another shader then that shader will have to be ran before it. There is probably a better solution but it works in my case.


Hope that helped

Share this post


Link to post
Share on other sites
and you don't have to put each group sequentially.

for example, have a 'PreProcess' stage at 0, a 'Main' stage at 64, and a 'PostProcess' stage at 128.

now, for three seperate passes that you know should be rendered in a specific order (but you still want rendered in the main stage) you'd do:

Pass 1 - Stage: Main
Pass 2 - Stage: Main + 1
Pass 3 - Stage: Main + 2

and they'll still be sorted after the preprocess stage, and before the postprocess stage, but be rendered in the correct order.

Share this post


Link to post
Share on other sites
if i understood this correct you have 3 passes by default and query the shaders pass configuration for the corresponding pass?

let me give you a example of how i have done it

texture -> associated with a .shader file just as it s in q3

cull everything->sort by texture no need to sort by shader since a texture will always have the same shader associated with it

-> render the rendermeshlist
in the rendermeshlist all the meshes are sorted by texture so i have only a single bind texture call to render everything

check if a mesh has more then x lights and decide if you need multiple passes if so set up for multiple passes and change states when needed

since i am using perpixellighting a lot and have the gf6800 as target system i make use of dynamic branching in the pixel and vertex shader

Share this post


Link to post
Share on other sites
I havn't built my shadersystem to be dependent on any effects I dynamicly choose the shaders depending on the material format

my shaders are built so that a mesh almost always resolves more than one shader a textured and lit mesh would resolve two shaders one to enable the textures and another to set up the lights.. this way I can use the same lighting shader whenever an object is lit regardless of the other.. so when I have a textured and lite mesh the both shaders will fall into the same pass and it doesn't mather if one is enabled before the other in this case..

BUT in some cases I want that the lighting shader and the texture shader should go into different passes, this I don't know how I could fix.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this