Ship the WeChat hot-update catalogs and the camp, TideWhale T2, UI atlas, and animation-lab work.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,355 @@
|
||||
Shader "Test/HomeCampXPbr"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[MainColor] _BaseColor("Color", Color) = (1,1,1,1)
|
||||
[MainTexture] _MainTex("Base (RGB:Albedo A:Alpha/AO)", 2D) = "white" {}
|
||||
_MixTex("Mix (RG:Normal B:Metallic A:Roughness)", 2D) = "white" {}
|
||||
|
||||
// 勾选:A 通道当透明(AlphaTest 裁剪);不勾选:A 通道当 AO
|
||||
[Toggle(_ALPHATEST_ON)] _AlphaTest("Alpha As Transparency (Clip)", Float) = 0
|
||||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||
|
||||
_Metallic("Metallic", Range(0.0, 1.0)) = 0.8
|
||||
_Roughness("Roughness", Range(0.0, 1.0)) = 0.6
|
||||
_AO("AO", Range(0.0, 1.0)) = 1.0
|
||||
|
||||
[HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
|
||||
[HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
|
||||
[HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Cull Off
|
||||
Tags{ "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags{ "LightMode" = "UniversalForward" }
|
||||
|
||||
ZWrite on
|
||||
|
||||
HLSLPROGRAM
|
||||
// Required to compile gles 2.0 with standard SRP library
|
||||
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
|
||||
#pragma prefer_hlslcc gles
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
#pragma target 2.0
|
||||
|
||||
#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 _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
|
||||
|
||||
#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 shader_feature_local_fragment _ALPHATEST_ON
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "XPbr_Base.hlsl"
|
||||
|
||||
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);
|
||||
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
|
||||
// normalWS and tangentWS already normalize.
|
||||
// this is required to avoid skewing the direction during interpolation
|
||||
// also required for per-vertex lighting and SH evaluation
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
||||
|
||||
half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
|
||||
|
||||
half fogFactor = 0;
|
||||
#if !defined(_FOG_FRAGMENT)
|
||||
fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
||||
#endif
|
||||
|
||||
half3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
|
||||
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
|
||||
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
|
||||
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
|
||||
|
||||
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);
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX
|
||||
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
|
||||
#else
|
||||
output.fogFactor = fogFactor;
|
||||
#endif
|
||||
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
output.shadowCoord = GetShadowCoord(vertexInput);
|
||||
#endif
|
||||
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.uv = TRANSFORM_TEX(input.texcoord, _MainTex);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// 基础贴图:rgb 漫反射,a 透明或 AO(由 _ALPHATEST_ON 决定语义)
|
||||
half4 albedoAlpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
// 混合贴图:rg 压缩法线,b 金属度,a 粗糙度
|
||||
half4 mixTex = SAMPLE_TEXTURE2D(_MixTex, sampler_MixTex, input.uv);
|
||||
|
||||
#if defined(_ALPHATEST_ON)
|
||||
clip(albedoAlpha.a - _Cutoff);
|
||||
half occlusion = 1.0;
|
||||
half alpha = albedoAlpha.a;
|
||||
#else
|
||||
half occlusion = lerp(1.0, albedoAlpha.a, _AO);
|
||||
half alpha = 1.0;
|
||||
#endif
|
||||
|
||||
half3 normalTS = DecodeSphereMap(mixTex.rg);
|
||||
half3 normalWS = TransformTangentToWorld(normalTS,
|
||||
half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
|
||||
|
||||
SurfaceData surfaceData = (SurfaceData)0;
|
||||
surfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
|
||||
surfaceData.metallic = saturate(mixTex.b * _Metallic);
|
||||
surfaceData.smoothness = 1.0 - saturate(mixTex.a * _Roughness);
|
||||
surfaceData.alpha = alpha;
|
||||
surfaceData.normalTS = normalTS;
|
||||
surfaceData.specular = half3(0.0, 0.0, 0.0);
|
||||
surfaceData.emission = half3(0.0, 0.0, 0.0);
|
||||
surfaceData.occlusion = occlusion;
|
||||
surfaceData.clearCoatMask = half(0.0);
|
||||
surfaceData.clearCoatSmoothness = half(0.0);
|
||||
|
||||
InputData inputData;
|
||||
input.normalWS.rgb = normalWS;//法线需要传入
|
||||
InitializeInputData(input, surfaceData.normalTS, inputData);
|
||||
|
||||
half4 color = UniversalFragmentPBR(inputData, surfaceData);
|
||||
|
||||
color.rgb = MixFog(color.rgb, inputData.fogCoord);
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ShadowCaster"
|
||||
Tags{ "LightMode" = "ShadowCaster" }
|
||||
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
ColorMask 0
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma prefer_hlslcc gles
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "XPbr_Base.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
|
||||
float3 _LightDirection;
|
||||
float3 _LightPosition;
|
||||
|
||||
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);
|
||||
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
||||
#if defined(_CASTING_PUNCTUAL_LIGHT_SHADOW)
|
||||
float3 lightDirectionWS = normalize(_LightPosition - positionWS);
|
||||
#else
|
||||
float3 lightDirectionWS = _LightDirection;
|
||||
#endif
|
||||
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
||||
#else
|
||||
positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
||||
#endif
|
||||
|
||||
output.positionCS = positionCS;
|
||||
output.uv = TRANSFORM_TEX(input.texcoord, _MainTex);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_TARGET
|
||||
{
|
||||
#if defined(_ALPHATEST_ON)
|
||||
half alpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv).a;
|
||||
clip(alpha - _Cutoff);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "DepthOnly"
|
||||
Tags{ "LightMode" = "DepthOnly" }
|
||||
|
||||
ZWrite On
|
||||
ColorMask R
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma prefer_hlslcc gles
|
||||
#pragma exclude_renderers d3d11_9x
|
||||
#pragma target 2.0
|
||||
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "XPbr_Base.hlsl"
|
||||
|
||||
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.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.uv = TRANSFORM_TEX(input.texcoord, _MainTex);
|
||||
return output;
|
||||
}
|
||||
|
||||
half frag(Varyings input) : SV_TARGET
|
||||
{
|
||||
#if defined(_ALPHATEST_ON)
|
||||
half alpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv).a;
|
||||
clip(alpha - _Cutoff);
|
||||
#endif
|
||||
return input.positionCS.z;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meta"
|
||||
Tags{ "LightMode" = "Meta" }
|
||||
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 2.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
||||
#pragma shader_feature EDITOR_VISUALIZATION
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _MainTex_ST;
|
||||
half4 _BaseColor;
|
||||
half _Cutoff;
|
||||
half _Metallic;
|
||||
half _Roughness;
|
||||
half _AO;
|
||||
CBUFFER_END
|
||||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D(_MixTex); SAMPLER(sampler_MixTex);
|
||||
|
||||
struct MetaAttributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float2 uv2 : TEXCOORD2;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct MetaVaryings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
float2 VizUV : TEXCOORD1;
|
||||
float4 LightCoord : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
MetaVaryings vert(MetaAttributes input)
|
||||
{
|
||||
MetaVaryings output = (MetaVaryings)0;
|
||||
output.positionCS = UnityMetaVertexPosition(input.positionOS.xyz, input.uv1, input.uv2);
|
||||
output.uv = TRANSFORM_TEX(input.uv0, _MainTex);
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
UnityEditorVizData(input.positionOS.xyz, input.uv0, input.uv1, input.uv2, output.VizUV, output.LightCoord);
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(MetaVaryings input) : SV_Target
|
||||
{
|
||||
half4 albedoAlpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
#if defined(_ALPHATEST_ON)
|
||||
clip(albedoAlpha.a - _Cutoff);
|
||||
#endif
|
||||
half4 mixTex = SAMPLE_TEXTURE2D(_MixTex, sampler_MixTex, input.uv);
|
||||
half3 albedo = albedoAlpha.rgb * _BaseColor.rgb;
|
||||
half metallic = saturate(mixTex.b * _Metallic);
|
||||
half smoothness = 1.0 - saturate(mixTex.a * _Roughness);
|
||||
half alpha = 1.0;
|
||||
|
||||
BRDFData brdfData;
|
||||
InitializeBRDFData(albedo, metallic, half3(0.0, 0.0, 0.0), smoothness, alpha, brdfData);
|
||||
|
||||
MetaInput metaInput;
|
||||
metaInput.Albedo = brdfData.diffuse + brdfData.specular * brdfData.roughness * 0.5;
|
||||
metaInput.Emission = half3(0.0, 0.0, 0.0);
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
metaInput.VizUV = input.VizUV;
|
||||
metaInput.LightCoord = input.LightCoord;
|
||||
#endif
|
||||
return UnityMetaFragment(metaInput);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack Off
|
||||
}
|
||||
Reference in New Issue
Block a user