Search Unity

Texture infinite zoom

Discussion in 'Shaders' started by RazorPudding, Sep 1, 2017.

  1. RazorPudding

    RazorPudding

    Joined:
    Sep 1, 2017
    Posts:
    8
    Hi,

    I'm new to shaders and having trouble with one that I'm sure must be quite simple. I want a texture that grows from the center continually, half my problem is I don't know what to call this, so it's hard to google it.

    Here's a video of a similar the effect, only difference is I want it to go outwards.


    This is what I was trying, but this just zooms out, I expected % to make it loop, but clearly I was wrong
    Code (csharp):
    1.     float4 color = tex2D(TextureSampler, input.TexCoords) * input.Color;
    2.     float2 center = float2(.5, .5);
    3.     Zoom = (AutoZoom * Time);
    4.     float2 deltaCenter = center - input.TexCoords;
    5.     float2 patternCoords = float2((center.x + (deltaCenter.x * Zoom)) % 1, (center.y + (deltaCenter.y * Zoom)) % 1);
    6.     float4 color2 = tex2D(PatternTextureSampler, patternCoords);
    7.     color2 *= color.a;
    8.     color += color2 * Intensity;
    9.     return color;
    Any guidance would be greatly appreciated.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    This particular effect is a little more complicated than you're thinking it is. It's not so much zooming in on the texture over and over, though with some careful texture work it could be done.

    What it's doing is called a tunnel or warp shader. It's calculating the inside surface of an infinitely long cylinder and mapping a texture to that. The amount of code you need for that isn't too much, but it is more complicated than just scaling a texture up. :)

    http://adrianboeing.blogspot.com/2011/01/webgl-tunnel-effect-explained.html?m=1
     
    Last edited: Sep 1, 2017
  3. RazorPudding

    RazorPudding

    Joined:
    Sep 1, 2017
    Posts:
    8
    Oh wow, I wasn't even close :)

    Thanks a lot, the code you linked worked out great.