diff options
| author | yum <yum.food.vr@gmail.com> | 2024-11-18 18:16:38 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-11-18 18:16:38 -0800 |
| commit | 8bc2ce35d518a37cc07fba23613d85822c9c0ea6 (patch) | |
| tree | c917bba999b5491d08291612d8472db2cda6ba84 | |
| parent | 5fdbeddf4b0002ae292c6f4081a0c9baeda919bf (diff) | |
Add ACES filmic toggle to main shader
| -rw-r--r-- | Editor/tooner.cs | 8 | ||||
| -rw-r--r-- | feature_macros.cginc | 1 | ||||
| -rw-r--r-- | pbr.cginc | 9 | ||||
| -rw-r--r-- | tone.cginc | 7 | ||||
| -rw-r--r-- | tone_iq.cginc | 7 | ||||
| -rw-r--r-- | tooner.shader | 1 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 8 |
7 files changed, 32 insertions, 9 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 2f87fb3..18aeaf7 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -2776,6 +2776,14 @@ public class ToonerGUI : ShaderGUI { EditorGUI.indentLevel -= 1; } + bc = FindProperty("_Aces_Filmic_Enable_Static"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Enable ACES filmic", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + SetKeyword("_ACES_FILMIC", enabled); + EditorGUI.BeginChangeCheck(); editor.LightmapEmissionProperty(); if (EditorGUI.EndChangeCheck()) { diff --git a/feature_macros.cginc b/feature_macros.cginc index 3367e7a..ec4c546 100644 --- a/feature_macros.cginc +++ b/feature_macros.cginc @@ -226,6 +226,7 @@ #pragma shader_feature_local _ _GIMMICK_GERSTNER_WATER_OCTAVE_1 #pragma shader_feature_local _ _GIMMICK_GERSTNER_WATER_COLOR_RAMP #pragma shader_feature_local _ _OPTIMIZE_INTERPOLATORS +#pragma shader_feature_local _ _ACES_FILMIC #endif // __FEATURE_MACROS_INC @@ -6,6 +6,7 @@ #include "interpolators.cginc" #include "MochieStandardBRDF.cginc" #include "poi.cginc" +#include "tone.cginc" #ifndef __PBR_INC #define __PBR_INC @@ -227,7 +228,7 @@ float4 getLitColor( { direct_light.dir = getDirectLightDirection(i); direct_light.ndotl = DotClamped(normal, direct_light.dir); -#define POI_LIGHTING +//#define POI_LIGHTING #if defined(POI_LIGHTING) direct_light.color = getPoiLightingDirect(normal); #else @@ -275,12 +276,12 @@ float4 getLitColor( // Do this to avoid division by 0. If both light sources are black, // sum_brightness could be 0; #if defined(_BRIGHTNESS_CLAMP) - brightnesses = max(brightnesses, _Min_Brightness); + brightnesses = smooth_max(brightnesses, _Min_Brightness); #endif float sum_brightness = brightnesses[0] + brightnesses[1]; float2 brightness_proportions = brightnesses / sum_brightness; #if defined(_BRIGHTNESS_CLAMP) - sum_brightness = clamp(sum_brightness, _Min_Brightness, _Max_Brightness); + sum_brightness = smooth_clamp(sum_brightness, _Min_Brightness, _Max_Brightness); #endif direct_light.color[2] = sum_brightness * brightness_proportions[0]; indirect_light.diffuse[2] = sum_brightness * brightness_proportions[1]; @@ -310,7 +311,7 @@ float4 getLitColor( // Specular has to be clamped separately to avoid artifacting. #if defined(_BRIGHTNESS_CLAMP) - indirect_light.specular[2] = clamp(indirect_light.specular[2], _Min_Brightness, _Max_Brightness); + indirect_light.specular[2] = smooth_clamp(indirect_light.specular[2], _Min_Brightness, _Max_Brightness); #endif direct_light.color = HSVtoRGB(direct_light.color); @@ -21,7 +21,7 @@ float3 aces_filmic(float3 x) { // Nice properties: // 1. At x=0, the derivative is 1. // 2. No transcendental ops, and branchless. -float3 smooth_clamp(float3 x, float k) { +float3 smooth_min(float3 x, float k) { // Derivation of `b` from `k`: // f(x, b) = b * x / (x + b) // We want f(1, b) = k. @@ -40,12 +40,15 @@ float3 smooth_clamp(float3 x, float k) { float b = k/(1-k); return b * x / (x + b); } -float smooth_clamp(float x, float k) { +float smooth_min(float x, float k) { float e = 1E-4; k = min(1-e, k); float b = k/(1-k); return b * x / (x + b); } +float smooth_clamp(float x, float lo, float hi) { + return smooth_max(smooth_min(x, hi), lo); +} #endif // __TONE_INC diff --git a/tone_iq.cginc b/tone_iq.cginc index d9d3bde..4d3845b 100644 --- a/tone_iq.cginc +++ b/tone_iq.cginc @@ -6,8 +6,10 @@ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // https://iquilezles.org/articles/functions/ -float almost_identity( float x, float m, float n ) +// Called "almost identity" there. +float smooth_max(float x, float n) { + float m = min(1, n*2); float a = 2.0*n - m; float b = 2.0*m - 3.0*n; float t = x/m; @@ -16,8 +18,9 @@ float almost_identity( float x, float m, float n ) x, x > m); } -float3 almost_identity( float3 x, float3 m, float3 n ) +float3 smooth_max(float3 x, float n) { + float m = min(1, n*2); float3 a = 2.0*n - m; float3 b = 2.0*m - 3.0*n; float3 t = x/m; diff --git a/tooner.shader b/tooner.shader index 6cf6c68..44cac77 100644 --- a/tooner.shader +++ b/tooner.shader @@ -193,6 +193,7 @@ Shader "yum_food/tooner" _NormalStr("Normal strength", Range(0, 10)) = 1 _Ambient_Occlusion("Ambient occlusion", 2D) = "white" {} _Ambient_Occlusion_Strength("Ambient occlusion", Range(0,1)) = 1 + _Aces_Filmic_Enable_Static("Enable ACES filmic tonemapping", Float) = 0 _Proximity_Dimming_Enable_Static("Enable proximity dimming", Float) = 0 _Proximity_Dimming_Min_Dist("Proximity dimming min distance", Float) = 0 diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 243393a..72b5827 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -16,12 +16,13 @@ #include "iq_sdf.cginc" #include "math.cginc" #include "motion.cginc" +#include "oklab.cginc" #include "pbr.cginc" #include "poi.cginc" #include "shear_math.cginc" +#include "tone.cginc" #include "tooner_scroll.cginc" #include "trochoid_math.cginc" -#include "oklab.cginc" #ifndef TOONER_LIGHTING #define TOONER_LIGHTING @@ -2467,6 +2468,11 @@ float4 effect(inout v2f i, out float depth) #if defined(_GLITTER) result.rgb += glitter_color_unlit * _Glitter_Brightness; #endif + +#if defined(_ACES_FILMIC) + result.rgb = aces_filmic(max(result.rgb, 0)); +#endif + // This version exists for compatibility with the Bakery lightmapper. We // specifically need to expose _EmissionMap and _EmissionColor. #if defined(_EMISSION) |
