Skip to content

Commit 3d478df

Browse files
authored
Feature/dx12 shadow test (#61)
* Just created a new project to check DXR shadow on Lit materials. [skip ci] * Deleted unnecessary scenes and their assets. [skip ci] * Added UnityChanLit.mat [skip ci] * Updated shadow debugging files including HDRP shaders. * Creating a test shader to show self shadow. [skip ci] * implementing a self shadow shader. [skip ci] * Self shadow shader is almost OK, maybe. [skip ci] * Deleted LitShaderTestProject. [skip ci] * Removed unnecessary arguments from UTS_SelfShdowMainLight() [skip ci] Co-authored-by: Toshiyuki Mori <[email protected]>
1 parent e761497 commit 3d478df

File tree

11 files changed

+190
-49
lines changed

11 files changed

+190
-49
lines changed

Toonshader_ProjectDX12Sandbox/Assets/Scenes/ToonShader_CelLook(DXRShadow).unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ MonoBehaviour:
836836
m_Name:
837837
m_EditorClassIdentifier:
838838
m_enableShadowmapDebugging: 1
839+
m_enableSelfShadowDebugging: 1
839840
m_enableBinalization: 0
840841
m_enableOutlineDebugging: 0
841842
--- !u!20 &794565945

Toonshader_ProjectDX12Sandbox/Assets/UnityChan/Materials/CellTouch_ToonShader_Main_Firefly.mat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Material:
201201
m_Floats:
202202
- _1st2nd_Shades_Feather: 0.0001
203203
- _1st_ShadeColor_Feather: 0.0001
204-
- _1st_ShadeColor_Step: 0.703
204+
- _1st_ShadeColor_Step: 0.507
205205
- _2nd_ShadeColor_Feather: 0.0001
206206
- _2nd_ShadeColor_Step: 0
207207
- _AORemapMax: 1
@@ -229,7 +229,7 @@ Material:
229229
- _AutoRenderQueue: 1
230230
- _BaseColorOverridden: 0
231231
- _BaseColorVisible: 1
232-
- _BaseColor_Step: 0.703
232+
- _BaseColor_Step: 0.507
233233
- _BaseShade_Feather: 0.0001
234234
- _Base_Speed: 0
235235
- _BlendMode: 0
@@ -423,7 +423,7 @@ Material:
423423
- _Tweak_MatcapMaskLevel: 0
424424
- _Tweak_RimLightMaskLevel: 0
425425
- _Tweak_ShadingGradeMapLevel: 0
426-
- _Tweak_SystemShadowsLevel: -0.066
426+
- _Tweak_SystemShadowsLevel: 0.115
427427
- _Tweak_transparency: 0
428428
- _UVBase: 0
429429
- _UVDetail: 0
@@ -446,7 +446,7 @@ Material:
446446
- _utsVersion: 2.075
447447
- _utsVersionX: 0
448448
- _utsVersionY: 3
449-
- _utsVersionZ: 0
449+
- _utsVersionZ: 1
450450
m_Colors:
451451
- _1st_ShadeColor: {r: 1, g: 1, b: 1, a: 1}
452452
- _2nd_ShadeColor: {r: 0.85294116, g: 0.82158303, b: 0.82158303, a: 1}

com.unity.toonshader/Editor/DebugShadowmapInspector.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DebugShadowmapInspector : Editor
1313
public override void OnInspectorGUI()
1414
{
1515
const string labelDebugShadowmap = "Show Shadowmap";
16+
const string labelDebugSelfShadow = "Show SelfShadow";
1617
const string labelBinalization = "Binalization";
1718
const string labelNoOutline = "No Outline";
1819

@@ -51,23 +52,35 @@ public override void OnInspectorGUI()
5152
EditorGUILayout.EndHorizontal();
5253

5354

54-
EditorGUILayout.BeginHorizontal();
55-
EditorGUI.BeginChangeCheck();
56-
bool showOutline = EditorGUILayout.Toggle(labelNoOutline, obj.m_enableOutlineDebugging);
57-
58-
if (EditorGUI.EndChangeCheck())
59-
{
60-
Undo.RecordObject(target, "Changed Outline flag");
61-
obj.m_enableOutlineDebugging = showOutline;
62-
isChanged = true;
63-
}
64-
EditorGUILayout.EndHorizontal();
65-
6655

6756
EditorGUI.indentLevel--;
6857
}
6958
EditorGUI.EndDisabledGroup();
7059

60+
EditorGUILayout.BeginHorizontal();
61+
EditorGUI.BeginChangeCheck();
62+
bool showSlefShadow = EditorGUILayout.Toggle(labelDebugSelfShadow, obj.m_enableSelfShadowDebugging);
63+
64+
if (EditorGUI.EndChangeCheck())
65+
{
66+
Undo.RecordObject(target, "Changed Self shadow debbuging flag");
67+
obj.m_enableSelfShadowDebugging = showSlefShadow;
68+
isChanged = true;
69+
}
70+
EditorGUILayout.EndHorizontal();
71+
72+
73+
EditorGUILayout.BeginHorizontal();
74+
EditorGUI.BeginChangeCheck();
75+
bool showOutline = EditorGUILayout.Toggle(labelNoOutline, obj.m_enableOutlineDebugging);
76+
77+
if (EditorGUI.EndChangeCheck())
78+
{
79+
Undo.RecordObject(target, "Changed Outline flag");
80+
obj.m_enableOutlineDebugging = showOutline;
81+
isChanged = true;
82+
}
83+
EditorGUILayout.EndHorizontal();
7184
if (isChanged)
7285
{
7386
// at leaset 2020.3.12f1, not neccessary. but, from which version??

com.unity.toonshader/Runtime/DebugShadowmap.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ public class DebugShadowmap : MonoBehaviour
2020
[SerializeField]
2121
internal bool m_enableShadowmapDebugging = false;
2222
[SerializeField]
23+
internal bool m_enableSelfShadowDebugging = false;
24+
[SerializeField]
2325
internal bool m_enableBinalization = false;
2426
[SerializeField]
2527
internal bool m_enableOutlineDebugging = false;
2628

2729

2830

29-
const string kDebugDefine = "UTS_DEBUG_SHADOWMAP";
31+
const string kDebugShadowmapDefine = "UTS_DEBUG_SHADOWMAP";
32+
const string kDebugSelfShadowDefine = "UTS_DEBUG_SELFSHADOW";
3033
const string kDebugDefineNoOutline = "UTS_DEBUG_SHADOWMAP_NO_OUTLINE";
3134
const string kDebugDefineBinalization = "UTS_DEBUG_SHADOWMAP_BINALIZATION";
3235
private static DebugShadowmap instance;
@@ -86,13 +89,24 @@ void Update()
8689
ApplyDebuggingFlag();
8790
}
8891

92+
void EnableSelfShadowKeyword()
93+
{
94+
Shader.EnableKeyword(kDebugSelfShadowDefine);
95+
}
96+
97+
void DisableSelfShadowKeyword()
98+
{
99+
Shader.DisableKeyword(kDebugSelfShadowDefine);
100+
}
101+
102+
89103
void EnableShadowmapKeyword()
90104
{
91-
Shader.EnableKeyword(kDebugDefine);
105+
Shader.EnableKeyword(kDebugShadowmapDefine);
92106
}
93107
void DisableShadowmapKeyword()
94108
{
95-
Shader.DisableKeyword(kDebugDefine);
109+
Shader.DisableKeyword(kDebugShadowmapDefine);
96110
}
97111

98112
void EnableOutlineKeyword()
@@ -164,6 +178,16 @@ void ApplyDebuggingFlag()
164178
{
165179
DisableShadowmapKeyword();
166180
}
181+
if (m_enableSelfShadowDebugging)
182+
{
183+
EnableSelfShadowKeyword();
184+
}
185+
else
186+
{
187+
DisableSelfShadowKeyword();
188+
}
189+
190+
167191
if (m_enableOutlineDebugging)
168192
{
169193
EnableOutlineKeyword();

com.unity.toonshader/Runtime/HDRP/Shaders/HDRPToon.shader

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,9 @@ Shader "HDRP/Toon"
534534
//enable GPU instancing support
535535
#pragma multi_compile_instancing
536536
#pragma instancing_options renderinglayer
537-
// enable debug shadowmap
538-
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP
537+
// enable debug shado
538+
#pragma multi_compile _ UTS_DEBUG_SELFSHADOW
539+
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP
539540
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP_NO_OUTLINE
540541

541542
//-------------------------------------------------------------------------------------

com.unity.toonshader/Runtime/HDRP/Shaders/HDRPToonOutline.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void Frag(PackedVaryingsToPS packedInput,
125125
discard;
126126
}
127127
#endif // _IS_CLIPPING_MATTE
128-
#if defined(UTS_DEBUG_SHADOWMAP) && defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
128+
#if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
129129
discard;
130130
#endif
131131

com.unity.toonshader/Runtime/HDRP/Shaders/HDRPToonTessellation.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ Shader "HDRP/ToonTessellation"
547547
#pragma multi_compile_instancing
548548
#pragma instancing_options renderinglayer
549549

550-
// enable debug shadowmap
550+
// enable debug shado
551+
#pragma multi_compile _ UTS_DEBUG_SELFSHADOW
551552
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP
552553
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP_NO_OUTLINE
553554
//-------------------------------------------------------------------------------------

com.unity.toonshader/Runtime/HDRP/Shaders/ShaderPassForwardUTS.hlsl

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void Frag(PackedVaryingsToPS packedInput,
205205
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(UTS_USE_RAYTRACING_SHADOW)
206206
if (UseScreenSpaceShadow(light, bsdfData.normalWS))
207207
{
208+
// HDRP Contact Shadow
208209
context.shadowValue = GetScreenSpaceColorShadow(posInput, light.screenSpaceShadowIndex).SHADOW_TYPE_SWIZZLE;
209210
}
210211
else
@@ -262,7 +263,10 @@ void Frag(PackedVaryingsToPS packedInput,
262263
int mainLightIndex = GetUtsMainLightIndex(builtinData);
263264
if ( mainLightIndex >= 0)
264265
{
265-
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
266+
#if defined(UTS_DEBUG_SELFSHADOW)
267+
if (_DirectionalShadowIndex >= 0)
268+
finalColor = UTS_SelfShdowMainLight(context, input, _DirectionalShadowIndex);
269+
#elif defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
266270
finalColor = UTS_MainLightShadingGrademap(context, input, mainLightIndex, inverseClipping, channelAlpha, utsData);
267271
#else
268272
finalColor = UTS_MainLight(context, input, mainLightIndex, inverseClipping, channelAlpha, utsData);
@@ -283,14 +287,15 @@ void Frag(PackedVaryingsToPS packedInput,
283287
float3 lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[i].color);
284288
float3 lightDirection = -_DirectionalLightDatas[i].forward;
285289
float notDirectional = 0.0f;
290+
#if defined(UTS_DEBUG_SELFSHADOW)
286291

287-
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
288-
float3 additionalLightColor = UTS_OtherLightsShadingGrademap(input, i_normalDir, lightColor, lightDirection, notDirectional, channelAlpha);
292+
#elif defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
289293

294+
finalColor += UTS_OtherLightsShadingGrademap(input, i_normalDir, lightColor, lightDirection, notDirectional, channelAlpha);
290295
#else
291-
float3 additionalLightColor = UTS_OtherLights(input, i_normalDir, lightColor, lightDirection, notDirectional, channelAlpha);
296+
finalColor += UTS_OtherLights(input, i_normalDir, lightColor, lightDirection, notDirectional, channelAlpha);
292297
#endif
293-
finalColor += additionalLightColor;
298+
294299
}
295300
}
296301
}
@@ -502,21 +507,13 @@ void Frag(PackedVaryingsToPS packedInput,
502507
s_lightData.angleScale, s_lightData.angleOffset);
503508
float3 additionalLightColor = ApplyCurrentExposureMultiplier(s_lightData.color) * attenuation;
504509
const float notDirectional = 1.0f;
510+
#if defined(UTS_DEBUG_SELFSHADOW)
505511

506-
#if defined(_SHADINGGRADEMAP) || defined(UTS_DEBUG_SHADOWMAP)
507-
float3 pointLightColor = UTS_OtherLightsShadingGrademap(input, i_normalDir, additionalLightColor, L, notDirectional, channelAlpha);
512+
#elif defined(_SHADINGGRADEMAP) || defined(UTS_DEBUG_SHADOWMAP)
513+
finalColor += UTS_OtherLightsShadingGrademap(input, i_normalDir, additionalLightColor, L, notDirectional, channelAlpha);
508514
#else
509-
float3 pointLightColor = UTS_OtherLights(input, i_normalDir, additionalLightColor, L, notDirectional, channelAlpha);
515+
finalColor += UTS_OtherLights(input, i_normalDir, additionalLightColor, L, notDirectional, channelAlpha);
510516
#endif
511-
512-
//#if USE_FPTL_LIGHTLIST
513-
// pointLightColor = float3(tileIndex.xy/30, 0.0);
514-
//#endif
515-
//#if USE_CLUSTERED_LIGHTLIST
516-
// pointLightColor = float3(0.0f, 0.0, 1.0);
517-
//#endif
518-
finalColor += pointLightColor;
519-
520517
}
521518

522519
}
@@ -573,7 +570,7 @@ void Frag(PackedVaryingsToPS packedInput,
573570
finalColor = finalColorWoEmissive + emissive;
574571

575572

576-
#if defined(_SHADINGGRADEMAP) || defined(UTS_DEBUG_SHADOWMAP)
573+
#if defined(_SHADINGGRADEMAP) || defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
577574
//v.2.0.4
578575
#ifdef _IS_TRANSCLIPPING_OFF
579576

@@ -605,13 +602,20 @@ void Frag(PackedVaryingsToPS packedInput,
605602
#endif
606603
#endif //#if defined(_SHADINGGRADEMAP)
607604

608-
#ifdef UTS_DEBUG_SHADOWMAP
609-
#ifdef UTS_DEBUG_SHADOWMAP_BINALIZATION
610-
outColor.rgb = context.shadowValue < 0.9f ? clamp(context.shadowValue - 0.2,0.0, 0.9) : 1.0f;
611-
#else
612-
outColor.rgb = context.shadowValue;
605+
#if defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
606+
outColor.rgb = 1;
607+
#ifdef UTS_DEBUG_SELFSHADOW
608+
outColor.rgb = min(finalColor, outColor.rgb);
613609
#endif
614-
#endif
610+
611+
#ifdef UTS_DEBUG_SHADOWMAP
612+
#ifdef UTS_DEBUG_SHADOWMAP_BINALIZATION
613+
outColor.rgb = min(context.shadowValue < 0.9f ? clamp(context.shadowValue - 0.2, 0.0, 0.9) : 1.0f, outColor.rgb);
614+
#else
615+
outColor.rgb = min(context.shadowValue, outColor.rgb);
616+
#endif
617+
#endif // ifdef UTS_DEBUG_SHADOWMAP
618+
#endif // defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
615619

616620
#ifdef _DEPTHOFFSET_ON
617621
outputDepth = posInput.deviceDepth;

com.unity.toonshader/Runtime/HDRP/Shaders/UtsLightLoop.hlsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ int GetUtsMainLightIndex(BuiltinData builtinData)
157157

158158
return mainLightIndex;
159159
}
160-
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
160+
161+
162+
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
161163
# include "ShadingGrademapOtherLight.hlsl"
162164
#else //#if defined(_SHADINGGRADEMAP)
163165
# include "DoubleShadeWithFeatherOtherLight.hlsl"
164166
#endif //#if defined(_SHADINGGRADEMAP)
165167

168+
# include "UtsSelfShadowMainLight.hlsl"
169+
170+
166171

167-
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
172+
#if defined(_SHADINGGRADEMAP)|| defined(UTS_DEBUG_SHADOWMAP)
168173
# include "ShadingGrademapMainLight.hlsl"
169174
#else
170175
# include "DoubleShadeWithFeatherMainLight.hlsl"

0 commit comments

Comments
 (0)