Hello.
I have texture2d array that has for example just colours (red, green, blue), and when i use it i want to blend just texture 1 and 3 but shader cannot do that because interpolation in UVs? I use it by SetUVS and just set texture index in 3rd uv value, then in shader get it.
Shader "Custom/Tex2DArray" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2DArray) = "white" {}
_MainTex2 ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_SliceRange("Slices", Range(1,24)) = 1
_UVScale("uv scale", Float) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma target 3.5
#include "UnityCG.cginc"
struct appdata{
float4 vertex : POSITION;
float3 uv : TEXCOORD2;
};
struct v2f
{
float3 uv : TEXCOORD2;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
UNITY_DECLARE_TEX2DARRAY (_MainTex);
sampler2D _MainTex2;
float4 _MainTex2_ST;
half _Glossiness;
half _Metallic;
fixed4 _Color;
float _SliceRange;
float _UVScale;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float f = floor(i.uv.z);
float c = ceil(i.uv.z);
float blendValue = i.uv.z - f;
fixed4 tex1 = UNITY_SAMPLE_TEX2DARRAY(_MainTex, float3(i.uv.xy, f));
fixed4 tex2 = UNITY_SAMPLE_TEX2DARRAY(_MainTex, float3(i.uv.xy, c));
fixed4 color = lerp (tex1, tex2, blendValue);
return color;
}
ENDCG
}
}
FallBack "Diffuse"
}
and it blend fine but i don’t want textures between…
like in image: