Hi!
I’m trying to write a simple surface shader which use a texture array and choose the index by the vertex color red value. The following code doesn’t work. I already read some forums about surface shaders, checked the documentetion multiple times and can’t figure out whats wrong. I already made a custom texturearray shader which works good(no lightning) but i want a surface shader for auto generated lightning.
Shader “Custom/NewTerrainSurfaceShader”
{
Properties
{
_MainTex(“Albedo (RGB)”, 2DArray) = “white” {}
_SliceRange(“Slices”, Range(1,16)) = 5
}
SubShader
{
Tags { “RenderType” = “Opaque” }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.5
#pragma require 2darray
UNITY_DECLARE_TEX2DARRAY(_MainTex);
float _SliceRange;
struct Input
{
float2 uv_MainTex;
float4 color : COLOR;
};
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = UNITY_SAMPLE_TEX2DARRAY(_MainTex, float3(IN.uv_MainTex.xy, IN.color.r * _SliceRange));
o.Albedo = c.rgb;
//o.Metallic = IN.color.g;
//o.Smoothness = IN.color.b;
//o.Alpha = IN.color.a;
}
ENDCG
}
FallBack “Diffuse”
}
Thanks for the help!