Hello,
Is there a way to fade an object with a shader that doesn’t use the _color?
I’m using SpeedTree and it’s got it’s own special shader it seems (“Nature/SpeedTree”)
Thanks!
Hello,
Is there a way to fade an object with a shader that doesn’t use the _color?
I’m using SpeedTree and it’s got it’s own special shader it seems (“Nature/SpeedTree”)
Thanks!
On speed tree, on the shader material does it have anything like a “Cut-off value”?
Alpha Cutoff yes.
What properties does the shader have, hard to help without knowing the shader code.
You could add an alpha float property and multiply the colour by the float value before returning it in the shader
Alpha Cutoff would work, was typing as those messages got posted
You can write a script, that effects the Alpha cutoff value, and make it fade,
using UnityEngine;
using System.Collections;
public class Tree_Dissolve : MonoBehaviour {
public GameObject tree;
public float cutoffvalue = 0.0f;
public bool fadeIn = false;
public bool fadeOut = false;
private float time = 0.01f;
public float timeToTake;
// Use this for initializatio
// Update is called once per frame
void Update ()
{
if (fadeOut)
{
time+= Time.deltaTime * 1.0f / timeToTake;;
cutoffvalue = Mathf.Lerp(0.0f, 1.0f, time);
gameObject.GetComponent<Renderer>().material.SetFloat("_Cutoff", cutoffvalue);
if (cutoffvalue >= 1.0f)
{
fadeOut = false;
}
}
}
}
this would fade the Alpha cutoff from 0 to 1, or 1 to 0, just change the Lerp values, to what makes the tree fade out
Also attatch it to the tree where the material is located
Edit: would like to mention this worked with a custom shader for an enemy of mine, not a tree from speed tree, might require different methods, but on this path
Cool! Thanks all!
This works perfect with every kind of tree with cutoff EXCEPT SpeedTree!
Doh!
Any insights besides not using SpeedTree?
if you do something like this it works fine.
using UnityEngine;
using System.Collections;
public class Tree_Dissolve : MonoBehaviour {
public GameObject tree;
public float cutoffvalue = 0.0f;
public bool fadeIn = false;
public bool fadeOut = true;
private float time = 0.01f;
public float timeToTake;
// Use this for initializatio
// Update is called once per frame
void Update ()
{
if (fadeOut)
{
time+= Time.deltaTime * 1.0f / timeToTake;;
cutoffvalue = Mathf.Lerp(0.0f, 1.0f, time);
gameObject.GetComponent<Renderer>().materials[1].SetFloat("_Cutoff", cutoffvalue);
gameObject.GetComponent<Renderer>().materials[2].SetFloat("_Cutoff", cutoffvalue);
gameObject.GetComponent<Renderer>().materials[4].SetFloat("_Cutoff", cutoffvalue);
if (cutoffvalue >= 1.0f)
{
fadeOut = false;
}
}
}
}
Ah nice I’ve never used speedtree before so didn’t know how many matrials it has glad you got what you needed !