我想知道如何将着色器与纹理图集一起使用。有谁知道我怎样才能只绘制图像的一部分?
目前看来 :
所需视图:
着色器源代码:
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"
}