Skip to content

Commit e99e470

Browse files
authored
Feature/task 820 hdrp compensation (#84)
* Added UI in CS files and params in the shaders to deal with Compensation. [skip ci] * removed duplicate multi_compile pragma in HDRPToon.shader. [skip ci] * Compensation started to work. * Fixed: GetExposureAdjustedColor() * Enabled _ToonEvAdjustmentCompensation. * The effect of exposure compensation was made to be similar to that of HDRP. * Updated CHANGELOG.md.
1 parent 8414bc6 commit e99e470

File tree

9 files changed

+60
-16
lines changed

9 files changed

+60
-16
lines changed

com.unity.toonshader/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22
## [0.4.1-preview] - 2021-10-27
3+
### Added
4+
* Something similar to exposure compensation.
35
### Fixed:
46
* typo in documants.
7+
* missing mono behaviors in sample scenes.
8+
59
## [0.4.0-preview] - 2021-10-13
610
### Added
711
* HDRP: Compatibility with Box Light, a spot light varietion, as main lights.

com.unity.toonshader/Editor/ModelToonEvAdjustmentInspector.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ public class ModelToonEvAdjustmentInspector : Editor
1313

1414
public override void OnInspectorGUI()
1515
{
16+
1617
const string labelLightAdjustment = "Toon EV Adjustment";
1718
const string labelLightAdjustmentCurve = "Curve";
1819
const string labelLightHighCutFilter = "Light High-Cut Filter";
1920
const string labeIgnoreVolumeExposure = "Ignore Volume Exposure";
20-
21+
const string labelCompensation = "Compensation";
2122

2223
bool isChanged = false;
2324

@@ -46,6 +47,17 @@ public override void OnInspectorGUI()
4647
}
4748

4849

50+
// Compensation
51+
EditorGUILayout.BeginHorizontal();
52+
EditorGUI.BeginChangeCheck();
53+
float compensation = EditorGUILayout.FloatField(labelCompensation, obj.m_Compensation);
54+
if (EditorGUI.EndChangeCheck())
55+
{
56+
Undo.RecordObject(target, "Changed Compensation");
57+
obj.m_Compensation = compensation;
58+
isChanged = true;
59+
}
60+
EditorGUILayout.EndHorizontal();
4961

5062

5163
// curve
@@ -57,7 +69,7 @@ public override void OnInspectorGUI()
5769
obj.m_ExposureAdjustmnt = exposureAdjustment;
5870
isChanged = true;
5971
}
60-
// = obj.m_AnimationCurve; // curve
72+
6173

6274

6375

com.unity.toonshader/Editor/SceneToonEvAdjustmentInspector.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ public class ToonEvAdjustmentCurveCurveInspector : Editor
1515
#endif //
1616
public override void OnInspectorGUI()
1717
{
18+
1819
const string labelLightAdjustment = "Toon EV Adjustment";
1920
const string labelLightAdjustmentCurve = "Curve";
2021
const string labelLightHighCutFilter = "Light High-Cut Filter";
2122
const string labeIgnoreVolumeExposure = "Ignore Volume Exposure";
22-
23+
const string labelCompensation = "Compensation";
2324
#if ADJUSTMENT_CURVE_DEBUG_UI
2425
const string labelExposureMin = "Min:";
2526
const string labelExposureMax = "Max:";
@@ -52,6 +53,17 @@ public override void OnInspectorGUI()
5253

5354

5455

56+
// Compensation
57+
EditorGUILayout.BeginHorizontal();
58+
EditorGUI.BeginChangeCheck();
59+
float compensation = EditorGUILayout.FloatField(labelCompensation, obj.m_Compensation);
60+
if (EditorGUI.EndChangeCheck())
61+
{
62+
Undo.RecordObject(target, "Changed Compensation");
63+
obj.m_Compensation = compensation;
64+
isChanged = true;
65+
}
66+
EditorGUILayout.EndHorizontal();
5567

5668
// curve
5769
EditorGUI.BeginChangeCheck();
@@ -62,7 +74,6 @@ public override void OnInspectorGUI()
6274
obj.m_ExposureAdjustmnt = exposureAdjustment;
6375
isChanged = true;
6476
}
65-
// = obj.m_AnimationCurve; // curve
6677

