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 Help - Whirlpool

Author
Message
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 17th Nov 2010 20:06 Edited at: 17th Nov 2010 20:56
I was referred to post again here, so I am sorry for the double topic post.

I'm pretty proficient in coding, but not fluent enough to grasp how to create a whirlpool effect. I have a distorted background texture but I have no idea how to swirl a texture or if it has to be done with an external texture. So my question is: Can/would someone mind providing or explaining an example of swirling a texture?

I gather I can swirl the texture based on SinTime and the texture coordinates, but I need an example or some info on how it's done. I've searched around but to no avail.

-Oh, I apologize if this is in the wrong forum, but I wasn't sure.

EDIT-
So I can rotate an image... if you have Dark shader, use the Background as the "back ground" image and a distort texture. The whole thing swirls and distorts... now if I could get this to swirl from a point.



Alright, here is a ripple effect (it's simple) and I'm still messing around with the code a bit, so never mind my clutter... if you have Dark Shader, use a Dynamic Background image and a distort texture. I'm not looking for a ripple though... looking for a swirl. Here it is...


Mess around with the sliders/settings and see how it ripples. If any one can point me in the right direction with Swirling it, I will be most grateful!

-Daryn

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2010 22:48
If you say "Green Gandalf" five times in front of a mirror he'll appear and solve your shader problems (according to legend)...

Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 17th Nov 2010 23:28 Edited at: 17th Nov 2010 23:28
MIRROR - Green Gandalf, Green Gandalf, Green Gandalf, Green Gandalf, Green Gandalf!!!

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Nov 2010 00:05
Hi Master,

I am the GG of the mirror. What is your command?
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 18th Nov 2010 00:12
I have a distort texture mapped in a sin/cos/-sin fashion rippling the background - I am trying to swirl the uv coords to a center point (preferably the objects center.) How would I swirl the texture color output while keeping the image distorted to achieve a whirlpool?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Nov 2010 01:00
Here's my first stab at a whirlpool effect. I know it's not quite what you want but you might be able to adapt it.
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 18th Nov 2010 01:30
Well G.G., if you replace the background image in Dark shader with a texture and place a blank image for the distort texture, the second bit of code I posted is doing the same thing lol. I'm trying to swirl an image into another and then distort it. I can rotate the image and offset the distorted texture for waves... but the actual swirling is the tricky part.

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Nov 2010 02:29
I'll look at your version tomorrow. I missed that part of your post.

Quote: "but the actual swirling is the tricky part."


I'm somewhat confused - I thought that was what my demo was doing. Perhaps you mean something else. Maybe it'll be clear what you mean when I try your code.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Nov 2010 17:09
I've tried your shader and it already does the whirlpool effect.

If you need to centre the swirl perhaps you could adapt the one I posted - that gives you control of the centre of the whirl via the vector poolUVCentre.

Yours is a very nice effect but the code seems unnecessarily complicated to me. For example the code often calculates float3s or float4s even though only a float2 is needed (tex2D uses only the xy component of its UV argument).

I confess I'm still confused about what the problem is exactly.
French gui
22
Years of Service
User Offline
Joined: 11th May 2004
Location: France
Posted: 18th Nov 2010 18:42
Quote: "Hi Master,

I am the GG of the mirror. What is your command?"


Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 19th Nov 2010 01:42 Edited at: 19th Nov 2010 02:19
I said it was cluttered
Here is what I am trying not to do - and I don't mean to sound prudish okay so please don't take how I phrase this as such.

When you use sin and cos (and tan) the coordinates of the texture being "whirlpoolified" are off-centered from a point based on Y and X uv axis' (using your uvpoolcentre or otherwise... this would be 0.5 for both X and Y for the center of the object/texture)

When you distort the dynamic background image (or are using an image with enough detail to see what you're doing) and swirl the texture using the sin/cos method above, the uv coordinates don't twist and flow to the center, they obscure and distort the texture's image around the pool's center point (as specified.)

A simple example of this can be done in DBPro... just look up the example provided for sin(#) and cos(#).

This is a perfect circle in DBPro (Or the sin/cos in .FX fils):


To create a simple swirl I use in DBPro:


You'll then see that the whirlpool code you provided - as well as my terrible technique of shader writing only wraps the texture's uv coordinated in a polar fashion. It appears to swirl on one side as it distorts/changes the pixel arrangement/color, but then reunites on the opposing side... take a look again at yours or mine

To create a true swirl, we need to increment one value (sin and cos). I'll see what I can come up with - this is a true Black Hole shader though... by all means (none taurus)

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Nov 2010 17:39
If you're trying to pull the texture towards the centre at the same time then one approach might be to look up a point that's further out on the same radius - and to make that offset gradually increase with time. In other words use a texture lookup similar to the DBPro swirl code you've just given.

If you do that simultaneously along all radii from the centre then I suspect there's a problem - the overall scale of the texture will gradually get smaller so that eventually the whole screen is filled with the average colour of the base texture (assuming the texture is wrapped rather than clamped).

At the moment I'm not sure of the best method. Food for thought. I'll be interested to see what you come up with.

In the meantime your shader gives a very nice effect already.
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 19th Nov 2010 19:01 Edited at: 19th Nov 2010 19:31
Okay I ran into my first brick wall... luckily those are bricks and not solid steel...

when in 2D cos and sin divide an image's swirl. They work in union to swirl the DBPro code I provided. HOWEVER and unfortunately - in shaders, where objects are 3D, the texture coordinates don't opperate in the same manner. X is sin, Y is cos (or vise versa) so now I need to figure out a way to variate the axis' with sin and cos and increment based on a "swirl amount" (using a for(...; ...<...; ...++))

(I should say... because it's a 3d object with a 2d texture on it, sin and cos are 3d relative and not 2d relative. That means that sin operates on the X and Y axis and cos Z or vise versa. I'll need to flip the sin of x on one side of the object's texture to swirl it - which is why the previous strip of fx code has only polarized the uv coords and not swirled them.)

I'll post what I come up with

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Nov 2010 03:18
Quote: "when in 2D cos and sin divide an image's swirl. They work in union to swirl the DBPro code I provided. HOWEVER and unfortunately - in shaders, where objects are 3D, the texture coordinates don't opperate in the same manner. X is sin, Y is cos (or vise versa) so now I need to figure out a way to variate the axis' with sin and cos and increment based on a "swirl amount" (using a for(...; ...<...; ...++))"


I really don't know what your problem is here. I wondered why you were using 3 or 4 texture coordinates in your shader when you only need 2 for 2D textures.

You just apply exactly the same methods to the X and Y UV coordinates as you did in your DBPro code that you posted. Why complicate matters by introducing the third (or even fourth?)unnecesary dimension? Look at my shader - the texture coords are all 2D. Perhaps I've misunderstood what you're trying to do?

Login to post a reply

Server time is: 2026-07-21 12:51:05
Your offset time is: 2026-07-21 12:51:05