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 / Help with adding aditable floats distortion shader?

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 14:17 Edited at: 10th Dec 2010 14:19
I'm hoping to edit the shader provided by Sven B with his image kit.

Basically I wanted to make it possible to scroll the distortion map "g_Map" by an editable float value so that the distortion can be moved in any direction (assuming it's a seemless image) to simulate water. Can anyone point me in the right direction?

*prays for the great Green Gandalf to magically appear with his mystical fraggle wisdom*

Here is the code from the shader:


I'll have some code to share if I ever get this stuff working!

I'm just trying to add an underwatery (real word?) effect to my Box2D game...

PS. could a MOD edit my stoopid spelling, it was meant to say "editable floats to a distortion shader"...

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 10th Dec 2010 16:01 Edited at: 10th Dec 2010 16:02
There are lots of ways you could do this.

Here's one way to do it with two floats (you could also use a vector):
-Add 2 variables at the top of the shader called "ScrollX" and "ScrollY" (or whatever else you want to call them)
ex.


-Use these variables to offset the distortion texture lookup (i.e. scroll the distortion texture by ScrollX,ScrollY):

So change this:


To this:


Then you would just use ImageKit's equivalent of SET EFFECT CONSTANT FLOAT to offset the texture in the X/Y directions from DBP. I haven't tested it but it should work. If not then GG can save the day


Guns, cinematics, stealth, items and more!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 16:17
Thanks a lot sixty! I'll put this code in.

I'm having some trouble with the shader anyway at the moment. I'm using it on a 2D scene and it works fine using the "Spiral" technique but not at all using the "Mapped" technique. Now I know the shader works normally using the Mapped technique because the Image Kit demo uses it but I can't get it to work on my scene no matter what I do!!

I've gone through the demo loads of times and can't see where I'm going wrong. Any ideas why it might work for one technique and not the other for a 2D scene anyone?

Here's my 'semi'-working setup code:


...and for displaying it:


Here's the spiral technique:


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2010 16:46 Edited at: 10th Dec 2010 16:49
[Edit Forgot to refresh before posting - cat was sick on carpet while I was composing this . Hence the delay.]

Your mirror is working well these days.

If I've understood you correctly you can simply change this bit



to something like this:



where you'll also need the following extra declarations among the declarations at the top of the shader code:



The distortion map sampler will also need to be changed to allow wrapping instead of clamping (was clamping really intended in the original shader?), i.e. change



to this



You'll need to experiment with the uvScrollSpeed values - values of 2, for example, will mean the distort texture scrolls twice per second. DBPro recognizes the Time semantic and passes elapsed time in seconds to the shader - in theory at least, i.e. it doesn't on my laptop for some obscure reason .

Well, that was my first thought anyway.

A slightly more efficient solution might be to do the multiplication by time in DBPro itself and just use



I'm assuming you know how to change the "tweakables" via DBPro.

[Health warning: suggestions untested. ]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 16:57
Thanks GG!

That's a nice way of doing it. I'll probably try the last version and deal with time in DBP.

Quote: "I'm assuming you know how to change the "tweakables" via DBPro."

Yes, thanks. I'm using Sven B's Image Kit so I'm not using the DBP commands.

Sorry to hear about your cat! Catsick is one of the worst kinds of sick...

Any idea why it might not be working in the "Mapped" technique when it does work for "Spiral"?

PS. I polish the mirror every day... (plus I get the impression you spend at least as much time on these forums as I do!)

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2010 17:12
Cat's been put out now so I can think in peace.

Quote: "Any idea why it might not be working in the "Mapped" technique when it does work for "Spiral"?"


Not quite sure what you mean by "it". The original shader or the edited one - and Sixty Squares edits or mine? What exactly doesn't work? Doesn't compile, doesn't scroll, or doesn't do something else?

Quote: "plus I get the impression you spend at least as much time on these forums as I do"


Yes - I'm still using my September leg injury as an excuse.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 17:26
Quote: "Not quite sure what you mean by "it". The original shader or the edited one - and Sixty Squares edits or mine? What exactly doesn't work? Doesn't compile, doesn't scroll, or doesn't do something else?"

When using the original shader I get the image I posted earlier using "Spiral" technique, but when I use the "Mapped" technique I don't get any noticeable change to the image.

It should edit the image like this:


baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 17:42 Edited at: 10th Dec 2010 17:42
OK my mistake! I wasn't getting an error from "load image" and was trying to load the map from the wrong place!

Here it is working!


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: 10th Dec 2010 17:46
Quote: "Here it is working!"


Which - the original? Good news anyway.

Quote: "I wasn't getting an error from "load image" and was trying to load the map from the wrong place!"


I think that may be a bug I reported a while back - you only get the error message for certain image types IIRC.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 17:50
Quote: "Which - the original?"

No a slightly edited version of yours. Still not scrolling yet though!

I'll play a bit more and let you know how it goes. Good to know we can use these commands to get fullscreen shaders working on 2D as well as 3D though!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2010 17:58
Quote: "Still not scrolling yet though!"


Quote: "I'll play a bit more and let you know how it goes."


OK - I'll continue to browse the forum for just a bit longer.

Quote: "Good to know we can use these commands to get fullscreen shaders working on 2D as well as 3D though!"


Yes indeed - perhaps it's time I looked at ImageKit.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 18:06
Eureka!!! It works!!!

I'll post a full working demo with all the code when I get the chance (tonight or over the weekend) but it's fantastic!!!

Thanks for all your help guys!

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 11th Dec 2010 22:09
Glad you've got it working


Guns, cinematics, stealth, items and more!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Dec 2010 14:22
I did a demo for this but Sven beat me to it with posting the code here:
http://forum.thegamecreators.com/?m=forum_view&t=177340&b=5

Login to post a reply

Server time is: 2024-04-24 07:55:13
Your offset time is: 2024-04-24 07:55:13