Skip to content

Commit

Permalink
Add back hdri distortion (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-de-tocqueville committed Sep 29, 2020
1 parent 9963ae2 commit cd7c840
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit cd7c840

Please sign in to comment.