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 / Gaussian blur shader - can't make RenderColorTarget work

Author
Message
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 22nd Aug 2014 23:25
Hi,

I am trying to write a gaussian blur shader that performs two passes, each one performing a blur in a different direction. The output of the first blur is used as the input to the second blur by passing it to a RenderColorTarget. This is where this shader doesn't seem to work, and after several hours and many different variants, I can't see any mistakes. The shader compiles, the single pass technique (SingleBlur) works, but the double pass technique (DoubleBlur) doesn't return anything. I've never used RenderColorTarget before and the way I am using it seems to be consistent with other examples....if you can see what I am doing wrong here that would be really appreciated.



Many thanks,
GrumpyOne

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 22nd Aug 2014 23:44
Ah .... I see

It was my vertex shader not the render color target. The issue is I am transforming the input position twice (once in each pass).

Once again...hours staring at a bit of code convinced it must be the issue when the error lay elsewhere.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 22nd Aug 2014 23:57
Or maybe not.... changing the vertex shader doesn't help so again I am left with the rendercolortarget not passing the result of the first pass... very confusing.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 00:40 Edited at: 23rd Aug 2014 00:54
I've got a blur shader using that approach somewhere. I'll try to locate it so you can see how it works.

Edit Just found a very crude test shader which works. The important thing is that it shows one way of using rendercolortarget. I've added a comment to the shader file which might be relevant to your problem.



Powered by Free Banners

Attachments

Login to view attachments
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 00:45
Hmmm...puzzling....

Using the tried and tested debugging technique of "strip it back to basics and see if it works". The shader below does pass on the texture through the RenderColorTarget, although it does nothing else. Clearly there is something else wrong with my blur shader.



GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 01:01
Quote: "The shader below does pass on the texture through the RenderColorTarget, although it does nothing else."


A sceptic might say it isn't doing anything. In a case like that I would do something in each pass that would convince you each pass it actually doing something, e.g. remove red colour in the first pass, then remove blue in the second. If the output texture is green then you know each pass is actually working as intended.



Powered by Free Banners
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 01:09
Thanks GG, will try it.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 01:23
Hmmm...so texture data is definitely not being transferred from the first pass to the second pass via rendercolortarget. The shader below produces an entirely red object with no green that was generated in the first pass. For the life of me I can't see why rendercolortarget isn't working.



GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 01:31
Got it...silly, stupid poorly documented HLSL....

It seems that a texture set as a rendercolortarget must be declared in an HLSL shader before a texture applied to the mesh. The compiler doesn't generate a warning for this. The shader below works...compare with the one in the previous post.



GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 12:08
Scratch the last... still not working. What the example above does is load nothing into inputTexture and load the models texture to swapTexture. It looks like it is completely ignoring the declaration of swapTexture as RenderColorTarget.

Looks like there is some small, critical step in making a render color target work properly that i don't know. As far as I can tell my syntax is identical to example shaders that do work. I am at a complete loss.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 12:15
I'll take a closer look today. The rendercolortarget stuff is a bit picky but works nicely once everything is in place.



Powered by Free Banners
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 12:23
Cheers GG....I am going to force myself to do something else in the meantime...before I go doolally

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 13:14
Try the attached two pass blur shader. I think it is closer to what you're trying to do. It's loosely based on the blur shader that comes with Dark Shader.

It's intended for use as a full-screen shader and works if loaded as such into Dark Shader. It blurs in two passes - a horizontal pass and a vertical pass. This is faster than doing the same thing in a single pass.

Post back if you need sample DBPro code as well.



Powered by Free Banners

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 13:26
Here's a simple practice demo I created many moons ago when I started playing with this stuff.

Have fun.



Powered by Free Banners

Attachments

Login to view attachments
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 14:01
Hi GG,

You may have guessed why I am trying to do this, as a fast image blur. Texture an object with the image I want to blur, apply the shader, use the camera to grab the resulting image.

I think perhaps the issue with my shader is that all defined textures in the shader need to be declared as rendercolortarget. It may simply not be possible to get the texture from the object and pass it through a render target. All the examples I've seen using rendercolortarget so far are camera effects rather than object effects, and all textures in the hlsl are defined as rendercolortarget.

There is, however, probably a solution. I can always use a camera effect instead of an object effect it just means grabbing the final image in a different way. However, your examples will prove useful in this, so thanks very much.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 14:45 Edited at: 23rd Aug 2014 14:49
[Edit I wrote the following before I saw your last comment. Object shaders are indeed another kettle of fish. I'm going to have to do something else now but hopefully there's something in this example which you'll find helpful.]

I think I've fixed your initial shader. Here's the revised version with comments:



I think I've added comments to all the vital steps - but I have fiddled with a few irrelevant things as well which you can ignore like deleting redundant brackets.

These changes allow the shader to run correctly as a fullscreen shader in Dark Shader. If you are using your own screen quad or other object you may need to tweak the vertex shader again.

I've been unable to find decent documentation on things like the bits between < and > in the technique and pass sections of the code so I sympathise. The only way that works for me is to work from a shader which is known to work. Not ideal but there we are.



Powered by Free Banners
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 23rd Aug 2014 15:43
Thanks! I had just converted your blur shader to do the same

On thinking about it a camera effect may not be able to do what I want since it may limit the input and output to screen resolution. Since I'm using the shader as a processing tool for images this isn't appropriate. Instead i might have to implement a single pass blur shader using a full 2D gaussian or a box blur. This will be slower, but I'm mainly interested in blurring faster than on the CPU so this won't be a problem.

Very much a pain that rendering to a target doesn't appear work with an object shader in DBPro. This may in fact be a show stopper for one of my projects.

Out of interest how does DBPro implement shaders? Is there some DLL somewhere that is an interface with direct x? I ask since XNA does seem to be able to use render targets in object shaders. I didn't realise the HLSL shaders were application dependent.

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 16:38
Quote: "Since I'm using the shader as a processing tool for images this isn't appropriate."


That's exactly what I've been doing recently - although I vaguely recall I gave up using intermediate render targets because of some complication that I can't now recall. Perhaps it was the same problem you're now having? Anyway, I've now refreshed my thoughts on this issue and I'll see if I can cook up a simple example.

Quote: "Very much a pain that rendering to a target doesn't appear work with an object shader in DBPro."


Don't give up on that quite yet. But it seems a depressingly familiar conclusion.

But, looking on the bright side, perhaps I've missed something?



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: 23rd Aug 2014 18:37 Edited at: 23rd Aug 2014 18:44
I've done a bit of experimenting and I'm having exactly the same problems you're describing.

What I ended up doing when I was playing with a blur shader was to split the two passes into two separate renders. That way you still get the speed benefit. It's just a bit messier because you have three images to play with.

You might like to look at the following thread where I made some progress with this approach. Not sure how I left things but if you really need this I could have another look. I think I called it sequential Gaussian blur and the basic idea was to successively blur the image by repeatedly applying the shader till you get the amount of blur you need. Probably not suitable for real time game play but might be useful if you're only after image processing.

sequential Gaussian blur discussed in this thread

Edit I think the demo is in my post dated 24th August 2013 on that thread.



Powered by Free Banners
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 24th Aug 2014 02:31
Thanks GG,

You've been a real help, now and many of your past posts. If you want any of the software listed below gratis let me know(support@hptware.co.uk).

Best,
gumpyone

GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2014 03:06
Thanks. I will.



Powered by Free Banners

Login to post a reply

Server time is: 2024-05-05 01:57:58
Your offset time is: 2024-05-05 01:57:58