阶段性完成

This commit is contained in:
SoulliesOfficial
2025-12-08 05:27:53 -05:00
parent ef7b479712
commit f7af60351b
8770 changed files with 15637030 additions and 208354 deletions

View File

@@ -0,0 +1,44 @@
// Copied from URP Blit.shader
Shader "Hidden/PotaToon/Blit"
{
Properties
{
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlendRGB", Int) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("DstBlendRGB", Int) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlendAlpha ("SrcBlendAlpha", Int) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlendAlpha ("DstBlendAlpha", Int) = 10
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
Pass
{
Name "Blit"
ZTest Always
ZWrite Off
Cull Off
Blend [_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Fragment
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
SAMPLER(sampler_BlitTexture);
half4 Fragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
half4 col = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv);
return col;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b0808c9524fb487685a365dd7d50bb43
timeCreated: 1762263877
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonBlit.shader
uploadId: 814994

View File

@@ -0,0 +1,288 @@
// Copied from URP Bloom shader
Shader "PotaToon/Bloom"
{
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
#if UNITY_VERSION >= 202230
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GlobalSamplers.hlsl"
#else
SAMPLER(sampler_PointClamp);
SAMPLER(sampler_LinearClamp);
#endif
#ifdef USE_FULL_PRECISION_BLIT_TEXTURE
TEXTURE2D_X_FLOAT(_BlitTexture);
#else
TEXTURE2D_X(_BlitTexture);
#endif
TEXTURE2D_X(_SourceTexLowMip);
TEXTURE2D_X(_PotaToonCharMask);
float4 _SourceTexLowMip_TexelSize;
uniform float4 _BlitTexture_TexelSize;
uniform float _BlitMipLevel;
uniform float2 _BlitTextureSize;
uniform float4 _BlitScaleBias;
float4 _Params; // x: scatter, y: clamp, z: threshold (linear), w: threshold knee
#define Scatter _Params.x
#define ClampMax _Params.y
#define Threshold _Params.z
#define ThresholdKnee _Params.w
float2 DynamicScalingApplyScaleBias(float2 xy, float4 dynamicScalingScaleBias)
{
return dynamicScalingScaleBias.zw + xy * dynamicScalingScaleBias.xy;
}
float2 DynamicScalingRemoveScaleBias(float2 xy, float4 dynamicScalingScaleBias)
{
return (xy - dynamicScalingScaleBias.zw) / dynamicScalingScaleBias.xy;
}
#define DYNAMIC_SCALING_APPLY_SCALEBIAS(uv) DynamicScalingApplyScaleBias(uv, _BlitScaleBias)
#define DYNAMIC_SCALING_REMOVE_SCALEBIAS(uv) DynamicScalingRemoveScaleBias(uv, _BlitScaleBias)
struct Attributes
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
output.positionCS = pos;
output.texcoord = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return output;
}
half4 EncodeHDR(half3 color)
{
#if UNITY_COLORSPACE_GAMMA
color = sqrt(color); // linear to γ
#endif
return half4(color, 1.0);
}
half3 DecodeHDR(half4 data)
{
half3 color = data.xyz;
#if UNITY_COLORSPACE_GAMMA
color *= color; // γ to linear
#endif
return color;
}
half3 SamplePrefilter(float2 uv, float2 offset)
{
float2 texelSize = _BlitTexture_TexelSize.xy;
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + texelSize * offset);
#if _ENABLE_ALPHA_OUTPUT
// When alpha is enabled, regions with zero alpha should not generate any bloom / glow. Therefore we pre-multipy the color with the alpha channel here and the rest
// of the computations remain float3. Still, when bloom is applied to the final image, bloom will still be spread on regions with zero alpha (see UberPost.compute)
color.xyz *= color.w;
#endif
return color.xyz;
}
half4 FragPrefilter(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
// Discard depending on charater / environment
bool isCharArea = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_PointClamp, uv).r > 0.5;
#if _POTA_TOON_CHARACTER_BLOOM
if (!isCharArea)
#else
if (isCharArea)
#endif
return 0;
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
uv = RemapFoveatedRenderingLinearToNonUniform(uv);
}
#endif
#if _BLOOM_HQ
half3 A = SamplePrefilter(uv, float2(-1.0, -1.0));
half3 B = SamplePrefilter(uv, float2( 0.0, -1.0));
half3 C = SamplePrefilter(uv, float2( 1.0, -1.0));
half3 D = SamplePrefilter(uv, float2(-0.5, -0.5));
half3 E = SamplePrefilter(uv, float2( 0.5, -0.5));
half3 F = SamplePrefilter(uv, float2(-1.0, 0.0));
half3 G = SamplePrefilter(uv, float2( 0.0, 0.0));
half3 H = SamplePrefilter(uv, float2( 1.0, 0.0));
half3 I = SamplePrefilter(uv, float2(-0.5, 0.5));
half3 J = SamplePrefilter(uv, float2( 0.5, 0.5));
half3 K = SamplePrefilter(uv, float2(-1.0, 1.0));
half3 L = SamplePrefilter(uv, float2( 0.0, 1.0));
half3 M = SamplePrefilter(uv, float2( 1.0, 1.0));
half2 div = (1.0 / 4.0) * half2(0.5, 0.125);
half3 color = (D + E + I + J) * div.x;
color += (A + B + G + F) * div.y;
color += (B + C + H + G) * div.y;
color += (F + G + L + K) * div.y;
color += (G + H + M + L) * div.y;
#else
half3 color = SamplePrefilter(uv, float2(0,0));
#endif
// User controlled clamp to limit crazy high broken spec
color = min(ClampMax, color);
// Thresholding
half brightness = Max3(color.r, color.g, color.b);
half softness = clamp(brightness - Threshold + ThresholdKnee, 0.0, 2.0 * ThresholdKnee);
softness = (softness * softness) / (4.0 * ThresholdKnee + 1e-4);
half multiplier = max(brightness - Threshold, softness) / max(brightness, 1e-4);
color *= multiplier;
// Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.
color = max(color, 0);
return EncodeHDR(color);
}
half4 FragBlurH(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 texelSize = _BlitTexture_TexelSize.xy * 2.0;
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
// 9-tap gaussian blur on the downsampled source
half3 c0 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(texelSize.x * 4.0, 0.0)));
half3 c1 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(texelSize.x * 3.0, 0.0)));
half3 c2 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(texelSize.x * 2.0, 0.0)));
half3 c3 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(texelSize.x * 1.0, 0.0)));
half3 c4 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv ));
half3 c5 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(texelSize.x * 1.0, 0.0)));
half3 c6 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(texelSize.x * 2.0, 0.0)));
half3 c7 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(texelSize.x * 3.0, 0.0)));
half3 c8 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(texelSize.x * 4.0, 0.0)));
half3 color = c0 * 0.01621622 + c1 * 0.05405405 + c2 * 0.12162162 + c3 * 0.19459459
+ c4 * 0.22702703
+ c5 * 0.19459459 + c6 * 0.12162162 + c7 * 0.05405405 + c8 * 0.01621622;
return EncodeHDR(color);
}
half4 FragBlurV(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 texelSize = _BlitTexture_TexelSize.xy;
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
// Optimized bilinear 5-tap gaussian on the same-sized source (9-tap equivalent)
half3 c0 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(0.0, texelSize.y * 3.23076923)));
half3 c1 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(0.0, texelSize.y * 1.38461538)));
half3 c2 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv ));
half3 c3 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(0.0, texelSize.y * 1.38461538)));
half3 c4 = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(0.0, texelSize.y * 3.23076923)));
half3 color = c0 * 0.07027027 + c1 * 0.31621622
+ c2 * 0.22702703
+ c3 * 0.31621622 + c4 * 0.07027027;
return EncodeHDR(color);
}
half3 Upsample(float2 uv)
{
half3 highMip = DecodeHDR(SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv));
#if _BLOOM_HQ
half3 lowMip = DecodeHDR(SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_SourceTexLowMip, sampler_LinearClamp), uv, _SourceTexLowMip_TexelSize.zwxy, (1.0).xx, unity_StereoEyeIndex));
#else
half3 lowMip = DecodeHDR(SAMPLE_TEXTURE2D_X(_SourceTexLowMip, sampler_LinearClamp, uv));
#endif
return lerp(highMip, lowMip, Scatter);
}
half4 FragUpsample(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
half3 color = Upsample(UnityStereoTransformScreenSpaceTex(input.texcoord));
return EncodeHDR(color);
}
ENDHLSL
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZTest Always ZWrite Off Cull Off
Pass
{
Name "Bloom Prefilter"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragPrefilter
#pragma multi_compile_local_fragment _ _BLOOM_HQ
#pragma multi_compile_fragment _ _ENABLE_ALPHA_OUTPUT
#pragma multi_compile_fragment _ _POTA_TOON_CHARACTER_BLOOM
ENDHLSL
}
Pass
{
Name "Bloom Blur Horizontal"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBlurH
ENDHLSL
}
Pass
{
Name "Bloom Blur Vertical"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBlurV
ENDHLSL
}
Pass
{
Name "Bloom Upsample"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragUpsample
#pragma multi_compile_local_fragment _ _BLOOM_HQ
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 95e1fac9bc3847869f6bbf6bbfe03915
timeCreated: 1742620293
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonBloom.shader
uploadId: 814994

View File

@@ -0,0 +1,65 @@
#ifndef POTA_TOON_SCREEN_POST_PASSES_INCLUDED
#define POTA_TOON_SCREEN_POST_PASSES_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
half4 FragPotaToonScreenOutline(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
#if UNITY_VERSION >= 202230
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.texcoord));
#else
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.uv));
#endif
#if _EXCLUDE_INNER_SCREEN_OUTLINES
bool isCharArea = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_LinearClamp, uv).r > 0.5;
if (isCharArea)
clip(-1);
#endif
const half3 lumWeight = half3(0.299, 0.587, 0.114);
const float2 sobelOffsets[9] = {
float2(-1, -1), float2(0, -1), float2(1, -1),
float2(-1, 0), float2(0, 0), float2(1, 0),
float2(-1, 1), float2(0, 1), float2(1, 1)
};
const half sobelX[9] = { -1, 0, 1, -2, 0, 2, -1, 0, 1 };
const half sobelY[9] = { -1, -2, -1, 0, 0, 0, 1, 2, 1 };
// Sobel Filter
half gx = 0;
half gxN = 0;
half gy = 0;
half gyN = 0;
UNITY_UNROLL
for (int i = 0; i < 9; i++)
{
float2 offsetUV = uv + sobelOffsets[i] * _ScreenSize.zw * _ScreenOutlineThickness;
half charArea = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_LinearClamp, offsetUV).r;
float3 sceneColor = SampleSceneColor(offsetUV);
float3 sceneNormal = SampleSceneNormals(offsetUV);
// Color
half lum = dot(sceneColor, lumWeight) * charArea;
gx += sobelX[i] * lum;
gy += sobelY[i] * lum;
// Normal
lum = dot(sceneNormal, lumWeight) * charArea;
gxN += sobelX[i] * lum;
gyN += sobelY[i] * lum;
}
half edge = sqrt(gx * gx + gy * gy);
edge += sqrt(gxN * gxN + gyN * gyN);
edge *= _ScreenOutlineEdgeStrength;
edge = saturate(edge);
return half4(_ScreenOutlineColor.rgb * edge, edge);
}
#endif

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6750bd952580f5c4d8dc6b91d55a04e2
timeCreated: 1742137796
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonScreenPostPasses.hlsl
uploadId: 814994

