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 / simple warning about use of texture object

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2013 14:01
Some time ago I said this:

texture object stage 0 query

I spent a merry hour last night (well it was 1am ) trying to debug a simple shader demo. Looked at it afresh this morning and noticed I had this:



instead of this:



Well, as revenant chaos suggested on the above thread, texture object without the stage number does indeed clear the shader. So it looks like I finally answered my own question.

The moral of this story is probably: don't start a new technical demo after midnight.

The demo now works perfectly and with luck I'll soon have a nice new blur shader for mrHandy.



Powered by Free Banners
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 18th Aug 2013 22:13
I've been looking for a simple blur shader that just blurs the texture on texture 0. If you've got one to share then I'd give it a serious look.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2013 23:20
Quote: "a simple blur shader that just blurs the texture on texture 0"


I posted two simple blur shaders on mrHandy's multi pass thread. You could look at those till I get my new version finished.

The new one will allow you to specify the width of the blur and the blur will be performed using repeated steps of a narrower blur. This has to be done by rendering a blur camera a variable number of times - ideally I would use a variable number of passes in the shader but that ain't possible in DX9 as far as I know.

For example, the latest test version will do 200 camera blur renders of a sample 576x768 image in 96 ms on my laptop - and much faster on my PC. The blurring is done using a 13x13 Gaussian blur. All that remains to do are the extra UI trimmings.

Is that what you are after?



Powered by Free Banners
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Aug 2013 23:22
Quote: "texture object without the stage number does indeed clear the shader"

You just solved a big problem I was having with my Oculus shader code last night. Awesome!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2013 23:48
Must have been something in the drinking water last night.



Powered by Free Banners
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Aug 2013 09:52
Quote: "Is that what you are after?"

I'm looking to blur the screen during live play so that it is used as the background of my title menu. It just needs to be a fast blur effect. Details like being able transition the blur intensity are not necessary. Something that simply makes the texture blurry when rendered on a screen quad, and is better than merely dropping the resolution.

...
...

No I changed my mind. Being able to change the blur width is a good idea since I can use it to transition the blur instead of popping it on and off full blast. I have an idea to integrate character selection with the live background I mentioned above. It'll look better if the blur can be made to transition off gradually.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2013 12:30
OK. I'll see what I can do.

The method I'm using at the moment will be a compromise. For small blur widths I'll be using a repeated Gaussian blur. However for larger blur widths that becomes unwieldy as too many repetitions are needed so I'm switching to a mipmap based blur initially and then smoothing that using the Gaussian blur procedure. The main thing to fiddle with is to get a smooth transition between the two methods. For your application though I'll have to find a neat way of doing the same thing without mipmaps, perhaps using intermediate render targets as in some of the Dark Shader shaders. So, as usual, watch this space.

However, if you only want a small amount of variable blur then I don't need the complications of mipmaps, etc, so perhaps we could try that first? What do you think?



Powered by Free Banners
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Aug 2013 13:31
Well I'm grateful you'd consider actually tailoring a shader for me. I'd make every effort to get the fullest use out of it.

Quote: "However, if you only want a small amount of variable blur then I don't need the complications of mipmaps, etc, so perhaps we could try that first? What do you think?"

That's hard to say without some sort of reference. Probably a strong enough blur to turn a picture of a person into a color blob. Probably fairly strong then.

Quote: "The method I'm using at the moment will be a compromise. For small blur widths I'll be using a repeated Gaussian blur. However for larger blur widths that becomes unwieldy as too many repetitions are needed ..."

Well I think in this case something that is a wide blur width but maybe has variable intensity instead of variable width is best. Would prolly make a faster shader and simpler shader too.

Thanks.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Aug 2013 17:50
Just tried out your other shaders, still haven't had time to write them into my game. However I'm seeing this awful ghosted image effect, like double vision when the when the blur gets anywhere near a half decent width.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2013 18:34 Edited at: 22nd Aug 2013 12:15
Yes, that's the issue I'll be removing - the new version gives you real blur like this:



