Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

X and Y are inverted in UV coordinates?

Discussion in 'Shaders' started by DimitriX89, Feb 13, 2018.

  1. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    550
    Hello! Recently I've wanted to create a time-based effect in the shader:
    Code (CSharp):
    1.             float2 ScrollX = (0.5,fmod(_Time.y,1));
    2.             fixed4 emissionGrd = tex2D (_EmissionGradient, ScrollX);
    (to advance the horizontal coordinate of the gradient texture over time). It works, but for some reason the Y axis counts as horizontal for UV. Is it normal? Sorry if it is a noob question
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    That's not proper syntax for setting a float2... I'm not even entirely sure what that does.

    float2 ScrollX = float2(0.5, frac(_Time.y));
     
  3. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    550
    Ok makes sense. I should've defined float 2 (though somehow it didnt prevent the shader from running) and I had no idea that frac function exists. Fmod indeed would not help here. Thanks!