- Home /
Accessing the alpha blend variable in a custom shader
I have a custom shader that I pulled from another question and i'm wondering how I pull the variable _BlendAlpha to use in a line of script like such:
renderer.material.WhatGoesHere = Mathf.Lerp(!inside ? 1 : 0, inside ? 1 : 0, 1);
Here is a link to the shader: http://puu.sh/41we6.txt
P.S. "inside" is a boolean P.P.S. "WhatGoesHere" is what i'm stuck on, just to clarify
Answer by aldonaletto · Aug 14, 2013 at 01:49 AM
You should use SetFloat:
renderer.material.SetFloat("_Blend", Mathf.Lerp(!inside ? 1 : 0, inside ? 1 : 0, 1));
NOTE: This Lerp will always return inside? 1: 0 - is this what you want?
Well if you change the state of the boolean then it'll shift from 1 to 0 ins$$anonymous$$d of 0 to 1 right?
Yes: the 1st and 2nd arguments are (0,1) when inside is true, (1,0) when it's false. What's weird is the 3rd Lerp argument: it's a constant 1, thus Lerp will always return the second argument. Usually it's a variable or function ranging from 0 to 1, and works like a slider between the 1st and 2nd arguments: 0 returns the first, 1 returns the second, 0.5 returns the average between both, and so on.
Thanks! Also I sovled the whole problem with the third argument.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112148im_/https://answers.unity.com/themes/thub/images/avi.jpg)