Hiya,
I’m pretty sure there is somehing wrong with my way of doing it, but I can’t figure it out. I’m trying to lerp between two textures, setting interpolation value using MaterialPropertyBlock and it seems like its just not working for me.
Shader pseudo
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTexFinal ("Albedo Final(RGB)", 2D) = "white" {}
_InterpolationValue("Interpolation value", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
sampler2D _MainTex;
sampler2D _MainTexMaxVelo;
half _InterpolationValue;
void surf(){
fixed4 c = lerp(tex2D (_MainTex, IN.uv_MainTex), tex2D(_MainTexFinal , IN.uv_MainTex), _InterpolationValue);
o.Albedo = c.rgb;
}
ENDCG
}
C# script used to change value
var rends = GetComponentsInChildren<MeshRenderer>();
mBlock = new MaterialPropertyBlock();
var ratio = 0.6f;
for (int i = 0; i < rends.Length; i++){
rends[i].GetPropertyBlock(mBlock);
mBlock.SetFloat("_InterpolationValue", ratio);
rends[i].SetPropertyBlock(mBlock);
}
_InterpolationValue works from shader inspector or if I use global Material.SetFloat(“_InterpolationValue”, ratio), but not from MaterialPropertyBlock.
I’ve read posts from @bgolus that MaterialPropertyBlock can change only inside CGPROGRAM which seems to be the case. So I’m kinda stuck here. Anyone?