Skip to content

Commit

Permalink
added khronos neutral to color adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
z3y committed Sep 4, 2024
1 parent 020f900 commit 7111f4c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Editor/Importer/LitImporterDefaultProperties.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

namespace z3y
{
public static class LitImporterConstants
{
public const string DefaultPropertiesInclude = @"
public static class LitImporterConstants
{
public const string DefaultPropertiesInclude = @"
[Enum(Opaque, 0, Cutout, 1, Fade, 2, Transparent, 3, Additive, 4, Multiply, 5)]_Mode(""Rendering Mode"", Float) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend(""Source Blend"", Float) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend(""Destination Blend"", Float) = 0
Expand All @@ -17,15 +17,15 @@ [HideInInspector] _OffsetFactor ("""", Float) = 0
[HideInInspector] _OffsetUnits ("""", Float) = 0
";

public const string DefaultPropertiesIncludeAfter = @"
public const string DefaultPropertiesIncludeAfter = @"
[ToggleUI] _BakeryAlphaDither(""Bakery Alpha Dither"", Float) = 0
[ToggleOff(_GLOSSYREFLECTIONS_OFF)] _GlossyReflections(""Reflections"", Float) = 1
[ToggleOff(_SPECULARHIGHLIGHTS_OFF)] _SpecularHighlights(""Specular Highlights"", Float) = 1
[HideInInspector] [NonModifiableTextureData] [NoScaleOffset] _DFG(""DFG"", 2D) = ""white"" {}
[HideInInspector] [NonModifiableTextureData] [NoScaleOffset] BlueNoise(""BlueNoise"", 2D) = ""white"" {}
";

public const string AreaLitProperties = @"
public const string AreaLitProperties = @"
[ToggleGroupStart] [Toggle(_AREALIT)] _AreaLitToggle (""Area Lit"", Float) = 0
[Indent] [NoScaleOffset] _LightMesh(""Light Mesh"", 2D) = ""black"" {}
[NoScaleOffset] _LightTex0(""Light Texture 0"", 2D) = ""white"" {}
Expand All @@ -35,7 +35,7 @@ [NoScaleOffset] _LightTex3(""Light Texture 3"", 2DArray) = ""black"" {}
[ToggleGroupEnd] [UnIndent] [ToggleOff] _OpaqueLights(""Opaque Lights"", Float) = 1.0
";

public const string DefaultConfigFile = @"
public const string DefaultConfigFile = @"
DEFINES_START
// comment out to set globally
Expand All @@ -53,13 +53,14 @@ [ToggleGroupEnd] [UnIndent] [ToggleOff] _OpaqueLights(""Opaque Lights"", Float)
// #ifndef UNITY_PBS_USE_BRDF1 // if android
// #define _ACES // enable aces on all materials and override aces toggle
// #define _NEUTRAL // enable neutral on all materials and override neutral toggle
// #define _KHRONOS_NEUTRAL // enable khronos neutral on all materials and override neutral toggle
// #endif
// #define USE_GLOBAL_LIGHTMAP_EXPOSURE // set a global shader property _UdonLightmapExposure with udon to adjust lightmap exposure (use value 0 by default)
DEFINES_END
";
}
}

}
4 changes: 4 additions & 0 deletions Editor/Inspector/DefaultInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ private void DrawPropertyRecursive(Property property, MaterialEditor materialEdi
if (property.childrenVisible)
{
//EditorGUI.indentLevel++;
if (property.children == null)
{
return;
}
foreach (var child in property.children)
{
DrawPropertyRecursive(child, materialEditor, materialProperties);
Expand Down
28 changes: 26 additions & 2 deletions ShaderLibrary/ColorAdjustments.litshader
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PROPERTIES_START
[Space(10)][Toggle(_ACES)] _Aces ("ACES", Float) = 0
// [Toggle(_AGX)] _Agx ("AgX", Float) = 0
[Toggle(_NEUTRAL)] _Neutral ("Neutral", Float) = 0
[Toggle(_KHRONOS_NEUTRAL)] _KhronosNeutral ("Khronos Neutral", Float) = 0

// [Space(10)] [Toggle(_DITHER)] _Dither ("Dither", Float) = 0
// _DitherIntensity ("Intensity", Float) = 1
Expand All @@ -20,6 +21,7 @@ DEFINES_START
#pragma shader_feature_local _COLORGARDING_TONE
#pragma shader_feature_local _NEUTRAL
#pragma shader_feature_local _ACES
#pragma shader_feature_local _KHRONOS_NEUTRAL
#define USE_LIGHTMAP_EXPOSURE
DEFINES_END

Expand Down Expand Up @@ -69,6 +71,26 @@ CODE_START



float3 CommerceToneMapping( float3 color )
{
float desaturation = 0.15;
float startCompression = 0.8 - 0.04;

float x = min(color.r, min(color.g, color.b));
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
color -= offset;

float peak = max(color.r, max(color.g, color.b));
if (peak < startCompression) return color;

float d = 1. - startCompression;
float newPeak = 1. - d * d / (peak + d - startCompression);
color *= newPeak / peak;

float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.);
return lerp(color, newPeak * float3(1, 1, 1), g);
}



half3 RRTAndODTFit2(half3 v)
Expand Down Expand Up @@ -130,9 +152,11 @@ CODE_START
{

#if defined(_NEUTRAL)
color = NeutralTonemap(color);
color = NeutralTonemap(color);
#elif defined(_ACES)
color = ACESFitted2(color);
color = ACESFitted2(color);
#elif defined(_KHRONOS_NEUTRAL)
color = CommerceToneMapping(color);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion ShaderLibrary/ColorAdjustments.litshader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7111f4c

Please sign in to comment.