阶段性完成
This commit is contained in:
8
Assets/PotaToon/Shaders/PotaToon/Eye.meta
Normal file
8
Assets/PotaToon/Shaders/PotaToon/Eye.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 369acbe072c538e48a2cef08e32a3e5b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
208
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEye.shader
Normal file
208
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEye.shader
Normal file
@@ -0,0 +1,208 @@
|
||||
Shader "PotaToon/Eye"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
// Base Settings
|
||||
[HideInInspector] _ToonType("Toon Type", Int) = 2
|
||||
[Enum(Opaque, 0, Cutout, 1, Refraction, 2, Transparent, 3)] _SurfaceType("Surface Type", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Int) = 2
|
||||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||
[HideInInspector] [Enum(OFF, 0, ON, 1)] _ZWriteMode("_ZWriteMode", Int) = 1
|
||||
[HideInInspector] _AutoRenderQueue("_AutoRenderQueue", Int) = 1
|
||||
|
||||
// Stencil
|
||||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 0
|
||||
_StencilRef("Stencil Ref", Range(0, 255)) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilPass("Stencil Pass Operation", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilFail("Stencil Fail Operation", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilZFail("Stencil ZFail Operation", Float) = 0
|
||||
|
||||
// Settings
|
||||
[HDR] _BaseColor("Color", Color) = (1,1,1,1)
|
||||
_MainTex("Main Tex", 2D) = "white" {}
|
||||
_ClippingMask ("Clipping Mask", 2D) = "white" {}
|
||||
_Exposure("Exposure", Range(1, 10)) = 1
|
||||
_MinIntensity("Minium Intensity", Range(0, 1)) = 0.1
|
||||
_IndirectDimmer ("Indirect Dimmer", Range(0, 10)) = 0
|
||||
[Toggle] _UseRefraction("Use Refraction", Int) = 1
|
||||
_RefractionWeight("Refraction Weight", Range(-0.1, 0.1)) = 0
|
||||
[HideInInspector] [Toggle] _UseHiLight("_UseHiLight", Int) = 0
|
||||
_HiLightTex("HighLight Tex", 2D) = "black" {}
|
||||
[Toggle] _UseHiLightJitter("Use Jittering", Int) = 0
|
||||
[HDR] _HiLightColor("HighLight Color", Color) = (1,1,1,1)
|
||||
_HiLightPowerR("HighLight Power for R Channel", Range(1, 64)) = 1
|
||||
_HiLightPowerG("HighLight Power for G Channel", Range(1, 64)) = 1
|
||||
_HiLightPowerB("HighLight Power for B Channel", Range(1, 64)) = 1
|
||||
_HiLightIntensityR("HighLight Intensity for R Channel", Range(0, 1)) = 1
|
||||
_HiLightIntensityG("HighLight Intensity for G Channel", Range(0, 1)) = 1
|
||||
_HiLightIntensityB("HighLight Intensity for B Channel", Range(0, 1)) = 1
|
||||
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _ClippingMaskCH ("ClippingMask Channel", Int) = 1
|
||||
|
||||
[HideInInspector] _FaceForward ("_FaceForward", Vector) = (0,0,1,0)
|
||||
[HideInInspector] _FaceUp ("_FaceUp", Vector) = (0,1,0,0)
|
||||
[HideInInspector] _HeadWorldPos ("_HeadWorldPos", Vector) = (0,0,0,0)
|
||||
|
||||
// Dither Fade
|
||||
[HideInInspector] _UseDitherFade ("_UseDitherFade", Int) = 0
|
||||
[HideInInspector] _DitherFadeMinZ ("_DitherFadeMinZ", Float) = 0
|
||||
[HideInInspector] _DitherFadeMaxZ ("_DitherFadeMaxZ", Float) = 0
|
||||
|
||||
// Blend
|
||||
[Enum(PotaToon.AlphaMode)] _Blend("__blend", Int) = 0
|
||||
[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
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.universal": "12.0.0"
|
||||
}
|
||||
Tags
|
||||
{
|
||||
"RenderType"="Opaque"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags { "LightMode" = "UniversalForward" }
|
||||
ZWrite[_ZWriteMode]
|
||||
Cull[_Cull]
|
||||
Blend [_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilPass]
|
||||
Fail[_StencilFail]
|
||||
ZFail[_StencilZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonEyeForwardKeywords.hlsl"
|
||||
#include "./PotaToonEyeInput.hlsl"
|
||||
#include "./PotaToonEyePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
// Skip Shadow Caster Pass
|
||||
Pass
|
||||
{
|
||||
Name "DepthOnly"
|
||||
Tags{"LightMode" = "DepthOnly"}
|
||||
|
||||
ZWrite On
|
||||
ColorMask R
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma vertex DepthOnlyVertex
|
||||
#pragma fragment DepthOnlyFragment
|
||||
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
|
||||
|
||||
//--------------------------------------
|
||||
// GPU Instancing
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#include "./PotaToonEyeInput.hlsl"
|
||||
#define _BaseMap _MainTex
|
||||
#define sampler_BaseMap sampler_linear_mirror
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
// This pass is used when drawing to a _CameraNormalsTexture texture
|
||||
Pass
|
||||
{
|
||||
Name "DepthNormals"
|
||||
Tags{"LightMode" = "DepthNormals"}
|
||||
|
||||
ZWrite On
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma vertex DepthNormalsVertex
|
||||
#pragma fragment DepthNormalsFragment
|
||||
|
||||
// -------------------------------------
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _NORMALMAP
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
|
||||
|
||||
//--------------------------------------
|
||||
// GPU Instancing
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#include "./PotaToonEyeInput.hlsl"
|
||||
#define _BaseMap _MainTex
|
||||
#define sampler_BaseMap sampler_linear_mirror
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "PotaToonCharacterMask"
|
||||
Tags {
|
||||
"LightMode" = "PotaToonCharacterMask"
|
||||
}
|
||||
ZWrite Off ZTest Always Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#define _USE_DITHER_FADE 1
|
||||
#define _BaseMapUV 0
|
||||
#define _ClippingMaskUV 0
|
||||
#include "./PotaToonEyeInput.hlsl"
|
||||
#include "../PotaToonCharMaskPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
// Must be sync with ForwardLit pass
|
||||
Name "OpaqueDitherFade"
|
||||
Tags{"LightMode" = "OpaqueDitherFade"}
|
||||
Cull[_Cull]
|
||||
Blend SrcAlpha Zero
|
||||
ZWrite[_ZWriteMode]
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilPass]
|
||||
Fail[_StencilFail]
|
||||
ZFail[_StencilZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonEyeForwardKeywords.hlsl"
|
||||
#define _USE_DITHER_FADE 1
|
||||
#include "./PotaToonEyeInput.hlsl"
|
||||
#include "./PotaToonEyePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
CustomEditor "PotaToon.Editor.PotaToonEyeShaderGUI"
|
||||
}
|
||||
16
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEye.shader.meta
Normal file
16
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEye.shader.meta
Normal file
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf585d0d717caed4fabcb3c580b2c2b8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEye.shader
|
||||
uploadId: 814994
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef POTA_TOON_EYE_FORWARD_KEYWORDS_INCLUDED
|
||||
#define POTA_TOON_EYE_FORWARD_KEYWORDS_INCLUDED
|
||||
|
||||
#pragma target 4.5
|
||||
#pragma multi_compile _ _FORWARD_PLUS
|
||||
#pragma multi_compile _ _LIGHT_LAYERS
|
||||
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#pragma multi_compile _ LIGHTMAP_ON DIRLIGHTMAP_COMBINED
|
||||
#pragma multi_compile _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
|
||||
#pragma multi_compile_fragment _ _USE_EYE_HI_LIGHT
|
||||
#pragma multi_compile_fragment _ _POTA_TOON_OIT
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39765c613e5a4e09a5d129a1e3573db8
|
||||
timeCreated: 1762341803
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyeForwardKeywords.hlsl
|
||||
uploadId: 814994
|
||||
51
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyeInput.hlsl
Normal file
51
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyeInput.hlsl
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef POTA_TOON_EYE_INPUT_INCLUDED
|
||||
#define POTA_TOON_EYE_INPUT_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
half4 _BaseColor;
|
||||
half4 _HiLightColor;
|
||||
half _BaseStep;
|
||||
half _StepSmoothness;
|
||||
half _Exposure;
|
||||
half _MinIntensity;
|
||||
half _IndirectDimmer;
|
||||
half _HiLightPowerR;
|
||||
half _HiLightPowerG;
|
||||
half _HiLightPowerB;
|
||||
half _HiLightIntensityR;
|
||||
half _HiLightIntensityG;
|
||||
half _HiLightIntensityB;
|
||||
half _RefractionWeight;
|
||||
half _Cutoff;
|
||||
half _DitherFadeMaxZ;
|
||||
half _DitherFadeMinZ;
|
||||
half _PotaToonPadding00_;
|
||||
uint _UseHiLightJitter;
|
||||
uint _UseRefraction;
|
||||
uint _ClippingMaskCH;
|
||||
uint _UseDitherFade;
|
||||
uint _ToonType;
|
||||
uint _SurfaceType;
|
||||
uint _PotaToonPadding01_;
|
||||
uint _PotaToonPadding02_;
|
||||
float4 _FaceForward;
|
||||
float4 _FaceUp;
|
||||
float4 _HeadWorldPos;
|
||||
float4 _MainTex_ST;
|
||||
float4 _ClippingMask_ST;
|
||||
float4 _HiLightTex_ST;
|
||||
CBUFFER_END
|
||||
|
||||
TEXTURE2D(_MainTex); SAMPLER(sampler_linear_mirror);
|
||||
TEXTURE2D(_ClippingMask);
|
||||
TEXTURE2D(_HiLightTex);
|
||||
|
||||
#define TRANSPARENT_SURFACE 3
|
||||
#define REFRACTION_SURFACE 2
|
||||
#define OIT_SURFACE 2
|
||||
#define FACE_TYPE 1
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92d5b17f17944e81b38c60962cf02cb1
|
||||
timeCreated: 1742049589
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyeInput.hlsl
|
||||
uploadId: 814994
|
||||
205
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyePass.hlsl
Normal file
205
Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyePass.hlsl
Normal file
@@ -0,0 +1,205 @@
|
||||
#ifndef POTA_TOON_EYE_PASS_INCLUDED
|
||||
#define POTA_TOON_EYE_PASS_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "../../Common/PotaToonCommon.hlsl"
|
||||
#if _POTA_TOON_OIT
|
||||
#include "../../OIT/LinkedListCreation.hlsl"
|
||||
#endif
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL; // Only used for bakedGI
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 staticLightmapUV : TEXCOORD1;
|
||||
float2 dynamicLightmapUV : TEXCOORD2;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 positionWS : TEXCOORD1;
|
||||
float3 positionOS : TEXCOORD2;
|
||||
float3 normalWS : TEXCOORD3; // Only used for bakedGI
|
||||
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 4);
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
float2 dynamicLightmapUV : TEXCOORD5; // Dynamic lightmap UVs
|
||||
#endif
|
||||
#ifdef USE_APV_PROBE_OCCLUSION
|
||||
float4 probeOcclusion : TEXCOORD6;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.positionOS = input.positionOS.xyz;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
output.uv = input.uv;
|
||||
output.normalWS = TransformObjectToWorldDir(input.normalOS);
|
||||
|
||||
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#endif
|
||||
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
[earlydepthstencil]
|
||||
#endif
|
||||
half4 frag(Varyings input, uint uSampleIdx : SV_SampleIndex) : SV_TARGET
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
input.normalWS = normalize(input.normalWS);
|
||||
float2 uv = input.uv;
|
||||
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
|
||||
InputData inputData = (InputData)0;
|
||||
inputData.positionWS = input.positionWS;
|
||||
inputData.normalizedScreenSpaceUV = normalizedScreenSpaceUV;
|
||||
|
||||
// Apply Refraction
|
||||
const float3 F = _FaceForward.xyz;
|
||||
const float3 V = normalize(_WorldSpaceCameraPos.xyz - input.positionWS.xyz);
|
||||
if (_UseRefraction > 0)
|
||||
{
|
||||
const float3 vWorld = _FaceUp.xyz;
|
||||
const float3 uWorld = cross(vWorld, F);
|
||||
float3 offset = float3(dot(uWorld, V), dot(vWorld, V), dot(F, V));
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
offset.y = -offset.y;
|
||||
#endif
|
||||
uv += lerp(0, offset.xy * _RefractionWeight, _UseRefraction);
|
||||
}
|
||||
float3 normalWS = F;
|
||||
|
||||
const half clippingMask = SelectMask(SAMPLE_TEXTURE2D(_ClippingMask, sampler_linear_mirror, TRANSFORM_TEX(uv, _ClippingMask)), _ClippingMaskCH);
|
||||
clip(clippingMask - 0.5);
|
||||
|
||||
const half4 baseMap = SAMPLE_TEXTURE2D(_MainTex, sampler_linear_mirror, TRANSFORM_TEX(uv, _MainTex));
|
||||
half3 baseColor = _BaseColor.rgb * baseMap.rgb;
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
#if _USE_EYE_HI_LIGHT
|
||||
// High light
|
||||
half3 hiColor = 0;
|
||||
half4 hiLightTexVar = SAMPLE_TEXTURE2D(_HiLightTex, sampler_linear_mirror, TRANSFORM_TEX(uv, _HiLightTex));
|
||||
float3 hiLightPower = float3(_HiLightPowerR, _HiLightPowerG, _HiLightPowerB);
|
||||
if (_UseHiLightJitter > 0)
|
||||
{
|
||||
hiLightPower = lerp(1, hiLightPower, cos(_Time.y * 40) > 0);
|
||||
}
|
||||
hiColor += (abs(PositivePow(hiLightTexVar.r, hiLightPower.r)) * _HiLightIntensityR).rrr;
|
||||
hiColor += (abs(PositivePow(hiLightTexVar.g, hiLightPower.g)) * _HiLightIntensityG).rrr;
|
||||
hiColor += (abs(PositivePow(hiLightTexVar.b, hiLightPower.b)) * _HiLightIntensityB).rrr;
|
||||
baseColor += hiColor * _HiLightColor.rgb;
|
||||
#endif
|
||||
half3 color = baseColor;
|
||||
|
||||
// Main Light
|
||||
Light mainLight = GetMainLight();
|
||||
half3 mainLightColor = mainLight.color.rgb * _Exposure;
|
||||
const float mainLightIntensity = 0.299 * mainLightColor.r + 0.587 * mainLightColor.g + 0.114 * mainLightColor.b;
|
||||
|
||||
color = lerp(color * mainLightColor, color * _MinIntensity, mainLightIntensity < _MinIntensity); // Don't apply lambert to guarantee whole eye shape.
|
||||
if (mainLightIntensity == 0)
|
||||
{
|
||||
color = 0;
|
||||
}
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
half3 additionalLightsColor = 0;
|
||||
|
||||
// Directional Lights
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
Light light = GetAdditionalLight(lightIndex, input.positionWS, 0);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
half3 lightColor = light.color.rgb * _Exposure;
|
||||
additionalLightsColor += baseColor * lightColor * light.distanceAttenuation;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Local Lights
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, 0);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
half3 lightColor = light.color.rgb * _Exposure;
|
||||
additionalLightsColor += lightColor * light.distanceAttenuation * light.shadowAttenuation;
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
|
||||
color += baseColor * additionalLightsColor;
|
||||
#endif
|
||||
|
||||
// GI
|
||||
half alpha = OutputAlpha(baseMap.a * _BaseColor.a, _SurfaceType >= OIT_SURFACE);
|
||||
BRDFData brdfData;
|
||||
InitializeBRDFData(baseColor, 0, 0, 1, alpha, brdfData);
|
||||
#if defined(DYNAMICLIGHTMAP_ON)
|
||||
half3 bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, normalWS);
|
||||
#elif UNITY_VERSION >= 202230 && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
half3 bakedGI = SAMPLE_GI(input.vertexSH, GetAbsolutePositionWS(inputData.positionWS), normalWS, GetWorldSpaceViewDir(inputData.positionWS), input.positionCS.xy, input.probeOcclusion, inputData.shadowMask);
|
||||
#else
|
||||
half3 bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, normalWS);
|
||||
#endif
|
||||
MixRealtimeAndBakedGI(mainLight, input.normalWS, bakedGI);
|
||||
#if UNITY_VERSION >= 202230
|
||||
half3 indirectLighting = GlobalIllumination(brdfData, brdfData, 0, bakedGI, 1, input.positionWS, normalWS, V, normalizedScreenSpaceUV);
|
||||
#else
|
||||
half3 indirectLighting = GlobalIllumination(brdfData, brdfData, 0, bakedGI, 1, input.positionWS, normalWS, V);
|
||||
#endif
|
||||
indirectLighting = max(0, indirectLighting * _IndirectDimmer); // Prevent NaN
|
||||
color += indirectLighting;
|
||||
|
||||
if (_UseDitherFade > 0
|
||||
#if !_USE_DITHER_FADE
|
||||
&& _SurfaceType >= OIT_SURFACE
|
||||
#endif
|
||||
)
|
||||
DitherFade(alpha, abs(TransformWorldToView(_HeadWorldPos.xyz).z), _DitherFadeMinZ, _DitherFadeMaxZ, inputData.positionCS.xy);
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
if (_SurfaceType >= OIT_SURFACE)
|
||||
{
|
||||
createFragmentEntry(half4(color, alpha), input.positionCS.xyz, uSampleIdx);
|
||||
clip(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return half4(color, alpha);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2ac9c94df0b4b52b6b59faa03c3977b
|
||||
timeCreated: 1742049485
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/Eye/PotaToonEyePass.hlsl
|
||||
uploadId: 814994
|
||||
611
Assets/PotaToon/Shaders/PotaToon/PotaToon.shader
Normal file
611
Assets/PotaToon/Shaders/PotaToon/PotaToon.shader
Normal file
@@ -0,0 +1,611 @@
|
||||
Shader "PotaToon/Toon"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
// Base Settings
|
||||
[HideInInspector] _ToonType("Toon Type", Int) = 0
|
||||
[Enum(Opaque, 0, Cutout, 1, Refraction, 2, Transparent, 3)] _SurfaceType("Surface Type", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Int) = 2
|
||||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||
[HideInInspector] [Enum(OFF, 0, ON, 1)] _ZWriteMode("_ZWriteMode", Int) = 1
|
||||
[HideInInspector] _AutoRenderQueue("_AutoRenderQueue", Int) = 1
|
||||
|
||||
// Stencil
|
||||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 0
|
||||
_StencilRef("Stencil Ref", Range(0, 255)) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilPass("Stencil Pass Operation", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilFail("Stencil Fail Operation", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilZFail("Stencil ZFail Operation", Float) = 0
|
||||
|
||||
// Main Settings
|
||||
_MainTex ("MainTex", 2D) = "white" {}
|
||||
[HDR] _BaseColor ("Base Color", Color) = (1,1,1,1)
|
||||
[HideInInspector] _UseShadeMap ("_UseShadeMap", Int) = 0
|
||||
_ShadeMap ("ShadeMap", 2D) = "white" {}
|
||||
_ShadeColor ("Shade Color", Color) = (0.75,0.75,0.75,1)
|
||||
_ShadowBorderMask ("AOMap", 2D) = "white" {}
|
||||
_BaseStep ("Base Step", Range(0, 1)) = 0.5
|
||||
_StepSmoothness ("Step Smoothness", Range(0, 0.2)) = 0.01
|
||||
[Toggle] _ReceiveLightShadow ("Receive Light Shadow", Int) = 1
|
||||
[Toggle] _UseMidTone ("Mid Tone", Int) = 1
|
||||
[HDR] _MidColor ("Mid Color", Color) = (0.5,0.2,0.2,1)
|
||||
_MidWidth ("Mid Thickness", Range(0, 1)) = 1
|
||||
_IndirectDimmer ("Indirect Dimmer", Range(0, 10)) = 1
|
||||
[Toggle] _UseVertexColor ("Vertex Color", Int) = 0
|
||||
[Toggle] _UseDarknessMode ("Use Darkness Mode", Int) = 0
|
||||
_NormalMap ("NormalMap", 2D) = "bump" {}
|
||||
_BumpScale ("Normal Scale", Range(0, 1)) = 0
|
||||
[Toggle] _UseNormalMap ("Use NormalMap", Int) = 0
|
||||
_ClippingMask ("Clipping Mask", 2D) = "white" {}
|
||||
|
||||
// High Light
|
||||
[HDR] _SpecularColor ("Specular Color", Color) = (0,0,0,1)
|
||||
_SpecularMap ("SpecularMap", 2D) = "white" {}
|
||||
_SpecularMask ("SpecularMask", 2D) = "white" {}
|
||||
_SpecularPower ("Specular Power", Range(0, 1)) = 0.5
|
||||
_SpecularSmoothness ("Specular Smoothness", Range(0, 0.5)) = 0.25
|
||||
|
||||
// Rim Light
|
||||
[HDR] _RimColor ("RimLight Color", Color) = (0,0,0,1)
|
||||
_RimMask ("RimLight Mask", 2D) = "white" {}
|
||||
_RimPower ("Rim Power", Range(0, 1)) = 0.5
|
||||
_RimSmoothness ("Rim Smoothness", Range(0, 0.5)) = 0.25
|
||||
[HDR] _ScreenRimTint ("Screen Rim Tint", Color) = (1,1,1,1)
|
||||
[Enum(Multiply, 0, Override, 1)] _ScreenRimTintMode ("Screen Rim Tint Mode", Int) = 0
|
||||
_ScreenRimWidthMultiplier ("Screen Rim Width Multiplier", Range(0, 1)) = 1
|
||||
[Toggle] _ScreenRimShadowFade ("Screen Rim Shadow Fade", Int) = 1
|
||||
|
||||
// MatCap
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode ("MatCap Mode", Int) = 0
|
||||
[HDR] _MatCapColor ("MatCap Color", Color) = (1,1,1,1)
|
||||
_MatCapTex ("MatCap Tex", 2D) = "black" {}
|
||||
_MatCapMask ("MatcapMask", 2D) = "white" {}
|
||||
_MatCapWeight ("Matcap Weight", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer ("Matcap Lighting Dimmer", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode2 ("MatCap2 Mode", Int) = 0
|
||||
[HDR] _MatCapColor2 ("MatCap2 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex2 ("MatCap Tex2", 2D) = "black" {}
|
||||
_MatCapMask2 ("MatcapMask2", 2D) = "white" {}
|
||||
_MatCapWeight2 ("Matcap Weight2", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer2 ("Matcap Lighting Dimmer2", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode3 ("MatCap3 Mode", Int) = 0
|
||||
[HDR] _MatCapColor3 ("MatCap2 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex3 ("MatCap Tex3", 2D) = "black" {}
|
||||
_MatCapMask3 ("MatcapMask3", 2D) = "white" {}
|
||||
_MatCapWeight3 ("Matcap Weight3", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer3 ("Matcap Lighting Dimmer3", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode4 ("MatCap4 Mode", Int) = 0
|
||||
[HDR] _MatCapColor4 ("MatCap4 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex4 ("MatCap Tex4", 2D) = "black" {}
|
||||
_MatCapMask4 ("MatcapMask4", 2D) = "white" {}
|
||||
_MatCapWeight4 ("Matcap Weight4", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer4 ("Matcap Lighting Dimmer4", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode5 ("MatCap5 Mode", Int) = 0
|
||||
[HDR] _MatCapColor5 ("MatCap5 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex5 ("MatCap Tex5", 2D) = "black" {}
|
||||
_MatCapMask5 ("MatcapMask5", 2D) = "white" {}
|
||||
_MatCapWeight5 ("Matcap Weight5", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer5 ("Matcap Lighting Dimmer5", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode6 ("MatCap6 Mode", Int) = 0
|
||||
[HDR] _MatCapColor6 ("MatCap6 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex6 ("MatCap Tex6", 2D) = "black" {}
|
||||
_MatCapMask6 ("MatcapMask6", 2D) = "white" {}
|
||||
_MatCapWeight6 ("Matcap Weight6", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer6 ("Matcap Lighting Dimmer6", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode7 ("MatCap7 Mode", Int) = 0
|
||||
[HDR] _MatCapColor7 ("MatCap7 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex7 ("MatCap Tex7", 2D) = "black" {}
|
||||
_MatCapMask7 ("MatcapMask7", 2D) = "white" {}
|
||||
_MatCapWeight7 ("Matcap Weight7", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer7 ("Matcap Lighting Dimmer7", Range(0, 1)) = 1
|
||||
|
||||
[Enum(None, 0, Add, 1, Multiply, 2)] _MatCapMode8 ("MatCap8 Mode", Int) = 0
|
||||
[HDR] _MatCapColor8 ("MatCap8 Color", Color) = (1,1,1,1)
|
||||
_MatCapTex8 ("MatCap Tex8", 2D) = "black" {}
|
||||
_MatCapMask8 ("MatcapMask8", 2D) = "white" {}
|
||||
_MatCapWeight8 ("Matcap Weight8", Range(0, 1)) = 1
|
||||
_MatCapLightingDimmer8 ("Matcap Lighting Dimmer8", Range(0, 1)) = 1
|
||||
|
||||
// Emission
|
||||
[HDR] _EmissionColor ("Emission Color", Color) = (0,0,0,1)
|
||||
_EmissionMap ("EmissionMap", 2D) = "white" {}
|
||||
_EmissionMask ("EmissionMask", 2D) = "white" {}
|
||||
|
||||
// Glitter
|
||||
[HideInInspector] [Toggle] _UseGlitter ("_UseGlitter", Int) = 0
|
||||
[HDR] _GlitterColor("Color", Color) = (1,1,1,1)
|
||||
_GlitterColorTex("Texture", 2D) = "white" {}
|
||||
_GlitterMainStrength("Main Color Strength", Range(0, 1)) = 0
|
||||
_GlitterEnableLighting("Enable Lighting", Range(0, 1)) = 1
|
||||
[Toggle] _GlitterBackfaceMask("Backface Mask", Int) = 0
|
||||
[Toggle] _GlitterApplyTransparency("Apply Transparency", Int) = 1
|
||||
_GlitterShadowMask("Shadow Mask", Range(0, 1)) = 0
|
||||
_GlitterParticleSize("Particle Size", Float) = 0.16
|
||||
_GlitterScaleRandomize("Scale Randomize", Range(0, 1)) = 0
|
||||
_GlitterContrast("Contrast", Float) = 50
|
||||
_GlitterSensitivity("Sensitivity", Float) = 100
|
||||
_GlitterBlinkSpeed("Blink Speed", Float) = 0.1
|
||||
_GlitterAngleLimit("Angle Limit", Float) = 0
|
||||
_GlitterLightDirection("Light Direction Strength", Float) = 0
|
||||
_GlitterColorRandomness("Color Randomness", Range(0, 1)) = 0
|
||||
_GlitterNormalStrength("NormalMap Strength", Range(0, 1)) = 1.0
|
||||
_GlitterPostContrast("Post Contrast", Float) = 1
|
||||
|
||||
// Outline
|
||||
[Enum(Normal, 0, Position, 1)] _OutlineMode("Outline Mode", Int) = 0
|
||||
[HideInInspector] [Toggle] _UseOutlineNormalMap("_UseOutlineNormalMap", Int) = 0
|
||||
_OutlineNormalMap ("NormalMap", 2D) = "bump" {}
|
||||
[Toggle] _BlendOutlineMainTex("Blend MainTex", Int) = 1
|
||||
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
|
||||
_OutlineWidthMask ("Outline Width Mask", 2D) = "white" {}
|
||||
_OutlineWidth ("Outline Width", Range(0, 10)) = 0.1
|
||||
_OutlineOffsetZ ("Depth Offset", Float) = 0
|
||||
|
||||
// Refraction
|
||||
_RefractionWeight ("Refraction Weight", Range(-1, 1)) = 0
|
||||
_RefractionBlurStep ("Refraction Blur Step", Range(0, 10)) = 0
|
||||
|
||||
// Character Shadow
|
||||
[Toggle] _DisableCharShadow ("Disable Cast Shadow", Int) = 0
|
||||
_DepthBias ("Cast Shadow Bias", Range(-1, 1)) = 0
|
||||
_NormalBias ("Cast Shadow Normal Bias", Range(-1, 1)) = 0
|
||||
_CharShadowSmoothnessOffset ("Smoothness", Range(0, 1)) = 0
|
||||
[HideInInspector] [Enum(3D, 0, 2D Face, 1)] _CharShadowType ("_CharShadowType", Int) = 0
|
||||
_2DFaceShadowWidth ("2D Shadow Width", Range(0, 1)) = 0.1
|
||||
|
||||
// Face SDF
|
||||
[HideInInspector] [Toggle] _UseFaceSDFShadow ("_UseFaceSDFShadow", Int) = 0
|
||||
_FaceSDFTex ("Face SDF", 2D) = "white" {}
|
||||
[Toggle] _SDFReverse("Reverse Face SDF", Int) = 0
|
||||
_SDFOffset("SDF_Offset", Range(-0.5, 0.5)) = 0
|
||||
_SDFBlur("SDF_Blur", Range(0, 1)) = 0
|
||||
[HideInInspector] _FaceForward ("_FaceForward", Vector) = (0,0,1,0)
|
||||
[HideInInspector] _FaceUp ("_FaceUp", Vector) = (0,1,0,0)
|
||||
|
||||
// Hair High Light
|
||||
[Toggle] _UseHairHighLight ("Use Hair High Light", Int) = 0
|
||||
_HairHighLightTex ("Hair Highlight Tex", 2D) = "black" {}
|
||||
[Toggle] _ReverseHairHighLightTex ("Reverse Hair Highlight Tex", Int) = 0
|
||||
_HairHiStrength("Hair Hi Strength", Range(0, 2)) = 1
|
||||
_HairHiUVOffset("Hair Hi UV Offset", Range(-1, 1)) = 0
|
||||
[HideInInspector] _HeadWorldPos ("_HeadWorldPos", Vector) = (0,0,0,0)
|
||||
|
||||
// Dither Fade
|
||||
[HideInInspector] _UseDitherFade ("_UseDitherFade", Int) = 0
|
||||
[HideInInspector] _DitherFadeMinZ ("_DitherFadeMinZ", Float) = 0
|
||||
[HideInInspector] _DitherFadeMaxZ ("_DitherFadeMaxZ", Float) = 0
|
||||
|
||||
// UV Channels
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _BaseMapUV ("Base UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _NormalMapUV ("NormalMap UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _ClippingMaskUV ("ClippingMask UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _FaceSDFUV ("FaceSDF UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _SpecularMapUV ("Specular UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _RimMaskUV ("RimMask UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _HairHiMapUV ("HairHigh UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _GlitterMapUV ("Glitter UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _EmissionMapUV ("Emission UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _OutlineMaskUV ("OutlineMask UV", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV1 ("MatCap UV1", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV2 ("MatCap UV2", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV3 ("MatCap UV3", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV4 ("MatCap UV4", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV5 ("MatCap UV5", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV6 ("MatCap UV6", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV7 ("MatCap UV7", Int) = 0
|
||||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _MatCapUV8 ("MatCap UV8", Int) = 0
|
||||
|
||||
// Mask Channels
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _ClippingMaskCH ("ClippingMask Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _SpecularMaskCH ("SpecularMask Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _RimMaskCH ("RimMask Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _EmissionMaskCH ("EmissionMask Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _OutlineMaskCH ("OutlineMask Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH1 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH2 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH3 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH4 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH5 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH6 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH7 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _MatCapMaskCH8 ("MatCapMask Channel", Int) = 0
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _AOMapCH ("AOMap Channel", Int) = 1
|
||||
[Enum(R, 0, G, 1, B, 2, A, 3)] _FaceSDFTexCH ("FaceSDF Channel", Int) = 0
|
||||
|
||||
// Blend
|
||||
[Enum(PotaToon.AlphaMode)] _Blend("__blend", Int) = 0
|
||||
[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
|
||||
|
||||
// Debug
|
||||
[Enum(None, 0, Lighting, 1, Texture, 2)] _DebugFaceSDF ("Debug Face SDF", Int) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.universal": "12.0.0"
|
||||
}
|
||||
Tags
|
||||
{
|
||||
"RenderType"="Opaque"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags{"LightMode" = "UniversalForward"}
|
||||
ZWrite[_ZWriteMode]
|
||||
Cull[_Cull]
|
||||
Blend [_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilPass]
|
||||
Fail[_StencilFail]
|
||||
ZFail[_StencilZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonForwardKeywords.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "Outline"
|
||||
Tags
|
||||
{
|
||||
"LightMode"="SRPDefaultUnlit"
|
||||
}
|
||||
Cull Front
|
||||
Blend [_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilPass]
|
||||
Fail[_StencilFail]
|
||||
ZFail[_StencilZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonOutlineKeywords.hlsl"
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonOutlinePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ShadowCaster"
|
||||
Tags{"LightMode" = "ShadowCaster"}
|
||||
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
#pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
|
||||
#pragma vertex ShadowPassVertex
|
||||
#pragma fragment ShadowPassFragment
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#define _BaseMap _MainTex
|
||||
#define sampler_BaseMap sampler_MainTex
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "DepthOnly"
|
||||
Tags{"LightMode" = "DepthOnly"}
|
||||
|
||||
ZWrite On
|
||||
ColorMask R
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma vertex DepthOnlyVertex
|
||||
#pragma fragment DepthOnlyFragment
|
||||
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
|
||||
|
||||
//--------------------------------------
|
||||
// GPU Instancing
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#define _BaseMap _MainTex
|
||||
#define sampler_BaseMap sampler_MainTex
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
// This pass is used when drawing to a _CameraNormalsTexture texture
|
||||
Pass
|
||||
{
|
||||
Name "DepthNormals"
|
||||
Tags{"LightMode" = "DepthNormals"}
|
||||
|
||||
ZWrite On
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma vertex DepthNormalsVertex
|
||||
#pragma fragment DepthNormalsFragment
|
||||
|
||||
// -------------------------------------
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _NORMALMAP
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA
|
||||
|
||||
#if UNITY_VERSION >= 202230
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
|
||||
#endif
|
||||
|
||||
//--------------------------------------
|
||||
// GPU Instancing
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#define _BaseMap _MainTex
|
||||
#define sampler_BaseMap sampler_MainTex
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "CharacterDepth"
|
||||
Tags{"LightMode" = "CharacterDepth"}
|
||||
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
Cull Off
|
||||
BlendOp Max
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
|
||||
#pragma vertex CharShadowVertex
|
||||
#pragma fragment CharShadowFragment
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "../ChracterShadow/CharacterShadowDepthPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "TransparentShadow"
|
||||
Tags {"LightMode" = "TransparentShadow"}
|
||||
|
||||
ZWrite Off
|
||||
ZTest Off
|
||||
Cull Off
|
||||
Blend One One
|
||||
BlendOp Max
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
|
||||
#pragma vertex TransparentShadowVert
|
||||
#pragma fragment TransparentShadowFragment
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "../ChracterShadow/TransparentShadowPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "TransparentAlphaSum"
|
||||
Tags {"LightMode" = "TransparentAlphaSum"}
|
||||
|
||||
ZWrite Off
|
||||
ZTest Off
|
||||
Cull Off
|
||||
Blend One One
|
||||
BlendOp Add
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
#pragma shader_feature_local _ALPHATEST_ON
|
||||
|
||||
#pragma vertex TransparentAlphaSumVert
|
||||
#pragma fragment TransparentAlphaSumFragment
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "../ChracterShadow/TransparentShadowPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "OITDepth"
|
||||
Tags {
|
||||
"LightMode" = "OITDepth"
|
||||
}
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Cull OFF
|
||||
ColorMask R
|
||||
BlendOp Max
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "./PotaToonInput.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 position : POSITION;
|
||||
};
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
output.positionCS = TransformObjectToHClip(input.position.xyz);
|
||||
return output;
|
||||
}
|
||||
|
||||
float frag(Varyings input) : SV_TARGET
|
||||
{
|
||||
return input.positionCS.z;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "TransparentOutline"
|
||||
Tags {
|
||||
"LightMode" = "TransparentOutline"
|
||||
}
|
||||
Cull Front
|
||||
ZWrite Off
|
||||
Blend [_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]
|
||||
ColorMask RGBA
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilOpPass]
|
||||
Fail[_StencilOpFail]
|
||||
ZFail[_StencilOpZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonOutlineKeywords.hlsl"
|
||||
#define _USE_DITHER_FADE 1
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonOutlinePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "PotaToonCharacterMask"
|
||||
Tags {
|
||||
"LightMode" = "PotaToonCharacterMask"
|
||||
}
|
||||
ZWrite Off ZTest Always Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
#define _USE_DITHER_FADE 1
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonCharMaskPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
// Must be sync with ForwardLit pass
|
||||
Name "OpaqueDitherFade"
|
||||
Tags{"LightMode" = "OpaqueDitherFade"}
|
||||
Cull[_Cull]
|
||||
Blend SrcAlpha Zero
|
||||
ZWrite[_ZWriteMode]
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilPass]
|
||||
Fail[_StencilFail]
|
||||
ZFail[_StencilZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonForwardKeywords.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#define _USE_DITHER_FADE 1
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonPass.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Name "OpaqueDitherFadeOutline"
|
||||
Tags {
|
||||
"LightMode" = "OpaqueDitherFadeOutline"
|
||||
}
|
||||
Cull Front
|
||||
ZWrite On
|
||||
Blend SrcAlpha Zero
|
||||
ColorMask RGBA
|
||||
Stencil
|
||||
{
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilOpPass]
|
||||
Fail[_StencilOpFail]
|
||||
ZFail[_StencilOpZFail]
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include_with_pragmas "./PotaToonOutlineKeywords.hlsl"
|
||||
#define _USE_DITHER_FADE 1
|
||||
#include "./PotaToonInput.hlsl"
|
||||
#include "./PotaToonOutlinePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
CustomEditor "PotaToon.Editor.PotaToonShaderGUI"
|
||||
}
|
||||
16
Assets/PotaToon/Shaders/PotaToon/PotaToon.shader.meta
Normal file
16
Assets/PotaToon/Shaders/PotaToon/PotaToon.shader.meta
Normal file
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc5c1aecf31d1844db2e888dbfff02a9
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToon.shader
|
||||
uploadId: 814994
|
||||
68
Assets/PotaToon/Shaders/PotaToon/PotaToonCharMaskPass.hlsl
Normal file
68
Assets/PotaToon/Shaders/PotaToon/PotaToonCharMaskPass.hlsl
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef POTA_TOON_CHAR_MASK_PASS_INCLUDED
|
||||
#define POTA_TOON_CHAR_MASK_PASS_INCLUDED
|
||||
|
||||
#include "../Common/PotaToonCommon.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
#if UNITY_VERSION < 600000
|
||||
SAMPLER(sampler_LinearClamp);
|
||||
#endif
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float4 texcoord0 : TEXCOORD0;
|
||||
float4 texcoord1 : TEXCOORD1;
|
||||
float4 texcoord2 : TEXCOORD2;
|
||||
float4 texcoord3 : TEXCOORD3;
|
||||
};
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float2 uv2 : TEXCOORD2;
|
||||
float2 uv3 : TEXCOORD3;
|
||||
};
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
output.positionCS = TransformObjectToHClip(input.position.xyz);
|
||||
output.uv0 = input.texcoord0.xy;
|
||||
output.uv1 = input.texcoord1.xy;
|
||||
output.uv2 = input.texcoord2.xy;
|
||||
output.uv3 = input.texcoord3.xy;
|
||||
return output;
|
||||
}
|
||||
|
||||
half2 frag(Varyings input) : SV_TARGET
|
||||
{
|
||||
const float2 ssUV = GetNormalizedScreenSpaceUV(input.positionCS.xy);
|
||||
const float sceneDepth = SampleSceneDepth(ssUV);
|
||||
const float linearDepth = LinearEyeDepth(sceneDepth, _ZBufferParams);
|
||||
const float inputLinearDepth = LinearEyeDepth(input.positionCS.z, _ZBufferParams);
|
||||
if (inputLinearDepth >= linearDepth + 0.01)
|
||||
clip(-1);
|
||||
|
||||
const float2 uvArray[4] = { input.uv0, input.uv1, input.uv2, input.uv3 };
|
||||
const float clippingMask = SelectMask(SAMPLE_TEXTURE2D(_ClippingMask, sampler_LinearClamp, TRANSFORM_TEX(SelectUV(_ClippingMaskUV, uvArray), _ClippingMask)), _ClippingMaskCH);
|
||||
clip(clippingMask - 0.5);
|
||||
|
||||
half alpha = 1;
|
||||
#if _ALPHATEST_ON
|
||||
alpha = SAMPLE_TEXTURE2D(_MainTex, sampler_LinearClamp, TRANSFORM_TEX(SelectUV(_BaseMapUV, uvArray), _MainTex)).a * _BaseColor.a;
|
||||
clip(alpha - 0.001);
|
||||
|
||||
if (_SurfaceType < OIT_SURFACE)
|
||||
alpha = 1;
|
||||
#endif
|
||||
|
||||
if (_UseDitherFade > 0)
|
||||
DistanceFade(alpha, abs(TransformWorldToView(_HeadWorldPos.xyz).z), _DitherFadeMinZ, _DitherFadeMaxZ);
|
||||
|
||||
// Save alpha to g channel for 2d face shadow attenuation
|
||||
return half2(1, _ToonType == FACE_TYPE ? 0 : alpha);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a65cf6f246042b3a71aa1a51bc86c0f
|
||||
timeCreated: 1756129379
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonCharMaskPass.hlsl
|
||||
uploadId: 814994
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef POTA_TOON_FORWARD_KEYWORDS_INCLUDED
|
||||
#define POTA_TOON_FORWARD_KEYWORDS_INCLUDED
|
||||
|
||||
#pragma target 4.5
|
||||
// -------------------------------------
|
||||
// Universal Render Pipeline keywords
|
||||
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
||||
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile _ _SHADOWS_SOFT
|
||||
#pragma multi_compile _ _FORWARD_PLUS
|
||||
#pragma multi_compile _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
|
||||
|
||||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
|
||||
// -------------------------------------
|
||||
// Unity defined keywords
|
||||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
||||
#pragma multi_compile _ LIGHTMAP_ON
|
||||
#pragma multi_compile _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
||||
#pragma multi_compile_fog
|
||||
|
||||
// -------------------------------------
|
||||
// Material keywords
|
||||
#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
#pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
|
||||
|
||||
// -------------------------------------
|
||||
// POTA Toon keywords
|
||||
#pragma multi_compile_fragment _ _POTA_TOON_OIT
|
||||
#pragma multi_compile_fragment _ _POTA_TOON_SCREEN_RIM
|
||||
#pragma multi_compile_local_fragment _ _USE_FACE_SDF
|
||||
#pragma multi_compile_local_fragment _ _USE_2D_FACE_SHADOW
|
||||
#pragma multi_compile_local_fragment _ _USE_GLITTER
|
||||
#pragma shader_feature_fragment _ _DEBUG_POTA_TOON
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b1aedde2c3a401390907dbfae4e6d48
|
||||
timeCreated: 1762255577
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonForwardKeywords.hlsl
|
||||
uploadId: 814994
|
||||
210
Assets/PotaToon/Shaders/PotaToon/PotaToonInput.hlsl
Normal file
210
Assets/PotaToon/Shaders/PotaToon/PotaToonInput.hlsl
Normal file
@@ -0,0 +1,210 @@
|
||||
#ifndef POTA_TOON_INPUT_INCLUDED
|
||||
#define POTA_TOON_INPUT_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
half4 _BaseColor;
|
||||
half4 _ShadeColor;
|
||||
uint _UseShadeMap;
|
||||
uint _DisableCharShadow;
|
||||
uint _UseDarknessMode;
|
||||
uint _UseNormalMap;
|
||||
half _BaseStep;
|
||||
half _StepSmoothness;
|
||||
half _RimPower;
|
||||
half _RimSmoothness;
|
||||
half4 _RimColor;
|
||||
half4 _ScreenRimTint;
|
||||
|
||||
half4 _MidColor;
|
||||
half4 _OutlineColor;
|
||||
uint _OutlineMode;
|
||||
uint _UseOutlineNormalMap;
|
||||
uint _UseMidTone;
|
||||
uint _BlendOutlineMainTex;
|
||||
|
||||
half _OutlineWidth;
|
||||
half _IndirectDimmer;
|
||||
half _SpecularPower;
|
||||
half _SpecularSmoothness;
|
||||
half4 _SpecularColor;
|
||||
|
||||
float _Cutoff;
|
||||
float _MidWidth;
|
||||
float _RefractionWeight;
|
||||
float _RefractionBlurStep;
|
||||
|
||||
uint _MatCapMode;
|
||||
uint _MatCapMode2;
|
||||
uint _MatCapMode3;
|
||||
uint _MatCapMode4;
|
||||
uint _MatCapMode5;
|
||||
uint _MatCapMode6;
|
||||
uint _MatCapMode7;
|
||||
uint _MatCapMode8;
|
||||
half _MatCapWeight;
|
||||
half _MatCapWeight2;
|
||||
half _MatCapWeight3;
|
||||
half _MatCapWeight4;
|
||||
half _MatCapWeight5;
|
||||
half _MatCapWeight6;
|
||||
half _MatCapWeight7;
|
||||
half _MatCapWeight8;
|
||||
half _MatCapLightingDimmer;
|
||||
half _MatCapLightingDimmer2;
|
||||
half _MatCapLightingDimmer3;
|
||||
half _MatCapLightingDimmer4;
|
||||
half _MatCapLightingDimmer5;
|
||||
half _MatCapLightingDimmer6;
|
||||
half _MatCapLightingDimmer7;
|
||||
half _MatCapLightingDimmer8;
|
||||
half4 _MatCapColor;
|
||||
half4 _MatCapColor2;
|
||||
half4 _MatCapColor3;
|
||||
half4 _MatCapColor4;
|
||||
half4 _MatCapColor5;
|
||||
half4 _MatCapColor6;
|
||||
half4 _MatCapColor7;
|
||||
half4 _MatCapColor8;
|
||||
|
||||
half4 _EmissionColor;
|
||||
|
||||
half _OutlineOffsetZ;
|
||||
half _GlitterMainStrength;
|
||||
half _GlitterEnableLighting;
|
||||
half _GlitterBackfaceMask;
|
||||
half _GlitterApplyTransparency;
|
||||
half _GlitterShadowMask;
|
||||
half _GlitterParticleSize;
|
||||
half _GlitterScaleRandomize;
|
||||
half _GlitterContrast;
|
||||
half _GlitterSensitivity;
|
||||
half _GlitterBlinkSpeed;
|
||||
half _GlitterAngleLimit;
|
||||
half _GlitterLightDirection;
|
||||
half _GlitterColorRandomness;
|
||||
half _GlitterNormalStrength;
|
||||
half _GlitterPostContrast;
|
||||
half4 _GlitterColor;
|
||||
|
||||
float _BumpScale;
|
||||
float _DepthBias;
|
||||
float _NormalBias;
|
||||
float _CharShadowSmoothnessOffset;
|
||||
half _2DFaceShadowWidth;
|
||||
half _ScreenRimWidthMultiplier;
|
||||
half _DitherFadeMaxZ;
|
||||
half _DitherFadeMinZ;
|
||||
|
||||
float4 _MainTex_ST;
|
||||
float4 _ShadeMap_ST;
|
||||
float4 _NormalMap_ST;
|
||||
float4 _ClippingMask_ST;
|
||||
float4 _FaceSDFTex_ST;
|
||||
float4 _OutlineWidthMask_ST;
|
||||
float4 _HairHighLightTex_ST;
|
||||
|
||||
float4 _FaceForward;
|
||||
float4 _FaceUp;
|
||||
uint _UseVertexColor;
|
||||
uint _SDFReverse;
|
||||
uint _UseHairHighLight;
|
||||
uint _ReverseHairHighLightTex;
|
||||
|
||||
float _SDFOffset;
|
||||
float _SDFBlur;
|
||||
float _HairHiStrength;
|
||||
float _HairHiUVOffset;
|
||||
float4 _HeadWorldPos;
|
||||
|
||||
uint _BaseMapUV;
|
||||
uint _NormalMapUV;
|
||||
uint _ClippingMaskUV;
|
||||
uint _FaceSDFUV;
|
||||
uint _SpecularMapUV;
|
||||
uint _RimMaskUV;
|
||||
uint _HairHiMapUV;
|
||||
uint _GlitterMapUV;
|
||||
uint _EmissionMapUV;
|
||||
uint _OutlineMaskUV;
|
||||
uint _MatCapUV1;
|
||||
uint _MatCapUV2;
|
||||
uint _MatCapUV3;
|
||||
uint _MatCapUV4;
|
||||
uint _MatCapUV5;
|
||||
uint _MatCapUV6;
|
||||
uint _MatCapUV7;
|
||||
uint _MatCapUV8;
|
||||
|
||||
uint _ToonType;
|
||||
uint _SurfaceType;
|
||||
uint _ClippingMaskCH;
|
||||
uint _SpecularMaskCH;
|
||||
uint _RimMaskCH;
|
||||
uint _EmissionMaskCH;
|
||||
uint _OutlineMaskCH;
|
||||
uint _MatCapMaskCH1;
|
||||
uint _MatCapMaskCH2;
|
||||
uint _MatCapMaskCH3;
|
||||
uint _MatCapMaskCH4;
|
||||
uint _MatCapMaskCH5;
|
||||
uint _MatCapMaskCH6;
|
||||
uint _MatCapMaskCH7;
|
||||
uint _MatCapMaskCH8;
|
||||
uint _AOMapCH;
|
||||
uint _FaceSDFTexCH;
|
||||
uint _ReceiveLightShadow;
|
||||
|
||||
uint _UseDitherFade;
|
||||
uint _ScreenRimTintMode;
|
||||
uint _ScreenRimShadowFade;
|
||||
uint _DebugFaceSDF;
|
||||
CBUFFER_END
|
||||
|
||||
float4 _BaseMap_ST;
|
||||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D(_ShadeMap);
|
||||
TEXTURE2D(_ShadowBorderMask);
|
||||
TEXTURE2D(_NormalMap);
|
||||
TEXTURE2D(_ClippingMask);
|
||||
TEXTURE2D(_SpecularMap); SAMPLER(sampler_SpecularMap);
|
||||
TEXTURE2D(_SpecularMask);
|
||||
TEXTURE2D(_RimMask);
|
||||
TEXTURE2D(_MatCapTex); SAMPLER(sampler_MatCapTex);
|
||||
TEXTURE2D(_MatCapMask);
|
||||
TEXTURE2D(_MatCapTex2);
|
||||
TEXTURE2D(_MatCapMask2);
|
||||
TEXTURE2D(_MatCapTex3);
|
||||
TEXTURE2D(_MatCapMask3);
|
||||
TEXTURE2D(_MatCapTex4);
|
||||
TEXTURE2D(_MatCapMask4);
|
||||
TEXTURE2D(_MatCapTex5);
|
||||
TEXTURE2D(_MatCapMask5);
|
||||
TEXTURE2D(_MatCapTex6);
|
||||
TEXTURE2D(_MatCapMask6);
|
||||
TEXTURE2D(_MatCapTex7);
|
||||
TEXTURE2D(_MatCapMask7);
|
||||
TEXTURE2D(_MatCapTex8);
|
||||
TEXTURE2D(_MatCapMask8);
|
||||
TEXTURE2D(_EmissionMask);
|
||||
TEXTURE2D(_GlitterColorTex);
|
||||
TEXTURE2D(_FaceSDFTex); SAMPLER(sampler_FaceSDFTex);
|
||||
TEXTURE2D(_HairHighLightTex); SAMPLER(sampler_HairHighLightTex);
|
||||
TEXTURE2D(_OutlineNormalMap);
|
||||
TEXTURE2D(_OutlineWidthMask); SAMPLER(sampler_OutlineWidthMask);
|
||||
|
||||
#define TRANSPARENT_SURFACE 3
|
||||
#define REFRACTION_SURFACE 2
|
||||
#define OIT_SURFACE 2
|
||||
#define FACE_TYPE 1
|
||||
|
||||
#if _DEBUG_POTA_TOON
|
||||
// Debug
|
||||
# define DEBUG_FACE_SDF_LIGHTING 1
|
||||
# define DEBUG_FACE_SDF_TEXTURE 2
|
||||
#endif
|
||||
|
||||
#endif
|
||||
14
Assets/PotaToon/Shaders/PotaToon/PotaToonInput.hlsl.meta
Normal file
14
Assets/PotaToon/Shaders/PotaToon/PotaToonInput.hlsl.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc4aae90177d1ea4da38c345a1014627
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonInput.hlsl
|
||||
uploadId: 814994
|
||||
279
Assets/PotaToon/Shaders/PotaToon/PotaToonLighting.hlsl
Normal file
279
Assets/PotaToon/Shaders/PotaToon/PotaToonLighting.hlsl
Normal file
@@ -0,0 +1,279 @@
|
||||
#ifndef POTA_TOON_LIGHTING_INCLUDED
|
||||
#define POTA_TOON_LIGHTING_INCLUDED
|
||||
|
||||
#if _POTA_TOON_SCREEN_RIM
|
||||
#include "../Common/PotaToonGlobalInput.hlsl"
|
||||
#endif
|
||||
#include "./PotaToonUtility.hlsl"
|
||||
|
||||
void HalfLambert(float3 lightDirection, float3 normalWS, float step, float smoothness, out float halfLambert, out float halfLambertStep)
|
||||
{
|
||||
float M = step + smoothness;
|
||||
float m = step - smoothness;
|
||||
halfLambert = dot(lightDirection, normalWS) * 0.5 + 0.5;
|
||||
halfLambertStep = LinearStep(m, M, halfLambert);
|
||||
}
|
||||
|
||||
half3 Specular(float3 lightDirection, half lightStrength, float3 normalWS, float3 viewDirection, float2 uv)
|
||||
{
|
||||
half3 specularColor;
|
||||
float3 halfDirection = normalize(viewDirection + lightDirection);
|
||||
float NdotH = saturate(dot(halfDirection, normalWS));
|
||||
float smoothness = exp2(10 * _SpecularPower + 1);
|
||||
float modifier = PositivePow(NdotH, smoothness);
|
||||
modifier = LinearStep(0.5 - _SpecularSmoothness, 0.5 + _SpecularSmoothness, modifier);
|
||||
float4 SpecularMap = SAMPLE_TEXTURE2D_LOD(_SpecularMap, sampler_SpecularMap, uv, 0);
|
||||
float SpecularMask = SelectMask(SAMPLE_TEXTURE2D_LOD(_SpecularMask, sampler_SpecularMap, uv, 0), _SpecularMaskCH);
|
||||
|
||||
specularColor = _SpecularColor.rgb * SpecularMap.rgb * (SpecularMask * lightStrength * _SpecularColor.a);
|
||||
specularColor *= modifier;
|
||||
|
||||
return specularColor;
|
||||
}
|
||||
|
||||
half3 MatCap(TEXTURE2D_PARAM(tex, smp), TEXTURE2D(mask), const half4 color, const float2 matcapUV, const float2 uv, const uint maskChannel)
|
||||
{
|
||||
half3 matcapMap = SAMPLE_TEXTURE2D_LOD(tex, smp, matcapUV, 0).rgb;
|
||||
float matcapMask = SelectMask(SAMPLE_TEXTURE2D_LOD(mask, smp, uv, 0), maskChannel);
|
||||
return matcapMask > 0 ? matcapMap * color.rgb * color.a : -1;
|
||||
}
|
||||
|
||||
half3 RimLighting(float3 normalWS, float3 viewDirection, half3 lighting, float facing, float2 uv, float charShadowAtten)
|
||||
{
|
||||
#if _USE_FACE_SDF
|
||||
return 0;
|
||||
#else
|
||||
float emission = LinearStep(0.5 - _RimSmoothness, 0.5 + _RimSmoothness, pow(1 - saturate(dot(viewDirection, normalWS)), _RimPower * 8));
|
||||
half3 rimColor = _RimColor.rgb * (emission * _RimColor.a);
|
||||
float rimMask = SelectMask(SAMPLE_TEXTURE2D(_RimMask, sampler_MainTex, uv), _RimMaskCH);
|
||||
if (facing < 0.1 || charShadowAtten > 0)
|
||||
{
|
||||
rimColor = 0;
|
||||
}
|
||||
return rimColor * lighting * rimMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if _POTA_TOON_SCREEN_RIM
|
||||
void ScreenRimLighting(inout half3 color, float2 ssUV, float charShadowAtten)
|
||||
{
|
||||
const float sceneDepth = SampleSceneDepth(ssUV);
|
||||
const float depthMultiplier = min(1, saturate((MaxScreenRimDist - LinearEyeDepth(sceneDepth, _ZBufferParams)) / MaxScreenRimDist));
|
||||
float3 lightDirCS = TransformWorldToHClipDir(_BrightestLightDirection.xyz);
|
||||
float sampleWidth = _ScreenRimWidth * _ScreenRimWidthMultiplier * depthMultiplier;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
lightDirCS.y = -lightDirCS.y;
|
||||
#endif
|
||||
float2 rimUV = ssUV + lightDirCS.xy * sampleWidth;
|
||||
const float2 o = _ScreenSize.zw * 2;
|
||||
float maskSample = SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_MainTex, rimUV).r
|
||||
+ SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_MainTex, rimUV + float2(o.x, o.y)).r
|
||||
+ SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_MainTex, rimUV + float2(o.x, -o.y)).r
|
||||
+ SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_MainTex, rimUV + float2(-o.x, o.y)).r
|
||||
+ SAMPLE_TEXTURE2D_X(_PotaToonCharMask, sampler_MainTex, rimUV + float2(-o.x, -o.y)).r;
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
bool isBehindChar = SampleSceneDepth(rimUV) < sceneDepth + 0.00001;
|
||||
#else
|
||||
bool isBehindChar = SampleSceneDepth(rimUV) > sceneDepth + 0.00001;
|
||||
#endif
|
||||
|
||||
if (maskSample < HALF_MIN && isBehindChar)
|
||||
{
|
||||
half3 targetColor = lerp(_ScreenRimColor.rgb * _ScreenRimTint.rgb, _ScreenRimTint.rgb, _ScreenRimTintMode);
|
||||
half3 screenRimColor = targetColor * lerp(1.0, (1.0 - charShadowAtten), _ScreenRimShadowFade);
|
||||
color += screenRimColor;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
half3 Emission(float2 uv)
|
||||
{
|
||||
half3 emissionMap = SAMPLE_TEXTURE2D(_EmissionMap, sampler_MainTex, uv).rgb;
|
||||
half emissionMask = SelectMask(SAMPLE_TEXTURE2D(_EmissionMask, sampler_MainTex, uv), _EmissionMaskCH);
|
||||
return _EmissionColor.rgb * emissionMap * (emissionMask * _EmissionColor.a);
|
||||
}
|
||||
|
||||
half3 MainLighting(Light mainLight, float3 positionWS, float3 normalWS, float3 viewDirection, float2 ssUV, float2 uv, half opacity, inout float charShadowAtten, float faceSDFAtten, inout float totalAttenuation, inout half3 midTone, half aoMap)
|
||||
{
|
||||
half3 currLighting = 0;
|
||||
half3 lightColor = mainLight.color * mainLight.distanceAttenuation;
|
||||
half lightStrength = 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b;
|
||||
const bool isBrightestLight = _UseBrightestLight == 0 || _IsBrightestLightMain > 0;
|
||||
const half3 shadeColor = lerp(_ShadeColor.rgb, 0, _UseDarknessMode);
|
||||
|
||||
// Ignore self-shadow as much as possible
|
||||
const bool needDefaultShadow = _ReceiveLightShadow > 0 && isBrightestLight;
|
||||
half mainLightShadowAtten = needDefaultShadow ? LinearStep(0, _StepSmoothness * 2, mainLight.shadowAttenuation) : 1;
|
||||
|
||||
bool isMidToneArea = false;
|
||||
const half midToneAtten = aoMap * lightStrength * mainLightShadowAtten;
|
||||
|
||||
// If Face type, adjust normal
|
||||
if (_ToonType == FACE_TYPE)
|
||||
{
|
||||
if (!isBrightestLight)
|
||||
normalWS = _FaceForward.xyz;
|
||||
}
|
||||
|
||||
// Compute Char Shadow
|
||||
if (_DisableCharShadow == 0 && isBrightestLight)
|
||||
{
|
||||
charShadowAtten = GetCharMainShadow(ssUV, positionWS, opacity, faceSDFAtten);
|
||||
float smoothnessOffset = _CharShadowSmoothnessOffset * 0.3;
|
||||
float stepCharShadowAtten = LinearStep(0.3 - smoothnessOffset, 0.7 + smoothnessOffset, charShadowAtten);
|
||||
|
||||
if (_UseMidTone > 0)
|
||||
{
|
||||
if (stepCharShadowAtten > 0)
|
||||
{
|
||||
float midToneStrength = 1.0 - LinearStep(0, _MidWidth, charShadowAtten);
|
||||
if (midToneStrength > 0)
|
||||
{
|
||||
isMidToneArea = true;
|
||||
midTone = _MidColor.rgb * midToneStrength * midToneAtten;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
charShadowAtten = stepCharShadowAtten;
|
||||
totalAttenuation = min(totalAttenuation, 1.0 - charShadowAtten);
|
||||
}
|
||||
|
||||
half3 lightDirection = isBrightestLight ? _BrightestLightDirection.xyz : mainLight.direction;
|
||||
// Diffuse
|
||||
float halfLambert, halfLambertStep;
|
||||
HalfLambert(lightDirection, normalWS, _BaseStep, _StepSmoothness, halfLambert, halfLambertStep);
|
||||
|
||||
// MidTone
|
||||
if (_UseMidTone > 0)
|
||||
{
|
||||
#if _USE_FACE_SDF
|
||||
// Apply mid tone attenuation for face sdf mid tone
|
||||
midTone *= midToneAtten;
|
||||
#endif
|
||||
|
||||
// If no character shadow
|
||||
if (charShadowAtten < HALF_MIN)
|
||||
{
|
||||
isMidToneArea = true;
|
||||
float midToneSmoothness = _StepSmoothness * _MidWidth;
|
||||
midTone += GetMidTone(halfLambert, _BaseStep, midToneSmoothness) * midToneAtten;
|
||||
halfLambertStep = LinearStep(_BaseStep - midToneSmoothness, _BaseStep + midToneSmoothness, halfLambert);
|
||||
}
|
||||
|
||||
if (needDefaultShadow)
|
||||
{
|
||||
float midToneSmoothness = _MidWidth * 0.5;
|
||||
midTone += GetMidTone(mainLightShadowAtten, 0.5, midToneSmoothness) * (aoMap * lightStrength);
|
||||
mainLightShadowAtten = LinearStep(0.5 - midToneSmoothness, 0.5 + midToneSmoothness, mainLightShadowAtten);
|
||||
}
|
||||
|
||||
if (halfLambertStep < HALF_MIN)
|
||||
isMidToneArea = false;
|
||||
|
||||
if (isMidToneArea == false)
|
||||
midTone = 0;
|
||||
}
|
||||
|
||||
if (isBrightestLight)
|
||||
{
|
||||
totalAttenuation = min(totalAttenuation, halfLambertStep);
|
||||
}
|
||||
|
||||
// Always apply step if main light
|
||||
currLighting = lerp(shadeColor, _BaseColor.rgb, halfLambertStep);
|
||||
|
||||
// Specular
|
||||
currLighting += Specular(lightDirection, lightStrength, normalWS, viewDirection, uv);
|
||||
|
||||
#if _USE_FACE_SDF
|
||||
// Override to FaceSDF if enabled
|
||||
if (isBrightestLight)
|
||||
currLighting = lerp(shadeColor, _BaseColor.rgb, faceSDFAtten);
|
||||
#endif
|
||||
|
||||
// Apply Character Shadow
|
||||
if (_DisableCharShadow == 0 && isBrightestLight)
|
||||
{
|
||||
currLighting = lerp(currLighting, shadeColor, charShadowAtten);
|
||||
}
|
||||
|
||||
// Apply main light shadow
|
||||
if (needDefaultShadow)
|
||||
{
|
||||
currLighting = lerp(shadeColor, currLighting, mainLightShadowAtten);
|
||||
totalAttenuation = min(totalAttenuation, mainLightShadowAtten);
|
||||
}
|
||||
|
||||
return currLighting * lightColor;
|
||||
}
|
||||
|
||||
half3 AdditionalLighting(Light light, float3 normalWS, float3 viewDirection, float2 ssUV, float2 uv, float3 positionWS, uint lightIndex, half opacity, inout float charShadowAtten, float faceSDFAtten, inout float totalAttenuation, inout half3 midTone)
|
||||
{
|
||||
half3 currLighting = 0;
|
||||
half3 lightColor = light.color * light.distanceAttenuation;
|
||||
half lightStrength = 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b;
|
||||
const bool isBrightestLight = _UseBrightestLight > 0 && _IsBrightestLightMain == 0 && _BrightestLightIndex == lightIndex;
|
||||
const half3 shadeColor = lerp(_ShadeColor.rgb, 0, _UseDarknessMode);
|
||||
|
||||
// If Face type, adjust normal
|
||||
if (_ToonType == FACE_TYPE)
|
||||
{
|
||||
if (!isBrightestLight)
|
||||
normalWS = _FaceForward.xyz;
|
||||
}
|
||||
|
||||
// Compute Char Shadow
|
||||
float stepLocalCharShadowAtten = 0;
|
||||
if (_DisableCharShadow == 0 && isBrightestLight)
|
||||
{
|
||||
float localCharShadowAtten = GetCharAdditionalShadow(ssUV, positionWS, opacity, lightIndex, faceSDFAtten, 0);
|
||||
float smoothnessOffset = _CharShadowSmoothnessOffset * 0.3;
|
||||
stepLocalCharShadowAtten = LinearStep(0.3 - smoothnessOffset, 0.7 + smoothnessOffset, localCharShadowAtten);
|
||||
charShadowAtten = stepLocalCharShadowAtten;
|
||||
totalAttenuation = min(totalAttenuation, 1.0 - charShadowAtten);
|
||||
}
|
||||
|
||||
// Diffuse
|
||||
float halfLambert, halfLambertStep;
|
||||
HalfLambert(light.direction, normalWS, _BaseStep, _StepSmoothness * 2, halfLambert, halfLambertStep); // Assume _StepSmoothness = [0, 0.1]
|
||||
if (isBrightestLight)
|
||||
{
|
||||
totalAttenuation = min(totalAttenuation, halfLambertStep);
|
||||
}
|
||||
currLighting = lerp(shadeColor, _BaseColor.rgb, halfLambertStep);
|
||||
|
||||
// Reduce MidTone intensity if lit by additional light
|
||||
if (halfLambertStep < HALF_MIN || halfLambertStep > (1.0 - HALF_MIN))
|
||||
{
|
||||
midTone *= 1.0 - saturate(lightStrength);
|
||||
}
|
||||
|
||||
// Specular
|
||||
currLighting += Specular(light.direction, lightStrength, normalWS, viewDirection, uv);
|
||||
|
||||
#if _USE_FACE_SDF
|
||||
// Override to FaceSDF if enabled
|
||||
if (isBrightestLight)
|
||||
currLighting = lerp(shadeColor, _BaseColor.rgb, faceSDFAtten);
|
||||
#endif
|
||||
|
||||
// Apply Character Shadow
|
||||
if (_DisableCharShadow == 0 && isBrightestLight)
|
||||
{
|
||||
currLighting = lerp(currLighting, shadeColor, stepLocalCharShadowAtten);
|
||||
}
|
||||
|
||||
if (_ReceiveLightShadow > 0 && isBrightestLight)
|
||||
{
|
||||
half lightShadowAtten = LinearStep(0, _StepSmoothness * 2, light.shadowAttenuation);
|
||||
currLighting = lerp(shadeColor, currLighting, lightShadowAtten);
|
||||
totalAttenuation = min(totalAttenuation, lightShadowAtten);
|
||||
}
|
||||
|
||||
return currLighting * lightColor;
|
||||
}
|
||||
|
||||
#endif
|
||||
10
Assets/PotaToon/Shaders/PotaToon/PotaToonLighting.hlsl.meta
Normal file
10
Assets/PotaToon/Shaders/PotaToon/PotaToonLighting.hlsl.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3823ee0ee8104473866a8090ad194816
|
||||
timeCreated: 1741269613
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonLighting.hlsl
|
||||
uploadId: 814994
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef POTA_TOON_OUTLINE_KEYWORDS_INCLUDED
|
||||
#define POTA_TOON_OUTLINE_KEYWORDS_INCLUDED
|
||||
|
||||
#pragma target 4.5
|
||||
#pragma multi_compile_fragment _ _POTA_TOON_OIT
|
||||
#pragma multi_compile _ _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile _ _FORWARD_PLUS
|
||||
#pragma multi_compile _ _LIGHT_LAYERS
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c47cfe42358b4a9c9b1d2f83309d13f6
|
||||
timeCreated: 1762255901
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonOutlineKeywords.hlsl
|
||||
uploadId: 814994
|
||||
170
Assets/PotaToon/Shaders/PotaToon/PotaToonOutlinePass.hlsl
Normal file
170
Assets/PotaToon/Shaders/PotaToon/PotaToonOutlinePass.hlsl
Normal file
@@ -0,0 +1,170 @@
|
||||
#ifndef POTA_TOON_OUTLINE_PASS_INCLUDED
|
||||
#define POTA_TOON_OUTLINE_PASS_INCLUDED
|
||||
|
||||
#include "../Common/PotaToonCommon.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RealtimeLights.hlsl"
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
#include "../OIT/OITOutlineUtils.hlsl"
|
||||
#endif
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float4 tangent : TANGENT;
|
||||
float2 texcoord0 : TEXCOORD0;
|
||||
float2 texcoord1 : TEXCOORD1;
|
||||
float2 texcoord2 : TEXCOORD2;
|
||||
float2 texcoord3 : TEXCOORD3;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float2 uv2 : TEXCOORD2;
|
||||
float2 uv3 : TEXCOORD3;
|
||||
float3 positionWS : TEXCOORD4;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VertexOutput vert (VertexInput v)
|
||||
{
|
||||
VertexOutput o = (VertexOutput)0;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
o.uv0 = v.texcoord0;
|
||||
o.uv1 = v.texcoord1;
|
||||
o.uv2 = v.texcoord2;
|
||||
o.uv3 = v.texcoord3;
|
||||
|
||||
const float2 uv = SelectUVVertex(_OutlineMaskUV, o.uv0, o.uv1, o.uv2, o.uv3);
|
||||
float3 normalWS = TransformObjectToWorldDir(v.normal);
|
||||
float3 tangentWS = TransformObjectToWorldDir(v.tangent.xyz);
|
||||
float3 bitangentWS = normalize(cross(normalWS, tangentWS) * v.tangent.w);
|
||||
float3x3 tangentTransform = float3x3(tangentWS, bitangentWS, normalWS);
|
||||
float4 normalMap = SAMPLE_TEXTURE2D_LOD(_OutlineNormalMap, sampler_OutlineWidthMask, uv, 0) * 2 - 1;
|
||||
float3 normal = lerp(v.normal, normalize(mul(normalMap.rgb, tangentTransform)), _UseOutlineNormalMap);
|
||||
|
||||
float outlineMask = SelectMask(SAMPLE_TEXTURE2D_LOD(_OutlineWidthMask, sampler_OutlineWidthMask, TRANSFORM_TEX(uv, _OutlineWidthMask), 0), _OutlineMaskCH);
|
||||
float outlineWidth = _OutlineWidth * 0.001 * outlineMask;
|
||||
|
||||
float positionOutlineWidth = outlineWidth * 2;
|
||||
float signVar = dot(normalize(v.vertex.xyz), normalize(v.normal)) < 0 ? -1 : 1;
|
||||
|
||||
o.pos = lerp(TransformObjectToHClip(normal * outlineWidth + v.vertex.xyz), TransformObjectToHClip((signVar * positionOutlineWidth) * normalize(v.vertex.xyz) + v.vertex.xyz), _OutlineMode);
|
||||
o.positionWS = TransformObjectToWorld(o.pos.xyz);
|
||||
|
||||
#if defined(UNITY_REVERSED_Z)
|
||||
const float outlineOffsetZ = _OutlineOffsetZ * -0.01;
|
||||
#else
|
||||
const float outlineOffsetZ = _OutlineOffsetZ * 0.01;
|
||||
#endif
|
||||
o.pos.z += outlineOffsetZ * TransformWorldToHClip(_WorldSpaceCameraPos).z;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
[earlydepthstencil]
|
||||
#endif
|
||||
half4 frag(VertexOutput i) : SV_TARGET
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(i);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
#if !_POTA_TOON_OIT
|
||||
// Skip outline for transparent objects if OIT not enabled.
|
||||
if (_SurfaceType >= OIT_SURFACE)
|
||||
{
|
||||
clip(-1);
|
||||
}
|
||||
#else
|
||||
float4 clipPos = TransformWorldToHClip(i.positionWS);
|
||||
float3 ndc = clipPos.xyz / clipPos.w;
|
||||
float2 ssUV = ndc.xy * 0.5 + 0.5;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
ssUV.y = 1.0 - ssUV.y;
|
||||
#endif
|
||||
|
||||
if (_SurfaceType >= OIT_SURFACE && SampleOITDepth(ssUV, ndc.z))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
const float2 uvArray[4] = { i.uv0, i.uv1, i.uv2, i.uv3 };
|
||||
half4 baseMap = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, TRANSFORM_TEX(SelectUV(_BaseMapUV, uvArray), _MainTex), 0);
|
||||
half3 finalColor = _OutlineColor.rgb;
|
||||
if (_BlendOutlineMainTex > 0)
|
||||
{
|
||||
finalColor *= baseMap.rgb;
|
||||
}
|
||||
|
||||
// Apply main color alpha by default to match color
|
||||
half alpha = OutputAlpha(_BaseColor.a, _SurfaceType >= OIT_SURFACE);
|
||||
#if _ALPHATEST_ON
|
||||
float cutoff = _Cutoff;
|
||||
if (_SurfaceType >= REFRACTION_SURFACE)
|
||||
cutoff = 0;
|
||||
clip(alpha - cutoff - 0.001);
|
||||
#endif
|
||||
|
||||
#if _USE_DITHER_FADE
|
||||
if (_UseDitherFade > 0)
|
||||
DistanceFade(alpha, abs(TransformWorldToView(_HeadWorldPos.xyz).z), _DitherFadeMinZ, _DitherFadeMaxZ);
|
||||
#endif
|
||||
|
||||
// Lighting Attenuation
|
||||
InputData inputData;
|
||||
inputData.positionWS = i.positionWS;
|
||||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(i.pos);
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
Light light = GetMainLight();
|
||||
half3 lightColor = light.color.rgb;
|
||||
half lightIntensity = 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b;
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
light = GetAdditionalLight(lightIndex, i.positionWS);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightColor = light.color * light.distanceAttenuation;
|
||||
lightIntensity += 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Local Lights
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
light = GetAdditionalLight(lightIndex, i.positionWS);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
lightColor = light.color * light.distanceAttenuation;
|
||||
lightIntensity += 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b;
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
#endif
|
||||
finalColor *= saturate(lightIntensity);
|
||||
|
||||
return half4(finalColor, alpha);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5bacb982d8f16f4bb9fc9352664f46e
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonOutlinePass.hlsl
|
||||
uploadId: 814994
|
||||
409
Assets/PotaToon/Shaders/PotaToon/PotaToonPass.hlsl
Normal file
409
Assets/PotaToon/Shaders/PotaToon/PotaToonPass.hlsl
Normal file
@@ -0,0 +1,409 @@
|
||||
#ifndef POTA_TOON_PASS_INCLUDED
|
||||
#define POTA_TOON_PASS_INCLUDED
|
||||
|
||||
#include "../ChracterShadow/DeclareCharacterShadowTexture.hlsl"
|
||||
#include "./PotaToonLighting.hlsl"
|
||||
#if _POTA_TOON_OIT
|
||||
#include "../OIT/LinkedListCreation.hlsl"
|
||||
#endif
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float3 normal : NORMAL;
|
||||
float4 tangent : TANGENT;
|
||||
float4 texcoord0 : TEXCOORD0;
|
||||
float4 texcoord1 : TEXCOORD1;
|
||||
float4 texcoord2 : TEXCOORD2;
|
||||
float4 texcoord3 : TEXCOORD3;
|
||||
float2 staticLightmapUV : TEXCOORD4;
|
||||
float2 dynamicLightmapUV : TEXCOORD5;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float2 uv2 : TEXCOORD2;
|
||||
float2 uv3 : TEXCOORD3;
|
||||
float3 positionWS : TEXCOORD4;
|
||||
float3 normalWS : TEXCOORD5;
|
||||
float3 tangentWS : TEXCOORD6;
|
||||
float3 bitangentWS : TEXCOORD7;
|
||||
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 8);
|
||||
half fogFactor : TEXCOORD9;
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
float4 shadowCoord : TEXCOORD10;
|
||||
#endif
|
||||
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
float2 dynamicLightmapUV : TEXCOORD11; // Dynamic lightmap UVs
|
||||
#endif
|
||||
|
||||
#ifdef USE_APV_PROBE_OCCLUSION
|
||||
float4 probeOcclusion : TEXCOORD12;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VertexOutput vert(VertexInput v)
|
||||
{
|
||||
VertexOutput o = (VertexOutput)0;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
|
||||
o.positionCS = vertexInput.positionCS;
|
||||
o.color = v.color;
|
||||
o.uv0 = v.texcoord0.xy;
|
||||
o.uv1 = v.texcoord1.xy;
|
||||
o.uv2 = v.texcoord2.xy;
|
||||
o.uv3 = v.texcoord3.xy;
|
||||
o.normalWS = TransformObjectToWorldDir(v.normal);
|
||||
o.positionWS = vertexInput.positionWS;
|
||||
o.tangentWS = TransformObjectToWorldDir(v.tangent.xyz);
|
||||
o.bitangentWS = normalize(cross(o.normalWS, o.tangentWS) * v.tangent.w);
|
||||
|
||||
OUTPUT_LIGHTMAP_UV(v.staticLightmapUV, unity_LightmapST, o.staticLightmapUV);
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
o.dynamicLightmapUV = v.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#endif
|
||||
OUTPUT_SH(o.normalWS, o.vertexSH);
|
||||
o.fogFactor = ComputeFogFactor(o.positionCS.z);
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
o.shadowCoord = GetShadowCoord(vertexInput);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
InputData InitializeInputData(VertexOutput input)
|
||||
{
|
||||
InputData inputData;
|
||||
inputData.positionWS = input.positionWS;
|
||||
inputData.positionCS = input.positionCS;
|
||||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
|
||||
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactor);
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
inputData.shadowCoord = input.shadowCoord;
|
||||
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
|
||||
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
|
||||
#else
|
||||
inputData.shadowCoord = float4(0, 0, 0, 0);
|
||||
#endif
|
||||
|
||||
#if defined(DYNAMICLIGHTMAP_ON)
|
||||
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
|
||||
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
inputData.shadowMask = 1;
|
||||
#else
|
||||
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
|
||||
#endif
|
||||
return inputData;
|
||||
}
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
[earlydepthstencil]
|
||||
#endif
|
||||
half4 frag(VertexOutput i, half facing : VFACE, uint uSampleIdx : SV_SampleIndex) : SV_TARGET
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(i);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
|
||||
half alpha = 0;
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
// Setup Input Data
|
||||
const float2 uvArray[4] = { i.uv0, i.uv1, i.uv2, i.uv3 };
|
||||
const float3 positionWS = i.positionWS;
|
||||
const float3 normalMap = UnpackNormalScale(SAMPLE_TEXTURE2D(_NormalMap, sampler_MainTex, TRANSFORM_TEX(SelectUV(_NormalMapUV, uvArray), _NormalMap)), _BumpScale);
|
||||
i.normalWS = normalize(i.normalWS);
|
||||
float3x3 tangentTransform = float3x3(i.tangentWS, i.bitangentWS, i.normalWS);
|
||||
float3 normalWS = lerp(i.normalWS, normalize(mul(normalMap.rgb, tangentTransform)), _UseNormalMap);
|
||||
|
||||
const float3 viewDir = normalize(_WorldSpaceCameraPos - i.positionWS).xyz;
|
||||
const float3 viewNormal = TransformWorldToViewDir(normalWS);
|
||||
|
||||
InputData inputData = InitializeInputData(i);
|
||||
const float2 normalizedScreenSpaceUV = inputData.normalizedScreenSpaceUV;
|
||||
|
||||
half4 vertexColor = lerp(1, i.color, _UseVertexColor);
|
||||
const half4 baseMap = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(SelectUV(_BaseMapUV, uvArray), _MainTex)) * vertexColor;
|
||||
half4 shadeMap = SAMPLE_TEXTURE2D(_ShadeMap, sampler_MainTex, TRANSFORM_TEX(SelectUV(_BaseMapUV, uvArray), _ShadeMap)) * vertexColor;
|
||||
shadeMap = lerp(baseMap, shadeMap, _UseShadeMap);
|
||||
const half opacity = baseMap.a * _BaseColor.a;
|
||||
const float clippingMask = SelectMask(SAMPLE_TEXTURE2D(_ClippingMask, sampler_MainTex, TRANSFORM_TEX(SelectUV(_ClippingMaskUV, uvArray), _ClippingMask)), _ClippingMaskCH);
|
||||
half3 finalColor = 0;
|
||||
float totalAttenuation = 1;
|
||||
|
||||
// Ambient Occlusion
|
||||
half aoMap = SelectMask(SAMPLE_TEXTURE2D_LOD(_ShadowBorderMask, sampler_MainTex, SelectUV(_BaseMapUV, uvArray), 0), _AOMapCH);
|
||||
aoMap = LinearStep(_BaseStep - _StepSmoothness, _BaseStep + _StepSmoothness, aoMap);
|
||||
|
||||
clip(clippingMask - 0.5);
|
||||
#if _ALPHATEST_ON
|
||||
float cutoff = _Cutoff;
|
||||
if (_SurfaceType >= REFRACTION_SURFACE)
|
||||
cutoff = 0;
|
||||
clip(opacity - cutoff - 0.001);
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// 0. Brightest Light ///
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
half3 midTone = 0;
|
||||
half3 directLighting = 0;
|
||||
|
||||
// Face SDF Shadow
|
||||
float faceSdfAtten = 1;
|
||||
#if _USE_FACE_SDF
|
||||
faceSdfAtten = GetFaceSDFAtten(TRANSFORM_TEX(SelectUV(_FaceSDFUV, uvArray), _FaceSDFTex));
|
||||
if (_UseMidTone > 0)
|
||||
{
|
||||
// Only calculate MidTone for the main light.
|
||||
if (_UseBrightestLight == 0 || _IsBrightestLightMain > 0)
|
||||
{
|
||||
midTone += GetMidTone(faceSdfAtten, 0, _StepSmoothness * _MidWidth);
|
||||
}
|
||||
}
|
||||
faceSdfAtten = LinearStep(-_StepSmoothness, _StepSmoothness, faceSdfAtten);
|
||||
totalAttenuation = faceSdfAtten;
|
||||
#endif
|
||||
totalAttenuation *= aoMap;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// 1. Direct Lighting ///
|
||||
/// - Apply step for the 'most powerful' light ///
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
float charShadowAtten = 0;
|
||||
half4 shadowMask = CalculateShadowMask(inputData);
|
||||
Light mainLight = GetMainLight(inputData.shadowCoord, i.positionWS, shadowMask);
|
||||
directLighting += MainLighting(mainLight, positionWS, normalWS, viewDir, normalizedScreenSpaceUV, SelectUV(_SpecularMapUV, uvArray), opacity, charShadowAtten, faceSdfAtten, totalAttenuation, midTone, aoMap);
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
half3 additionalLightsColor = 0;
|
||||
|
||||
// Directional Lights
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
Light light = GetAdditionalLight(lightIndex, positionWS, shadowMask);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
additionalLightsColor += AdditionalLighting(light, normalWS, viewDir, normalizedScreenSpaceUV, SelectUV(_SpecularMapUV, uvArray), positionWS, lightIndex, opacity, charShadowAtten, faceSdfAtten, totalAttenuation, midTone);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Local Lights
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
Light light = GetAdditionalLight(lightIndex, positionWS, shadowMask);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
additionalLightsColor += AdditionalLighting(light, normalWS, viewDir, normalizedScreenSpaceUV, SelectUV(_SpecularMapUV, uvArray), positionWS, lightIndex, opacity, charShadowAtten, faceSdfAtten, totalAttenuation, midTone);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
|
||||
directLighting += additionalLightsColor;
|
||||
#endif
|
||||
|
||||
half3 textureAlbedo = lerp(shadeMap.rgb, baseMap.rgb, totalAttenuation);
|
||||
directLighting *= textureAlbedo;
|
||||
// Set directLighting result to zero if there's no light.
|
||||
if (_BrightestLightIndex < 0)
|
||||
{
|
||||
directLighting = 0;
|
||||
}
|
||||
|
||||
if (_UseMidTone > 0)
|
||||
{
|
||||
midTone *= textureAlbedo;
|
||||
finalColor += midTone;
|
||||
}
|
||||
finalColor += directLighting;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// 2. Indirect Lighting (We don't apply step) ///
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
BRDFData brdfData;
|
||||
half3 finalBaseColor = lerp(shadeMap.rgb * _ShadeColor.rgb, baseMap.rgb * _BaseColor.rgb, totalAttenuation);
|
||||
InitializeBRDFData(finalBaseColor, 0, 0, 0, alpha, brdfData);
|
||||
#if defined(DYNAMICLIGHTMAP_ON)
|
||||
half3 bakedGI = SAMPLE_GI(i.staticLightmapUV, i.dynamicLightmapUV, i.vertexSH, normalWS);
|
||||
#elif UNITY_VERSION >= 202230 && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
half3 bakedGI = SAMPLE_GI(i.vertexSH, GetAbsolutePositionWS(positionWS), normalWS, viewDir, i.positionCS.xy, i.probeOcclusion, inputData.shadowMask);
|
||||
#else
|
||||
half3 bakedGI = SAMPLE_GI(i.staticLightmapUV, i.vertexSH, normalWS);
|
||||
#endif
|
||||
MixRealtimeAndBakedGI(mainLight, normalWS, bakedGI);
|
||||
#if UNITY_VERSION >= 202230
|
||||
half3 indirectLighting = GlobalIllumination(brdfData, (BRDFData)0, 0, bakedGI, 1, positionWS, normalWS, viewDir, normalizedScreenSpaceUV);
|
||||
#else
|
||||
half3 indirectLighting = GlobalIllumination(brdfData, (BRDFData)0, 0, bakedGI, 1, positionWS, normalWS, viewDir);
|
||||
#endif
|
||||
indirectLighting = max(0, indirectLighting * _IndirectDimmer); // Prevent NaN
|
||||
finalColor += indirectLighting;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 3. Global Lighting (Rim, Matcap, etc.) from accumulated light (Direct + Indirect) ///
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
half3 lighting = directLighting + indirectLighting;
|
||||
|
||||
// Composition before global lighting
|
||||
finalColor = min(finalColor, finalBaseColor * _MaxToonBrightness + midTone);
|
||||
|
||||
// Hair High Light
|
||||
if (_UseHairHighLight > 0)
|
||||
{
|
||||
half3 hairHighLight = AnisotropicHairHighlight(viewDir, SelectUV(_HairHiMapUV, uvArray), positionWS, totalAttenuation) * lighting;
|
||||
finalColor += hairHighLight;
|
||||
}
|
||||
|
||||
// Matcap
|
||||
half3 matcapAddColor = 0;
|
||||
half3 totalMatcapAddColor = 0;
|
||||
half3 totalMatcapMultiplyColor = 1;
|
||||
{
|
||||
const float2 matcapUV = viewNormal.xy * 0.5 + 0.5;
|
||||
const half3 matcapLighting = MatCap(TEXTURE2D_ARGS(_MatCapTex, sampler_MatCapTex), _MatCapMask, _MatCapColor, matcapUV, SelectUV(_MatCapUV1, uvArray), _MatCapMaskCH1);
|
||||
const half3 matcap2Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex2, sampler_MatCapTex), _MatCapMask2, _MatCapColor2, matcapUV, SelectUV(_MatCapUV2, uvArray), _MatCapMaskCH2);
|
||||
const half3 matcap3Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex3, sampler_MatCapTex), _MatCapMask3, _MatCapColor3, matcapUV, SelectUV(_MatCapUV3, uvArray), _MatCapMaskCH3);
|
||||
const half3 matcap4Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex4, sampler_MatCapTex), _MatCapMask4, _MatCapColor4, matcapUV, SelectUV(_MatCapUV4, uvArray), _MatCapMaskCH4);
|
||||
const half3 matcap5Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex5, sampler_MatCapTex), _MatCapMask5, _MatCapColor5, matcapUV, SelectUV(_MatCapUV5, uvArray), _MatCapMaskCH5);
|
||||
const half3 matcap6Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex6, sampler_MatCapTex), _MatCapMask6, _MatCapColor6, matcapUV, SelectUV(_MatCapUV6, uvArray), _MatCapMaskCH6);
|
||||
const half3 matcap7Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex7, sampler_MatCapTex), _MatCapMask7, _MatCapColor7, matcapUV, SelectUV(_MatCapUV7, uvArray), _MatCapMaskCH7);
|
||||
const half3 matcap8Lighting = MatCap(TEXTURE2D_ARGS(_MatCapTex8, sampler_MatCapTex), _MatCapMask8, _MatCapColor8, matcapUV, SelectUV(_MatCapUV8, uvArray), _MatCapMaskCH8);
|
||||
if (_MatCapMode > 0 && matcapLighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcapLighting, 0, _MatCapMode - 1), _MatCapWeight);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcapLighting, _MatCapMode - 1), _MatCapWeight);
|
||||
}
|
||||
if (_MatCapMode2 > 0 && matcap2Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap2Lighting, 0, _MatCapMode2 - 1), _MatCapWeight2);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer2);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap2Lighting, _MatCapMode2 - 1), _MatCapWeight2);
|
||||
}
|
||||
if (_MatCapMode3 > 0 && matcap3Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap3Lighting, 0, _MatCapMode3 - 1), _MatCapWeight3);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer3);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap3Lighting, _MatCapMode3 - 1), _MatCapWeight3);
|
||||
}
|
||||
if (_MatCapMode4 > 0 && matcap4Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap4Lighting, 0, _MatCapMode4 - 1), _MatCapWeight4);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer4);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap4Lighting, _MatCapMode4 - 1), _MatCapWeight4);
|
||||
}
|
||||
if (_MatCapMode5 > 0 && matcap5Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap5Lighting, 0, _MatCapMode5 - 1), _MatCapWeight5);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer5);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap5Lighting, _MatCapMode5 - 1), _MatCapWeight5);
|
||||
}
|
||||
if (_MatCapMode6 > 0 && matcap6Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap6Lighting, 0, _MatCapMode6 - 1), _MatCapWeight6);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer6);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap6Lighting, _MatCapMode6 - 1), _MatCapWeight6);
|
||||
}
|
||||
if (_MatCapMode7 > 0 && matcap7Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap7Lighting, 0, _MatCapMode7 - 1), _MatCapWeight7);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer7);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap7Lighting, _MatCapMode7 - 1), _MatCapWeight7);
|
||||
}
|
||||
if (_MatCapMode8 > 0 && matcap8Lighting.r >= 0)
|
||||
{
|
||||
matcapAddColor = lerp(0, lerp(matcap8Lighting, 0, _MatCapMode8 - 1), _MatCapWeight8);
|
||||
totalMatcapAddColor += lerp(matcapAddColor, matcapAddColor * lighting, _MatCapLightingDimmer8);
|
||||
totalMatcapMultiplyColor *= lerp(1, lerp(1, matcap8Lighting, _MatCapMode8 - 1), _MatCapWeight8);
|
||||
}
|
||||
}
|
||||
finalColor *= totalMatcapMultiplyColor;
|
||||
finalColor += totalMatcapAddColor;
|
||||
|
||||
// Rim Light
|
||||
half3 rimLight = RimLighting(normalWS, viewDir, lighting, facing, SelectUV(_RimMaskUV, uvArray), charShadowAtten);
|
||||
finalColor += rimLight;
|
||||
#if _POTA_TOON_SCREEN_RIM
|
||||
ScreenRimLighting(finalColor, normalizedScreenSpaceUV, charShadowAtten);
|
||||
#endif
|
||||
|
||||
#if _USE_GLITTER
|
||||
// Glitter
|
||||
half3 glitterColor = Glitter(finalColor, opacity, viewDir, i.normalWS, normalWS, SelectUV(_GlitterMapUV, uvArray), textureAlbedo, totalAttenuation, _BrightestLightDirection.xyz, lighting);
|
||||
finalColor += glitterColor;
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 4. Emission ///
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
finalColor += Emission(SelectUV(_EmissionMapUV, uvArray));
|
||||
|
||||
// Return
|
||||
finalColor = MixFog(finalColor, inputData.fogCoord);
|
||||
alpha = OutputAlpha(opacity, _SurfaceType >= OIT_SURFACE);
|
||||
|
||||
if (_UseDitherFade > 0
|
||||
#if !_USE_DITHER_FADE
|
||||
&& _SurfaceType >= OIT_SURFACE
|
||||
#endif
|
||||
)
|
||||
DitherFade(alpha, abs(TransformWorldToView(_HeadWorldPos.xyz).z), _DitherFadeMinZ, _DitherFadeMaxZ, inputData.positionCS.xy);
|
||||
|
||||
// Refraction
|
||||
if (_SurfaceType == REFRACTION_SURFACE)
|
||||
ApplyRefraction(viewDir, TransformObjectToWorldDir(float3(0, 0, 1)), normalizedScreenSpaceUV, opacity, finalColor);
|
||||
|
||||
#if _POTA_TOON_OIT
|
||||
if (_SurfaceType >= OIT_SURFACE)
|
||||
{
|
||||
createFragmentEntry(half4(finalColor, alpha), i.positionCS.xyz, uSampleIdx);
|
||||
clip(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _DEBUG_POTA_TOON
|
||||
// Apply Debug
|
||||
if (_DebugFaceSDF == DEBUG_FACE_SDF_LIGHTING)
|
||||
{
|
||||
finalColor = faceSdfAtten.rrr;
|
||||
alpha = 1;
|
||||
}
|
||||
if (_DebugFaceSDF == DEBUG_FACE_SDF_TEXTURE)
|
||||
{
|
||||
finalColor = SelectMask(SAMPLE_TEXTURE2D(_FaceSDFTex, sampler_FaceSDFTex, TRANSFORM_TEX(SelectUV(_FaceSDFUV, uvArray), _FaceSDFTex)), _FaceSDFTexCH);
|
||||
alpha = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return half4(finalColor, alpha);
|
||||
}
|
||||
|
||||
#endif
|
||||
14
Assets/PotaToon/Shaders/PotaToon/PotaToonPass.hlsl.meta
Normal file
14
Assets/PotaToon/Shaders/PotaToon/PotaToonPass.hlsl.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f94573fa0022447937852d96cd22a3
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonPass.hlsl
|
||||
uploadId: 814994
|
||||
301
Assets/PotaToon/Shaders/PotaToon/PotaToonUtility.hlsl
Normal file
301
Assets/PotaToon/Shaders/PotaToon/PotaToonUtility.hlsl
Normal file
@@ -0,0 +1,301 @@
|
||||
#ifndef POTA_TOON_UTILITY_INCLUDED
|
||||
#define POTA_TOON_UTILITY_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#include "../../Shaders/ChracterShadow/CharacterShadowInput.hlsl"
|
||||
#include "../../Shaders/ChracterShadow/DeclareCharacterShadowTexture.hlsl"
|
||||
#include "../Common/PotaToonCommon.hlsl"
|
||||
|
||||
// Reference: UE5 SpiralBlur-Texture
|
||||
half SpiralBlur(TEXTURE2D_PARAM(tex, samplerTex), float2 UV, uint maskCH, float Distance, float DistanceSteps, float RadialSteps, float RadialOffset, float KernelPower)
|
||||
{
|
||||
half CurColor = 0;
|
||||
float2 NewUV = UV;
|
||||
int i = 0;
|
||||
float StepSize = Distance / (int)DistanceSteps;
|
||||
float CurDistance = 0;
|
||||
float2 CurOffset = 0;
|
||||
float SubOffset = 0;
|
||||
float accumdist = 0;
|
||||
|
||||
while (i < (int)DistanceSteps)
|
||||
{
|
||||
CurDistance += StepSize;
|
||||
for (int j = 0; j < (int)RadialSteps; j++)
|
||||
{
|
||||
SubOffset +=1;
|
||||
CurOffset.x = cos(TWO_PI * (SubOffset / RadialSteps));
|
||||
CurOffset.y = sin(TWO_PI * (SubOffset / RadialSteps));
|
||||
NewUV.x = UV.x + CurOffset.x * CurDistance;
|
||||
NewUV.y = UV.y + CurOffset.y * CurDistance;
|
||||
float distpow = pow(CurDistance, KernelPower);
|
||||
CurColor += SelectMask(SAMPLE_TEXTURE2D(tex, samplerTex, NewUV), maskCH) * distpow;
|
||||
accumdist += distpow;
|
||||
}
|
||||
SubOffset += RadialOffset;
|
||||
i++;
|
||||
}
|
||||
CurColor /= accumdist;
|
||||
return DistanceSteps < 1 ? SelectMask(SAMPLE_TEXTURE2D(tex, samplerTex, UV), maskCH) : CurColor;
|
||||
}
|
||||
|
||||
float GetFaceSDFAtten(float2 uv)
|
||||
{
|
||||
const float3 lightDir = _BrightestLightDirection.xyz;
|
||||
// Construct TBN based on face forward & up
|
||||
// Transform lightDir to TBN space
|
||||
const float3 N = _FaceUp.xyz;
|
||||
const float3 T = _FaceForward.xyz;
|
||||
const float3 B = cross(T, N);
|
||||
const float3x3 TBN = float3x3(T, B, N);
|
||||
const float3 lightT = mul(TBN, lightDir);
|
||||
|
||||
float3 forwardT = mul(TBN, _FaceForward.xyz);
|
||||
float2 l = normalize(lightT.xy);
|
||||
float2 n = normalize(forwardT.xy);
|
||||
half NoL = dot(l, n);
|
||||
|
||||
bool isBack = false;
|
||||
if (NoL < 0)
|
||||
{
|
||||
isBack = true;
|
||||
}
|
||||
|
||||
bool flipped = 1.0 - l.y > COS_45;
|
||||
uv.x = lerp(uv.x, 1 - uv.x, flipped); // Assume the sdf texture is symmetry.
|
||||
|
||||
// Reverse if need
|
||||
uv.x = lerp(uv.x, 1.0 - uv.x, _SDFReverse);
|
||||
|
||||
// Sample
|
||||
float atten = SpiralBlur(TEXTURE2D_ARGS(_FaceSDFTex, sampler_FaceSDFTex), uv, _FaceSDFTexCH, _SDFBlur * 0.01 + 0.01, _CharShadowSampleQuality * 4, 8, 0.62, 1) + _SDFOffset;
|
||||
|
||||
NoL = 1.0 - NoL;
|
||||
return isBack ? -1 : atten - NoL;
|
||||
}
|
||||
|
||||
|
||||
float GetCharMainShadow(float2 ssUV, float3 worldPos, half opacity, float sdfAtten = 1, half sdfMask = 0)
|
||||
{
|
||||
float faceSDF = 0;
|
||||
#if _USE_FACE_SDF
|
||||
faceSDF = 1.0 - sdfAtten;
|
||||
// if (sdfMask > 0.01) // Ignore if masked
|
||||
// {
|
||||
// return faceSDF;
|
||||
// }
|
||||
#endif
|
||||
const float isFace = _ToonType == FACE_TYPE ? 1.0 : 0.0;
|
||||
return max(faceSDF, SampleCharacterAndTransparentShadow(ssUV, worldPos, opacity, isFace));
|
||||
}
|
||||
|
||||
float GetCharAdditionalShadow(float2 ssUV, float3 worldPos, half opacity, uint lightIndex, float sdfAtten = 1, half sdfMask = 0)
|
||||
{
|
||||
float faceSDF = 0;
|
||||
#if _USE_FACE_SDF
|
||||
uint i;
|
||||
ADDITIONAL_CHARSHADOW_CHECK(i, lightIndex);
|
||||
faceSDF = 1.0 - sdfAtten;
|
||||
// if (sdfMask > 0.01) // Ignore if masked
|
||||
// {
|
||||
// return faceSDF;
|
||||
// }
|
||||
#endif
|
||||
const float isFace = _ToonType == FACE_TYPE ? 1.0 : 0.0;
|
||||
return max(faceSDF, SampleAdditionalCharacterAndTransparentShadow(ssUV, worldPos, opacity, isFace, lightIndex));
|
||||
}
|
||||
|
||||
|
||||
half3 GetMidTone(float atten, float step, float smoothness)
|
||||
{
|
||||
half3 midTone = half3(0, 0, 0);
|
||||
if (_UseMidTone > 0)
|
||||
{
|
||||
if (abs(atten - step) < smoothness)
|
||||
midTone = _MidColor.rgb * (1.0 - abs(atten - step) * rcp(max(0.00001, smoothness)));
|
||||
}
|
||||
return midTone;
|
||||
}
|
||||
|
||||
|
||||
half3 AnisotropicHairHighlight(float3 viewDirection, float2 uv, float3 worldPos, float totalAtten)
|
||||
{
|
||||
float dotViewUp = saturate(dot(viewDirection, _FaceUp.xyz));
|
||||
float sinVU = sqrt(1 - dotViewUp * dotViewUp);
|
||||
float2 hairUV = float2(uv.x, uv.y + sinVU * _HairHiUVOffset);
|
||||
half3 hairHiTex = SAMPLE_TEXTURE2D_LOD(_HairHighLightTex, sampler_HairHighLightTex, TRANSFORM_TEX(hairUV, _HairHighLightTex), 0).rgb;
|
||||
if (_ReverseHairHighLightTex > 0)
|
||||
hairHiTex = 1.0 - hairHiTex;
|
||||
hairHiTex *= _HairHiStrength * (totalAtten * 0.75 + 0.25);
|
||||
float3 hairDir = normalize(worldPos - _HeadWorldPos.xyz);
|
||||
float dotVH = dot(viewDirection, hairDir) * 0.5 + 0.5;
|
||||
return PositivePow(lerp(0, hairHiTex, dotVH), 2.2);
|
||||
}
|
||||
|
||||
void ApplyRefraction(float3 viewDirection, float3 forward, float2 screenSpaceUV, half opacity, inout half3 color)
|
||||
{
|
||||
float3 vWorld = TransformObjectToWorldDir(float3(0, 1, 0));
|
||||
float3 uWorld = cross(vWorld, forward);
|
||||
float2 offset = float2(dot(uWorld, viewDirection), dot(vWorld, viewDirection));
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
offset.y = -offset.y;
|
||||
#endif
|
||||
const float2 refractedUV = screenSpaceUV - offset * (_RefractionWeight * 0.01);
|
||||
|
||||
const float2 o = _ScreenSize.zw * _RefractionBlurStep;
|
||||
|
||||
// Gaussian Blur
|
||||
half3 sceneColor = SampleSceneColor(refractedUV) * 0.148;
|
||||
sceneColor += SampleSceneColor(refractedUV + float2(o.x, 0)) * 0.118;
|
||||
sceneColor += SampleSceneColor(refractedUV - float2(o.x, 0)) * 0.118;
|
||||
sceneColor += SampleSceneColor(refractedUV + float2(0, o.y)) * 0.118;
|
||||
sceneColor += SampleSceneColor(refractedUV - float2(0, o.y)) * 0.118;
|
||||
sceneColor += SampleSceneColor(refractedUV + float2(o.x, o.y)) * 0.095;
|
||||
sceneColor += SampleSceneColor(refractedUV - float2(o.x, o.y)) * 0.095;
|
||||
sceneColor += SampleSceneColor(refractedUV + float2(-o.x, o.y)) * 0.095;
|
||||
sceneColor += SampleSceneColor(refractedUV + float2(o.x, -o.y)) * 0.095;
|
||||
|
||||
color = color * opacity + sceneColor * (1 - opacity);
|
||||
}
|
||||
|
||||
#if _USE_GLITTER
|
||||
// Glitter - Source: lilToon
|
||||
void HashRGB4(float2 pos, out float3 noise0, out float3 noise1, out float3 noise2, out float3 noise3)
|
||||
{
|
||||
// Hash
|
||||
// https://www.shadertoy.com/view/MdcfDj
|
||||
#define M1 1597334677U
|
||||
#define M2 3812015801U
|
||||
#define M3 2912667907U
|
||||
uint2 q = (uint2)pos;
|
||||
uint4 q2 = uint4(q.x, q.y, q.x+1, q.y+1) * uint4(M1, M2, M1, M2);
|
||||
uint3 n0 = (q2.x ^ q2.y) * uint3(M1, M2, M3);
|
||||
uint3 n1 = (q2.z ^ q2.y) * uint3(M1, M2, M3);
|
||||
uint3 n2 = (q2.x ^ q2.w) * uint3(M1, M2, M3);
|
||||
uint3 n3 = (q2.z ^ q2.w) * uint3(M1, M2, M3);
|
||||
noise0 = float3(n0) * (1.0/float(0xffffffffU));
|
||||
noise1 = float3(n1) * (1.0/float(0xffffffffU));
|
||||
noise2 = float3(n2) * (1.0/float(0xffffffffU));
|
||||
noise3 = float3(n3) * (1.0/float(0xffffffffU));
|
||||
#undef M1
|
||||
#undef M2
|
||||
#undef M3
|
||||
}
|
||||
|
||||
float NsqDistance(float2 a, float2 b)
|
||||
{
|
||||
return dot(a-b,a-b);
|
||||
}
|
||||
|
||||
float4 Voronoi(float2 pos, out float2 nearoffset, float scaleRandomize)
|
||||
{
|
||||
#if defined(SHADER_API_D3D9) || defined(SHADER_API_D3D11_9X)
|
||||
#define M1 46203.4357
|
||||
#define M2 21091.5327
|
||||
#define M3 35771.1966
|
||||
float2 q = trunc(pos);
|
||||
float4 q2 = float4(q.x, q.y, q.x+1, q.y+1);
|
||||
float3 noise0 = frac(sin(dot(q2.xy,float2(12.9898,78.233))) * float3(M1, M2, M3));
|
||||
float3 noise1 = frac(sin(dot(q2.zy,float2(12.9898,78.233))) * float3(M1, M2, M3));
|
||||
float3 noise2 = frac(sin(dot(q2.xw,float2(12.9898,78.233))) * float3(M1, M2, M3));
|
||||
float3 noise3 = frac(sin(dot(q2.zw,float2(12.9898,78.233))) * float3(M1, M2, M3));
|
||||
#undef M1
|
||||
#undef M2
|
||||
#undef M3
|
||||
#else
|
||||
float3 noise0, noise1, noise2, noise3;
|
||||
HashRGB4(pos, noise0, noise1, noise2, noise3);
|
||||
#endif
|
||||
|
||||
// Get the nearest position
|
||||
float4 fracpos = frac(pos).xyxy + float4(0.5,0.5,-0.5,-0.5);
|
||||
float4 dist4 = float4(NsqDistance(fracpos.xy,noise0.xy), NsqDistance(fracpos.zy,noise1.xy), NsqDistance(fracpos.xw,noise2.xy), NsqDistance(fracpos.zw,noise3.xy));
|
||||
dist4 = lerp(dist4, dist4 / max(float4(noise0.z, noise1.z, noise2.z, noise3.z), 0.001), scaleRandomize);
|
||||
|
||||
float3 nearoffset0 = dist4.x < dist4.y ? float3(0,0,dist4.x) : float3(1,0,dist4.y);
|
||||
float3 nearoffset1 = dist4.z < dist4.w ? float3(0,1,dist4.z) : float3(1,1,dist4.w);
|
||||
nearoffset = nearoffset0.z < nearoffset1.z ? nearoffset0.xy : nearoffset1.xy;
|
||||
|
||||
float4 near0 = dist4.x < dist4.y ? float4(noise0,dist4.x) : float4(noise1,dist4.y);
|
||||
float4 near1 = dist4.z < dist4.w ? float4(noise2,dist4.z) : float4(noise3,dist4.w);
|
||||
return near0.w < near1.w ? near0 : near1;
|
||||
}
|
||||
|
||||
float3 CalcGlitter(float2 uv, float3 normalDirection, float3 viewDirection, float3 cameraDirection, float3 lightDirection, float4 glitterParams1, float4 glitterParams2, float glitterPostContrast, float glitterSensitivity, float glitterScaleRandomize, uint glitterAngleRandomize)
|
||||
{
|
||||
// glitterParams1
|
||||
// x: Scale, y: Scale, z: Size, w: Contrast
|
||||
// glitterParams2
|
||||
// x: Speed, y: Angle, z: Light Direction, w:
|
||||
|
||||
#define GLITTER_MIPMAP 1
|
||||
#define GLITTER_ANTIALIAS 1
|
||||
|
||||
#if GLITTER_MIPMAP == 1
|
||||
float2 pos = uv * glitterParams1.xy;
|
||||
float2 dd = fwidth(pos);
|
||||
float factor = frac(sin(dot(floor(pos/floor(dd + 3.0)),float2(12.9898,78.233))) * 46203.4357) + 0.5;
|
||||
float2 factor2 = floor(dd + factor * 0.5);
|
||||
pos = pos/max(1.0,factor2) + glitterParams1.xy * factor2;
|
||||
#else
|
||||
float2 pos = uv * glitterParams1.xy + glitterParams1.xy;
|
||||
#endif
|
||||
float2 nearoffset;
|
||||
float4 near = Voronoi(pos, nearoffset, glitterScaleRandomize);
|
||||
|
||||
|
||||
// Glitter
|
||||
float3 glitterNormal = abs(frac(near.xyz*14.274 + _Time.x * glitterParams2.x) * 2.0 - 1.0);
|
||||
glitterNormal = normalize(glitterNormal * 2.0 - 1.0);
|
||||
float glitter = dot(glitterNormal, cameraDirection);
|
||||
glitter = abs(frac(glitter * glitterSensitivity + glitterSensitivity) - 0.5) * 4.0 - 1.0;
|
||||
glitter = saturate(1.0 - (glitter * glitterParams1.w + glitterParams1.w));
|
||||
glitter = pow(glitter, glitterPostContrast);
|
||||
// Circle
|
||||
#if GLITTER_ANTIALIAS == 1
|
||||
glitter *= saturate((glitterParams1.z-near.w) / fwidth(near.w));
|
||||
#else
|
||||
glitter = near.w < glitterParams1.z ? glitter : 0.0;
|
||||
#endif
|
||||
// Angle
|
||||
float3 halfDirection = normalize(viewDirection + lightDirection * glitterParams2.z);
|
||||
float nh = saturate(dot(normalDirection, halfDirection));
|
||||
glitter = saturate(glitter * saturate(nh * glitterParams2.y + 1.0 - glitterParams2.y));
|
||||
// Random Color
|
||||
float3 glitterColor = glitter - glitter * frac(near.xyz*278.436) * glitterParams2.w;
|
||||
return glitterColor;
|
||||
}
|
||||
|
||||
float3 Glitter(inout float3 color, half alpha, float3 viewDirection, float3 normalWS, float3 normalDirection, float2 uv, float3 albedo, half shadowAtten, float3 lightDirection, float3 lightColor)
|
||||
{
|
||||
float3 glitter = 0;
|
||||
float4 glitterParams1 = float4(256, 256, _GlitterParticleSize, _GlitterContrast);
|
||||
float4 glitterParams2 = float4(_GlitterBlinkSpeed, _GlitterAngleLimit, _GlitterLightDirection, _GlitterColorRandomness);
|
||||
float3 glitterCameraDirection = -GetViewForwardDir();
|
||||
|
||||
// Normal
|
||||
float3 N = lerp(normalWS, normalDirection, _GlitterNormalStrength);
|
||||
|
||||
// Color
|
||||
float4 glitterColor = _GlitterColor;
|
||||
float2 glitterPos = uv;
|
||||
float2 uvGlitterColor = uv; //fd.uv0;
|
||||
glitterColor *= SAMPLE_TEXTURE2D_LOD(_GlitterColorTex, sampler_MainTex, uvGlitterColor, 0);
|
||||
glitterColor.rgb *= CalcGlitter(glitterPos, N, viewDirection, glitterCameraDirection, lightDirection, glitterParams1, glitterParams2, _GlitterPostContrast, _GlitterSensitivity, _GlitterScaleRandomize, 0);
|
||||
glitterColor.rgb = lerp(glitterColor.rgb, glitterColor.rgb * albedo, _GlitterMainStrength);
|
||||
#if _ALPHATEST_ON
|
||||
if (_GlitterApplyTransparency > 0)
|
||||
glitterColor.a *= alpha;
|
||||
#endif
|
||||
|
||||
// Blend
|
||||
glitterColor.a = lerp(glitterColor.a, glitterColor.a * shadowAtten, _GlitterShadowMask);
|
||||
glitterColor.rgb = lerp(glitterColor.rgb, glitterColor.rgb * lightColor, _GlitterEnableLighting);
|
||||
glitter = glitterColor.rgb * glitterColor.a;
|
||||
color.rgb += glitter;
|
||||
return glitter;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UNIVERSAL_TOON_CUSTOM_UTILITY_INCLUDED
|
||||
14
Assets/PotaToon/Shaders/PotaToon/PotaToonUtility.hlsl.meta
Normal file
14
Assets/PotaToon/Shaders/PotaToon/PotaToonUtility.hlsl.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cf31e813fdee9c4dafb09840d9aaedd
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 316069
|
||||
packageName: PotaToon
|
||||
packageVersion: 1.3.6
|
||||
assetPath: Assets/PotaToon/Shaders/PotaToon/PotaToonUtility.hlsl
|
||||
uploadId: 814994
|
||||
Reference in New Issue
Block a user