From eeb426c7138fc92ab0e8cf90a1bc58034f2e86fd Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 15 Sep 2020 15:58:19 +0200 Subject: [PATCH 01/21] Removing blend keyword. --- ...dSurfaceMaterialDescriptionPreprocessor.cs | 4 +- .../FBXMaterialDescriptionPostprocessor.cs | 2 +- .../PhysicalMaterial3DsMaxPreprocessor.cs | 2 +- ...ketchupMaterialDescriptionPostprocessor.cs | 2 +- ...ThreeDSMaterialDescriptionPostprocessor.cs | 2 +- .../ShaderGraph/Templates/ShaderPass.template | 5 ++- .../Editor/Material/Unlit/BaseUnlitGUI.cs | 9 ---- .../VFXAbstractParticleHDRPLitOutput.cs | 6 +-- .../Runtime/Material/AxF/AxF.shader | 4 +- .../Runtime/Material/AxF/AxFProperties.hlsl | 1 + .../Material/Decal/DecalProperties.hlsl | 1 + .../Material/LayeredLit/LayeredLit.shader | 1 - .../LayeredLit/LayeredLitTessellation.shader | 1 - .../Runtime/Material/Lit/Lit.shader | 1 - .../Runtime/Material/Lit/LitProperties.hlsl | 1 + .../Material/Lit/LitTessellation.shader | 4 +- .../Runtime/Material/Material.hlsl | 44 ++++++++++++------- .../Runtime/Material/MaterialBlendModeEnum.cs | 17 +++++++ .../Material/MaterialBlendModeEnum.cs.hlsl | 15 +++++++ .../MaterialBlendModeEnum.cs.hlsl.meta | 10 +++++ .../Material/MaterialBlendModeEnum.cs.meta | 11 +++++ .../Runtime/Material/MaterialExtension.cs | 9 ---- .../Runtime/Material/Unlit/Unlit.shader | 1 - .../Material/Unlit/UnlitProperties.hlsl | 1 + 24 files changed, 100 insertions(+), 54 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXArnoldSurfaceMaterialDescriptionPreprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXArnoldSurfaceMaterialDescriptionPreprocessor.cs index c6775590533..aa1957b53b8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXArnoldSurfaceMaterialDescriptionPreprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXArnoldSurfaceMaterialDescriptionPreprocessor.cs @@ -98,11 +98,11 @@ void CreateFromMayaArnoldStandardSurfaceMaterial(MaterialDescription description material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = 3000; } else @@ -203,11 +203,11 @@ void CreateFrom3DsMaxArnoldStandardSurfaceMaterial(MaterialDescription descripti material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = 3000; } else diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXMaterialDescriptionPostprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXMaterialDescriptionPostprocessor.cs index e39eefdd90f..5543ea28e8a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXMaterialDescriptionPostprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/FBXMaterialDescriptionPostprocessor.cs @@ -75,11 +75,11 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/PhysicalMaterial3DsMaxPreprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/PhysicalMaterial3DsMaxPreprocessor.cs index 867bc9574be..dc699bcf51f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/PhysicalMaterial3DsMaxPreprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/PhysicalMaterial3DsMaxPreprocessor.cs @@ -205,11 +205,11 @@ void CreateFrom3DsPhysicalMaterial(MaterialDescription description, Material mat material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = 3000; } else diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/SketchupMaterialDescriptionPostprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/SketchupMaterialDescriptionPostprocessor.cs index 4b4685ea559..af6e3c6b6ef 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/SketchupMaterialDescriptionPostprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/SketchupMaterialDescriptionPostprocessor.cs @@ -60,11 +60,11 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/ThreeDSMaterialDescriptionPostprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/ThreeDSMaterialDescriptionPostprocessor.cs index 33e9d433cdb..289a8f66c88 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/ThreeDSMaterialDescriptionPostprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/ThreeDSMaterialDescriptionPostprocessor.cs @@ -53,11 +53,11 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); + material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); - material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index 021e1615703..2598b5c3e79 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -97,6 +97,9 @@ Pass $splice(HybridV1InjectedBuiltinProperties) + // Graph Properties + $splice(GraphProperties) + // Includes $splice(PreGraphIncludes) @@ -116,8 +119,6 @@ Pass // -------------------------------------------------- // Graph - // Graph Properties - $splice(GraphProperties) // Graph Functions $splice(GraphFunctions) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/BaseUnlitGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/BaseUnlitGUI.cs index e326dd4ece8..867543932f7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/BaseUnlitGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/BaseUnlitGUI.cs @@ -38,11 +38,6 @@ public static void SetupBaseUnlitKeywords(this Material material) bool transparentWritesMotionVec = (surfaceType == SurfaceType.Transparent) && material.HasProperty(kTransparentWritingMotionVec) && material.GetInt(kTransparentWritingMotionVec) > 0; CoreUtils.SetKeyword(material, "_TRANSPARENT_WRITES_MOTION_VEC", transparentWritesMotionVec); - // These need to always been set either with opaque or transparent! So a users can switch to opaque and remove the keyword correctly - CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", false); - CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", false); - CoreUtils.SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", false); - HDRenderQueue.RenderQueueType renderQueueType = HDRenderQueue.GetTypeByRenderQueueValue(material.renderQueue); bool needOffScreenBlendFactor = renderQueueType == HDRenderQueue.RenderQueueType.AfterPostprocessTransparent || renderQueueType == HDRenderQueue.RenderQueueType.LowTransparent; @@ -93,10 +88,6 @@ public static void SetupBaseUnlitKeywords(this Material material) { BlendMode blendMode = material.GetBlendMode(); - CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", BlendMode.Alpha == blendMode); - CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", BlendMode.Additive == blendMode); - CoreUtils.SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", BlendMode.Premultiply == blendMode); - // When doing off-screen transparency accumulation, we change blend factors as described here: https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html switch (blendMode) { diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs index bd047060442..897b29b235b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs @@ -431,13 +431,13 @@ public override IEnumerable> additionalRep switch (blendMode) { case BlendMode.Alpha: - forwardDefines.WriteLine("#define _BLENDMODE_ALPHA"); + forwardDefines.WriteLine("#define _BlendMode 0"); break; case BlendMode.Additive: - forwardDefines.WriteLine("#define _BLENDMODE_ADD"); + forwardDefines.WriteLine("#define _BlendMode 1"); break; case BlendMode.AlphaPremultiplied: - forwardDefines.WriteLine("#define _BLENDMODE_PRE_MULTIPLY"); + forwardDefines.WriteLine("#define _BlendMode 4"); break; } if (!isBlendModeOpaque) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index 4a50d27ff0b..ea3143667cc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -120,7 +120,8 @@ Shader "HDRP/AxF" // [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 -// [ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 + // We never set this as it is always 1, but its definition is needed when performing blending in Material.hlsl + [HideInInspector][ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 [ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0 [Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 // This is for the editor only, see BaseLitUI.cs: _DoubleSidedConstants will be set based on the mode. @@ -177,7 +178,6 @@ Shader "HDRP/AxF" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING // easily handled in material.hlsl, so adding this already. #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl index 59d7ab2b016..7cced1b697f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl @@ -120,6 +120,7 @@ float _AlphaCutoff; float _UseShadowThreshold; float _AlphaCutoffShadow; float4 _DoubleSidedConstants; +float _BlendMode; // Specular AA float _EnableGeometricSpecularAA; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl index de428ae8d3b..44d9ec4b974 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl @@ -23,6 +23,7 @@ float _AORemapMin; float _AORemapMax; float _MetallicScale; float _DecalMaskMapBlueScale; +float _BlendMode; float _Smoothness; float _AO; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 3a322d992ff..80a63c6fbe2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -454,7 +454,6 @@ Shader "HDRP/LayeredLit" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index 585db9520ab..063163a0120 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -462,7 +462,6 @@ Shader "HDRP/LayeredLitTessellation" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index d83743bdb8d..ace79a8ef8e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -285,7 +285,6 @@ Shader "HDRP/Lit" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT #pragma shader_feature_local _TRANSPARENT_WRITES_MOTION_VEC diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl index 2968c9e784b..7e4a6c35f91 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl @@ -112,6 +112,7 @@ float _DistortionVectorBias; float _DistortionBlurScale; float _DistortionBlurRemapMin; float _DistortionBlurRemapMax; +float _BlendMode; float _PPDMaxSamples; float _PPDMinSamples; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 8163e8398b9..d08561b45d6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -292,7 +292,6 @@ Shader "HDRP/LitTessellation" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _BLENDMODE_PRESERVE_SPECULAR_LIGHTING #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT @@ -337,7 +336,6 @@ Shader "HDRP/LitTessellation" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" //------------------------------------------------------------------------------------- // variable declaration @@ -353,6 +351,8 @@ Shader "HDRP/LitTessellation" // LitShading.hlsl implements the light loop API. // LitData.hlsl is included here, LitShading.hlsl is included below for shading passes only. + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + ENDHLSL SubShader diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl index 3c08ecd5dc9..c068b2a5907 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl @@ -10,12 +10,12 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl" // Guidelines for Material Keyword. // There is a set of Material Keyword that a HD shaders must define (or not define). We call them system KeyWord. // .Shader need to define: // - _SURFACE_TYPE_TRANSPARENT if they use a transparent material -// - _BLENDMODE_ALPHA, _BLENDMODE_ADD, _BLENDMODE_PRE_MULTIPLY for blend mode // - _BLENDMODE_PRESERVE_SPECULAR_LIGHTING for correct lighting when blend mode are use with a Lit material // - _ENABLE_FOG_ON_TRANSPARENT if fog is enable on transparent surface // - _DISABLE_DECALS if the material don't support decals @@ -33,7 +33,9 @@ float4 ApplyBlendMode(float3 diffuseLighting, float3 specularLighting, float opa // When doing off screen rendering (low-res transparency or after post process pass) and rendering opaque objects, opacity needs to be set to zero for proper compositing. if (_OffScreenRendering != 0) opacity = 0; -#endif + + return float4(diffuseLighting + specularLighting, opacity); +#else // ref: http://advances.realtimerendering.com/other/2016/naughty_dog/NaughtyDog_TechArt_Final.pdf // Lit transparent object should have reflection and transmission. @@ -41,19 +43,21 @@ float4 ApplyBlendMode(float3 diffuseLighting, float3 specularLighting, float opa // However reflection should not be affected by blend mode. For example a glass should still display reflection and not lose the highlight when blend // This is the purpose of following function, "Cancel" the blend mode effect on the specular lighting but not on the diffuse lighting #ifdef _BLENDMODE_PRESERVE_SPECULAR_LIGHTING - // In the case of _BLENDMODE_ALPHA the code should be float4(diffuseLighting + (specularLighting / max(opacity, 0.01)), opacity) + // In the case of alpha blend mode the code should be float4(diffuseLighting + (specularLighting / max(opacity, 0.01)), opacity) // However this have precision issue when reaching 0, so we change the blend mode and apply src * src_a inside the shader instead - #if defined(_BLENDMODE_ADD) || defined(_BLENDMODE_ALPHA) - return float4(diffuseLighting * opacity + specularLighting, opacity); - #else // defined(_BLENDMODE_PRE_MULTIPLY) - return float4(diffuseLighting + specularLighting, opacity); - #endif + if (_BlendMode == BLENDMODE_ALPHA || _BlendMode == BLENDMODE_ADDITIVE) + return float4(diffuseLighting * opacity + specularLighting, opacity); + else + return float4(diffuseLighting + specularLighting, opacity); #else - #if defined(_BLENDMODE_ADD) || defined(_BLENDMODE_ALPHA) - return float4((diffuseLighting + specularLighting) * opacity, opacity); - #else // defined(_BLENDMODE_PRE_MULTIPLY) - return float4(diffuseLighting + specularLighting, opacity); - #endif + + if (_BlendMode == BLENDMODE_ALPHA || _BlendMode == BLENDMODE_ADDITIVE) + return float4((diffuseLighting + specularLighting) * opacity, opacity); + else + return float4(diffuseLighting + specularLighting, opacity); + +#endif + #endif } @@ -76,23 +80,29 @@ float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 i float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha - #if defined(_BLENDMODE_ALPHA) + if (_BlendMode == BLENDMODE_ALPHA) + { // Regular alpha blend need to multiply fog color by opacity (as we do src * src_a inside the shader) // result.rgb = lerp(result.rgb, unpremul_volColor * result.a, volOpacity); // result.rgb = result.rgb + volOpacity * (unpremul_volColor * result.a - result.rgb); // result.rgb = result.rgb + volColor * result.a - result.rgb * volOpacity; result.rgb = result.rgb * (1 - volOpacity) + volColor * result.a; - #elif defined(_BLENDMODE_ADD) + } + else if (_BlendMode == BLENDMODE_ADDITIVE) + { // For additive, we just need to fade to black with fog density (black + background == background color == fog color) result.rgb = result.rgb * (1.0 - volOpacity); - #elif defined(_BLENDMODE_PRE_MULTIPLY) + } + else if (_BlendMode == BLENDMODE_PREMULTIPLY) + { // For Pre-Multiplied Alpha Blend, we need to multiply fog color by src alpha to match regular alpha blending formula. // result.rgb = lerp(result.rgb, unpremul_volColor * result.a, volOpacity); result.rgb = result.rgb * (1 - volOpacity) + volColor * result.a; // Note: this formula for color is correct, assuming we apply the Over operator afterwards // (see the appendix in the Deep Compositing paper). But do we? // Additionally, we do not modify the alpha here, which is most certainly WRONG. - #endif + } + #else // Evaluation of fog for opaque objects is currently done in a full screen pass independent from any material parameters. // but this funtction is called in generic forward shader code so we need it to be neutral in this case. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs new file mode 100644 index 00000000000..490a973dbf1 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs @@ -0,0 +1,17 @@ +// This enum definition really belongs to MaterialExtension.cs, however for limitation of the parser that generates HLSL definitions, +// hlsl code is not generated from files that use C# 7+ features, so this needs to be in its own file for now. Will need to move back +// MaterialExtension.cs once the parser is updated to support C# 7. +using UnityEngine.Rendering; + +namespace UnityEditor.Rendering.HighDefinition +{ + // Enum values are hardcoded for retro-compatibility. Don't change them. + [GenerateHLSL] + enum BlendMode + { + // Note: value is due to code change, don't change the value + Alpha = 0, + Premultiply = 4, + Additive = 1 + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl new file mode 100644 index 00000000000..1651cc12044 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl @@ -0,0 +1,15 @@ +// +// This file was automatically generated. Please don't edit by hand. +// + +#ifndef MATERIALBLENDMODEENUM_CS_HLSL +#define MATERIALBLENDMODEENUM_CS_HLSL +// +// UnityEditor.Rendering.HighDefinition.BlendMode: static fields +// +#define BLENDMODE_ALPHA (0) +#define BLENDMODE_PREMULTIPLY (4) +#define BLENDMODE_ADDITIVE (1) + + +#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl.meta new file mode 100644 index 00000000000..a46d46508d7 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: ea277db9c382b5348b7a8993b2c547e3 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.meta new file mode 100644 index 00000000000..35a87afc1c9 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c91a0012882f0914c971134f6ea58d5d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialExtension.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialExtension.cs index d9641a7a16a..e5422c068e4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialExtension.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialExtension.cs @@ -17,15 +17,6 @@ enum SurfaceType Transparent } - // Enum values are hardcoded for retro-compatibility. Don't change them. - enum BlendMode - { - // Note: value is due to code change, don't change the value - Alpha = 0, - Premultiply = 4, - Additive = 1 - } - enum DisplacementMode { None, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index d330af0812b..4e46d1018dd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -113,7 +113,6 @@ Shader "HDRP/Unlit" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT #pragma shader_feature_local _ADD_PRECOMPUTED_VELOCITY diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl index ea9aa29b447..d259d3ae6df 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl @@ -25,6 +25,7 @@ float _DistortionVectorBias; float _DistortionBlurScale; float _DistortionBlurRemapMin; float _DistortionBlurRemapMax; +float _BlendMode; // Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" // value that exist to identify if the GI emission need to be enabled. From a8c6b124df50b328def075ab07ac02eca4ce6566 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 15 Sep 2020 16:19:13 +0200 Subject: [PATCH 02/21] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 7d7edb7890c..c6e8a58c90a 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -88,6 +88,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Improved performance to avoid generating coarse stencil buffer when not needed. - Remove HTile generation for decals (faster without). - Improving SSGI Filtering and fixing a blend issue with RTGI. +- Removed BLEND shader keywords. ## [10.0.0] - 2019-06-10 From 9565a43651c10f042a570f5f84c28be2a9a34aee Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Thu, 1 Oct 2020 21:16:15 +0200 Subject: [PATCH 03/21] Update DecalProperties.hlsl --- .../Runtime/Material/Decal/DecalProperties.hlsl | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl index 44d9ec4b974..de428ae8d3b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl @@ -23,7 +23,6 @@ float _AORemapMin; float _AORemapMax; float _MetallicScale; float _DecalMaskMapBlueScale; -float _BlendMode; float _Smoothness; float _AO; From d6a14a1e0e21cf419bdfa88988e6ba14a434ef9c Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 2 Oct 2020 08:46:18 +0200 Subject: [PATCH 04/21] revert change in AxF shader --- .../Runtime/Material/AxF/AxF.shader | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index d523c06e715..44cb5cbb602 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -120,8 +120,7 @@ Shader "HDRP/AxF" // [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 - // We never set this as it is always 1, but its definition is needed when performing blending in Material.hlsl - [HideInInspector][ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 +// [HideInInspector][ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 [ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0 [Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 // This is for the editor only, see BaseLitUI.cs: _DoubleSidedConstants will be set based on the mode. From e24374393713f916a4fab16fd213e7a1ad8f6122 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Fri, 2 Oct 2020 21:36:34 +0200 Subject: [PATCH 05/21] fix compile issue with ordering when using VT --- .../Editor/Material/ShaderGraph/HDTarget.cs | 3 --- .../ShaderGraph/Templates/ShaderPass.template | 13 ++++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index 156f6cf827e..ecb2f283f52 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -855,7 +855,6 @@ static class CoreDefines static class CoreIncludes { // CorePregraph - public const string kTextureStack = "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"; public const string kShaderVariables = "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"; public const string kFragInputs = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"; public const string kMaterial = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"; @@ -933,7 +932,6 @@ static class CoreIncludes public static IncludeCollection CorePregraph = new IncludeCollection { - { kTextureStack, IncludeLocation.Pregraph }, // TODO: put this on a conditional { kShaderVariables, IncludeLocation.Pregraph }, { kFragInputs, IncludeLocation.Pregraph }, { kDebugDisplay, IncludeLocation.Pregraph }, @@ -943,7 +941,6 @@ static class CoreIncludes public static IncludeCollection RaytracingCorePregraph = new IncludeCollection { // Pregraph includes - { CoreIncludes.kTextureStack, IncludeLocation.Pregraph }, { CoreIncludes.kFragInputs, IncludeLocation.Pregraph }, // Ray Tracing macros should be included before shader variables to guarantee that the macros are overriden diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index 619c5df8969..682ed590287 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -26,6 +26,7 @@ Pass #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB // -------------------------------------------------- // Defines @@ -108,20 +109,22 @@ Pass // Dots Instancing $splice(DotsInstancingOptions) + // Various properties + $splice(HybridV1InjectedBuiltinProperties) - // Graph Properties + // -- Graph Properties $splice(GraphProperties) - // Includes - $splice(PreGraphIncludes) - - // Properties used by SceneSelectionPass + // -- Properties used by SceneSelectionPass #ifdef SCENESELECTIONPASS int _ObjectId; int _PassValue; #endif + // Includes + $splice(PreGraphIncludes) + // -------------------------------------------------- // Structs and Packing From 82db84eeb2c2873c2065e137aa04ae6767cf2631 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Fri, 2 Oct 2020 21:47:27 +0200 Subject: [PATCH 06/21] update comment --- .../VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs index 897b29b235b..0ec5076c057 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs @@ -428,16 +428,16 @@ public override IEnumerable> additionalRep var forwardDefines = new VFXShaderWriter(); forwardDefines.WriteLine("#define _ENABLE_FOG_ON_TRANSPARENT"); forwardDefines.WriteLine("#define _DISABLE_DECALS"); - switch (blendMode) + switch (blendMode) // see MaterialBlendModeEnum.cs { case BlendMode.Alpha: - forwardDefines.WriteLine("#define _BlendMode 0"); + forwardDefines.WriteLine("#define _BlendMode 0"); // BLENDMODE_ALPHA (0) break; case BlendMode.Additive: - forwardDefines.WriteLine("#define _BlendMode 1"); + forwardDefines.WriteLine("#define _BlendMode 1"); // BLENDMODE_ADDITIVE (1) break; case BlendMode.AlphaPremultiplied: - forwardDefines.WriteLine("#define _BlendMode 4"); + forwardDefines.WriteLine("#define _BlendMode 4"); // BLENDMODE_PREMULTIPLY (4) break; } if (!isBlendModeOpaque) From d4c0ceacee87a587482aff021922c1e34789e86f Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Fri, 2 Oct 2020 21:56:10 +0200 Subject: [PATCH 07/21] Update Upgrading-from-2020.1-to-2020.2.md --- .../Upgrading-from-2020.1-to-2020.2.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md index 817205919ec..d1a21ddfe39 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -154,6 +154,19 @@ to: For example, the call in the Lit shader has been updated to: `float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness), lightData.rangeCompressionFactorCompensation, posInput.positionNDC);` +From 10.x, the shader keywords _BLENDMODE_ALPHA _BLENDMODE_ADD and _BLENDMODE_PRE_MULTIPLY have been removed. They are no longer used and the property _Blendmode is used instead. +For example in Material.hlsl, the following lines: +``` + #if defined(_BLENDMODE_ADD) || defined(_BLENDMODE_ALPHA) + return float4(diffuseLighting * opacity + specularLighting, opacity); +``` +is replace by +``` + if (_BlendMode == BLENDMODE_ALPHA || _BlendMode == BLENDMODE_ADDITIVE) + return float4(diffuseLighting * opacity + specularLighting, opacity); +``` +This reduced the number of shader variant. In case of custom shader it can be required to move the include of Material.hlsl after the declaration of the property _Blendmode. + ## raytracing From Unity 2020.2, the Raytracing Node in shader graph now apply the raytraced path (previously low path) to all raytraced effects but path tracing. From 2e945e708536a936920618ba3c5b31334e9fb357 Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Fri, 2 Oct 2020 22:00:41 +0200 Subject: [PATCH 08/21] update comment + optimized code version (in case of bad compiler) --- .../Runtime/Material/Material.hlsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl index c068b2a5907..3c1a660a0a6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl @@ -80,6 +80,7 @@ float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 i float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha + /* if (_BlendMode == BLENDMODE_ALPHA) { // Regular alpha blend need to multiply fog color by opacity (as we do src * src_a inside the shader) @@ -102,6 +103,9 @@ float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 i // (see the appendix in the Deep Compositing paper). But do we? // Additionally, we do not modify the alpha here, which is most certainly WRONG. } + */ + // Branch expression above reduce to this one below. The resulting generated code is exactly the same, but we never know if we met a bad compiler. + result.rgb = result.rgb * (1.0 - volOpacity) + (_BlendMode != BLENDMODE_ADDITIVE) ? volColor * result.a : 0.0; #else // Evaluation of fog for opaque objects is currently done in a full screen pass independent from any material parameters. From a9d8502a3622002392407a6f32fd890a2ed087ee Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Sat, 3 Oct 2020 12:11:27 +0200 Subject: [PATCH 09/21] update comment revert (wrong) optimization --- .../Runtime/Material/Material.hlsl | 5 +---- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl index 3c1a660a0a6..9fc118668d4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl @@ -72,6 +72,7 @@ float4 ApplyBlendMode(float3 color, float opacity) // Used for transparent object. input color is color + alpha of the original transparent pixel. // This must be call after ApplyBlendMode to work correctly +// Caution: Must stay in sync with VFXApplyFog in VFXCommon.hlsl float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 inputColor) { float4 result = inputColor; @@ -80,7 +81,6 @@ float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 i float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha - /* if (_BlendMode == BLENDMODE_ALPHA) { // Regular alpha blend need to multiply fog color by opacity (as we do src * src_a inside the shader) @@ -103,9 +103,6 @@ float4 EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, float4 i // (see the appendix in the Deep Compositing paper). But do we? // Additionally, we do not modify the alpha here, which is most certainly WRONG. } - */ - // Branch expression above reduce to this one below. The resulting generated code is exactly the same, but we never know if we met a bad compiler. - result.rgb = result.rgb * (1.0 - volOpacity) + (_BlendMode != BLENDMODE_ADDITIVE) ? volColor * result.a : 0.0; #else // Evaluation of fog for opaque objects is currently done in a full screen pass independent from any material parameters. diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index e055fc79581..3c81ddefda2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -139,9 +139,11 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) float3 V = GetWorldSpaceNormalizeViewDir(posRWS); + // Caution: This is a copy/paste of EvaluateAtmosphericScattering in Material.hlsl because there is no _BlendMode here float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha + #if VFX_BLENDMODE_ALPHA color.rgb = color.rgb * (1 - volOpacity) + volColor * color.a; #elif VFX_BLENDMODE_ADD From c29c2c2ef62734ec757447a4166a40dbb8359db9 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sat, 3 Oct 2020 17:29:07 +0200 Subject: [PATCH 10/21] remove unused multicopmile in test --- .../2208_And_2209_Reflection_Stencil/StencilShowShader.shader | 1 - .../2208_And_2209_Reflection_Stencil/StencilWriteShader.shader | 1 - 2 files changed, 2 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilShowShader.shader b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilShowShader.shader index 4fddac06f1a..ea14c9eaf94 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilShowShader.shader +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilShowShader.shader @@ -88,7 +88,6 @@ Shader "Custom/StencilShowShader" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT //enable GPU instancing support diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilWriteShader.shader b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilWriteShader.shader index d6eb76b74a3..3cc31cfb464 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilWriteShader.shader +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2208_And_2209_Reflection_Stencil/StencilWriteShader.shader @@ -88,7 +88,6 @@ Shader "Custom/StencilWriteShader" // Keyword for transparent #pragma shader_feature _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY #pragma shader_feature_local _ENABLE_FOG_ON_TRANSPARENT //enable GPU instancing support From e3183f037ad8a7124f8de72aac1358566e25ffe0 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sat, 3 Oct 2020 18:28:49 +0200 Subject: [PATCH 11/21] candidate fix for VFX --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 20 ++++++++++++------- .../VFXGraph/Shaders/VFXLitPixelOutput.hlsl | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 3c81ddefda2..b0b43a55bde 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -132,18 +132,13 @@ void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS) } float3 VFXGetPositionRWS(float3 posWS); //Forward declaration because this function is actually implemented in VFXCommonOutput.hlsl (but expected to be used in fragment only) -float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) -{ - float3 posRWS = VFXGetPositionRWS(posWS); - PositionInputs posInput = GetPositionInput(posCS.xy, _ScreenSize.zw, posCS.z, posCS.w, posRWS, uint2(0,0)); - - float3 V = GetWorldSpaceNormalizeViewDir(posRWS); +float4 VFXApplyFog(PositionInputs posInput, float3 V, float4 color) +{ // Caution: This is a copy/paste of EvaluateAtmosphericScattering in Material.hlsl because there is no _BlendMode here float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha - #if VFX_BLENDMODE_ALPHA color.rgb = color.rgb * (1 - volOpacity) + volColor * color.a; #elif VFX_BLENDMODE_ADD @@ -156,6 +151,17 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) #endif return color; + +} + +float4 VFXApplyFog(float4 color, float4 posCS, float3 posWS) +{ + float3 posRWS = VFXGetPositionRWS(posWS); + PositionInputs posInput = GetPositionInput(posCS.xy, _ScreenSize.zw, posCS.z, posCS.w, posRWS, uint2(0,0)); + + float3 V = GetWorldSpaceNormalizeViewDir(posRWS); + + return VFXApplyFog(posInput, V, color); } #ifdef VFX_VARYING_PS_INPUTS diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl index f658426087e..54c303f8a3f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl @@ -33,7 +33,7 @@ float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const BuiltinDat specularLighting *= GetCurrentExposureMultiplier(); float4 outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); - outColor = EvaluateAtmosphericScattering(posInput, GetWorldSpaceNormalizeViewDir(posRWS), outColor); + outColor = VFXApplyFog(posInput, GetWorldSpaceNormalizeViewDir(posRWS), outColor); #ifdef DEBUG_DISPLAY // Same code in ShaderPassForward.shader From 4f9ee94abce6aaa767c05529264b3e8ddb572d54 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 09:42:17 +0200 Subject: [PATCH 12/21] Revert "candidate fix for VFX" This reverts commit e3183f037ad8a7124f8de72aac1358566e25ffe0. --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 20 +++++++------------ .../VFXGraph/Shaders/VFXLitPixelOutput.hlsl | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index b0b43a55bde..3c81ddefda2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -132,13 +132,18 @@ void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS) } float3 VFXGetPositionRWS(float3 posWS); //Forward declaration because this function is actually implemented in VFXCommonOutput.hlsl (but expected to be used in fragment only) - -float4 VFXApplyFog(PositionInputs posInput, float3 V, float4 color) +float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) { + float3 posRWS = VFXGetPositionRWS(posWS); + PositionInputs posInput = GetPositionInput(posCS.xy, _ScreenSize.zw, posCS.z, posCS.w, posRWS, uint2(0,0)); + + float3 V = GetWorldSpaceNormalizeViewDir(posRWS); + // Caution: This is a copy/paste of EvaluateAtmosphericScattering in Material.hlsl because there is no _BlendMode here float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha + #if VFX_BLENDMODE_ALPHA color.rgb = color.rgb * (1 - volOpacity) + volColor * color.a; #elif VFX_BLENDMODE_ADD @@ -151,17 +156,6 @@ float4 VFXApplyFog(PositionInputs posInput, float3 V, float4 color) #endif return color; - -} - -float4 VFXApplyFog(float4 color, float4 posCS, float3 posWS) -{ - float3 posRWS = VFXGetPositionRWS(posWS); - PositionInputs posInput = GetPositionInput(posCS.xy, _ScreenSize.zw, posCS.z, posCS.w, posRWS, uint2(0,0)); - - float3 V = GetWorldSpaceNormalizeViewDir(posRWS); - - return VFXApplyFog(posInput, V, color); } #ifdef VFX_VARYING_PS_INPUTS diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl index 54c303f8a3f..f658426087e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl @@ -33,7 +33,7 @@ float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const BuiltinDat specularLighting *= GetCurrentExposureMultiplier(); float4 outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); - outColor = VFXApplyFog(posInput, GetWorldSpaceNormalizeViewDir(posRWS), outColor); + outColor = EvaluateAtmosphericScattering(posInput, GetWorldSpaceNormalizeViewDir(posRWS), outColor); #ifdef DEBUG_DISPLAY // Same code in ShaderPassForward.shader From 4d7bc8c0d31a50e86a7f33636c05b643d106fc7f Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 11:03:15 +0200 Subject: [PATCH 13/21] Another tentative fix --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 3c81ddefda2..10bdd4ea7a0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -139,10 +139,14 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) float3 V = GetWorldSpaceNormalizeViewDir(posRWS); - // Caution: This is a copy/paste of EvaluateAtmosphericScattering in Material.hlsl because there is no _BlendMode here +#ifndef SHADERPASS +#error SHADERPASS should always be defined. +#endif + +#ifdef SHADERPASS && SHADERPASS == SHADERPASS_FORWARD float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha - +#endif #if VFX_BLENDMODE_ALPHA color.rgb = color.rgb * (1 - volOpacity) + volColor * color.a; From 83071088d2b8f08c35ee8e99607cde033a798ee1 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 11:28:59 +0200 Subject: [PATCH 14/21] Try differently --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 10bdd4ea7a0..2521f77c2d2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -139,11 +139,7 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) float3 V = GetWorldSpaceNormalizeViewDir(posRWS); -#ifndef SHADERPASS -#error SHADERPASS should always be defined. -#endif - -#ifdef SHADERPASS && SHADERPASS == SHADERPASS_FORWARD +#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_FORWARD) float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha #endif From 6dd8c6d8cfa0f3b974ff67b41a1a9308b4590b90 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 11:58:41 +0200 Subject: [PATCH 15/21] Fix compile issue. --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 2521f77c2d2..c0929c2fe53 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -139,8 +139,9 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) float3 V = GetWorldSpaceNormalizeViewDir(posRWS); + float3 volColor = 0; + float3 volOpacity = 0; #if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_FORWARD) - float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha #endif From 0d41c06aec0b39f31b44f67364663122904fef97 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 14:39:15 +0200 Subject: [PATCH 16/21] Another vfx fix attempt. --- .../Runtime/VFXGraph/Shaders/VFXLit.hlsl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl index 52c493d8436..d32ea3b9064 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl @@ -11,9 +11,9 @@ // Make VFX only sample probe volumes as SH0 for performance. #define PROBE_VOLUMES_SAMPLING_MODE PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L0 -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" // The light loop (or lighting architecture) is in charge to: @@ -38,6 +38,10 @@ #else // (SHADERPASS == SHADERPASS_FORWARD) + #if (SHADERPASS == SHADERPASS_GBUFFER) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #endif + #ifdef HDRP_MATERIAL_TYPE_SIMPLE #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl" #else @@ -159,4 +163,4 @@ SurfaceData VFXGetSurfaceData(const VFX_VARYING_PS_INPUTS i, float3 normalWS,con } -#endif \ No newline at end of file +#endif From b07cec0649ff483b4f4d5bfcb59da356c2f772a3 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 16:04:30 +0200 Subject: [PATCH 17/21] Latest flavour of fix. --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 5 +---- .../Runtime/VFXGraph/Shaders/VFXDefines.hlsl | 12 ++++++++++++ .../Runtime/VFXGraph/Shaders/VFXLit.hlsl | 6 +----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index c0929c2fe53..78684f3182c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -139,11 +139,8 @@ float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS) float3 V = GetWorldSpaceNormalizeViewDir(posRWS); - float3 volColor = 0; - float3 volOpacity = 0; -#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_FORWARD) + float3 volColor, volOpacity; EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha -#endif #if VFX_BLENDMODE_ALPHA color.rgb = color.rgb * (1 - volOpacity) + volColor * color.a; diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXDefines.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXDefines.hlsl index f18665dbebd..e75eeb8556a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXDefines.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXDefines.hlsl @@ -1,5 +1,17 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialBlendModeEnum.cs.hlsl" + +#if VFX_BLENDMODE_ALPHA + #define _BlendMode BLENDMODE_ALPHA +#elif VFX_BLENDMODE_ADD + #define _BlendMode BLENDMODE_ADDITIVE +#elif VFX_BLENDMODE_PREMULTIPLY + #define _BlendMode BLENDMODE_PREMULTIPLY +#else + //Opaque, doesn't really matter what we specify, but a definition is needed to avoid compilation errors. + #define _BlendMode BLENDMODE_ALPHA +#endif #if IS_TRANSPARENT_PARTICLE && !HDRP_LIT // Fog for opaque is handled in a dedicated pass #define USE_FOG 1 diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl index d32ea3b9064..03fb93a5a65 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLit.hlsl @@ -11,9 +11,9 @@ // Make VFX only sample probe volumes as SH0 for performance. #define PROBE_VOLUMES_SAMPLING_MODE PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L0 +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #if (SHADERPASS == SHADERPASS_FORWARD) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" // The light loop (or lighting architecture) is in charge to: @@ -38,10 +38,6 @@ #else // (SHADERPASS == SHADERPASS_FORWARD) - #if (SHADERPASS == SHADERPASS_GBUFFER) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #endif - #ifdef HDRP_MATERIAL_TYPE_SIMPLE #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl" #else From dbb63b45fe2c13e0b3a018ee59622e4fb2d36b33 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 5 Oct 2020 17:25:50 +0200 Subject: [PATCH 18/21] Remove old defines --- .../Outputs/VFXAbstractParticleHDRPLitOutput.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs index 0ec5076c057..467a80a226d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs @@ -428,18 +428,7 @@ public override IEnumerable> additionalRep var forwardDefines = new VFXShaderWriter(); forwardDefines.WriteLine("#define _ENABLE_FOG_ON_TRANSPARENT"); forwardDefines.WriteLine("#define _DISABLE_DECALS"); - switch (blendMode) // see MaterialBlendModeEnum.cs - { - case BlendMode.Alpha: - forwardDefines.WriteLine("#define _BlendMode 0"); // BLENDMODE_ALPHA (0) - break; - case BlendMode.Additive: - forwardDefines.WriteLine("#define _BlendMode 1"); // BLENDMODE_ADDITIVE (1) - break; - case BlendMode.AlphaPremultiplied: - forwardDefines.WriteLine("#define _BlendMode 4"); // BLENDMODE_PREMULTIPLY (4) - break; - } + if (!isBlendModeOpaque) { if (preserveSpecularLighting) From bb5730a1cc70e446475499ba11fc605bd4ac0fd2 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 7 Oct 2020 12:26:51 +0200 Subject: [PATCH 19/21] Fix hybrid --- .../Editor/Material/ShaderGraph/HDTarget.cs | 2 -- .../Editor/Material/ShaderGraph/Templates/ShaderPass.template | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index ecb2f283f52..d6ef21eb621 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -932,8 +932,6 @@ static class CoreIncludes public static IncludeCollection CorePregraph = new IncludeCollection { - { kShaderVariables, IncludeLocation.Pregraph }, - { kFragInputs, IncludeLocation.Pregraph }, { kDebugDisplay, IncludeLocation.Pregraph }, { kMaterial, IncludeLocation.Pregraph }, }; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index 682ed590287..34231b87c85 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -25,6 +25,8 @@ Pass $splice(GraphKeywords) #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB From c26d61290d4bed064ccb9fa2f2a65ca85c3b10c4 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 7 Oct 2020 12:47:16 +0200 Subject: [PATCH 20/21] Update includes in ray tracing --- .../Editor/Material/ShaderGraph/HDTarget.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index d6ef21eb621..267e7ebdbc0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -939,11 +939,7 @@ static class CoreIncludes public static IncludeCollection RaytracingCorePregraph = new IncludeCollection { // Pregraph includes - { CoreIncludes.kFragInputs, IncludeLocation.Pregraph }, - - // Ray Tracing macros should be included before shader variables to guarantee that the macros are overriden { CoreIncludes.kRaytracingMacros, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderVariables, IncludeLocation.Pregraph }, { CoreIncludes.kMaterial, IncludeLocation.Pregraph }, { CoreIncludes.kShaderVariablesRaytracing, IncludeLocation.Pregraph }, { CoreIncludes.kShaderVariablesRaytracingLightLoop, IncludeLocation.Pregraph }, From f20716566f8c7ca31eaed77194205c3c2e30b7a5 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Thu, 8 Oct 2020 00:28:55 +0200 Subject: [PATCH 21/21] Update Upgrading-from-2020.1-to-2020.2.md --- .../Documentation~/Upgrading-from-2020.1-to-2020.2.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md index 52138c08965..bb0f4665d4c 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -183,6 +183,8 @@ From 10.x, HDRP includes a new optimization for [Planar Reflection Probes](Plana For example, the call in the Lit shader has been updated to: `float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections, lightData.rangeCompressionFactorCompensation, posInput.positionNDC);` +## Raytracing + From Unity 2020.2, the Raytracing Node in shader graph now apply the raytraced path (previously low path) to all raytraced effects but path tracing. ## Custom pass API