Skip to content

Remove BLEND keywords and replace with constant branch #1884

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 27 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eeb426c
Removing blend keyword.
FrancescoC-unity Sep 15, 2020
a8c6b12
Changelog
FrancescoC-unity Sep 15, 2020
b45cf64
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 1, 2020
9565a43
Update DecalProperties.hlsl
sebastienlagarde Oct 1, 2020
d6a14a1
revert change in AxF shader
FrancescoC-unity Oct 2, 2020
e96956e
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 2, 2020
e243743
fix compile issue with ordering when using VT
sebastienlagarde Oct 2, 2020
82db84e
update comment
sebastienlagarde Oct 2, 2020
d4c0cea
Update Upgrading-from-2020.1-to-2020.2.md
sebastienlagarde Oct 2, 2020
2e945e7
update comment + optimized code version (in case of bad compiler)
sebastienlagarde Oct 2, 2020
a9d8502
update comment revert (wrong) optimization
sebastienlagarde Oct 3, 2020
7ad64a0
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 3, 2020
a96f083
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 3, 2020
c29c2c2
remove unused multicopmile in test
sebastienlagarde Oct 3, 2020
e3183f0
candidate fix for VFX
sebastienlagarde Oct 3, 2020
4f9ee94
Revert "candidate fix for VFX"
FrancescoC-unity Oct 5, 2020
4d7bc8c
Another tentative fix
FrancescoC-unity Oct 5, 2020
8307108
Try differently
FrancescoC-unity Oct 5, 2020
6dd8c6d
Fix compile issue.
FrancescoC-unity Oct 5, 2020
0d41c06
Another vfx fix attempt.
FrancescoC-unity Oct 5, 2020
b07cec0
Latest flavour of fix.
FrancescoC-unity Oct 5, 2020
dbb63b4
Remove old defines
FrancescoC-unity Oct 5, 2020
8acf5ff
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 5, 2020
bb5730a
Fix hybrid
FrancescoC-unity Oct 7, 2020
c26d612
Update includes in ray tracing
FrancescoC-unity Oct 7, 2020
112a16d
Merge branch 'HDRP/staging' into HDRP/remove-blend-keyword
sebastienlagarde Oct 7, 2020
f207165
Update Upgrading-from-2020.1-to-2020.2.md
sebastienlagarde Oct 7, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -169,6 +169,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Improve performance of GPU light AABB generation
- Removed the max clamp value for the RTR, RTAO and RTGI's ray length (case 1279849).
- Meshes assigned with a decal material are not visible anymore in ray-tracing or path-tracing.
- Removed BLEND shader keywords.

## [10.0.0] - 2019-06-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,23 @@ 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.

From 10.x, HDRP includes a new optimization for [Planar Reflection Probes](Planar-Reflection-Probe.md). Now, when a shader samples a probe's environment map, it samples from mip level 0 if the LightData.roughReflections parameter is enabled (has a value of 1.0). You must update your custom shaders to take this behavior into account.
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,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
Expand Down Expand Up @@ -209,11 +209,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -933,22 +932,14 @@ 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 },
{ kMaterial, IncludeLocation.Pregraph },
};

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
{ CoreIncludes.kRaytracingMacros, IncludeLocation.Pregraph },
{ CoreIncludes.kShaderVariables, IncludeLocation.Pregraph },
{ CoreIncludes.kMaterial, IncludeLocation.Pregraph },
{ CoreIncludes.kShaderVariablesRaytracing, IncludeLocation.Pregraph },
{ CoreIncludes.kShaderVariablesRaytracingLightLoop, IncludeLocation.Pregraph },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ 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

// --------------------------------------------------
// Defines
Expand Down Expand Up @@ -108,17 +111,22 @@ Pass
// Dots Instancing
$splice(DotsInstancingOptions)

// Various properties

$splice(HybridV1InjectedBuiltinProperties)

// Includes
$splice(PreGraphIncludes)
// -- Graph Properties
$splice(GraphProperties)

// Properties used by SceneSelectionPass
// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif

// Includes
$splice(PreGraphIncludes)

// --------------------------------------------------
// Structs and Packing

Expand All @@ -129,8 +137,6 @@ Pass
// --------------------------------------------------
// Graph

// Graph Properties
$splice(GraphProperties)

// Graph Functions
$splice(GraphFunctions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
var forwardDefines = new VFXShaderWriter();
forwardDefines.WriteLine("#define _ENABLE_FOG_ON_TRANSPARENT");
forwardDefines.WriteLine("#define _DISABLE_DECALS");
switch (blendMode)
{
case BlendMode.Alpha:
forwardDefines.WriteLine("#define _BLENDMODE_ALPHA");
break;
case BlendMode.Additive:
forwardDefines.WriteLine("#define _BLENDMODE_ADD");
break;
case BlendMode.AlphaPremultiplied:
forwardDefines.WriteLine("#define _BLENDMODE_PRE_MULTIPLY");
break;
}

if (!isBlendModeOpaque)
{
if (preserveSpecularLighting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Shader "HDRP/AxF"


// [ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0
// [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.
Expand Down Expand Up @@ -180,7 +180,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ float _AlphaCutoff;
float _UseShadowThreshold;
float _AlphaCutoffShadow;
float4 _DoubleSidedConstants;
float _BlendMode;

// Specular AA
float _EnableGeometricSpecularAA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ float _DistortionVectorBias;
float _DistortionBlurScale;
float _DistortionBlurRemapMin;
float _DistortionBlurRemapMax;
float _BlendMode;

float _PPDMaxSamples;
float _PPDMinSamples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,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

Expand Down Expand Up @@ -357,6 +356,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
Expand Down
Loading