6778

6879

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ Shader "HDRP/Toon"
10661066
#pragma multi_compile _IS_OUTLINE_CLIPPING_NO _IS_OUTLINE_CLIPPING_YES
10671067
#pragma multi_compile _OUTLINE_NML _OUTLINE_POS
10681068
#pragma shader_feature _ _IS_CLIPPING_MATTE
1069-
#pragma multi_compile _ UTS_DEBUG_SHADOWMAP_NO_OUTLINE
1069+
10701070
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
10711071
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
10721072

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ void Frag(PackedVaryingsToPS packedInput,
497497
float3 envLightColor = envColor;
498498
float3 envLightIntensity = GetLightAttenuation(envLightColor) < 1 ? GetLightAttenuation(envLightColor) : 1;
499499
float3 finalColorWoEmissive = SATURATE_IF_SDR(finalColor) + (envLightColor * envLightIntensity * _GI_Intensity * smoothstep(1, 0, envLightIntensity / 2));
500+
500501
finalColorWoEmissive = GetExposureAdjustedColor(finalColorWoEmissive );
502+
finalColorWoEmissive = ApplyCompensation(finalColorWoEmissive);
501503
finalColor = finalColorWoEmissive + emissive;
502504

503505

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int _ToonEvAdjustmentCurve;
3030
float _ToonEvAdjustmentValueArray[128];
3131
float _ToonEvAdjustmentValueMin;
3232
float _ToonEvAdjustmentValueMax;
33+
float _ToonEvAdjustmentCompensation;
3334
float _ToonIgnoreExposureMultiplier;
3435

3536

@@ -73,11 +74,21 @@ float WeightSample(PositionInputs positionInput)
7374
return 1.0 - saturate(weight);
7475
}
7576

77+
float3 ApplyCompensation(float3 originalColor)
78+
{
79+
float3 ev100_Color = ConvertToEV100(originalColor) +_ToonEvAdjustmentCompensation * 0.5f;
80+
81+
82+
float3 resultColor = max(0, ConvertFromEV100(ev100_Color));
83+
return resultColor;
84+
}
85+
7686
float3 ApplyCurrentExposureMultiplier(float3 color)
7787
{
78-
return color * lerp(GetCurrentExposureMultiplier(),1, _ToonIgnoreExposureMultiplier);
88+
return color * lerp(GetCurrentExposureMultiplier(), 1, _ToonIgnoreExposureMultiplier);
7989
}
8090

