Files
ft/Client/Assets/ABPackage/pkgDownloads/EventCubeMelt/WeaponHighLight.shader
2026-06-29 21:18:33 +08:00

135 lines
4.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SimpleWeaponHighlight.shader
// 基于URP/Lit的简化版仅添加自发光强度控制
Shader "URP/Weapon/SimpleHighlight"
{
Properties
{
// 基础属性
[MainTexture] _BaseMap("Base Texture", 2D) = "white" {}
[MainColor] _BaseColor("Base Color", Color) = (1,1,1,1)
// 材质属性
_Metallic("Metallic", Range(0, 1)) = 0.5
_Smoothness("Smoothness", Range(0, 1)) = 0.5
// 核心:自发光强度控制
[HDR] _EmissionColor("Emission Color", Color) = (1,1,1,1)
_EmissionStrength("Emission Strength", Range(0, 10)) = 0.0
}
SubShader
{
Tags
{
"RenderType"="Opaque"
"RenderPipeline"="UniversalPipeline"
"Queue"="Geometry"
}
// 主光照通道
Pass
{
Name "ForwardLit"
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
// URP核心库
#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.core/ShaderLibrary/Color.hlsl"
// 纹理和采样器
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
// 材质属性缓冲区
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
float4 _BaseColor;
float _Metallic;
float _Smoothness;
float4 _EmissionColor;
float _EmissionStrength;
CBUFFER_END
// 顶点输入结构
struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
};
// 顶点输出结构
struct Varyings
{
float2 uv : TEXCOORD0;
float3 normalWS : TEXCOORD1;
float3 viewDirWS : TEXCOORD2;
float4 positionHCS : SV_POSITION;
};
// 顶点着色器
Varyings vert(Attributes input)
{
Varyings output;
// 顶点位置变换
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.positionHCS = vertexInput.positionCS;
// 法线变换
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS);
output.normalWS = normalInput.normalWS;
// 视线方向
output.viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
// 纹理坐标
output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
return output;
}
// 片元着色器
half4 frag(Varyings input) : SV_Target
{
// 采样基础纹理
half4 baseColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
// 获取主光源
Light mainLight = GetMainLight();
// 基础光照计算Lambert漫反射
float3 normalWS = normalize(input.normalWS);
float NdotL = saturate(dot(normalWS, mainLight.direction));
float3 diffuse = baseColor.rgb * NdotL * mainLight.color;
// 高光计算简化版Blinn-Phong
float3 viewDirWS = normalize(input.viewDirWS);
float3 halfDir = normalize(mainLight.direction + viewDirWS);
float NdotH = saturate(dot(normalWS, halfDir));
float specular = pow(NdotH, _Smoothness * 128.0) * _Metallic;
float3 specularColor = specular * mainLight.color;
// 自发光计算(核心)
float3 emission = _EmissionColor.rgb * _EmissionStrength;
// 最终颜色合成:基础光照 + 高光 + 自发光
float3 finalColor = diffuse + specularColor + emission;
return half4(finalColor, baseColor.a);
}
ENDHLSL
}
// 使用URP Lit的阴影和深度Pass保持兼容性
UsePass "Universal Render Pipeline/Lit/ShadowCaster"
UsePass "Universal Render Pipeline/Lit/DepthOnly"
}
FallBack "Universal Render Pipeline/Lit"
}