Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HDRP Custom Sky Shader

Discussion in 'High Definition Render Pipeline' started by TimDoesDev, Jan 14, 2021.

  1. TimDoesDev

    TimDoesDev

    Joined:
    Feb 23, 2018
    Posts:
    35
    Hi, I'm trying to adapt this shader from Harry Alisavakis to work with HDRP:
    https://halisavakis.com/my-take-on-shaders-sky-shader/

    I've created a custom sky and all those requirements but I cannot get the actual shader to work.
    I tried to simplify the shader to only use a gradient and nothing else but it also didn't work.

    I then tried to convert the simplified version to HLSL and to look similar to how the HDRP Gradient sky is working but keeping the math from Harrys shader. This also didn't work and resulted in only the bottom gradient being shown.

    I tried to convert and only use this part of the fragment shader from Harry:

    float2 uv = float2(atan2(i.uv.x,i.uv.z) / UNITY_TWO_PI, asin(i.uv.y) / UNITY_HALF_PI);
    float middleThreshold = smoothstep(0.0, 0.5 - (1.0 - _MiddleSmoothness) / 2.0, i.uv.y - _MiddleOffset);
    float topThreshold = smoothstep(0.5, 1.0 - (1.0 - _TopSmoothness) / 2.0 , i.uv.y - _TopOffset);
    fixed4 col = lerp(_ColorBottom, _ColorMiddle, middleThreshold);
    col = lerp(col, _ColorTop, topThreshold);


    My Code looks something like this when in HLSL form

    float2 uv = float2(atan2(i.uv.x,i.uv.z) / TWO_PI, asin(i.uv.y) / HALF_PI);
    float middleThreshold = smoothstep(0.0, 0.5 - (1.0) / 2.0, i.uv.y );
    float topThreshold = smoothstep(0.5, 1.0 - (1.0) / 2.0 , i.uv.y );
    float4 col = lerp(_ColorBottom, _ColorMiddle, middleThreshold);
    col = lerp(col, _ColorTop, topThreshold);
    return col;


    Hence my question is: Does the vertex shader actually pass proper UV data for the skybox in HDRP?

    I'm not really shader-savy but I'm trying to learn!

    All the best,
    Tim
     
  2. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    72
    The sky system is not using a spherical mesh to render the sky so you don't have UVs.
    It uses a fullscreen quad where for each pixel we provide the direction in which the pixel is looking. This can be used to sample HDRI cubemaps for example.
    For more detail please take a look at the documentation, the example should be mostly up to date:
    https://docs.unity3d.com/Packages/c...nition@10.2/manual/Creating-a-Custom-Sky.html
     
  3. TimDoesDev

    TimDoesDev

    Joined:
    Feb 23, 2018
    Posts:
    35
    Thank you for your reply Julien. That explains a lot! I have looked at the documentation step by step but I find that it is completely missing information on how the actual sky shaders expect to be setup, but maybe it is because of my lack of knowledge I didn't intuitively understand it from just looking at the HDRI shader?
     
  4. TimDoesDev

    TimDoesDev

    Joined:
    Feb 23, 2018
    Posts:
    35
    Also, does this mean that I HAVE to use HLSL?
     
  5. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    72
    Yes, in SRP all shaders use HLSL. It should not make much of a difference though.