Skip to content

Hd/fix backplate globalcubemap2 #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Changed the clamping approach for RTR and RTGI (in both perf and quality) to improve visual quality.
- Changed the warning message for ray traced area shadows (case 1303410).
- Disabled specular occlusion for what we consider medium and larger scale ao > 1.25 with a 25cm falloff interval.
- Removed backplate from rendering of lighting cubemap as it did not really work conceptually and caused artefacts.

## [10.3.0] - 2020-12-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ These properties only appear if you enable [more options](More-Options.md).
| -**Shadow Tint** | Specifies the color to tint shadows cast onto the backplate. |
| - **Reset Color** | Resets the saved **Shadow Tint** for the shadow. HDRP calculates a new default shadow tint when the HDRI changes. |

**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting.
**Note**: To use ambient occlusion in the backplate, increase the value of the **Direct Lighting Strength** property on the [Ambient Occlusion](Override-Ambient-Occlusion.md) component override. As the backplate does not have global illumination, it can only get ambient occlusion from direct lighting.

**Limitation**: The backplate don't affect the Sky lighting (Sky Reflection / Ligthmaps / LightProbes / Ambient Probe). It will not appear with the default sky reflection but only in local reflection probes.
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,6 @@ Shader "Hidden/HDRP/Sky/HDRISky"
return results;
}

float4 FragBakingBackplate(Varyings input) : SV_Target
{
return RenderBackplate(input, 1.0);
}

float4 FragRenderBackplate(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
Expand All @@ -338,12 +333,6 @@ Shader "Hidden/HDRP/Sky/HDRISky"
return depth;
}

float FragBakingBackplateDepth(Varyings input) : SV_Depth
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return GetDepthWithBackplate(input);
}

float4 FragRenderBackplateDepth(Varyings input, out float depth : SV_Depth) : SV_Target0
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
Expand Down Expand Up @@ -392,20 +381,6 @@ Shader "Hidden/HDRP/Sky/HDRISky"
ENDHLSL
}

// HDRI Sky with Backplate
// For cubemap with Backplate
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off

HLSLPROGRAM
#pragma fragment FragBakingBackplate
ENDHLSL
}

// For fullscreen Sky with Backplate
Pass
{
Expand All @@ -419,20 +394,6 @@ Shader "Hidden/HDRP/Sky/HDRISky"
ENDHLSL
}

// HDRI Sky with Backplate for PreRenderSky (Depth Only Pass)
// DepthOnly For cubemap with Backplate
Pass
{
ZWrite On
ZTest LEqual
Blend Off
Cull Off

HLSLPROGRAM
#pragma fragment FragBakingBackplateDepth
ENDHLSL
}

// DepthOnly For fullscreen Sky with Backplate
Pass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class HDRISkyRenderer : SkyRenderer

private static int m_RenderCubemapID = 0; // FragBaking
private static int m_RenderFullscreenSkyID = 1; // FragRender
private static int m_RenderCubemapWithBackplateID = 2; // FragBakingBackplate
private static int m_RenderFullscreenSkyWithBackplateID = 3; // FragRenderBackplate
private static int m_RenderDepthOnlyCubemapWithBackplateID = 4; // FragBakingBackplateDepth
private static int m_RenderDepthOnlyFullscreenSkyWithBackplateID = 5; // FragRenderBackplateDepth
private static int m_RenderFullscreenSkyWithBackplateID = 2; // FragRenderBackplate
private static int m_RenderDepthOnlyFullscreenSkyWithBackplateID = 3; // FragRenderBackplateDepth

public HDRISkyRenderer()
{
Expand Down Expand Up @@ -92,16 +90,10 @@ public override bool RequiresPreRenderSky(BuiltinSkyParameters builtinParams)
return hdriSky.enableBackplate.value;
}

public override void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
public override void PreRenderSky(BuiltinSkyParameters builtinParams)
{
var hdriSky = builtinParams.skySettings as HDRISky;

int passID;
if (renderForCubemap)
passID = m_RenderDepthOnlyCubemapWithBackplateID;
else
passID = m_RenderDepthOnlyFullscreenSkyWithBackplateID;

float intensity, phi, backplatePhi;
GetParameters(out intensity, out phi, out backplatePhi, builtinParams, hdriSky);

Expand All @@ -113,7 +105,7 @@ public override void PreRenderSky(BuiltinSkyParameters builtinParams, bool rende

m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);

CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, passID);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, m_RenderDepthOnlyFullscreenSkyWithBackplateID);
}
}

Expand All @@ -123,19 +115,20 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo
float intensity, phi, backplatePhi;
GetParameters(out intensity, out phi, out backplatePhi, builtinParams, hdriSky);
int passID;
if (hdriSky.enableBackplate.value == false)
if (renderForCubemap)
{
if (renderForCubemap)
passID = m_RenderCubemapID;
else
passID = m_RenderFullscreenSkyID;
passID = m_RenderCubemapID;
}
else
{
if (renderForCubemap)
passID = m_RenderCubemapWithBackplateID;
if (hdriSky.enableBackplate.value == false)
{
passID = m_RenderFullscreenSkyID;
}
else
{
passID = m_RenderFullscreenSkyWithBackplateID;
}
}

if (hdriSky.enableDistortion.value == true)
Expand Down Expand Up @@ -182,6 +175,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo
shadowFilter |= unchecked((uint)LightFeatureFlags.Area);
m_SkyHDRIMaterial.SetInt(HDShaderIDs._BackplateShadowFilter, unchecked((int)shadowFilter));


// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, m_PropertyBlock, passID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ public void Build(HDRenderPipelineAsset hdAsset, RenderPipelineResources default
m_SkyboxBSDFCubemapIntermediate = RTHandles.Alloc(resolution, resolution, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureDimension.Cube, useMipMap: true, autoGenerateMips: false, filterMode: FilterMode.Trilinear, name: "SkyboxBSDFIntermediate");
m_CubemapScreenSize = new Vector4((float)resolution, (float)resolution, 1.0f / (float)resolution, 1.0f / (float)resolution);

var cubeProj = Matrix4x4.Perspective(90.0f, 1.0f, 0.01f, 1.0f);

for (int i = 0; i < 6; ++i)
{
var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
Expand Down Expand Up @@ -962,7 +960,7 @@ public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer
}

if (preRenderSky)
skyContext.skyRenderer.PreRenderSky(m_BuiltinParameters, false, hdCamera.camera.cameraType != CameraType.Reflection || skyContext.skySettings.includeSunInBaking.value);
skyContext.skyRenderer.PreRenderSky(m_BuiltinParameters);

if (skyContext.HasClouds() && skyContext.cloudRenderer.RequiresPreRenderClouds(m_BuiltinParameters))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ public abstract class SkyRenderer
/// <param name="builtinParams">Engine parameters that you can use to render the sky.</param>
/// <param name="renderForCubemap">Pass in true if you want to render the sky into a cubemap for lighting. This is useful when the sky renderer needs a different implementation in this case.</param>
/// <param name="renderSunDisk">If the sky renderer supports the rendering of a sun disk, it must not render it if this is set to false.</param>
public virtual void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk) {}
[System.Obsolete("Please override PreRenderSky(BuiltinSkyParameters) instead.")]
public virtual void PreRenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
{
PreRenderSky(builtinParams);
}

/// <summary>
/// Preprocess for rendering the sky. Called before the DepthPrePass operations
/// </summary>
/// <param name="builtinParams">Engine parameters that you can use to render the sky.</param>
public virtual void PreRenderSky(BuiltinSkyParameters builtinParams) {}


/// <summary>
/// Whether the PreRenderSky step is required.
Expand Down