diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index e91db2633de..61f032a16e2 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Optimizations for the physically based depth of field. - Converted most TGA textures files to TIF to reduce the size of HDRP material samples. - Changed sample scene in HDRP material samples: add shadow transparency (raster, ray-traced, path-traced). +- Support for encoded HDR cubemaps, configurable via the HDR Cubemap Encoding project setting. ## [13.1.1] - 2021-10-04 diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/ReflectionProbesPreview.shader b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/ReflectionProbesPreview.shader index ddb3a183778..957c2d9bfec 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/ReflectionProbesPreview.shader +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/ReflectionProbesPreview.shader @@ -28,6 +28,7 @@ Shader "Hidden/Debug/ReflectionProbePreview" #pragma fragment frag #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" struct appdata @@ -45,6 +46,7 @@ Shader "Hidden/Debug/ReflectionProbePreview" TEXTURECUBE(_Cubemap); SAMPLER(sampler_Cubemap); + float4 _Cubemap_HDR; float3 _CameraWorldPosition; float _MipLevel; @@ -67,6 +69,7 @@ Shader "Hidden/Debug/ReflectionProbePreview" float3 V = normalize(i.positionWS - GetPrimaryCameraPosition()); float3 R = reflect(V, i.normalWS); float4 color = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, R, _MipLevel).rgba; + color.rgb = DecodeHDREnvironment(color, _Cubemap_HDR); color = color * exp2(_Exposure) * GetCurrentExposureMultiplier(); return float4(color); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Core/CoreResources/BlitCubeTextureFace.shader b/com.unity.render-pipelines.high-definition/Runtime/Core/CoreResources/BlitCubeTextureFace.shader index f98dd74f784..e44b4ed3107 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Core/CoreResources/BlitCubeTextureFace.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Core/CoreResources/BlitCubeTextureFace.shader @@ -15,6 +15,7 @@ Shader "Hidden/SRP/BlitCubeTextureFace" #pragma editor_sync_compilation #pragma prefer_hlslcc gles #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" #pragma vertex vert #pragma fragment frag @@ -22,6 +23,7 @@ Shader "Hidden/SRP/BlitCubeTextureFace" TEXTURECUBE(_InputTex); SAMPLER(sampler_InputTex); + float4 _InputTex_HDR; float _FaceIndex; float _LoD; @@ -59,7 +61,9 @@ Shader "Hidden/SRP/BlitCubeTextureFace" float4 frag (Varyings input) : SV_Target { - return SAMPLE_TEXTURECUBE_LOD(_InputTex, sampler_InputTex, input.texcoord, _LoD); + float4 color = SAMPLE_TEXTURECUBE_LOD(_InputTex, sampler_InputTex, input.texcoord, _LoD); + color.rgb = DecodeHDREnvironment(color, _InputTex_HDR); + return color; } ENDHLSL diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/ReflectionProbeCache.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/ReflectionProbeCache.cs index 20f9b0e8188..dfd0f67cf7e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/ReflectionProbeCache.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/ReflectionProbeCache.cs @@ -142,27 +142,21 @@ Texture[] ConvolveProbeTexture(CommandBuffer cmd, Texture texture) // 2) to the proper reflection probe cache size bool sizeMismatch = cubeTexture.width != m_ProbeSize || cubeTexture.height != m_ProbeSize; bool formatMismatch = (GraphicsFormatUtility.GetGraphicsFormat(cubeTexture.format, false) != m_TempRenderTexture.graphicsFormat); - if (formatMismatch || sizeMismatch) + + // We comment the following warning as they have no impact on the result but spam the console, it is just that we waste offline time and a bit of quality for nothing. + if (sizeMismatch) { - // We comment the following warning as they have no impact on the result but spam the console, it is just that we waste offline time and a bit of quality for nothing. - if (sizeMismatch) - { - // Debug.LogWarningFormat("Baked Reflection Probe {0} does not match HDRP Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize); - } - else if (cubeTexture.graphicsFormat == GraphicsFormat.RGB_BC6H_UFloat || cubeTexture.graphicsFormat == GraphicsFormat.RGB_BC6H_SFloat) - { - // Debug.LogWarningFormat("Baked Reflection Probe {0} is compressed but the HDRP Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name); - } - ConvertTexture(cmd, cubeTexture, m_TempRenderTexture); + // Debug.LogWarningFormat("Baked Reflection Probe {0} does not match HDRP Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize); } - else + else if (formatMismatch && (cubeTexture.graphicsFormat == GraphicsFormat.RGB_BC6H_UFloat || cubeTexture.graphicsFormat == GraphicsFormat.RGB_BC6H_SFloat)) { - for (int f = 0; f < 6; f++) - { - cmd.CopyTexture(cubeTexture, f, 0, m_TempRenderTexture, f, 0); - } + // Debug.LogWarningFormat("Baked Reflection Probe {0} is compressed but the HDRP Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name); } + // Convert the cubemap to match the size and texture format used for the cache + // This will also take care of decoding manually encoded HDR cubemaps (RGBM, dLDR) + ConvertTexture(cmd, cubeTexture, m_TempRenderTexture); + // Ideally if input is not compressed and has mipmaps, don't do anything here. Problem is, we can't know if mips have been already convolved offline... cmd.GenerateMips(m_TempRenderTexture); convolutionSourceTexture = m_TempRenderTexture; 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 cde9fdc022e..83363eaab31 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 @@ -32,6 +32,7 @@ Shader "Hidden/HDRP/Sky/HDRISky" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SDF2D.hlsl" @@ -49,6 +50,7 @@ Shader "Hidden/HDRP/Sky/HDRISky" TEXTURECUBE(_Cubemap); SAMPLER(sampler_Cubemap); + float4 _Cubemap_HDR; TEXTURE2D(_Flowmap); SAMPLER(sampler_Flowmap); @@ -203,8 +205,8 @@ Shader "Hidden/HDRP/Sky/HDRISky" #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; + float3 color1 = DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir + alpha.x * dd, 0), _Cubemap_HDR); + float3 color2 = DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir + alpha.y * dd, 0), _Cubemap_HDR); // Blend color samples return lerp(color1, color2, abs(2.0 * alpha.x)); @@ -212,7 +214,7 @@ Shader "Hidden/HDRP/Sky/HDRISky" else #endif - return SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb; + return DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0), _Cubemap_HDR); } float4 GetColorWithRotation(float3 dir, float exposure, float2 cos_sin) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/IntegrateHDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/IntegrateHDRISky.shader index 6a71fddefab..f9760c745c8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/IntegrateHDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/IntegrateHDRISky.shader @@ -23,6 +23,7 @@ Shader "Hidden/HDRP/IntegrateHDRI" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" struct Attributes @@ -37,6 +38,7 @@ Shader "Hidden/HDRP/IntegrateHDRI" }; TextureCube _Cubemap; + float4 _Cubemap_HDR; Varyings Vert(Attributes input) { @@ -65,7 +67,7 @@ Shader "Hidden/HDRP/IntegrateHDRI" { // SphericalToCartesian function is for Z up, lets move to Y up with TransformGLtoDX float3 L = TransformGLtoDX(SphericalToCartesian(phi, cos(theta))); - real3 val = SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0).rgb; + real3 val = DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0), _Cubemap_HDR).rgb; sum += (cos(theta)*sin(theta)*coef)*val; } }