- Home /
Question by
Paul-B · Feb 23, 2019 at 01:19 AM ·
shaderoptimizationtimemobile devices
Change input values based on Time
I have a simple curved shader that lets me bend an object using the material the shader is on in both the x and y axis.
I am current using a bunch of if statements to change the value of the curvature depending on the value a timer. Is there there a way to change the input value given to the shader that changes the "bend" or curvature based on time that doesn't resolve around using a bunch of if/if else statements?
Example Code:
void Update ()
{
seconds += Time.deltaTime;
ChangeBendValue(seconds, 0.000001F);
}
void ChangeBendValue(float time, float changeByValue)
{
if (time > 3f && time < 7f)
{
maxSidewardsCurvature += changeByValue;
if (maxSidewardsCurvature >= 0.0001f)
{
maxSidewardsCurvature = 0.0001f;
}
mat.SetFloat("_Curvature2", maxSidewardsCurvature);
}
if (time > 7f && time < 10f)
{
maxSidewardsCurvature -= changeByValue;
if (maxSidewardsCurvature <= -0.0001f)
{
maxSidewardsCurvature = -0.0001f;
}
mat.SetFloat("_Curvature2", maxSidewardsCurvature - changeByValue);
}
if (time > 10f && time < 15f)
{
maxUpwardsCurvature -= changeByValue;
if (maxUpwardsCurvature <= -0.0001f)
{
maxUpwardsCurvature = -0.0001f;
}
mat.SetFloat("_Curvature", maxUpwardsCurvature - changeByValue);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612192255im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Optimisation: fewer draw calls or smaller draws? 1 Answer
Grass performance 0 Answers
Unity Texture Black And White 1 Answer
Do materials with same texture yet different shaders share the texture? 1 Answer
How is SinTime measured in shaders? 1 Answer