Skip to content

Commit 671d2da

Browse files
laylaarabEvergreen
authored andcommitted
Add option for transparent materials to choose whether to contribute to SSR
1 parent 3b933ec commit 671d2da

10 files changed

Lines changed: 72 additions & 5 deletions

File tree

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/Shaders/LitShader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.Rendering;
45

56
namespace UnityEditor.Rendering.Universal.ShaderGUI
67
{
@@ -63,6 +64,13 @@ public override void DrawAdvancedOptions(Material material)
6364
#if URP_SCREEN_SPACE_REFLECTION
6465
if (litProperties.screenSpaceReflections != null)
6566
materialEditor.ShaderProperty(litProperties.screenSpaceReflections, LitGUI.Styles.screenSpaceReflectionsText);
67+
68+
if (litProperties.screenSpaceReflectionsContributeTransparent != null)
69+
{
70+
bool isTransparent = material.renderQueue >= (int)RenderQueue.Transparent;
71+
if (isTransparent)
72+
materialEditor.ShaderProperty(litProperties.screenSpaceReflectionsContributeTransparent, LitGUI.Styles.screenSpaceReflectionsContributeTransparentText);
73+
}
6674
#endif
6775

6876
base.DrawAdvancedOptions(material);

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/Shaders/ParticlesSimpleLitShader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override void DrawSurfaceInputs(Material material)
4040

4141
public override void DrawAdvancedOptions(Material material)
4242
{
43-
SimpleLitGUI.Advanced(shadingModelProperties);
43+
SimpleLitGUI.Advanced(shadingModelProperties, materialEditor, material);
4444

4545
materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
4646
ParticleGUI.FadingOptions(material, materialEditor, particleProps);

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/Shaders/SimpleLitShader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override void DrawSurfaceInputs(Material material)
4444

4545
public override void DrawAdvancedOptions(Material material)
4646
{
47-
SimpleLitGUI.Advanced(shadingModelProperties);
47+
SimpleLitGUI.Advanced(shadingModelProperties, materialEditor, material);
4848
base.DrawAdvancedOptions(material);
4949
}
5050

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitGUI.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public static class Styles
9696
public static GUIContent screenSpaceReflectionsText =
9797
EditorGUIUtility.TrTextContent("Screen Space Reflections",
9898
"When enabled, the Material samples screen space reflections.");
99+
100+
/// <summary>
101+
/// The text and tooltip for the screen space reflections contribute transparent GUI.
102+
/// </summary>
103+
public static GUIContent screenSpaceReflectionsContributeTransparentText =
104+
EditorGUIUtility.TrTextContent("Contribute Screen Space Reflections",
105+
"When enabled, this Material will contribute to screen space reflections. This will include the object in the transparency-depth prepass.");
99106
#endif
100107

101108
/// <summary>
@@ -236,6 +243,11 @@ public struct LitProperties
236243
/// The MaterialProperty for screen space reflections.
237244
/// </summary>
238245
public MaterialProperty screenSpaceReflections;
246+
247+
/// <summary>
248+
/// The MaterialProperty for screen space reflections contribute transparent.
249+
/// </summary>
250+
public MaterialProperty screenSpaceReflectionsContributeTransparent;
239251
#endif
240252

241253
/// <summary>
@@ -284,8 +296,8 @@ public LitProperties(MaterialProperty[] properties)
284296
reflections = BaseShaderGUI.FindProperty("_EnvironmentReflections", properties, false);
285297
#if URP_SCREEN_SPACE_REFLECTION
286298
screenSpaceReflections = BaseShaderGUI.FindProperty("_ScreenSpaceReflections", properties, false);
299+
screenSpaceReflectionsContributeTransparent = BaseShaderGUI.FindProperty("_ScreenSpaceReflectionsContributeTransparent", properties, false);
287300
#endif
288-
289301
clearCoat = BaseShaderGUI.FindProperty("_ClearCoat", properties, false);
290302
clearCoatMap = BaseShaderGUI.FindProperty("_ClearCoatMap", properties, false);
291303
clearCoatMask = BaseShaderGUI.FindProperty("_ClearCoatMask", properties, false);
@@ -493,6 +505,9 @@ public static void SetMaterialKeywords(Material material)
493505
if (material.HasProperty("_ScreenSpaceReflections"))
494506
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONS_OFF",
495507
material.GetFloat("_ScreenSpaceReflections") == 0.0f);
508+
if (material.HasProperty("_ScreenSpaceReflectionsContributeTransparent"))
509+
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF",
510+
material.GetFloat("_ScreenSpaceReflectionsContributeTransparent") == 0.0f && material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent);
496511
#endif
497512
if (material.HasProperty("_OcclusionMap"))
498513
CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/SimpleLitGUI.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public struct SimpleLitProperties
9191
/// </summary>
9292
public MaterialProperty bumpMapProp;
9393

