locked
WormHole effect in directX and c# RRS feed

  • Question

  • I am trying to create an effect called wormhole effect. I am trying to achieve this using a shader file but i am not getting exact effect. Does anyone have any idea or any smple shader file which can help me.

    The effect looks something like this

    The shader file I am trying to improve is based on "Ripple" effect but I am not able to get that much smooth effect. I need to implement this effect urgently.

    /// <class>RippleTransitionEffect</class>

    /// <description>A transition effect </description>
    /// <summary>The amount(%) of the transition from first texture to the second texture. </summary>
    /// <minValue>0</minValue>
    /// <maxValue>1</maxValue>
    /// <defaultValue>0</defaultValue>
    float Progress : register(C0);

    sampler input : register(s0);

    texture Texture;
    sampler Texture2 = sampler_state
    {
        texture = <Texture>;
        magfilter = LINEAR;
        minfilter = LINEAR;
        mipfilter = LINEAR;
        AddressU = mirror;
        AddressV = mirror;
    };



    float4 Ripple(float2 uv,float progress)
    {
      float radius = progress *  0.75;
      float FuzzyAmount = 0.001;
      float2 CenterPoint = float2(0.5,0.5);
      float fromCenter = length((uv - CenterPoint) / float2(0.75, 1));
      float distFromCircle = fromCenter - radius;  

      float frequency = 10;
      float speed = 1;
      float amplitude = 0.005;

      float wave = cos(frequency * distFromCircle - speed * progress) + 2;
      float offset1 = progress * wave * amplitude;
      float offset2 = (1.0 - progress) * wave * amplitude;
      float2 normToUV = (uv - CenterPoint) / distFromCircle;
     
      float2 newUV1 = CenterPoint + normToUV * (distFromCircle + offset1);
      float2 newUV2 = CenterPoint + normToUV * (distFromCircle + offset2);

      float4 c1 = tex2D(Texture2, newUV1);
      float4 c2 = tex2D(input, newUV2);

      float p = saturate((distFromCircle + FuzzyAmount) / (1.0 * FuzzyAmount));
      return lerp(c1, c2, p );
    }


    float4 main(float2 tex: TEXCOORD) : COlOR
    {
      return Ripple(tex, Progress);
    }


    technique TransformTexture {
      pass P0     {        
        PixelShader  = compile ps_2_0 main();
      }
    }

    Any help will be of great value.

    Thanks.

    • Moved by Bob Shen Monday, May 7, 2012 2:32 AM XNA issue (From:Visual C# General)
    Thursday, April 19, 2012 11:12 AM

Answers