- Home /
How can I fade out a model?
I have a fbx model in my scene. How can I fade out the model? I tried using renderer.material.color and reduce its alpha channel, but this doesn't work.
renderer.material.color will only work with a shader that supports transparency. Experiment with different shaders...especially if they have 'transparency' in their names ;).
The fbx model comes in different parts, and they are grouped into a parent gameobject. This gameobject itself has no shaders. The individual parts have shaders but changing them also changes their appearance. There are also many parts and changing every single one of their shaders is difficult. Is there any other ways to fade out a model?
Not directly that I know of, but you might take a look at $$anonymous$$aterial.Lerp(). I've not had occasion to use it, but it might work for you. That is you leave your materials alone when fully visible, but you could then Lerp to one that supports alpha (perhaps one that is already invisible). It is only a theory. $$anonymous$$aybe someone else on the list can give you a better idea if it would work.
$$anonymous$$aterial.Lerp just changes color values and floats on a material.
Answer by whydoidoit · Mar 31, 2013 at 12:05 AM
The only thing I can think of doing that doesn't involve complicated specialised shaders is to render the object to a render texture and then fade the alpha of a shader that renders the texture over the main cameras view.
If you render the object to the RenderTexture in OnPostRender of the main camera and don't clear the depth of the object's camera then it will also appear correctly behind other scene objects.
Sounds like an interesting technique. But I'm still quite confused with how I should go about doing it. I tried creating a RenderTexture, got my main camera to render texture on it. Since my main camera captures all layers, everything in the scene is displayed on the RenderTexture. If I don't clear the depth, it will affect my main scene.
Yeah you'd need a few stages:
Render the main camera to a texture not displaying the fading model
Render the main camera to a different texture with a replacement shader to write the depth (would write nothing else)
Render a second camera not clearing anything to the second texture, just displaying the model to fade
Have a third camera which rendered the two textures in order to the actual display surface. This one would have a shader to modify the alpha value of the second texture to fade in and out your model.
Cool! But wouldn't this be very expensive for just fading a model? I'm thinking if it would still worth to do a fade. I'm not very familiar with shaders. What kind of shader do I have to use to allow me to modify the alpha value and yet doesn't affect its appearance? The transparency shaders will change the way the materials on the model look.
Well it's pretty expensive - it's not much worse than an iOS depth of field or something - the shaders are all lightweight. But yes, fading a model isn't particularly cheap I'm afraid - not without doing as Eric says and fading all of the parts - though that clearly has unintended effects of seeing the model through itself.
Answer by Eric5h5 · Apr 01, 2013 at 05:21 PM
Changing renderer.material.color.a does work, but you need to use a transparent shader. If the model is in many parts, just put them in an array and iterate through the array.
Thanks! But changing to a transparent shader, for some reason, changes the way the model looks. The model looks "brighter" and the colours are somewhat off from the original one too. The original shader is diffuse. I changed it to transparent diffuse and a few others but they all affect the model's appearance.
Your answer
Follow this Question
Related Questions
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
Make model fade out. Transparency help. 1 Answer
Imported model gives error: "Transform.rotation is no longer valid" 2 Answers
Mesh Collidor Faster 1 Answer
how to rotate 3d model in touch using guy texture object 1 Answer