Jump to content
  • Advertisement
Sign in to follow this  
cherryyosh

Adding shaders to deferred rendering

This topic is 3408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been working on a deferred render for a while now and am now at the point where I can start adding multipul shaders. Currently I have a parallex shader I wish to add, but the questin is how? I could do a forward render based approach, either by rendering the objects last (think hwo you handle alpha objects), or rendering them first to the FBO. The issue with this is that using a large amount of of other shaders, as will most likly happen with the bump mapping, this can cancel out the benifits of deferred rendering.. So how have others done this?

Share this post


Link to post
Share on other sites
Advertisement
From what I understand, the main benefit of deferred shading is that it allows you to defer the lighting, meaning normals, positions and colours of pixels only need to be calculated once. This means (to me) that first you render using your shaders, but calculating only normal, position and colour, then once your G-buffer is full, then you apply your lighting and other effects that can be applied using just the G-buffer info. So in your case the parallax shader would be applied to the geometry you are rendering into the G-buffer initially but with no lighting calculations, only calculating the normal, position and color.

Share this post


Link to post
Share on other sites
You could also have a look into light indexed rendering, which would allow you to combine deferred shading and forward rendering.

In a deferred shading approach you could also store a material id per fragment and defer execution of shaders until that fragment is shaded. With light indexed rendering you could apply your shaders normally and use some z-only pass to reduce overdraw and execution of expensive shaders.

Share this post


Link to post
Share on other sites
Quote:
Original post by bluntman
From what I understand, the main benefit of deferred shading is that it allows you to defer the lighting, meaning normals, positions and colours of pixels only need to be calculated once. This means (to me) that first you render using your shaders, but calculating only normal, position and colour, then once your G-buffer is full, then you apply your lighting and other effects that can be applied using just the G-buffer info. So in your case the parallax shader would be applied to the geometry you are rendering into the G-buffer initially but with no lighting calculations, only calculating the normal, position and color.


So according to you I would need to use a forwards based (rending everything with the given shaders ) first. While this does make since, it seems like there should be a better way to do this, perhaps something like a stencil buffer with a bitwise setting for what shaders should be used.. If no one else has any idea's, ill start experimenting with ways and ideas to speed this up, because the main benefit of a deferred method is the fact that I only run expensive shaders on visible pixels..

Share this post


Link to post
Share on other sites
Quote:
Original post by cherryyosh
If no one else has any idea's, ill start experimenting with ways and ideas to speed this up, because the main benefit of a deferred method is the fact that I only run expensive shaders on visible pixels..
The depth-prepass takes care of that. Typically you don't perform any shading during the depth-prepass.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by cherryyosh
If no one else has any idea's, ill start experimenting with ways and ideas to speed this up, because the main benefit of a deferred method is the fact that I only run expensive shaders on visible pixels..
The depth-prepass takes care of that. Typically you don't perform any shading during the depth-prepass.


Does the depth prepass work on everything, IE. the whole scene is rendered to the depth before being rendered. My understanding, although most likely flawed, is that it it draws each object as it comes, filtering out the ones that fail the depth test. This is rather then batching all the drawing untill it knows the scene is complete to filter out everything based on the depth and run the shaders.

Share this post


Link to post
Share on other sites
Depth prepass means you render all opaque objects without shaders or very limited shaders (e.g. for skinning), generally no textures (expect maybe alpha maps for alpha testing), no color writes etc. It's much like drawing the depth buffer for a shadow map and with all the expensive stuff disabled the GPU really excels on that.

After the depth prepass you render the scene normally. Depth testing now cancels out every not visible fragment (except those of transparent objects) and thus only calls expensive shaders where necessary.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
Depth prepass means you render all opaque objects without shaders or very limited shaders (e.g. for skinning), generally no textures (expect maybe alpha maps for alpha testing), no color writes etc. It's much like drawing the depth buffer for a shadow map and with all the expensive stuff disabled the GPU really excels on that.

After the depth prepass you render the scene normally. Depth testing now cancels out every not visible fragment (except those of transparent objects) and thus only calls expensive shaders where necessary.


This is great information, thanks so much. I am guessing using this method I will need to modify the other codes so that they write to the GBuffer, in this way the offsets for the bump maps are stored. Or is there still a better way to do it?

Share this post


Link to post
Share on other sites
Sorry I have to raise this. but my question still stands. How can I use this to do things such as bump mapping. when Creating the gbuffer will override anything I do. Do I simply need to coustom create all my shaders to run on a 'frist pass' where it writes everything to to gbuffer after doing the depth prepass?

Share this post


Link to post
Share on other sites
I guess you mean altering the fragments' depth in your shaders. Well that should be done in your depth prepass. You should, however, analyze your application whether you'll really need a depth prepass or just use the gbuffer, deferring execution of expensive shaders. You then would have to render a fullscreen quad using a so called uber-shader which gets a fragment's material id and executes the corresponding shader part.

Keep in mind that if you output depth in your depth prepass the GPU won't be as fast. The acceleration of the depth pass only works if you meet certain constraints (for example no color writes, no stencil writes etc.).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!