Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[HDRP] Bunch of bugfixes for HDRP (Version 7)
Check height as well as width for shadow desc (#13457)
Fix the ray tracing quality node at creation (#12362)
Clear the custom pass buffers when using fullscreen debug modes (#12535)
test if material has diffusion profile (#12522)
Fix input remapping (#12484)
Adapt the HDRP error message to not display the API if the build target is not supported (#12536)
Hide SpriteMask scene view draw mode as it is not supported by HDRP. (#12567)
Fixed custom pass UI refresh when changing the injection point (#12576)
Fix warnings in DofGatherUtils (#12580)
Fix refraction proxy volume fallback when center of object is outside of the screen. (#12610)
Fixed render graph error when opaque objects are disabled inthe frame settings (#13185)
Fix various warning in shader code. (#13181)
Fix the rendering pass changed on multiple SG material at the same time (#12621)
set min distance (#12617)
Improve the documentation of the ray tracing extend shadow culling (#12613)
  • Loading branch information
sebastienlagarde committed Aug 19, 2022
1 parent 53ae0c9 commit 0bb2787
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 39 deletions.
Expand Up @@ -289,7 +289,7 @@ float3 GetDebugMipColorIncludingMipReduction(float3 originalColor, uint mipCount

// Mip count has been reduced but the texelSize was not updated to take that into account
uint mipReductionLevel = originalTextureMipCount - mipCount;
uint mipReductionFactor = 1 << mipReductionLevel;
uint mipReductionFactor = 1U << mipReductionLevel;
if (mipReductionFactor)
{
float oneOverMipReductionFactor = 1.0 / mipReductionFactor;
Expand Down
Expand Up @@ -599,7 +599,7 @@ uint BinarySearchRow(uint j, real needle, TEXTURE2D(haystack), uint n)
{
i = 0;

for (uint b = 1 << firstbithigh(n - 1); b != 0; b >>= 1)
for (uint b = 1U << firstbithigh(n - 1); b != 0; b >>= 1)
{
uint p = i | b;
v = LOAD_TEXTURE2D(haystack, uint2(p, j)).r;
Expand Down
Expand Up @@ -69,7 +69,7 @@ public class ManualRTASManager : MonoBehaviour
| **Property** | **Description** |
| ------------------------ | ------------------------------------------------------------ |
| **Ray Bias** | Specifies the bias value HDRP applies when casting rays for all effects. This value should remain unchained unless your scene scale is significantly smaller or larger than average. |
| **Extend Shadow Culling** | Extends the sets of GameObjects that HDRP includes in shadow maps for more accurate shadows in ray traced effects. |
| **Extend Shadow Culling** | Extends the sets of GameObjects that HDRP includes in shadow maps for more accurate shadows in ray traced effects. For Directional lights, cascades are not extended, but additional objects may appear in the cascades.|
| **Extend Camera Culling** | Extends the sets of GameObjects that HDRP includes in the rendering. This is a way to force skinned mesh animations for GameObjects that are not in the frustum. |
| **Directional Shadow Ray Length** | Controls the maximal ray length for ray traced directional shadows. |
| **Directional Shadow Fallback Intensity** | The shadow intensity value HDRP applies to a point when there is a [Directional Light](Light-Component.md) in the Scene and the point is outside the Light's shadow cascade coverage. This property helps to remove light leaking in certain environments, such as an interior room with a Directional Light outside. |
Expand Down
Expand Up @@ -87,6 +87,9 @@ private static void SetupHDPropertiesOnImport(Material mat)

private static void SetDefaultDiffusionProfile(Material mat)
{
if (!mat.HasVector("Diffusion_Profile_Asset"))
return;

string matDiffProfile = HDUtils.ConvertVector4ToGUID(mat.GetVector("Diffusion_Profile_Asset"));
string guid = "";
long localID;
Expand Down
Expand Up @@ -170,6 +170,7 @@ enum DisplacementModeLitTessellation { None = DisplacementMode.None, Tessellatio
MaterialProperty blendMode = null;
MaterialProperty enableBlendModePreserveSpecularLighting = null;
MaterialProperty enableFogOnTransparent = null;
private const string kRenderQueueTypeShaderGraph = "_RenderQueueType";

// Lit properties
MaterialProperty doubleSidedNormalMode = null;
Expand Down Expand Up @@ -246,9 +247,11 @@ int renderQueue
get => (materialEditor.targets[0] as Material).renderQueue;
set
{
foreach (var target in materialEditor.targets)
foreach (Material target in materialEditor.targets)
{
(target as Material).renderQueue = value;
if (target.HasProperty(kRenderQueueTypeShaderGraph))
target.SetFloat(kRenderQueueTypeShaderGraph, (int)HDRenderQueue.GetTypeByRenderQueueValue(value));
target.renderQueue = value;
}
}
}
Expand Down Expand Up @@ -415,10 +418,10 @@ protected void DrawAlphaCutoffGUI()
{
EditorGUI.indentLevel++;

if (showAlphaClipThreshold && alphaCutoff != null)
if (alphaCutoff != null)
materialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText);

if (showAlphaClipThreshold && (m_Features & Features.AlphaCutoffShadowThreshold) != 0)
if ((m_Features & Features.AlphaCutoffShadowThreshold) != 0)
{
// For shadergraphs we show this slider only if the feature is enabled in the shader settings.
bool showUseShadowThreshold = useShadowThreshold != null;
Expand All @@ -438,7 +441,7 @@ protected void DrawAlphaCutoffGUI()

// With transparent object and few specific materials like Hair, we need more control on the cutoff to apply
// This allow to get a better sorting (with prepass), better shadow (better silhouettes fidelity) etc...
if (showAlphaClipThreshold && surfaceTypeValue == SurfaceType.Transparent)
if (surfaceTypeValue == SurfaceType.Transparent)
{
// TODO: check if passes exists
if (transparentDepthPrepassEnable != null && transparentDepthPrepassEnable.floatValue == 1.0f)
Expand Down Expand Up @@ -612,9 +615,9 @@ void SurfaceTypePopup()

// Shader graph only property, used to transfer the render queue from the shader graph to the material,
// because we can't use the renderqueue from the shader as we have to keep the renderqueue on the material side.
if (material.HasProperty("_RenderQueueType"))
if (material.HasProperty(kRenderQueueTypeShaderGraph))
{
renderQueueType = (HDRenderQueue.RenderQueueType)material.GetFloat("_RenderQueueType");
renderQueueType = (HDRenderQueue.RenderQueueType)material.GetFloat(kRenderQueueTypeShaderGraph);
}
// To know if we need to update the renderqueue, mainly happens if a material is created from a shader graph shader
// with default render-states.
Expand Down
Expand Up @@ -23,6 +23,8 @@ sealed class CustomPassVolumeEditor : Editor

const string k_DefaultListName = "Custom Passes";

static MethodInfo reorderableListInvalidateCacheMethod = typeof(ReorderableList).GetMethod("InvalidateCacheRecursive", BindingFlags.NonPublic | BindingFlags.Instance);

static class Styles
{
public static readonly GUIContent isGlobal = EditorGUIUtility.TrTextContent("Mode", "Global Volumes affect the Camera wherever the Camera is in the Scene and Local Volumes affect the Camera if they encapsulate the Camera within the bounds of their Collider. A camera volume is applied only for the target camera.");
Expand Down Expand Up @@ -188,7 +190,11 @@ void SetMode(int value)
}
}
if (EditorGUI.EndChangeCheck())
{
// UUM-8410 custom pass UI height is not updated
reorderableListInvalidateCacheMethod.Invoke(m_CustomPassList, null);
serializedObject.ApplyModifiedProperties();
}
}

void DrawCustomPassReorderableList()
Expand Down
Expand Up @@ -28,8 +28,10 @@ class PathTracingEditor : VolumeComponentEditor
SerializedDataParameter m_UseAOV;
SerializedDataParameter m_Temporal;

#if !(ENABLE_UNITY_DENOISING_PLUGIN && UNITY_EDITOR_WIN)
// This is used to prevent users from spamming the denoising package install button
bool s_DisplayDenoisingButtonInstall = true;
#endif

public override void OnEnable()
{
Expand Down
Expand Up @@ -361,7 +361,8 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
#endif

#if HAS_REFRACTION

uint perPixelEnvStart = envLightStart;
uint perPixelEnvCount = envLightCount;
// For refraction to be stable, we should reuse the same refraction probe for the whole object.
// Otherwise as if the object span different tiles it could produce a different refraction probe picking and thus have visual artifacts.
// For this we need to find the tile that is at the center of the object that is being rendered.
Expand Down Expand Up @@ -391,7 +392,11 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
{
envLightData = FetchEnvLight(FetchIndex(envLightStart, 0));
}
else // If no refraction probe, use sky with a default proxy extent.
else if (perPixelEnvCount > 0) // If no refraction probe at the object center, we either fallback on the per pixel result.
{
envLightData = FetchEnvLight(FetchIndex(perPixelEnvStart, 0));
}
else // .. or the sky
{
envLightData = InitDefaultRefractionEnvLightData(0);
}
Expand Down
Expand Up @@ -194,7 +194,9 @@ public TextureHandle GetOutputTexture(RenderGraph renderGraph)
Debug.Assert(m_Output.IsValid());
var requestedDesc = GetAtlasDesc();
// We check if we need to refresh the desc. It is needed for directional lights.
if (renderGraph.GetTextureDesc(m_Output).width != requestedDesc.width)
var outputDesc = renderGraph.GetTextureDesc(m_Output);
if (outputDesc.width != requestedDesc.width ||
outputDesc.height != requestedDesc.height)
{
renderGraph.RefreshSharedTextureDesc(m_Output, requestedDesc);
}
Expand Down
Expand Up @@ -363,7 +363,7 @@ float3 GetMaterialAbsorption(MaterialData mtlData, SurfaceData surfaceData, floa
return exp(-mtlData.bsdfData.absorptionCoefficient * REFRACTION_THIN_DISTANCE);
#else
// We allow a reasonable max distance of 10 times the "atDistance" (so that objects do not end up appearing black)
return exp(-mtlData.bsdfData.absorptionCoefficient * min(dist, surfaceData.atDistance * 10.0));
return exp(-mtlData.bsdfData.absorptionCoefficient * min(dist, max(surfaceData.atDistance, REAL_EPS) * 10.0));
#endif
}
#endif
Expand Down
Expand Up @@ -49,17 +49,8 @@ void GetPreIntegratedFGDGGXAndDisneyDiffuse(float NdotV, float perceptualRoughne

void GetPreIntegratedFGDGGXAndLambert(float NdotV, float perceptualRoughness, float3 fresnel0, out float3 specularFGD, out float diffuseFGD, out float reflectivity)
{
float2 preFGD = SAMPLE_TEXTURE2D_LOD(_PreIntegratedFGD_GGXDisneyDiffuse, s_linear_clamp_sampler, float2(NdotV, perceptualRoughness), 0).xy;

// Pre-integrate GGX FGD
// Integral{BSDF * <N,L> dw} =
// Integral{(F0 + (1 - F0) * (1 - <V,H>)^5) * (BSDF / F) * <N,L> dw} =
// (1 - F0) * Integral{(1 - <V,H>)^5 * (BSDF / F) * <N,L> dw} + F0 * Integral{(BSDF / F) * <N,L> dw}=
// (1 - F0) * x + F0 * y = lerp(x, y, F0)
specularFGD = lerp(preFGD.xxx, preFGD.yyy, fresnel0);
GetPreIntegratedFGDGGXAndDisneyDiffuse(NdotV, perceptualRoughness, fresnel0, specularFGD, diffuseFGD, reflectivity);
diffuseFGD = 1.0;

reflectivity = preFGD.y;
}

TEXTURE2D(_PreIntegratedFGD_CharlieAndFabric);
Expand Down
Expand Up @@ -170,7 +170,7 @@ void AccumulateSample(SampleData sampleData, float weight, inout AccumData accum
#endif
}

CTYPE ResolveBackGroundEstimate(SampleData centerSample, float fgAlpha, float4 bgEstimate, float4 bgEstimateAlpha)
CTYPE ResolveBackGroundEstimate(SampleData centerSample, float fgAlpha, float4 bgEstimate, float bgEstimateAlpha)
{
CTYPE result;
result.xyz = bgEstimate.w > 0 ? bgEstimate.xyz / bgEstimate.w : centerSample.color.xyz;
Expand Down
Expand Up @@ -255,6 +255,7 @@ internal enum HDProfileId
EdgeAdaptiveSpatialUpsampling,
PrepareProbeVolumeList,
ProbeVolumeDebug,
CustomPassBufferClearDebug,

AOVExecute,
AOVOutput,
Expand Down
Expand Up @@ -80,7 +80,7 @@ public partial class HDRenderPipeline
UpdateParentExposure(m_RenderGraph, hdCamera);

TextureHandle backBuffer = m_RenderGraph.ImportBackbuffer(target.id);
TextureHandle colorBuffer = CreateColorBuffer(m_RenderGraph, hdCamera, msaa);
TextureHandle colorBuffer = CreateColorBuffer(m_RenderGraph, hdCamera, msaa, true);
m_NonMSAAColorBuffer = CreateColorBuffer(m_RenderGraph, hdCamera, false);
TextureHandle currentColorPyramid = m_RenderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain));
TextureHandle rayCountTexture = RayCountManager.CreateRayCountTexture(m_RenderGraph);
Expand Down Expand Up @@ -1750,7 +1750,7 @@ class RenderDistortionPassData
}
}

TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool msaa)
TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool msaa, bool fallbackToBlack = false)
{
#if UNITY_2020_2_OR_NEWER
FastMemoryDesc colorFastMemDesc;
Expand All @@ -1768,7 +1768,8 @@ TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool
msaaSamples = msaa ? hdCamera.msaaSamples : MSAASamples.None,
clearBuffer = NeedClearColorBuffer(hdCamera),
clearColor = GetColorBufferClearColor(hdCamera),
name = msaa ? "CameraColorMSAA" : "CameraColor"
name = msaa ? "CameraColorMSAA" : "CameraColor",
fallBackToBlackTexture = fallbackToBlack
#if UNITY_2020_2_OR_NEWER
, fastMemoryDesc = colorFastMemDesc
#endif
Expand Down
Expand Up @@ -2191,9 +2191,22 @@ AOVRequestData aovRequest
}
}

using (new ProfilingScope(null, ProfilingSampler.Get(HDProfileId.CustomPassVolumeUpdate)))
if (m_DebugDisplaySettings.IsDebugDisplayRemovePostprocess())
{
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.CustomPass))
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.CustomPassBufferClearDebug)))
{
if (m_CustomPassColorBuffer.IsValueCreated && m_CustomPassDepthBuffer.IsValueCreated)
CoreUtils.SetRenderTarget(cmd, m_CustomPassColorBuffer.Value, m_CustomPassDepthBuffer.Value, ClearFlag.All);
else if (m_CustomPassColorBuffer.IsValueCreated)
CoreUtils.SetRenderTarget(cmd, m_CustomPassColorBuffer.Value, ClearFlag.Color);
else if (m_CustomPassDepthBuffer.IsValueCreated)
CoreUtils.SetRenderTarget(cmd, m_CustomPassDepthBuffer.Value, ClearFlag.Depth);
}
}

if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.CustomPass))
{
using (new ProfilingScope(null, ProfilingSampler.Get(HDProfileId.CustomPassVolumeUpdate)))
CustomPassVolume.Update(hdCamera);
}

Expand Down
Expand Up @@ -302,7 +302,7 @@ float3 GetPunctualEmission(LightData lightData, float3 outgoingDir, float dist)
if (lightData.cookieMode != COOKIEMODE_NONE)
{
LightLoopContext context;
emission *= EvaluateCookie_Punctual(context, lightData, -dist * outgoingDir);
emission *= EvaluateCookie_Punctual(context, lightData, -dist * outgoingDir).rgb;
}
#endif

Expand Down Expand Up @@ -498,7 +498,7 @@ bool SampleLights(LightList lightList,
}
else // lightType == PTLIGHT_SKY
{
float2 uv = SampleSky(inputSample);
float2 uv = SampleSky(inputSample.xy);
outgoingDir = MapUVToSkyDirection(uv);
value = GetSkyValue(outgoingDir);
pdf = GetSkyLightWeight(lightList) * GetSkyPDFFromValue(value);
Expand Down
Expand Up @@ -69,7 +69,7 @@ bool IsSkySamplingEnabled()

float GetSkyCDF(PTSKY_TEXTURE2D(cdf), uint i, uint j)
{
return cdf[uint2(i, j)];
return cdf[uint2(i, j)].x;
}

// Dichotomic search
Expand Down
Expand Up @@ -69,9 +69,9 @@ public sealed class RayTracingSettings : VolumeComponent
public ClampedFloatParameter rayBias = new ClampedFloatParameter(0.001f, 0.0f, 0.1f);

/// <summary>
/// Enables the override of the shadow culling. This increases the validity area of shadow maps outside of the frustum.
/// When enabled, the culling region for punctual and area lights shadow maps is increased from frustum culling to extended culling. For Directional lights, cascades are not extended, but additional objects may appear in the cascades.
/// </summary>
[Tooltip("Enables the override of the shadow culling. This increases the validity area of shadow maps outside of the frustum.")]
[Tooltip("When enabled, the culling region for punctual and area lights shadow maps is increased from frustum culling to extended culling. For Directional lights, cascades are not extended, but additional objects may appear in the cascades.")]
[FormerlySerializedAs("extendCulling")]
public BoolParameter extendShadowCulling = new BoolParameter(false);

Expand Down
Expand Up @@ -74,7 +74,7 @@ struct PixelCoordinates
void TraceGBuffer(PixelCoordinates coords)
{
// Read the depth value
float depthValue = LOAD_TEXTURE2D_X(_DepthTexture, coords.geometryCoords);
float depthValue = LOAD_TEXTURE2D_X(_DepthTexture, coords.geometryCoords).x;
ApplyRayTracingDepthOffset(depthValue);

// Read the direction
Expand Down
Expand Up @@ -21,7 +21,8 @@ static private bool RejectDrawMode(SceneView.CameraMode cameraMode)
cameraMode.drawMode == DrawCameraMode.DeferredSmoothness ||
cameraMode.drawMode == DrawCameraMode.DeferredNormal ||
cameraMode.drawMode == DrawCameraMode.ValidateAlbedo ||
cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular
cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular ||
cameraMode.drawMode == DrawCameraMode.SpriteMask
)
return false;

Expand Down
Expand Up @@ -1167,9 +1167,11 @@ internal static string GetUnsupportedAPIMessage(string graphicAPI)
var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
string currentPlatform = buildTarget.ToString();
var osFamily = BuildTargetToOperatingSystemFamily(buildTarget);
bool isSupportedBuildTarget = IsSupportedBuildTarget(buildTarget);
#else
string currentPlatform = SystemInfo.operatingSystem;
var osFamily = SystemInfo.operatingSystemFamily;
bool isSupportedBuildTarget = true;
#endif

string os = null;
Expand All @@ -1186,7 +1188,12 @@ internal static string GetUnsupportedAPIMessage(string graphicAPI)
break;
}

string msg = "Platform " + currentPlatform + " with graphics API " + graphicAPI + " is not supported with HDRP";
string msg;

if (isSupportedBuildTarget)
msg = "Platform " + currentPlatform + " with graphics API " + graphicAPI + " is not supported with HDRP";
else
msg = "Platform " + currentPlatform + " is not supported with HDRP";

// Display more information to the users when it should have use Metal instead of OpenGL
if (graphicAPI.StartsWith("OpenGL"))
Expand Down
Expand Up @@ -196,7 +196,8 @@ internal override ShaderInput Copy()
keywordDefinition = keywordDefinition,
keywordScope = keywordScope,
entries = entries,
keywordStages = keywordStages
keywordStages = keywordStages,
overrideReferenceName = overrideReferenceName
};
}

Expand Down

0 comments on commit 0bb2787

Please sign in to comment.