Files
HauntedBloodlines/Assets/AmplifyShaders/StencilObjectHDRP.shader
2025-05-29 22:31:40 +03:00

128 lines
4.4 KiB
Plaintext

Shader "Custom/StencilObjectHDRP"
{
Properties
{
_BaseColor("Base Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_NormalMap("Normal Map", 2D) = "bump" {}
_NormalStrength("Normal Strength", Range(0,2)) = 1
_Metallic("Metallic", Range(0,1)) = 0.0
_Smoothness("Smoothness", Range(0,1)) = 0.5
}
SubShader
{
Tags { "RenderPipeline"="HDRenderPipeline" "RenderType"="Opaque" "Queue"="Geometry" }
Pass
{
Name "ForwardLit"
Tags { "LightMode"="ForwardOnly" }
Stencil
{
Ref 1
Comp Equal
Pass Keep
}
ZTest Always
Cull Back
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.5
#pragma multi_compile _ NORMALMAP
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
float3 GetIndexColor(int index)
{
float3 colors[5] = {
float3(1, 0, 0), // Red
float3(0, 1, 0), // Green
float3(0, 0, 1), // Blue
float3(1, 1, 0), // Yellow
float3(1, 0, 1) // Magenta
};
return colors[index % 5];
}
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
float3 normalWS : TEXCOORD1;
float3 tangentWS : TEXCOORD2;
float3 bitangentWS : TEXCOORD3;
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);
float4 _BaseColor;
float _NormalStrength;
float _Metallic;
float _Smoothness;
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = IN.uv;
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
OUT.tangentWS = TransformObjectToWorldDir(IN.tangentOS.xyz);
OUT.bitangentWS = cross(OUT.normalWS, OUT.tangentWS) * IN.tangentOS.w;
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
float4 albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv) * _BaseColor;
float3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, IN.uv));
normalTS.xy *= _NormalStrength;
normalTS.z = sqrt(1.0 - saturate(dot(normalTS.xy, normalTS.xy)));
float3 normalWS = normalize(
normalTS.x * IN.tangentWS +
normalTS.y * IN.bitangentWS +
normalTS.z * IN.normalWS
);
BuiltinData builtinData;
ZERO_INITIALIZE(BuiltinData, builtinData);
SurfaceData surfaceData;
ZERO_INITIALIZE(SurfaceData, surfaceData);
surfaceData.baseColor = albedo.rgb;
surfaceData.normalWS = normalWS;
surfaceData.perceptualSmoothness = _Smoothness;
surfaceData.metallic = _Metallic;
surfaceData.ambientOcclusion = 1.0;
surfaceData.specularColor = 0.5.xxx;
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
builtinData.color = EvaluateBSDF(bsdfData, normalWS);
return half4(builtinData.color, 1.0);
}
ENDHLSL
}
}
}