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
float4x4 WorldViewProj : WorldViewProjection;
float4x4 World : World;
float3 eyepos : CameraPosition;
float fTime : Time;
float STime : SinTime;
float distortSize
<
string UIWidget = "slider";
float UIMax = 0.2;
float UIMin = 0.0;
float UIStep = 0.001;
> = 0.05;
float distortSpeed
<
string UIWidget = "slider";
float UIMax = 0.4;
float UIMin = 0.0;
float UIStep = 0.001;
> = 0.1;
float Rotations
<
string UIWidget = "slider";
float UIMax = 5.0;
float UIMin = 0.0;
float UIStep = 0.001;
> = 0.05;
float Offset
<
string UIWidget = "slider";
float UIMax = 5.0;
float UIMin = 0.0;
float UIStep = 0.001;
> = 0.05;
float Normality
<
string UIWidget = "slider";
float UIMax = 25.0;
float UIMin = 0.0;
float UIStep = 0.001;
> = 0.05;
texture Background : DIFFUSE
<
string ResourceName = "";
string Type = "2D";
string Dynamic = "Background";
>;
sampler texture1 = sampler_state
{
Texture = <Background>;
MinFilter = Anisotropic;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
texture DistortTex : DIFFUSE
<
string ResourceName = "";
string Type = "2D";
>;
sampler distortSmp = sampler_state
{
Texture = <DistortTex>;
MinFilter = Anisotropic;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
AddressW = Wrap;
};
struct app_in
{
float4 pos : POSITION;
float3 uv : TEXCOORD0;
float4 normal :NORMAL;
};
struct vs_out
{
float4 pos : POSITION;
float3 uv : TEXCOORD0;
float4 projUV : TEXCOORD1;
float4 normal : TEXCOORD2;
float4 wpos : TEXCOORD3;
};
vs_out DefaultVertexShader( app_in IN )
{
vs_out OUT;
OUT.pos = mul( IN.pos, WorldViewProj );
OUT.wpos = mul (IN.pos, World);
OUT.uv = IN.uv;
OUT.normal=IN.normal;
OUT.projUV = float4( OUT.pos.x*0.5 + 0.5*OUT.pos.w, 0.5*OUT.pos.w - OUT.pos.y*0.5, OUT.pos.w, OUT.pos.w );
return OUT;
}
float4 DefaultPixelShader( vs_out IN ) : COLOR
{
//create an offset from the time and variable values
float2 offset = float2( sin(fTime*distortSpeed), cos(fTime*distortSpeed) );
//convert into 0-1 range
float3 uv = IN.projUV.xyz / IN.projUV.w;
float3 center = {IN.projUV.x, IN.projUV.y, IN.projUV.z};
center.y=IN.normal.y*Rotations-(atan(fTime)*Rotations);
center.x=IN.normal.x*Rotations-(sin(fTime-Offset)*Rotations);
center.z=IN.normal.z*Rotations-(cos(fTime-Offset)*Rotations);
float3 Center=mul(center, IN.wpos.xyz/Offset)*Normality;
uv = uv + (tex2D(distortSmp, Center ) - 0.5) * distortSize;
float4 UVRotation=(tex2D(texture1, uv));
return UVRotation;
}
technique MyShader
{
pass p0
{
VertexShader = compile vs_1_1 DefaultVertexShader( );
PixelShader = compile ps_2_0 DefaultPixelShader( );
}
}
Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
