我想知道如何使用纹理地图集着色器。有谁知道如何才能得到图像的一部分?
当前观点:
期望的观点:
着色器源代码:
Shader "Test/WeaponMaker" {
Properties {
_WeaponTex ("Weapon Box Background", 2D) = "white" {}
_BoxTex ("Weapon", 2D) = "white" {}
_WeaponColor("Weapon Color", color) = (0.0, 0.0, 0.0, 0.0)
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf NoLighting
sampler2D _WeaponTex;
sampler2D _BoxTex;
half4 _WeaponColor;
struct Input {
float2 uv_WeaponTex;
float2 uv_BoxTex;
};
fixed4 LightingNoLighting(SurfaceOutput output, fixed3 lightDir, fixed atten){
fixed4 light = 0;
light.rgb = output.Albedo;
light.a = output.Alpha;
return light;
}
half2 CalculatorBoxUV(half2 uv, half2 weaponPosition, half2 scale){
uv = (uv - weaponPosition) * scale;
return uv;
}
void surf (Input IN, inout SurfaceOutput output) {
half4 weaponTex = tex2D (_WeaponTex, IN.uv_WeaponTex);
half4 boxTex = 0;
half4 finalBoxTex = 0;
boxTex = tex2D(_BoxTex, CalculatorBoxUV(IN.uv_BoxTex, half2(0.35, 0.35), half2(3, 3)));
finalBoxTex.rgb += boxTex.rgb;
finalBoxTex.a += boxTex.r;
output.Albedo = lerp(weaponTex.rgb, finalBoxTex.rgb * _WeaponColor.rgb, finalBoxTex.a);
}
ENDCG
}
FallBack "Diffuse"
}