That used 200 iterations of a 13x13 Gaussian blur filter with standard deviation 2 (in this context I'll be calling the standard deviation the width - the overall width of the filter, i.e. 13 in this case, is larger as the weights gradually fade away from their central peak). The effective width of the blur is 20 in this example [20 = square root of (iterations x standard deviation)]. [Edit Ouch! Can't believe I wrote that. That formula should be effective width = square root of (iterations) x standard deviation which gives a value of about 28 not 20. ]

It takes 15 ms on my laptop with the NVidia GFX card enabled .



Powered by Free Banners

Attachments

Login to view attachments
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 22nd Aug 2013 05:24 Edited at: 22nd Aug 2013 05:25
That's about the upper limit of what I was shooting for, although I might dial it back myself 25-50%.
Do you have an ETA on this? No rush.
That's a slick dew you got.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2013 12:17
Quote: "That's about the upper limit of what I was shooting for, although I might dial it back myself 25-50%."


That simplifies things somewhat. I'll get on to it over the next day or so. The present version works on images rather than full-screen camera renders but the changes should be simple ...



Powered by Free Banners
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 22nd Aug 2013 13:17
Quote: "That simplifies things somewhat. I'll get on to it over the next day or so. The present version works on images rather than full-screen camera renders but the changes should be simple ..."

I'm sending camera 4 output to a screen quad on camera 0 with camera zero also drawing a 2d menu. So I should just be able to apply the shader to the screen quad and not the camera. I stole the screen quad function from evolved so it doesn't need a special shader to work. If anything allowing the shader on an object makes it more versatile.

I noticed you guys are using some sort of screen quad shader. Is there any benefit to that? I'll post a non-shader quad function in a little bit.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 22nd Aug 2013 13:56 Edited at: 22nd Aug 2013 13:58


I use these functions.

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Aug 2013 16:11 Edited at: 22nd Aug 2013 17:18
@ GG - For such extreme blurring calculations it would be far more efficient to implement a 2D fast fourier transform. The reason being image filters require a convolution in the spacial domain, where as in the frequency domain it's only a simple multiplication (i.e. your example could be reduced to requiring only 1 pass instead of 200 to achieve the same effect).

Page 21 - 29 in this document goes through the theory.
http://www.ati.com/developer/shaderx/ShaderX2_AdvancedImageProcessing.pdf

You can throw all sorts of other filters on top of the blur in the same pass without much fuss if you so desire. Doing a 2D FFT isn't exactly simple, but you would be able to reduce the pass count to about 60 (it takes around 30 passes to do the transform, 1 pass to do the blur, and around 30 passes to transform it back).

[EDIT] Here is a more in-depth explanation of how it works, though it's targeted for the CPU and not the GPU. It's still good to understand the theory: http://lodev.org/cgtutor/fourier.html

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2013 20:32
@TheComet

Thanks for that suggestion, I'll look into it. There probably comes a point where even a simple DBPro in-code wide blur using bitmaps or memblocks would be more efficient - but I haven't looked into that either. I was mainly interested in a pure GPU based method though so your suggestions sound useful.



Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2013 20:58
Just looking at your first reference now and there might be a snag in any DBPro implementation. On pages 22-23 it says:

Quote: "The first thing to note when using a GPU to implement an FFT based on the decimation in time algorithm is that, to maintain most of its efficiency improvements, the algorithm must be implemented in multiple passes by rendering to floating point temporary buffers. If the spatial domain image is color (i.e. has multiple channels) these temporary buffers will need to be set up as multiple render targets since the frequency domain representation of the image uses complex numbers thus doubling the number of channels on the output."


That could be awkward. Anyway, I still haven't finished digesting the method yet. I've been aware of the FFT for over 40 years () but have never actually used it (and still don't fully understand it ).



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Aug 2013 15:26
Hmm, you're right that is going to be quite awkward with conventional DBP methods.

You could use ImageKit. Use the command IK Create Render Target for creating targets for every channel required, then use IK Paste Image On Image, which allows you to run a pixel shader on a texture and paste the result into a render target.

I would assume you only need a total of 2 render targets, since the result of the 2D FFT is going to be 6 32-bit floats for every pixel.

I'm honestly surprised GPU's haven't yet implemented 2D FFT on a hardware level. All of these convolutions with 13x13 gaussian blur filters combined with multiple passes could be eliminated, greatly improving post-processing efficiency.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 17:10
Would you be interested in implementing the FFT method?

I've looked at those two links (and a few other references on my bookshelf here) and the method looks interesting. However, aside from the two render targets issue (which could probably be worked around) I've not been able to work out how to construct the indexing textures which seem to be required. I'm also unsure how the final inverse FFT is put together (the first link seems to omit all the essential information). Overall it would be a lot of work to get this up and running and I'm going to stick with my current approach which I do understand. But I'd be very pleased to be shown how simple the FFT method is to apply in DBPro.



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Aug 2013 17:28
Quote: "Would you be interested in implementing the FFT method?"


I am extremely interested in it, and I've written some image filter implementations without the GPU just to understand the method. The problem is:

Quote: "I'd be very pleased to be shown how simple the FFT method is to apply in DBPro. "


It's definitely not simple. And to boost, a parallel processing implementation is far less trivial than programming it on the CPU.

I'm also unsure of the payoff, because the transformations aren't exactly low-cost. You'd have to evaluate the speed of conventional methods vs the speed of doing 2D FFTs, and determine at what point it makes sense to use FFTs. Your extreme blurring example above would be one such case.

Quote: "I'm also unsure how the final inverse FFT is put together"


I could answer this question if you seek the single-threaded answer, but I haven't fully understood the butterfly algorithm yet, so I'm just as baffled as you.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 20:29
Quote: "I could answer this question if you seek the single-threaded answer, but I haven't fully understood the butterfly algorithm yet, so I'm just as baffled as you."


Sounds like we're in the same state on this one. I'd certainly like to see this implemented because it strikes me as a neat way of blurring - you just omit progresssively lower frequencies to increase the blur.

For the moment though I'm going to stick with what I understand - I usually get better results that way.



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Aug 2013 20:49 Edited at: 23rd Aug 2013 20:51
Quote: "For the moment though I'm going to stick with what I understand - I usually get better results that way."


That's the issue with shaders isn't it? That feeling when your screen is just BLACK and you have absolutely no idea why. No matter what you do or tweak, no matter how many hours you waste, no matter how much you simplify your shader code until you are trying to output a single colour to the screen, that pesky neon tube continues to tease you by lighting up pixels it doesn't have to, because they're all black.

...and then you notice you set the alpha channel to 0.0f.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 23:22
Painfully familiar.



Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Aug 2013 01:49
@Mage

I've had to modify my plans somewhat. The method I was thinking of using is probably too slow for a full-screen effect so it's back to the drawing board for me . Have you tried the one that comes with Dark Shader?

I've attached a simple demo which shows one way of gradually increasing the blur of a screen scene image. It needs the extra accuracy of the floating point image formats, otherwise the blurring ceases after a certain point because of rounding errors.

The present shader allows different amounts of blurring by simply varying the number of times you apply the blur and in the demo an extra blur is added each sync after you press the return key. To get a more satisfactory way of varying the blur I'll probably have to use something like the Dark Shader version - but I suspect it'll still be slow on a full-screen image.



Powered by Free Banners

Attachments

Login to view attachments
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 26th Aug 2013 23:16
Thanks lots, ill take a look at this tonight.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 27th Aug 2013 11:20 Edited at: 27th Aug 2013 11:24
This isn't gonna work. The blur isn't a live effect. The scene freezes as soon as the blur effect activates.
The idea is to have an animated background that has been blurred so that it doesn't clash with foreground menu elements.

To be specific I was thinking I could add a feature where the menu slides out of the way during character selection, and the blur effect transitions off while characters pop into the screen in some stylized form. If would work better if the blur didn't pop off 100% instantly for this, as a smooth transition would look better.

Performance: It's always a good thing but in this case the menu is running probably 20 objects/textures max. There's a lot of performance resources available, so something in the medium performance range could work here.

I was gonna slap a big paragraph about a bunch of stuff to try and explain further but instead I'll post a video.



It's pretty much a full and complete game. I don't normally post gameplay so I thought I'd tease a bit of that while I'm at it.

I uploaded in 1080p but it seems youtube made the quality suck. The intro menu has a blur effect in place. All I'm doing is overlapping a bunch of cameras to make it blur. This is a huge performance hit, and not nearly enough blur. Also FRAPS doesn't like this, gets confused, and it's caused that part to be a bit choppy. You'll notice the gameplay is a lot more fluid.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2013 12:49
Quote: "The blur isn't a live effect"


Yes, I know. You need to add some controls and code to vary the blur in real time. I'm still trying to find a method that gives you variable wide blur in real time at an acceptable fps. It ain't easy. The main problem is that whatever you do you're going to need the equivalent of several renders per screen sync and that's the cause of the slowdown. One option which I haven't tested yet is to switch to downsampling in the shader when the blur width is above a certain amount (a bit like using mipmaps). That might speed things up a bit but will still need some full screen blur added to avoid a blocky effect.



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Aug 2013 13:21 Edited at: 27th Aug 2013 13:22
Quote: "Yes, I know. You need to add some controls and code to vary the blur in real time. I'm still trying to find a method that gives you variable wide blur in real time at an acceptable fps."

I've written part of the 2D FFT implementation. My understanding of the butterfly algorithm still isn't quite complete, but I've been able to break down the DFT formula to reflect it (on paper), which means I can reverse it.

But...
Quote: "It ain't easy."



Doesn't downsampling the image and then stretching it over the entire screen cause a blur effect?

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2013 17:49
Quote: "Doesn't downsampling the image and then stretching it over the entire screen cause a blur effect?"


Yes. That was my point - but it produces a low resolution, rather blocky, blur. You still need to add some full resolution blur to make it look satisfactory. Then there's the issue of getting smooth transition from one blur width to another in real time which I think is one of the things Mage wants.

Quote: "I've written part of the 2D FFT implementation."


Well done. I'm looking forward to seeing the full implementation - and don't forget the blur width needs to be smoothly adjustable as well.



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Aug 2013 18:12 Edited at: 27th Aug 2013 18:14
Quote: "Yes. That was my point - but it produces a low resolution, rather blocky, blur. You still need to add some full resolution blur to make it look satisfactory."


Hmm, blocky you say? Isn't that a filtering issue? You need to "upsample" the downsampled image again with linear interpolation between each texel, then there shouldn't be any blocks. Granted it's not a true gaussian blur, but it's something.

Quote: "Well done. I'm looking forward to seeing the full implementation - and don't forget the blur width needs to be smoothly adjustable as well."


The workflow should look like this when it's complete (if it gets complete):
> Image --> 2D FFT --> FFToutput
> FFToutput --> [however many shaders you like] --> FFTinput
> FFTinput --> reverse 2D FFT --> final

I'm having some doubts about scalability as it stands, because the width and height of the input image changes the number of passes required, the scramble lookup textures, and the butterfly lookup textures, which means they need to be generated by DBP (or whatever host program using the shaders) whenever the screen size changes, and in the case of DBP's horrible implementation of objects, re-applied to all objects using the FFT shader.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2013 23:43
Quote: "Hmm, blocky you say? Isn't that a filtering issue? You need to "upsample" the downsampled image again with linear interpolation between each texel, then there shouldn't be any blocks."


I'll be convinced by a working demonstration. My suspicion though is that the standard linear filtering isn't sufficient to smooth out the blocks.



Powered by Free Banners
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 28th Aug 2013 00:13 Edited at: 28th Aug 2013 00:27
I wonder why you can't just make a big blur effect and merely weighting the final blurred pixel against the original source pixel in a linear manner using a 0.0 to 1.0 variable.

In principle this would act just like photoshop producing a blurred layer overtop the non-blurred image whose intensity is controlled by opacity.

In this case you should be able to mimic the effect.

Color = source * input + blurred * (1 - input)
Weighting the blurred pixel against the source pixel could look something like this. Where input is the blurr intensity variable that the DBP programmer can control. Source and blurred are the pixels. Color is the final weighted pixel.

I don't see anything wrong with this kind of blending. It should produce a sufficient transition able effect cutting a massive portion of the difficulty in designing the shader.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Aug 2013 00:28
Quote: "I wonder why you can't just make a big blur effect "


That is the problem.



Powered by Free Banners

Login to post a reply

Server time is: 2024-05-18 19:18:48
Your offset time is: 2024-05-18 19:18:48