Files
PotionMaker/Assets/MesshingAround/StylizedPotionsPack/Shaders/BuiltIn/Stylized_Tint.shader
2026-03-27 16:34:08 +09:00

99 lines
3.6 KiB
GLSL

Shader "MesshingAround/Stylized_Tint (Built-in)"
{
Properties
{
[Header(Color)]
[Space(5)]
[NoScaleOffset]_GradientTexture("GradientTexture(LUT)", 2D) = "white" {}
_GradientIndex("GradientIndex", Float) = 48
_GradientCount("GradientCount", Float) = 110
[Header(Emission)]
[Space(5)]
_EmissionColor("EmissionColor", Color) = (0, 0, 0, 0)
_EmissionStrength("EmissionStrength", Float) = 0
[Header(Glossy)]
[Space(5)]
_Smoothness("Smoothness(Glossy)", Range(0, 1)) = 0
[HideInInspector] _GrayscaleTex("GrayscaleTex", 2D) = "white" {}
[HideInInspector][NoScaleOffset] unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
[HideInInspector][NoScaleOffset] unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
[HideInInspector][NoScaleOffset] unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
}
SubShader
{
Tags
{
"RenderType" = "Opaque"
"Queue" = "Geometry"
}
LOD 200
CGPROGRAM
#pragma surface surf StandardSpecular fullforwardshadows
#pragma target 3.0
#pragma multi_compile_instancing
sampler2D _GrayscaleTex;
sampler2D _GradientTexture;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float, _GradientIndex)
UNITY_DEFINE_INSTANCED_PROP(float, _GradientCount)
UNITY_DEFINE_INSTANCED_PROP(float4, _EmissionColor)
UNITY_DEFINE_INSTANCED_PROP(float, _EmissionStrength)
UNITY_DEFINE_INSTANCED_PROP(float, _Smoothness)
UNITY_INSTANCING_BUFFER_END(Props)
struct Input
{
float2 uv_GrayscaleTex;
};
// LUT sampling function - MATCHES URP EXACTLY
// Uses grayscale.r as U coordinate and calculated V from gradient index
float4 SampleLUTFromGrayscale(float2 uv, float gradientIndex, float gradientCount)
{
// Round the gradient index and add 0.5 (URP does this)
float roundedIndex = round(gradientIndex);
float adjustedIndex = roundedIndex + 0.5;
// Calculate V coordinate
float vCoord = adjustedIndex / gradientCount;
// Sample grayscale texture
float4 grayscaleSample = tex2D(_GrayscaleTex, uv);
// Use R channel as U coordinate (like URP)
float2 lutUV = float2(grayscaleSample.r, vCoord);
return tex2D(_GradientTexture, lutUV);
}
void surf(Input IN, inout SurfaceOutputStandardSpecular o)
{
// Get instanced properties
float gradientIndex = UNITY_ACCESS_INSTANCED_PROP(Props, _GradientIndex);
float gradientCount = UNITY_ACCESS_INSTANCED_PROP(Props, _GradientCount);
float4 emissionColor = UNITY_ACCESS_INSTANCED_PROP(Props, _EmissionColor);
float emissionStrength = UNITY_ACCESS_INSTANCED_PROP(Props, _EmissionStrength);
float smoothness = UNITY_ACCESS_INSTANCED_PROP(Props, _Smoothness);
// Sample LUT using grayscale texture (set by PotionTextureSetup.cs)
float4 lutColor = SampleLUTFromGrayscale(IN.uv_GrayscaleTex, gradientIndex, gradientCount);
// Set surface properties
o.Albedo = lutColor.rgb;
o.Emission = emissionColor.rgb * emissionStrength;
o.Smoothness = smoothness;
o.Specular = float3(0, 0, 0);
o.Alpha = 1.0;
}
ENDCG
}
FallBack "Standard"
}