How do I change the scale over a time for a shader?
So, i have been working on a project since a week, and i got a big problem!
I have a simple line renderer and a repeating/tiling texture added. Heres a picture for visualisation:
The next thing i did was writing a little code to change the offset with the time. So the lines are going in one direction:
The problem is that it looks kind of weird, because the little repeating line textures are just disappearing at the end of the line (renderer). So i would like to change the shader so that it would change the size of the little textured repeating lines with time. That means the lines would get tinier and shrink/fade away. Not just continuosly stay big and just disappear.The problem is, i dont know how to achieve that goal. I looked through many questions but i didnt find any helpfull answeres. Do i have to write a shader myself? And if yes, could you help me out? I never did that before. Also, i would prefer a c# solution :)
Thank you, NeoN!
Answer by dan_wipf · Mar 23, 2019 at 07:11 AM
well have you tried to change the animation curve? this will give you an idea.
var lr = GetComponent<LineRenderer>();
AnimationCurve curve = new AnimationCurve();
curve.AddKey(0.0f, 0.0f);
curve.AddKey(1.0f, 1.0f);
// or reversed
curve.AddKey(1.0f, 1.0f);
curve.AddKey(0.0f, 0.0f);
lr.widthCurve = curve;
Yep, the linerenderer has an inbuild scaling tool over lifetime aswell, the problem is that it just cuts of the circle ins$$anonymous$$d of scaling each individual circle down. Heres a picture:
And thats how i would like it to look (Drawn with my astonishing paint skills):
Thanks for your quick answer!
ok played around with linerenderer, and i guess it’s not achievable with a simple setup.
so what i would do is setting a start point and an end point as a vector3 position, them you make a vector3 Lerp loop:
Vector3 startPos = new Vector3(0,0,0);
Vector3 EndPos = new Vector3(0,10,0);
int Steps = 5;
GameObject sprite;
List<GameObject>() allObjects;
//before any change you want to destroy the spawned objects first with a for loop => for(int i = 0; i<allObjects.Count){ Destroy(AllObjects[i]);}
for(int i = 0; i<Steps; i++){
var pos = Vector3.Lerp(startPos,ensPos,i+1/Steps);
var obj = Instantiate(sprite,pos,Quaternion.Identity);
obj.transform.size *= i/Steps;
allObjects.Add(obj);
}
that’s just pseudo codr fyi => but you might get an idea what i forgot to write in code is, that you want to set the parent of the instantiatex objects to maybe the object where the script is called from
Your answer