View File

@@ -0,0 +1,104 @@
#ifndef POTA_TOON_TONE_MAPPING_INCLUDED
#define POTA_TOON_TONE_MAPPING_INCLUDED
// Custom tonemapping settings
float4 _CustomToneCurve;
float4 _ToeSegmentA;
float4 _ToeSegmentB;
float4 _MidSegmentA;
float4 _MidSegmentB;
float4 _ShoSegmentA;
float4 _ShoSegmentB;
TEXTURE3D(_TonyMcMapfaceLut);
#if _POTA_TOON_TONEMAP_FILMIC
// Filmic Tonemapping Operators http://filmicworlds.com/blog/filmic-tonemapping-operators/
// Source: https://github.com/dmnsgn/glsl-tone-map/blob/main/filmic.glsl
float3 Filmic(float3 x) {
float3 X = max(0.0, x - 0.004);
float3 result = (X * (6.2 * X + 0.5)) / (X * (6.2 * X + 1.7) + 0.06);
return pow(result, 2.2);
}
#endif
#if _POTA_TOON_TONEMAP_UCHIMURA
// Uchimura 2017, "HDR theory and practice"
// Math: https://www.desmos.com/calculator/gslcdxvipg
// Source: https://www.slideshare.net/nikuque/hdr-theory-and-practicce-jp
// https://github.com/dmnsgn/glsl-tone-map/blob/main/uchimura.glsl
float3 Uchimura(float3 x, float P, float a, float m, float l, float c, float b) {
float l0 = ((P - m) * l) / a;
float L0 = m - m / a;
float L1 = m + (1.0 - m) / a;
float S0 = m + l0;
float S1 = m + a * l0;
float C2 = (a * P) / (P - S1);
float CP = -C2 / P;
float3 w0 = float3(1.0 - smoothstep(0.0, m, x));
float3 w2 = float3(step(m + l0, x));
float3 w1 = float3(1.0 - w0 - w2);
float3 T = float3(m * PositivePow(x / m, c) + b);
float3 S = float3(P - (P - S1) * exp(CP * (x - S0)));
float3 L = float3(m + a * (x - m));
return T * w0 + L * w1 + S * w2;
}
float3 Uchimura(float3 x) {
const float P = 1.0; // max display brightness
const float a = 1.0; // contrast
const float m = 0.22; // linear section start
const float l = 0.4; // linear section length
const float c = 1.33; // black
const float b = 0.0; // pedestal
return Uchimura(x, P, a, m, l, c, b);
}
#endif
#if _POTA_TOON_TONEMAP_TONY
// Source: https://github.com/h3r2tic/tony-mc-mapface
SAMPLER(sampler_linear_clamp);
float3 TonyMcMapface(float3 stimulus) {
// Apply a non-linear transform that the LUT is encoded with.
const float3 encoded = stimulus / (stimulus + 1.0);
// Align the encoded range to texel centers.
const float LUT_DIMS = 48.0;
float3 uv = encoded * ((LUT_DIMS - 1.0) / LUT_DIMS) + 0.5 / LUT_DIMS;
// #if UNITY_UV_STARTS_AT_TOP
// uv.y = 1.0 - uv.y;
// #endif
return SAMPLE_TEXTURE3D_LOD(_TonyMcMapfaceLut, sampler_linear_clamp, uv, 0).rgb;
}
#endif
float3 ApplyPotaToonToneMap(float3 input)
{
float3 output = input;
#if _POTA_TOON_TONEMAP_NEUTRAL
output = NeutralTonemap(input);
#elif _POTA_TOON_TONEMAP_ACES
float3 aces = unity_to_ACES(input);
output = AcesTonemap(aces);
#elif _POTA_TOON_TONEMAP_FILMIC
output = Filmic(input);
#elif _POTA_TOON_TONEMAP_UCHIMURA
output = Uchimura(input);
#elif _POTA_TOON_TONEMAP_TONY
output= TonyMcMapface(input);
#elif _POTA_TOON_TONEMAP_CUSTOM
output = CustomTonemap(input, _CustomToneCurve.xyz, _ToeSegmentA, _ToeSegmentB.xy, _MidSegmentA, _MidSegmentB.xy, _ShoSegmentA, _ShoSegmentB.xy);
#endif
return saturate(output);
}
#endif

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ebeb72ede0414c8d9d50c242393baaa8
timeCreated: 1742137796
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonToneMapping.hlsl
uploadId: 814994