91+
8192
float3 GetExposureAdjustedColor(float3 originalColor)
8293
{
8394
if (_ToonEvAdjustmentCurve != 0)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ int _ToonEvAdjustmentCurve;
182182
float _ToonEvAdjustmentValueArray[128];
183183
float _ToonEvAdjustmentValueMin;
184184
float _ToonEvAdjustmentValueMax;
185+
float _ToonEvAdjustmentCompensation;
185186
#endif //#if !defined(_UTS_TOON_EV_PER_MODEL)
186187

187188

com.unity.toonshader/Runtime/ModelToonEvAdjustment.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace Unity.Rendering.Toon
1515
[DisallowMultipleComponent]
1616
public class ModelToonEvAdjustment : MonoBehaviour
1717
{
18-
const string kExposureAdjustmentPorpName = "_ToonEvAdjustmentCurve";
18+
const string kCompensationPorpName = "_ToonEvAdjustmentCompensation";
19+
const string kExposureAdjustmentPropName = "_ToonEvAdjustmentCurve";
1920
const string kExposureArrayPropName = "_ToonEvAdjustmentValueArray";
2021
const string kExposureMinPropName = "_ToonEvAdjustmentValueMin";
2122
const string kExposureMaxPropName = "_ToonEvAdjustmentValueMax";
@@ -42,6 +43,8 @@ public class ModelToonEvAdjustment : MonoBehaviour
4243
internal float[] m_ExposureArray;
4344
[SerializeField]
4445
internal float m_Max, m_Min;
46+
[SerializeField]
47+
internal float m_Compensation;
4548

4649
internal GameObject[] m_Objs;
4750
[SerializeField]
@@ -142,13 +145,12 @@ void Update()
142145
{
143146
m_Renderers[ii].GetPropertyBlock(m_MaterialPropertyBlocks[ii]);
144147

145-
// materialPropertyBlocks[ii].SetColor("_UnlitColor", col);
146148
m_MaterialPropertyBlocks[ii].SetFloatArray(kExposureArrayPropName, m_ExposureArray);
147149
m_MaterialPropertyBlocks[ii].SetFloat(kExposureMinPropName, m_Min);
148150
m_MaterialPropertyBlocks[ii].SetFloat(kExposureMaxPropName, m_Max);
149-
m_MaterialPropertyBlocks[ii].SetInt(kExposureAdjustmentPorpName, m_ExposureAdjustmnt ? 1 : 0);
151+
m_MaterialPropertyBlocks[ii].SetInt(kExposureAdjustmentPropName, m_ExposureAdjustmnt ? 1 : 0);
150152
m_MaterialPropertyBlocks[ii].SetInt(kToonLightFilterPropName, m_ToonLightHiCutFilter ? 1 : 0);
151-
153+
m_MaterialPropertyBlocks[ii].SetFloat(kCompensationPorpName, m_Compensation);
152154

153155
m_Renderers[ii].SetPropertyBlock(m_MaterialPropertyBlocks[ii]);
154156
}

com.unity.toonshader/Runtime/SceneToonEvAdjustment.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class SceneToonEvAdjustment : MonoBehaviour
1919

2020
const int kAdjustmentCurvePrecision = 128;
2121

22-
23-
const string kExposureAdjustmentPorpName = "_ToonEvAdjustmentCurve";
22+
const string kCompensationPorpName = "_ToonEvAdjustmentCompensation";
23+
const string kExposureAdjustmentPropName = "_ToonEvAdjustmentCurve";
2424
const string kExposureArrayPropName = "_ToonEvAdjustmentValueArray";
2525
const string kExposureMinPropName = "_ToonEvAdjustmentValueMin";
2626
const string kExposureMaxPropName = "_ToonEvAdjustmentValueMax";
@@ -40,7 +40,8 @@ public class SceneToonEvAdjustment : MonoBehaviour
4040
[SerializeField]
4141
internal float m_Max, m_Min;
4242
[SerializeField]
43-
internal bool m_DebugUI;
43+
internal float m_Compensation;
44+
4445

4546
private static SceneToonEvAdjustment instance;
4647
#if UNITY_EDITOR
@@ -128,10 +129,10 @@ void Update()
128129
Shader.SetGlobalFloatArray(kExposureArrayPropName, m_ExposureArray);
129130
Shader.SetGlobalFloat(kExposureMinPropName, m_Min);
130131
Shader.SetGlobalFloat(kExposureMaxPropName, m_Max);
131-
Shader.SetGlobalInt(kExposureAdjustmentPorpName, m_ExposureAdjustmnt ? 1 : 0);
132+
Shader.SetGlobalInt(kExposureAdjustmentPropName, m_ExposureAdjustmnt ? 1 : 0);
132133
Shader.SetGlobalInt(kToonLightFilterPropName, m_ToonLightHiCutFilter ? 1 : 0);
133134
Shader.SetGlobalInt(kIgonoreVolumeExposurePropName, m_IgnorVolumeExposure ? 1: 0);
134-
135+
Shader.SetGlobalFloat(kCompensationPorpName, m_Compensation);
135136
}
136137

137138
void EnableSrpCallbacks()
@@ -192,7 +193,7 @@ void Release()
192193
if (m_initialized)
193194
{
194195
m_ExposureArray = null;
195-
Shader.SetGlobalInt(kExposureAdjustmentPorpName, 0);
196+
Shader.SetGlobalInt(kExposureAdjustmentPropName, 0);
196197
Shader.SetGlobalInt(kToonLightFilterPropName, 0);
197198
}
198199

0 commit comments

Comments
 (0)