From cd7c8400def49523aff9b96b3757a1b3d0479538 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 29 Sep 2020 14:25:24 +0200 Subject: [PATCH] Add back hdri distortion (#2049) --- .../Runtime/Sky/HDRISky/HDRISky.shader | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 8960eebf36b..aaf2e547cb0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -184,6 +184,35 @@ Shader "Hidden/HDRP/Sky/HDRISky" float3 GetSkyColor(float3 dir) { +#if SKY_MOTION + if (dir.y >= 0 || !_UpperHemisphere) + { + float2 alpha = frac(float2(_ScrollFactor, _ScrollFactor + 0.5)) - 0.5; + +#ifdef USE_FLOWMAP + float3 tangent = normalize(cross(dir, float3(0.0, 1.0, 0.0))); + float3 bitangent = cross(tangent, dir); + + float3 windDir = RotationUp(dir, _ScrollDirection); + float2 flow = SAMPLE_TEXTURE2D_LOD(_Flowmap, sampler_Flowmap, GetLatLongCoords(windDir, _UpperHemisphere), 0).rg * 2.0 - 1.0; + + float3 dd = flow.x * tangent + flow.y * bitangent; +#else + float3 windDir = RotationUp(float3(0, 0, 1), _ScrollDirection); + windDir.x *= -1.0; + float3 dd = windDir*sin(dir.y*PI*0.5); +#endif + + // Sample twice + float3 color1 = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir - alpha.x*dd, 0).rgb; + float3 color2 = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir - alpha.y*dd, 0).rgb; + + // Blend color samples + return lerp(color1, color2, abs(2.0 * alpha.x)); + } + else +#endif + return SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb; }