Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / shader "multipass" - how does it work?

Author
Message
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Aug 2013 12:29 Edited at: 12th Aug 2013 12:31
Hi. I have basic questions:
1. what does second pass (and following) in shader exactly? Does it renders whole scene for second time?
2. Why do we need alphablending? Can we just render the result from first pass (i.e. without alphablending)?
2a. What alphablending values (source and destination) do?
3. How it can be optimized in DBP?

"Just because you’re unique, doesn’t mean you’re useful"

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 12th Aug 2013 12:45
1. The same as the first pass: The shader is executed once for every visible object in the scene. Usually you use SET OBJECT MASK to separate objects from different passes. Most of the time, the second pass only renders a quad (a plain object) which is positioned in front of the camera and textured with the result of the last pass. This way, you can apply filters and stuff such as bloom or edge detect.

2. Alpha blending is used in cases such as fur, where you must render the object a lot of times and add the resulting images together (blend them).

2a. http://www.opengl.org/wiki/Blending#Source.2C_Destination.2C_and_the_buffer

3. We must summon GG to answer this one

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Aug 2013 13:23 Edited at: 12th Aug 2013 13:26
That's not exactly multipass you are talking about. SET OBJECT MASK separates cameras, not passes. And I meant alphablending in multipass only.



"Just because you’re unique, doesn’t mean you’re useful"

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2013 14:33 Edited at: 12th Aug 2013 14:52
In a shader a pass simply renders an object in the usual way. You might need alphablending to avoid the second pass simply overwriting the results of the first pass. Different passes can use different render targets so you can look up the results of an earlier pass in a later pass.

Quote: "And I meant alphablending in multipass only."


Multipass shaders only apply to the object or objects with that shader applied (which may or may not be a screen quad). Multipass shaders are used for a variety of reasons:

1. A single pass would consume too many instructions. This is less relevant with PS3 shaders but used to be necessary to apply things like specular reflection and bumpmapping from many lights using PS1/2. In this case you'd need additive alphablending so the extra light gets added to the results of previous passes. There are many other alphablending options and the best place to find out is the MS DX9 SDK.

2. You might want to use the results of the first pass to modify the second pass. An example of this is certain types of shadow rendering where the first pass gives you information about the shadow and later passes use that information. A good example of this is one of Bond1's planar shadow shaders. [Edit: I think that's not quite right - the first pass renders a flat object representing the object's shadow and the second renders the shadow casting object in the usual way. Will check and report back later.]

3. An extension of 2. is to use an intermediate render target in earlier passes. This can be useful for blur and bloom effects where you first render the scene and then blur it in later passes.

The last one needs to be used with caution as there's a bug in DBPro where the shader compiler erroneously assumes that all techniques have the same number of passes.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Aug 2013 14:49
@Green Gandalf
Quote: "You might want to use the results of the first pass to modify the second pass."

Yes, I want to make iamge blur with several passes to get it very smooth, so I don't need blending because following pass will use previous pass result only (screen quad). Could you please give an example?

"Just because you’re unique, doesn’t mean you’re useful"

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2013 14:55 Edited at: 12th Aug 2013 14:56
I'll try but must get on with something else right now. Do you want the whole scene to be blurred or just the one object, i.e. so its outline isn't blurred for example? In the first case a simpler solution is to use a fullscreen shader to blur the output from another camera.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 14th Aug 2013 13:24
Yes, fullscreen shader on a quad. So all objects will be excluded except the quad, what will boost perfomance when blurring.

"Just because you’re unique, doesn’t mean you’re useful"

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Aug 2013 13:30
OK.

Quote: "Yes, I want to make iamge blur with several passes to get it very smooth, so I don't need blending because following pass will use previous pass result only (screen quad). Could you please give an example?"


I'm sure I've got a demo lying around that does that as long as you don't need too many, or a variable number of, passes. I'll dig it out.



Powered by Free Banners
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Aug 2013 13:53
I've attached a zip file containing two old blur demos of mine. They both use multiple passes and you should be able to see how to widen the blur when you study the code. One of the demos shows you how to do the blurring in two steps, i.e. a horizontal pass followed by a vertical one (or vice versa ). This is faster than using a single pass - especially if you use a wide filter.

I'm currently working on a new version which will allow you to create very smooth blur of a scene or image by doing several renders with a simple blur filter. However I have to solve an irritating technical issue first - i.e. repeated blurring of an image using a narrow filter ceases to blur after a certain point. I'm fairly sure this is because each render gets RGB values rounded to their usual byte values so beyond a certain point the changes get lost. The solution is probably simple, i.e. use floating point image formats instead. Just haven't had time to study and implement that yet.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 14th Aug 2013 23:41
Thanks a lot, Green Gandalf! I'll take a look at it ASAP.

"Just because you’re unique, doesn’t mean you’re useful"

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2013 14:04
I believe I have finally worked out a way of getting arbitrarily wide blur widths very quickly using a shader. I hope to post a demo later this week - I'll probably start a new thread for it though. If so I'll link this to it.



Powered by Free Banners
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 19th Aug 2013 16:19
Thanks, Green Gandalf! I just have found some time to study shaders. It will take time, probably till you post the new one. Also, what do you think about starting a new shader pack? I mean many of advanced coders like you here have a plenty of short shader examples of this or that.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Aug 2013 02:01
@mr Handy

I've posted another blur demo on the following thread:

http://forum.thegamecreators.com/?m=forum_view&t=207333&b=1&msg=2481295#m2481295

That demo could probably be improved by combining the three separate renders into a single technique by using multiple passes. My original plan has changed because it was too slow for real-time rendering of an entire screen.



Powered by Free Banners
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Aug 2013 02:14
Quote: "My original plan has changed because it was too slow for real-time rendering of an entire screen."


2D FFT?

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Aug 2013 02:25
@Green Gandalf
Why it has several cameras?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Aug 2013 15:11
Quote: "Why it has several cameras?"


For ease of development - it kept the shader simple. When I've decided on the final method I'm going to use I can then see what optimisations are possible. For example, combining the three camera renders into a single render with three passes (horizontal blur, vertical blur, screen display) might be faster. Not sure till I try. For the moment though I'm concentrating on trying to get decent variable width blur at an acceptable speed.

One possibility which looks promising from some quick tests is to use a non-Gaussian blur as in this revised shader code:



The problem with that is that the width has to be hard coded into the various techniques - and the blur isn't as good as Gaussian blur. However after you've run the shader a few times on the same image it's as good as Gaussian blur (because of the central limit theorem). It might be faster still to use a simple box filter at the heart - again, after about 12 iterations, I'd expect that to look like Gaussian blur too for the same reason. I'm still getting speed issues though.

Such extreme blurs are probably fine though at the end of a scene when nothing much is happening and you just want something like a fade out combined with increasing blur.

If I understood the method sufficiently I could use TheComet's suggestion.



Powered by Free Banners

Login to post a reply

Server time is: 2026-07-07 01:53:56
Your offset time is: 2026-07-07 01:53:56