View File

@@ -0,0 +1,379 @@
Shader "PotaToon/UberPost"
{
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#if UNITY_VERSION >= 202230
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl"
#else
#include "./PotaToonUtilsFor2021.hlsl"
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
TEXTURE2D_X(_BlitTexture);
#endif
#include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl"
// #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DynamicScalingClamping.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "./PotaToonToneMapping.hlsl"
#include "../ChracterShadow/CharacterShadowInput.hlsl"
#pragma multi_compile_local_fragment _ _ENABLE_ALPHA_OUTPUT
#pragma multi_compile_local_fragment _ _BLOOM_LQ _BLOOM_HQ _BLOOM_LQ_DIRT _BLOOM_HQ_DIRT
#pragma multi_compile_local_fragment _ _POTA_TOON_TONEMAP_NEUTRAL _POTA_TOON_TONEMAP_ACES _POTA_TOON_TONEMAP_FILMIC _POTA_TOON_TONEMAP_UCHIMURA _POTA_TOON_TONEMAP_TONY _POTA_TOON_TONEMAP_CUSTOM
TEXTURE2D_X(_Bloom_Texture);
TEXTURE2D(_LensDirt_Texture);
TEXTURE2D_X(_PotaToonCharMask);
float _PostExposure;
float _ScreenRimWidth;
float _CharGammaAdjust;
float _LensDirt_Intensity;
float _ScreenOutlineThickness;
float _ScreenOutlineEdgeStrength;
float4 _ScreenOutlineColor;
float4 _HueSatCon;
float4 _ColorFilter;
float4 _ColorBalance;
float4 _ScreenRimColor;
float4 _BloomTexture_TexelSize;
float4 _Bloom_Texture_TexelSize;
float4 _Bloom_Params;
float4 _LensDirt_Params;
#define BloomIntensity _Bloom_Params.x
#define BloomTint _Bloom_Params.yzw
#define LensDirtScale _LensDirt_Params.xy
#define LensDirtOffset _LensDirt_Params.zw
#define LensDirtIntensity _LensDirt_Intensity.x
#define MaxScreenRimDist _ScreenRimColor.a
#define AlphaScale 1.0
#define AlphaBias 0.0
// Hardcoded dependencies to reduce the number of variants
#if _BLOOM_LQ || _BLOOM_HQ || _BLOOM_LQ_DIRT || _BLOOM_HQ_DIRT
#define BLOOM
#if _BLOOM_LQ_DIRT || _BLOOM_HQ_DIRT
#define BLOOM_DIRT
#endif
#endif
void ApplyColorAdjustments(inout half3 colorLinear)
{
// White balance in LMS space
float3 colorLMS = LinearToLMS(colorLinear);
colorLMS *= _ColorBalance.xyz;
colorLinear = LMSToLinear(colorLMS);
// Do contrast in log after white balance
float3 colorLog = LinearToLogC(colorLinear);
colorLog = (colorLog - ACEScc_MIDGRAY) * _HueSatCon.z + ACEScc_MIDGRAY;
colorLinear = LogCToLinear(colorLog);
// Color filter is just an unclipped multiplier
colorLinear *= _ColorFilter.xyz;
// Do NOT feed negative values to the following color ops
colorLinear = max(0.0, colorLinear);
// HSV operations
float satMult = 1.0;
float3 hsv = RgbToHsv(colorLinear);
{
// Hue Shift & Hue Vs Hue
float hue = hsv.x + _HueSatCon.x;
hsv.x = RotateHue(hue, 0.0, 1.0);
}
colorLinear = HsvToRgb(hsv);
// Global saturation
float luma = GetLuminance(colorLinear);
colorLinear = luma.xxx + (_HueSatCon.yyy * satMult) * (colorLinear - luma.xxx);
// We don't saturate the output (To preserve HDR)
colorLinear = max(0.0, colorLinear);
}
half4 PotaToonPostProcess(float2 uv)
{
bool isCharArea = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_LinearClamp, uv).r > 0.5;
#if !defined(BLOOM)
if (!isCharArea)
clip(-1);
#endif
// NOTE: Hlsl specifies missing input.a to fill 1 (0 for .rgb).
// InputColor is a "bottom" layer for alpha output.
half4 inputColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
half3 color = inputColor.rgb;
#if UNITY_COLORSPACE_GAMMA
{
color = GetSRGBToLinear(color);
inputColor = GetSRGBToLinear(inputColor); // Deadcode removal if no effect on output color
}
#endif
// Bloom
#if defined(BLOOM)
{
float2 uvBloom = uv;
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
uvBloom = RemapFoveatedRenderingNonUniformToLinear(uvBloom);
}
#endif
#if _BLOOM_HQ
half3 bloom = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_Bloom_Texture, sampler_LinearClamp), SCREEN_COORD_REMOVE_SCALEBIAS(uvBloom), _Bloom_Texture_TexelSize.zwxy, (1.0).xx, unity_StereoEyeIndex).xyz;
#else
half3 bloom = SAMPLE_TEXTURE2D_X(_Bloom_Texture, sampler_LinearClamp, SCREEN_COORD_REMOVE_SCALEBIAS(uvBloom)).xyz;
#endif
#if UNITY_COLORSPACE_GAMMA
bloom *= bloom; // γ to linear
#endif
bloom *= BloomIntensity;
color += bloom * BloomTint;
#if defined(BLOOM_DIRT)
{
// UVs for the dirt texture should be DistortUV(uv * DirtScale + DirtOffset) but
// considering we use a cover-style scale on the dirt texture the difference
// isn't massive so we chose to save a few ALUs here instead in case lens
// distortion is active.
half3 dirt = SAMPLE_TEXTURE2D(_LensDirt_Texture, sampler_LinearClamp, uv * LensDirtScale + LensDirtOffset).xyz;
dirt *= LensDirtIntensity;
color += dirt * bloom.xyz;
}
#endif
#if _ENABLE_ALPHA_OUTPUT
// Bloom should also spread in areas with zero alpha, so we save the image with bloom here to do the mixing at the end of the shader
inputColor.xyz = color.xyz;
#endif
if (!isCharArea)
return half4(color, 1);
}
#endif
// Apply Post Exposure
color *= _PostExposure;
// Assume the input as srgb if more contrast required.
color = lerp(color, GetSRGBToLinear(color), _CharGammaAdjust);
// Tone Mapping
color = ApplyPotaToonToneMap(color);
// Color Adjustments
ApplyColorAdjustments(color);
// When Unity is configured to use gamma color encoding, we ignore the request to convert to gamma 2.0 and instead fall back to sRGB encoding
#if _GAMMA_20 && !UNITY_COLORSPACE_GAMMA
{
color = LinearToGamma20(color);
inputColor = LinearToGamma20(inputColor);
}
// Back to sRGB
#elif UNITY_COLORSPACE_GAMMA || _LINEAR_TO_SRGB_CONVERSION
{
color = GetLinearToSRGB(color);
inputColor = LinearToSRGB(inputColor);
}
#endif
// Alpha mask
#if _ENABLE_ALPHA_OUTPUT
{
// Post processing is not applied on pixels with zero alpha
// The alpha scale and bias control how steep is the transition between the post-processed and plain regions
half alpha = inputColor.a * AlphaScale + AlphaBias;
// Saturate is necessary to avoid issues when additive blending pushes the alpha over 1.
// NOTE: in UNITY_COLORSPACE_GAMMA we alpha blend in gamma here, linear otherwise.
color.xyz = lerp(inputColor.xyz, color.xyz, saturate(alpha));
}
#endif
#if _ENABLE_ALPHA_OUTPUT
// Saturate is necessary to avoid issues when additive blending pushes the alpha over 1.
return half4(color, saturate(inputColor.a));
#else
return half4(color, 1);
#endif
}
half4 PotaToonPostProcessEnvironment(float2 uv)
{
bool isCharArea = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_LinearClamp, uv).r > 0.5;
if (isCharArea)
clip(-1);
// NOTE: Hlsl specifies missing input.a to fill 1 (0 for .rgb).
// InputColor is a "bottom" layer for alpha output.
half4 inputColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
half3 color = inputColor.rgb;
#if UNITY_COLORSPACE_GAMMA
{
color = GetSRGBToLinear(color);
inputColor = GetSRGBToLinear(inputColor); // Deadcode removal if no effect on output color
}
#endif
// Bloom
#if defined(BLOOM)
{
float2 uvBloom = uv;
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
uvBloom = RemapFoveatedRenderingNonUniformToLinear(uvBloom);
}
#endif
#if _BLOOM_HQ
half3 bloom = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_Bloom_Texture, sampler_LinearClamp), SCREEN_COORD_REMOVE_SCALEBIAS(uvBloom), _Bloom_Texture_TexelSize.zwxy, (1.0).xx, unity_StereoEyeIndex).xyz;
#else
half3 bloom = SAMPLE_TEXTURE2D_X(_Bloom_Texture, sampler_LinearClamp, SCREEN_COORD_REMOVE_SCALEBIAS(uvBloom)).xyz;
#endif
#if UNITY_COLORSPACE_GAMMA
bloom *= bloom; // γ to linear
#endif
bloom *= BloomIntensity;
color += bloom * BloomTint;
#if defined(BLOOM_DIRT)
{
// UVs for the dirt texture should be DistortUV(uv * DirtScale + DirtOffset) but
// considering we use a cover-style scale on the dirt texture the difference
// isn't massive so we chose to save a few ALUs here instead in case lens
// distortion is active.
half3 dirt = SAMPLE_TEXTURE2D(_LensDirt_Texture, sampler_LinearClamp, uv * LensDirtScale + LensDirtOffset).xyz;
dirt *= LensDirtIntensity;
color += dirt * bloom.xyz;
}
#endif
#if _ENABLE_ALPHA_OUTPUT
// Bloom should also spread in areas with zero alpha, so we save the image with bloom here to do the mixing at the end of the shader
inputColor.xyz = color.xyz;
#endif
}
#endif
// Apply Post Exposure
color *= _PostExposure;
// Tone Mapping
color = ApplyPotaToonToneMap(color);
// Color Adjustments
ApplyColorAdjustments(color);
// When Unity is configured to use gamma color encoding, we ignore the request to convert to gamma 2.0 and instead fall back to sRGB encoding
#if _GAMMA_20 && !UNITY_COLORSPACE_GAMMA
{
color = LinearToGamma20(color);
inputColor = LinearToGamma20(inputColor);
}
// Back to sRGB
#elif UNITY_COLORSPACE_GAMMA || _LINEAR_TO_SRGB_CONVERSION
{
color = GetLinearToSRGB(color);
inputColor = LinearToSRGB(inputColor);
}
#endif
// Alpha mask
#if _ENABLE_ALPHA_OUTPUT
{
// Post processing is not applied on pixels with zero alpha
// The alpha scale and bias control how steep is the transition between the post-processed and plain regions
half alpha = inputColor.a * AlphaScale + AlphaBias;
// Saturate is necessary to avoid issues when additive blending pushes the alpha over 1.
// NOTE: in UNITY_COLORSPACE_GAMMA we alpha blend in gamma here, linear otherwise.
color.xyz = lerp(inputColor.xyz, color.xyz, saturate(alpha));
}
#endif
#if _ENABLE_ALPHA_OUTPUT
// Saturate is necessary to avoid issues when additive blending pushes the alpha over 1.
return half4(color, saturate(inputColor.a));
#else
return half4(color, 1);
#endif
}
ENDHLSL
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
ZTest Always ZWrite Off Cull Off
Pass
{
Name "POTAToonUberPostCharacter"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
#if UNITY_VERSION >= 202230
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.texcoord));
#else
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.uv));
#endif
return PotaToonPostProcess(uv);
}
ENDHLSL
}
Pass
{
Name "POTAToonUberPostEnvironment"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
#if UNITY_VERSION >= 202230
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.texcoord));
#else
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(UnityStereoTransformScreenSpaceTex(input.uv));
#endif
return PotaToonPostProcessEnvironment(uv);
}
ENDHLSL
}
Pass
{
Name "POTAToonScreenOutline"
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#include "./PotaToonScreenPostPasses.hlsl"
#pragma multi_compile_local_fragment _ _EXCLUDE_INNER_SCREEN_OUTLINES
#pragma vertex Vert
#pragma fragment FragPotaToonScreenOutline
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 97ae76f59185b6340bc9bd2298df2d15
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonUberPost.shader
uploadId: 814994

View File

@@ -0,0 +1,25 @@
#ifndef POTA_TOON_UTILS_2021_INCLUDED
#define POTA_TOON_UTILS_2021_INCLUDED
float2 ScreenCoordApplyScaleBias(float2 xy, float4 screenCoordScaleBias)
{
return screenCoordScaleBias.zw + xy * screenCoordScaleBias.xy;
}
float2 ScreenCoordRemoveScaleBias(float2 xy, float4 screenCoordScaleBias)
{
return (xy - screenCoordScaleBias.zw) / screenCoordScaleBias.xy;
}
// Note that SCREEN_SIZE_OVERRIDE will be redefined in HDRP to use _PostProcessScreenSize.
#if defined(SCREEN_COORD_OVERRIDE)
#define SCREEN_COORD_APPLY_SCALEBIAS(xy) ScreenCoordApplyScaleBias(xy, _ScreenCoordScaleBias)
#define SCREEN_COORD_REMOVE_SCALEBIAS(xy) ScreenCoordRemoveScaleBias(xy, _ScreenCoordScaleBias)
#define SCREEN_SIZE_OVERRIDE _ScreenSizeOverride
#else
#define SCREEN_COORD_APPLY_SCALEBIAS(xy) xy
#define SCREEN_COORD_REMOVE_SCALEBIAS(xy) xy
#define SCREEN_SIZE_OVERRIDE _ScreenSize
#endif
#endif // UNITY_SCREEN_COORD_OVERRIDE_INCLUDED

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b6fc7501b84a4af41b50b02772a577cc
timeCreated: 1742137796
AssetOrigin:
serializedVersion: 1
productId: 316069
packageName: PotaToon
packageVersion: 1.3.6
assetPath: Assets/PotaToon/Shaders/PostProcessing/PotaToonUtilsFor2021.hlsl
uploadId: 814994