chore: checkpoint current workspace changes
This commit is contained in:
187
docs/reference/NahidaUnity/Shaders/Genshin.shader
Normal file
187
docs/reference/NahidaUnity/Shaders/Genshin.shader
Normal file
@@ -0,0 +1,187 @@
|
||||
Shader "Genshin"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Header(General)]
|
||||
[MainTexture]_BaseMap("Base Map", 2D) = "white" {}
|
||||
[MainColor] _BaseColor("Base Color", Color) = (1,1,1,1)
|
||||
[ToggleUI] _IsDay("Is Day", Float) = 1
|
||||
[Toggle(_DOUBLE_SIDED)] _DoubleSided("Double Sided", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 2
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 0
|
||||
|
||||
[Header(Shadow)]
|
||||
_LightMap("Light Map", 2D) = "white" {}
|
||||
_LightDirectionMultiplier("Light Direction Multiplier", Vector) = (1,1,1,0)
|
||||
_ShadowOffset("Shadow Offset", Float) = 0
|
||||
_ShadowSmoothness("Shadow Smoothness", Float) = 0
|
||||
[HDR] _ShadowColor("Shadow Color", Color) = (1,1,1,1)
|
||||
_ShadowRamp("Shadow Ramp", 2D) = "white" {}
|
||||
[ToggleUI] _UseCustomMaterialType("Use Custom Material Type", Float) = 0
|
||||
_CustomMaterialType("Custom Material Type", Float) = 1
|
||||
|
||||
[Header(Emission)]
|
||||
[Toggle(_EMISSION)] _UseEmission("Use Emission", Float) = 0
|
||||
_EmissionIntensity("Emission Intensity", Float) = 1
|
||||
|
||||
[Header(Normal)]
|
||||
[Toggle(_NORMAL_MAP)] _UseNormalMap("Use Normal Map", Float) = 0
|
||||
[Normal] _NormalMap("Normal Map", 2D) = "bump" {}
|
||||
|
||||
[Header(Face)]
|
||||
[Toggle(_IS_FACE)] _IsFace("Is Face", Float) = 0
|
||||
_FaceDirection("Face Direction", Vector) = (0,0,1,0)
|
||||
_FaceShadowOffset("Face Shadow Offset", Float) = 0
|
||||
_FaceBlushColor("Face Blush Color", Color) = (1,1,1,1)
|
||||
_FaceBlushStrength("Face Blush Strength", Float) = 1
|
||||
_FaceLightMap("Face Light Map", 2D) = "white" {}
|
||||
_FaceShadow("Face Shadow", 2D) = "white" {}
|
||||
|
||||
[Header(Specular)]
|
||||
[Toggle(_SPECULAR)] _UseSpecular("Use Specular", Float) = 0
|
||||
_SpecularSmoothness("Specular Smoothness", Float) = 1
|
||||
_NonmetallicIntensity("Nonmetallic Intensity", Float) = 1
|
||||
_MetallicIntensity("Metallic Intensity", Float) = 1
|
||||
_MetalMap("Metal Map", 2D) = "white" {}
|
||||
|
||||
[Header(Rim Light)]
|
||||
[Toggle(_RIM)] _UseRim("Use Rim", Float) = 0
|
||||
_RimOffset("Rim Offset", Float) = 1
|
||||
_RimThreshold("Rim Threshold", Float) = 1
|
||||
_RimIntensity("Rim Intensity", Float) = 1
|
||||
|
||||
[Header(Outline)]
|
||||
[ToggleUI] _UseSmoothNormal("Use Smooth Normal", Float) = 0
|
||||
_OutlineWidth("Outline Width", Float) = 1
|
||||
_OutlineWidthParams("Outline Width Params", Vector) = (0,1,0,1)
|
||||
_OutlineZOffset("Outline Z Offset", Float) = 0
|
||||
_ScreenOffset("Screen Offset", Vector) = (0,0,0,0)
|
||||
_OutlineColor("Outline Color", Color) = (0,0,0,1)
|
||||
_OutlineColor2("Outline Color 2", Color) = (0,0,0,1)
|
||||
_OutlineColor3("Outline Color 3", Color) = (0,0,0,1)
|
||||
_OutlineColor4("Outline Color 4", Color) = (0,0,0,1)
|
||||
_OutlineColor5("Outline Color 5", Color) = (0,0,0,1)
|
||||
}
|
||||
|
||||
Subshader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType" = "Opaque"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"UniversalMaterialType" = "Lit"
|
||||
"IgnoreProjector" = "True"
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Forward"
|
||||
Tags {"LightMode" = "UniversalForward"}
|
||||
|
||||
Cull[_Cull]
|
||||
ZWrite On
|
||||
Blend[_SrcBlend][_DstBlend]
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
// Universal 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_fragment _ _ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
#pragma multi_compile _ _FORWARD_PLUS
|
||||
#pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS
|
||||
|
||||
// Unity defined keywords
|
||||
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
|
||||
#pragma multi_compile _ SHADOWS_SHADOWMASK
|
||||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
||||
#pragma multi_compile _ LIGHTMAP_ON
|
||||
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
|
||||
#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile_fragment _ DEBUG_DISPLAY
|
||||
|
||||
#pragma shader_feature_local_fragment _DOUBLE_SIDED
|
||||
#pragma shader_feature_local_fragment _EMISSION
|
||||
#pragma shader_feature_local_fragment _NORMAL_MAP
|
||||
#pragma shader_feature_local_fragment _IS_FACE
|
||||
#pragma shader_feature_local_fragment _SPECULAR
|
||||
#pragma shader_feature_local_fragment _RIM
|
||||
|
||||
#pragma vertex ForwardPassVertex
|
||||
#pragma fragment ForwardPassFragment
|
||||
|
||||
#include "GenshinInput.hlsl"
|
||||
#include "GenshinForwardPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ShadowCaster"
|
||||
Tags{"LightMode" = "ShadowCaster"}
|
||||
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
ColorMask 0
|
||||
Cull[_Cull]
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex ShadowPassVertex
|
||||
#pragma fragment ShadowPassFragment
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
||||
#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 vertex DepthOnlyVertex
|
||||
#pragma fragment DepthOnlyFragment
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Outline"
|
||||
Tags {"LightMode" = "SRPDefaultUnlit"}
|
||||
|
||||
Cull Front
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex OutlinePassVertex
|
||||
#pragma fragment OutlinePassFragment
|
||||
|
||||
#include "GenshinInput.hlsl"
|
||||
#include "GenshinOutlinePass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
183
docs/reference/NahidaUnity/Shaders/GenshinForwardPass.hlsl
Normal file
183
docs/reference/NahidaUnity/Shaders/GenshinForwardPass.hlsl
Normal file
@@ -0,0 +1,183 @@
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 tangentOS : TANGENT;
|
||||
float4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 backUV : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 backUV : TEXCOORD1;
|
||||
float3 positionWS : TEXCOORD2;
|
||||
half3 tangentWS : TEXCOORD3;
|
||||
half3 bitangentWS : TEXCOORD4;
|
||||
half3 normalWS : TEXCOORD5;
|
||||
float4 positionNDC : TEXCOORD6;
|
||||
half4 color : COLOR;
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
half GetShadow(Varyings input, half3 lightDirection, half aoFactor)
|
||||
{
|
||||
half NDotL = dot(input.normalWS, lightDirection);
|
||||
half halfLambert = 0.5 * NDotL + 0.5;
|
||||
half shadow = saturate(2.0 * halfLambert * aoFactor);
|
||||
return lerp(shadow, 1.0, step(0.9, aoFactor));
|
||||
}
|
||||
|
||||
half GetFaceShadow(Varyings input, half3 lightDirection)
|
||||
{
|
||||
half3 F = SafeNormalize(half3(_FaceDirection.x, 0.0, _FaceDirection.z));
|
||||
half3 L = SafeNormalize(half3(lightDirection.x, 0.0, lightDirection.z));
|
||||
half FDotL = dot(F, L);
|
||||
half FCrossL = cross(F, L).y;
|
||||
|
||||
half2 shadowUV = input.uv;
|
||||
shadowUV.x = lerp(shadowUV.x, 1.0 - shadowUV.x, step(0.0, FCrossL));
|
||||
half faceShadowMap = SAMPLE_TEXTURE2D(_FaceLightMap, sampler_FaceLightMap, shadowUV).r;
|
||||
half faceShadow = step(-0.5 * FDotL + 0.5 + _FaceShadowOffset, faceShadowMap);
|
||||
|
||||
half faceMask = SAMPLE_TEXTURE2D(_FaceShadow, sampler_FaceShadow, input.uv).a;
|
||||
half maskedFaceShadow = lerp(faceShadow, 1.0, faceMask);
|
||||
|
||||
return maskedFaceShadow;
|
||||
}
|
||||
|
||||
half3 GetShadowColor(half shadow, half material, half day)
|
||||
{
|
||||
int index = 4;
|
||||
index = lerp(index, 1, step(0.2, material));
|
||||
index = lerp(index, 2, step(0.4, material));
|
||||
index = lerp(index, 0, step(0.6, material));
|
||||
index = lerp(index, 3, step(0.8, material));
|
||||
|
||||
half rangeMin = 0.5 + _ShadowOffset - _ShadowSmoothness;
|
||||
half rangeMax = 0.5 + _ShadowOffset;
|
||||
half2 rampUV = half2(smoothstep(rangeMin, rangeMax, shadow), index / 10.0 + 0.5 * day + 0.05);
|
||||
half3 shadowRamp = SAMPLE_TEXTURE2D(_ShadowRamp, sampler_ShadowRamp, rampUV);
|
||||
|
||||
half3 shadowColor = shadowRamp * lerp(_ShadowColor, 1.0, smoothstep(0.9, 1.0, rampUV.x));
|
||||
shadowColor = lerp(shadowColor, 1.0, step(rangeMax, shadow));
|
||||
|
||||
return shadowColor;
|
||||
}
|
||||
|
||||
half3 GetSpecular(Varyings input, half3 lightDirection, half3 albedo, half3 lightMap)
|
||||
{
|
||||
half3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
||||
half3 H = SafeNormalize(lightDirection + V);
|
||||
half NDotH = dot(input.normalWS, H);
|
||||
half blinnPhong = pow(saturate(NDotH), _SpecularSmoothness);
|
||||
|
||||
half3 normalVS = TransformWorldToViewNormal(input.normalWS, true);
|
||||
half2 matcapUV = 0.5 * normalVS.xy + 0.5;
|
||||
half3 metalMap = SAMPLE_TEXTURE2D(_MetalMap, sampler_MetalMap, matcapUV);
|
||||
|
||||
half3 nonMetallic = step(1.1, lightMap.b + blinnPhong) * lightMap.r * _NonmetallicIntensity;
|
||||
half3 metallic = blinnPhong * lightMap.b * albedo * metalMap * _MetallicIntensity;
|
||||
half3 specular = lerp(nonMetallic, metallic, step(0.9, lightMap.r));
|
||||
|
||||
return specular;
|
||||
}
|
||||
|
||||
half GetRim(Varyings input)
|
||||
{
|
||||
half3 normalVS = TransformWorldToViewNormal(input.normalWS, true);
|
||||
float2 uv = input.positionNDC.xy / input.positionNDC.w;
|
||||
float2 offset = float2(_RimOffset * normalVS.x / _ScreenParams.x, 0.0);
|
||||
|
||||
float depth = LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams);
|
||||
float offsetDepth = LinearEyeDepth(SampleSceneDepth(uv + offset), _ZBufferParams);
|
||||
half rim = smoothstep(0.0, _RimThreshold, offsetDepth - depth) * _RimIntensity;
|
||||
|
||||
half3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
||||
half NDotV = dot(input.normalWS, V);
|
||||
half fresnel = pow(saturate(1.0 - NDotV), 5.0);
|
||||
|
||||
return rim * fresnel;
|
||||
}
|
||||
|
||||
Varyings ForwardPassVertex(Attributes input)
|
||||
{
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
||||
|
||||
Varyings output = (Varyings)0;
|
||||
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
|
||||
output.backUV = TRANSFORM_TEX(input.backUV, _BaseMap);
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
output.tangentWS = normalInput.tangentWS;
|
||||
output.bitangentWS = normalInput.bitangentWS;
|
||||
output.normalWS = normalInput.normalWS;
|
||||
output.positionNDC = vertexInput.positionNDC;
|
||||
output.color = input.color;
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
|
||||
output.positionCS.xy += _ScreenOffset.xy * output.positionCS.w;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 ForwardPassFragment(Varyings input, FRONT_FACE_TYPE facing : FRONT_FACE_SEMANTIC) : SV_TARGET
|
||||
{
|
||||
#if _DOUBLE_SIDED
|
||||
input.uv = lerp(input.uv, input.backUV, IS_FRONT_VFACE(facing, 0.0, 1.0));
|
||||
#endif
|
||||
|
||||
half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv);
|
||||
half3 albedo = baseMap.rgb * _BaseColor.rgb;
|
||||
half alpha = baseMap.a;
|
||||
|
||||
#if _IS_FACE
|
||||
albedo = lerp(albedo, _FaceBlushColor.rgb, _FaceBlushStrength * alpha);
|
||||
#endif
|
||||
|
||||
#if _NORMAL_MAP
|
||||
half3x3 tangentToWorld = half3x3(input.tangentWS, input.bitangentWS, input.normalWS);
|
||||
half4 normalMap = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.uv);
|
||||
half3 normalTS = UnpackNormal(normalMap);
|
||||
half3 normalWS = TransformTangentToWorld(normalTS, tangentToWorld, true);
|
||||
input.normalWS = normalWS;
|
||||
#endif
|
||||
|
||||
Light mainLight = GetMainLight();
|
||||
half3 lightDirection = SafeNormalize(mainLight.direction * _LightDirectionMultiplier);
|
||||
|
||||
half4 lightMap = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv);
|
||||
half material = lerp(lightMap.a, _CustomMaterialType, _UseCustomMaterialType);
|
||||
#if _IS_FACE
|
||||
half shadow = GetFaceShadow(input, lightDirection);
|
||||
#else
|
||||
half aoFactor = lightMap.g * input.color.r;
|
||||
half shadow = GetShadow(input, lightDirection, aoFactor);
|
||||
#endif
|
||||
half3 shadowColor = GetShadowColor(shadow, material, _IsDay);
|
||||
|
||||
half3 specular = 0.0;
|
||||
#if _SPECULAR
|
||||
specular = GetSpecular(input, lightDirection, albedo, lightMap.rgb);
|
||||
#endif
|
||||
|
||||
half3 emission = 0.0;
|
||||
#if _EMISSION
|
||||
emission = albedo * _EmissionIntensity * alpha;
|
||||
#endif
|
||||
|
||||
half3 rim = 0.0;
|
||||
#if _RIM
|
||||
rim = albedo * GetRim(input);
|
||||
#endif
|
||||
|
||||
half3 finalColor = albedo * shadowColor + specular + emission + rim;
|
||||
half finalAlpha = 1.0;
|
||||
|
||||
return half4(finalColor, finalAlpha);
|
||||
}
|
||||
51
docs/reference/NahidaUnity/Shaders/GenshinInput.hlsl
Normal file
51
docs/reference/NahidaUnity/Shaders/GenshinInput.hlsl
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _BaseMap_ST;
|
||||
half4 _BaseColor;
|
||||
half _IsDay;
|
||||
half _Cull;
|
||||
half _SrcBlend;
|
||||
half _DstBlend;
|
||||
|
||||
half4 _LightDirectionMultiplier;
|
||||
half _ShadowOffset;
|
||||
half _ShadowSmoothness;
|
||||
half4 _ShadowColor;
|
||||
half _UseCustomMaterialType;
|
||||
half _CustomMaterialType;
|
||||
|
||||
half _EmissionIntensity;
|
||||
|
||||
half4 _FaceDirection;
|
||||
half _FaceShadowOffset;
|
||||
half4 _FaceBlushColor;
|
||||
half _FaceBlushStrength;
|
||||
|
||||
half _SpecularSmoothness;
|
||||
half _NonmetallicIntensity;
|
||||
half _MetallicIntensity;
|
||||
|
||||
half _RimOffset;
|
||||
half _RimThreshold;
|
||||
half _RimIntensity;
|
||||
|
||||
half _UseSmoothNormal;
|
||||
half _OutlineWidth;
|
||||
half4 _OutlineWidthParams;
|
||||
half _OutlineZOffset;
|
||||
half4 _ScreenOffset;
|
||||
half4 _OutlineColor;
|
||||
half4 _OutlineColor2;
|
||||
half4 _OutlineColor3;
|
||||
half4 _OutlineColor4;
|
||||
half4 _OutlineColor5;
|
||||
CBUFFER_END
|
||||
|
||||
TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);
|
||||
TEXTURE2D(_LightMap); SAMPLER(sampler_LightMap);
|
||||
TEXTURE2D(_ShadowRamp); SAMPLER(sampler_ShadowRamp);
|
||||
TEXTURE2D(_NormalMap); SAMPLER(sampler_NormalMap);
|
||||
TEXTURE2D(_FaceLightMap); SAMPLER(sampler_FaceLightMap);
|
||||
TEXTURE2D(_FaceShadow); SAMPLER(sampler_FaceShadow);
|
||||
TEXTURE2D(_MetalMap); SAMPLER(sampler_MetalMap);
|
||||
81
docs/reference/NahidaUnity/Shaders/GenshinOutlinePass.hlsl
Normal file
81
docs/reference/NahidaUnity/Shaders/GenshinOutlinePass.hlsl
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 tangentOS : TANGENT;
|
||||
float4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 smoothNormal : TEXCOORD7;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
float GetOutlineWidth(float positionVS_Z)
|
||||
{
|
||||
float fovFactor = 2.414 / UNITY_MATRIX_P[1].y;
|
||||
float z = abs(positionVS_Z * fovFactor);
|
||||
|
||||
float4 params = _OutlineWidthParams;
|
||||
float k = saturate((z - params.x) / (params.y - params.x));
|
||||
float width = lerp(params.z, params.w, k);
|
||||
|
||||
return 0.01 * _OutlineWidth * width;
|
||||
}
|
||||
|
||||
float4 GetOutlinePosition(VertexPositionInputs vertexInput, VertexNormalInputs normalInput, half4 vertexColor)
|
||||
{
|
||||
float z = vertexInput.positionVS.z;
|
||||
float width = GetOutlineWidth(z) * vertexColor.a;
|
||||
|
||||
half3 normalVS = TransformWorldToViewNormal(normalInput.normalWS);
|
||||
normalVS = SafeNormalize(half3(normalVS.xy, 0.0));
|
||||
|
||||
float3 positionVS = vertexInput.positionVS;
|
||||
positionVS += 0.01 * _OutlineZOffset * SafeNormalize(positionVS);
|
||||
positionVS += width * normalVS;
|
||||
|
||||
float4 positionCS = TransformWViewToHClip(positionVS);
|
||||
positionCS.xy += _ScreenOffset.zw * positionCS.w;
|
||||
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
Varyings OutlinePassVertex(Attributes input)
|
||||
{
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
||||
|
||||
half3x3 tangentToWorld = half3x3(normalInput.tangentWS, normalInput.bitangentWS, normalInput.normalWS);
|
||||
half3 normalTS = 2.0 * (input.smoothNormal - 0.5);
|
||||
half3 normalWS = TransformTangentToWorld(normalTS, tangentToWorld, true);
|
||||
normalInput.normalWS = lerp(normalInput.normalWS, normalWS, _UseSmoothNormal);
|
||||
|
||||
float4 positionCS = GetOutlinePosition(vertexInput, normalInput, input.color);
|
||||
|
||||
Varyings output = (Varyings)0;
|
||||
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
|
||||
output.positionCS = positionCS;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 OutlinePassFragment(Varyings input) : SV_TARGET
|
||||
{
|
||||
half4 lightMap = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv);
|
||||
half material = lightMap.a;
|
||||
|
||||
half4 color = _OutlineColor5;
|
||||
color = lerp(color, _OutlineColor4, step(0.2, material));
|
||||
color = lerp(color, _OutlineColor3, step(0.4, material));
|
||||
color = lerp(color, _OutlineColor2, step(0.6, material));
|
||||
color = lerp(color, _OutlineColor, step(0.8, material));
|
||||
|
||||
return color;
|
||||
}
|
||||
262
docs/reference/NahidaUnity/Shaders/URPGenshinPostProcess.shader
Normal file
262
docs/reference/NahidaUnity/Shaders/URPGenshinPostProcess.shader
Normal file
@@ -0,0 +1,262 @@
|
||||
Shader "URPGenshinPostProcess"
|
||||
{
|
||||
HLSLINCLUDE
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
|
||||
|
||||
#pragma multi_compile_local_fragment _ _BLOOM_COLOR _BLOOM_BRIGHTNESS
|
||||
#pragma multi_compile_local_fragment _ _TONEMAPPING
|
||||
|
||||
float2 _BlitTexture_TexelSize;
|
||||
half _BloomThreshold;
|
||||
half _BloomIntensity;
|
||||
half4 _BloomWeights;
|
||||
half4 _BloomColor;
|
||||
half _BlurRadius;
|
||||
half _Exposure;
|
||||
half _Contrast;
|
||||
half _Saturation;
|
||||
|
||||
TEXTURE2D(_BloomTextureA);
|
||||
TEXTURE2D(_BloomTextureB);
|
||||
TEXTURE2D(_BloomTextureC);
|
||||
TEXTURE2D(_BloomTextureD);
|
||||
|
||||
const static int kernelSize = 9;
|
||||
const static float kernelOffsets[9] = {
|
||||
-4.0,
|
||||
-3.0,
|
||||
-2.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
2.0,
|
||||
3.0,
|
||||
4.0,
|
||||
};
|
||||
const static float kernel[9] = {
|
||||
0.01621622,
|
||||
0.05405405,
|
||||
0.12162162,
|
||||
0.19459459,
|
||||
0.22702703,
|
||||
0.19459459,
|
||||
0.12162162,
|
||||
0.05405405,
|
||||
0.01621622
|
||||
};
|
||||
|
||||
half4 Prefilter(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
|
||||
|
||||
#if _BLOOM_BRIGHTNESS
|
||||
half brightness = max(max(color.r, color.g), color.b);
|
||||
color.rgb *= saturate(brightness - _BloomThreshold);
|
||||
#else
|
||||
color.rgb = max(color.rgb - _BloomThreshold, 0.0);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 GaussianBlur(float2 uv, float2 direction)
|
||||
{
|
||||
float2 offset = _BlurRadius * _BlitTexture_TexelSize * direction;
|
||||
half4 color = 0.0;
|
||||
|
||||
UNITY_UNROLL
|
||||
for (int i = 0; i < kernelSize; i++)
|
||||
{
|
||||
float2 sampleUV = uv + kernelOffsets[i] * offset;
|
||||
color += kernel[i] * SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, sampleUV);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 HorizontalBlur1x(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
return GaussianBlur(uv, float2(1.0, 0.0));
|
||||
}
|
||||
|
||||
half4 HorizontalBlur2x(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
return GaussianBlur(uv, float2(2.0, 0.0));
|
||||
}
|
||||
|
||||
half4 VerticalBlur1x(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
return GaussianBlur(uv, float2(0.0, 1.0));
|
||||
}
|
||||
|
||||
half4 VerticalBlur2x(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
return GaussianBlur(uv, float2(0.0, 2.0));
|
||||
}
|
||||
|
||||
half4 Upsample(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
half4 color = 0.0;
|
||||
half4 weights = _BloomWeights;
|
||||
|
||||
color += SAMPLE_TEXTURE2D_X(_BloomTextureA, sampler_LinearClamp, uv) * weights.x;
|
||||
color += SAMPLE_TEXTURE2D_X(_BloomTextureB, sampler_LinearClamp, uv) * weights.y;
|
||||
color += SAMPLE_TEXTURE2D_X(_BloomTextureC, sampler_LinearClamp, uv) * weights.z;
|
||||
color += SAMPLE_TEXTURE2D_X(_BloomTextureD, sampler_LinearClamp, uv) * weights.w;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half3 Tonemap(half3 color)
|
||||
{
|
||||
half3 c0 = (1.36 * color + 0.047) * color;
|
||||
half3 c1 = (0.93 * color + 0.56) * color + 0.14;
|
||||
return saturate(c0 / c1);
|
||||
}
|
||||
|
||||
half4 ColorGrading(Varyings input) : SV_TARGET
|
||||
{
|
||||
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
half4 baseMap = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
|
||||
half3 color = baseMap.rgb;
|
||||
half alpha = baseMap.a;
|
||||
|
||||
#if _BLOOM_COLOR || _BLOOM_BRIGHTNESS
|
||||
// Bloom
|
||||
half3 bloom = SAMPLE_TEXTURE2D_X(_BloomTextureA, sampler_LinearClamp, uv).rgb;
|
||||
bloom *= _BloomIntensity * _BloomColor.rgb;
|
||||
color += bloom;
|
||||
#endif
|
||||
|
||||
// Exposure
|
||||
color *= _Exposure;
|
||||
|
||||
#if _TONEMAPPING
|
||||
// Tonemapping
|
||||
color = Tonemap(color);
|
||||
#endif
|
||||
|
||||
// Contrast
|
||||
half3 colorLog = LinearToLogC(color);
|
||||
colorLog = lerp(ACEScc_MIDGRAY, colorLog, _Contrast);
|
||||
color = LogCToLinear(colorLog);
|
||||
|
||||
// Saturation
|
||||
half luma = dot(color, half3(0.2126, 0.7152, 0.0722));
|
||||
color = lerp(luma, color, _Saturation);
|
||||
|
||||
return float4(color, alpha);
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
|
||||
Subshader
|
||||
{
|
||||
Tags { "RenderPipeline" = "UniversalPipeline" }
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Blit"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragBilinear
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomPrefilter"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Prefilter
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomHorizontalBlur1x"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment HorizontalBlur1x
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomHorizontalBlur2x"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment HorizontalBlur2x
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomVerticalBlur1x"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment VerticalBlur1x
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomVerticalBlur2x"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment VerticalBlur2x
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "BloomUpsample"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Upsample
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ColorGrading"
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vert
|
||||
#pragma fragment ColorGrading
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user