94+
#if URP_SCREEN_SPACE_REFLECTION
95+
/// <summary>
96+
/// The MaterialProperty for screen space reflections contribute transparent.
97+
/// </summary>
98+
public MaterialProperty screenSpaceReflectionsContributeTransparent;
99+
#endif
100+
94101
/// <summary>
95102
/// Constructor for the <c>SimpleLitProperties</c> container struct.
96103
/// </summary>
@@ -104,6 +111,9 @@ public SimpleLitProperties(MaterialProperty[] properties)
104111
smoothnessMapChannel = BaseShaderGUI.FindProperty("_SmoothnessSource", properties, false);
105112
smoothness = BaseShaderGUI.FindProperty("_Smoothness", properties, false);
106113
bumpMapProp = BaseShaderGUI.FindProperty("_BumpMap", properties, false);
114+
#if URP_SCREEN_SPACE_REFLECTION
115+
screenSpaceReflectionsContributeTransparent = BaseShaderGUI.FindProperty("_ScreenSpaceReflectionsContributeTransparent", properties, false);
116+
#endif
107117
}
108118
}
109119

@@ -122,8 +132,10 @@ public static void Inputs(SimpleLitProperties properties, MaterialEditor materia
122132
/// <summary>
123133
/// Draws the advanced GUI.
124134
/// </summary>
125-
/// <param name="properties"></param>
126-
public static void Advanced(SimpleLitProperties properties)
135+
/// <param name="properties">The SimpleLit properties.</param>
136+
/// <param name="materialEditor">The material editor.</param>
137+
/// <param name="material">The material to use.</param>
138+
public static void Advanced(SimpleLitProperties properties, MaterialEditor materialEditor, Material material)
127139
{
128140
SpecularSource specularSource = (SpecularSource)properties.specHighlights.floatValue;
129141
EditorGUI.BeginChangeCheck();
@@ -132,6 +144,15 @@ public static void Advanced(SimpleLitProperties properties)
132144
if (EditorGUI.EndChangeCheck())
133145
properties.specHighlights.floatValue = enabled ? (float)SpecularSource.SpecularTextureAndColor : (float)SpecularSource.NoSpecular;
134146
EditorGUI.showMixedValue = false;
147+
148+
#if URP_SCREEN_SPACE_REFLECTION
149+
if (properties.screenSpaceReflectionsContributeTransparent != null)
150+
{
151+
bool isTransparent = material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent;
152+
if (isTransparent)
153+
materialEditor.ShaderProperty(properties.screenSpaceReflectionsContributeTransparent, LitGUI.Styles.screenSpaceReflectionsContributeTransparentText);
154+
}
155+
#endif
135156
}
136157

137158
/// <summary>
@@ -156,6 +177,12 @@ public static void DoSpecularArea(SimpleLitProperties properties, MaterialEditor
156177
public static void SetMaterialKeywords(Material material)
157178
{
158179
UpdateMaterialSpecularSource(material);
180+
181+
#if URP_SCREEN_SPACE_REFLECTION
182+
if (material.HasProperty("_ScreenSpaceReflectionsContributeTransparent"))
183+
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF",
184+
material.GetFloat("_ScreenSpaceReflectionsContributeTransparent") == 0.0f && material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent);
185+
#endif
159186
}
160187

161188
private static void UpdateMaterialSpecularSource(Material material)

Packages/com.unity.render-pipelines.universal/Shaders/ComplexLit.shader

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Shader "Universal Render Pipeline/Complex Lit"
2525
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
2626
[ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0
2727
[ToggleOff] _ScreenSpaceReflections("Screen Space Reflections", Float) = 1.0
28+
[ToggleOff] _ScreenSpaceReflectionsContributeTransparent("Screen Space Reflections Contribute Transparent", Float) = 1.0
2829

2930
_BumpScale("Scale", Float) = 1.0
3031
_BumpMap("Normal Map", 2D) = "bump" {}
@@ -407,6 +408,7 @@ Shader "Universal Render Pipeline/Complex Lit"
407408
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
408409
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
409410
#pragma shader_feature_local_fragment _SCREENSPACEREFLECTIONS_OFF
411+
#pragma shader_feature_local_fragment _SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF
410412

411413
// -------------------------------------
412414
// Universal Pipeline keywords

Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Shader "Universal Render Pipeline/Lit"
2222
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
2323
[ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0
2424
[ToggleOff] _ScreenSpaceReflections("Screen Space Reflections", Float) = 1.0
25+
[ToggleOff] _ScreenSpaceReflectionsContributeTransparent("Screen Space Reflections Contribute Transparent", Float) = 1.0
2526

2627
_BumpScale("Scale", Float) = 1.0
2728
_BumpMap("Normal Map", 2D) = "bump" {}
@@ -405,6 +406,7 @@ Shader "Universal Render Pipeline/Lit"
405406
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
406407
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
407408
#pragma shader_feature_local_fragment _SCREENSPACEREFLECTIONS_OFF
409+
#pragma shader_feature_local_fragment _SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF
408410

409411
// -------------------------------------
410412
// Unity defined keywords

Packages/com.unity.render-pipelines.universal/Shaders/LitDepthNormalsPass.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ void DepthNormalsFragment(
120120
LODFadeCrossFade(input.positionCS);
121121
#endif
122122

123+
#if _SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF_KEYWORD_DECLARED
124+
if (_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF)
125+
discard;
126+
#endif
127+
123128
#if defined(_GBUFFER_NORMALS_OCT)
124129
float3 normalWS = normalize(input.normalWS);
125130
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms

Packages/com.unity.render-pipelines.universal/Shaders/SimpleLit.shader

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Shader "Universal Render Pipeline/Simple Lit"
1515
_SmoothnessSource("Smoothness Source", Float) = 0.0
1616
_SpecularHighlights("Specular Highlights", Float) = 1.0
1717

18+
[ToggleOff] _ScreenSpaceReflectionsContributeTransparent("Screen Space Reflections Contribute Transparent", Float) = 1.0
19+
1820
[HideInInspector] _BumpScale("Scale", Float) = 1.0
1921
[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}
2022

@@ -352,6 +354,7 @@ Shader "Universal Render Pipeline/Simple Lit"
352354
#pragma shader_feature_local _NORMALMAP
353355
#pragma shader_feature_local _ALPHATEST_ON
354356
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
357+
#pragma shader_feature_local_fragment _SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF
355358

356359
// -------------------------------------
357360
// Unity defined keywords

Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitDepthNormalsPass.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void DepthNormalsFragment(
8787
LODFadeCrossFade(input.positionCS);
8888
#endif
8989

90+
#if _SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF_KEYWORD_DECLARED
91+
if (_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF)
92+
discard;
93+
#endif
94+
9095
#if defined(_GBUFFER_NORMALS_OCT)
9196
float3 normalWS = normalize(input.normalWS);
9297
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms

0 commit comments

Comments
 (0)