56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
Shader "Blocks/VoxelLit"
|
||
{
|
||
Properties
|
||
{
|
||
_MainTexArray ("Texture Array", 2DArray) = "" {}
|
||
_Glossiness ("Smoothness", Range(0,1)) = 0.0
|
||
_Metallic ("Metallic", Range(0,1)) = 0.0
|
||
}
|
||
|
||
SubShader
|
||
{
|
||
Tags { "RenderType"="Opaque" }
|
||
LOD 200
|
||
|
||
CGPROGRAM
|
||
// Standard surface shader с кастомным vertex для передачи texIndex
|
||
#pragma surface surf Standard fullforwardshadows vertex:vert
|
||
#pragma target 3.5
|
||
#pragma require 2darray
|
||
|
||
UNITY_DECLARE_TEX2DARRAY(_MainTexArray);
|
||
|
||
struct Input
|
||
{
|
||
float2 uv_MainTexArray; // стандартный UV (0-1 по грани)
|
||
float texIndex; // индекс слоя в Texture2DArray
|
||
};
|
||
|
||
half _Glossiness;
|
||
half _Metallic;
|
||
|
||
// Vertex-функция: читаем texIndex из канала UV1 (mesh.uv2)
|
||
void vert(inout appdata_full v, out Input o)
|
||
{
|
||
UNITY_INITIALIZE_OUTPUT(Input, o);
|
||
o.uv_MainTexArray = v.texcoord.xy;
|
||
o.texIndex = v.texcoord1.x; // UV1.x = индекс текстуры
|
||
}
|
||
|
||
void surf(Input IN, inout SurfaceOutputStandard o)
|
||
{
|
||
fixed4 c = UNITY_SAMPLE_TEX2DARRAY(
|
||
_MainTexArray,
|
||
float3(IN.uv_MainTexArray, IN.texIndex)
|
||
);
|
||
o.Albedo = c.rgb;
|
||
o.Metallic = _Metallic;
|
||
o.Smoothness = _Glossiness;
|
||
o.Alpha = c.a;
|
||
}
|
||
ENDCG
|
||
}
|
||
|
||
FallBack "Diffuse"
|
||
}
|