Search Unity

World Position Smoothed Out

Discussion in 'Shaders' started by Drommedhar, Aug 5, 2016.

  1. Drommedhar

    Drommedhar

    Joined:
    Sep 24, 2013
    Posts:
    78
    Hi guys,

    I hope someone here can help me out (it's really the first time for me creating complex shader in Unity with Shaderforge).
    I used to work in UE4 for some time already and wanted to create some shader in Unity. But unfortunately I'm currently stuck with a big problem.
    I need to use the Absolute World Position inside the shader. I already figured out that the Coordinates in Unity are colored differently then in UE4 and that the direction is also inverted. I'm fine with that.
    But this is how the world position looks in UE4:


    And this is what I get in Unity 5.4:

    As you can see, they are completely smoothed out and even sometimes not really at the place they should be.
    Because of that a lot of stuff I try to do with them is just bugging like crazy.
    Is there a way in Unity to get "Hard Edged" data on a mesh like in UE4?

    Thanks in advance for your help.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    It looks to me like the UE shader is grabbing the world position of the object and uses that same position for every pixel's color calculation, while the unity shader is grabbing the world space position per-pixel (or maybe per-vertex and it gets interpolated by the rasterizer), therefore calculating the color of each pixel separately.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    The value you were getting from Unreal wasn't "hard edged", it was just at a different scale. If you zoom in really close to your box at the transitions in Unreal it'll be just as smooth as Unity. What you're seeing in Unreal is the position values totally blown out.

    If you multiply the world position by 100 or 200 you'll probably get something that looks pretty close to Unreal.
     
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    They are smooth because position are continuous aren't they? I mean if that UE4 is world position then all these point in the flat color should be at the same position (the color value) which obviously they aren't ...
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    A standard Unity box is 1 unit wide, so the "world position" range for a centered cube is -0.5 to 0.5. The standard Unreal box I think is either 128 or 256 units wide, so a range of at least -64 to 64. When you render world position directly any value > 1 is just going to get clamped to the maximum display brightness of 1, and minimum of 0, so it just looks like solid colors. Since the standard Unity cube doesn't even reach 1 unit distance it has a smooth gradient from 0 to 0.5 visible, where the Unreal cube is going from zero to >1 within the first two pixels and getting clamped.
     
    neoshaman likes this.
  6. Drommedhar

    Drommedhar

    Joined:
    Sep 24, 2013
    Posts:
    78
    Thanks for your info. Good to know about that. I knew there was more to it than I thought ^^