Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Digital materialization effect

Discussion in 'General Graphics' started by virginiaelizabethgil, Oct 30, 2018.

  1. virginiaelizabethgil

    virginiaelizabethgil

    Joined:
    Oct 4, 2018
    Posts:
    1
    Hello, I hope I'm posting this in the right section. I have a mesh which I need to animate in a sort of sci-fi digital materialization effect, where the mesh starts with a transparent wirefrime material and gradually "fills in" until it becomes a solid material with a simple diffuse color.

    I've been trying to implement this animation using the Material.lerp example code found here: https://docs.unity3d.com/ScriptReference/Material.Lerp.html But this isn't quite working, it's only fading between the solid material and black, or between the transparent wireframe and invisibility depending on which one i assign as material1 or material2.

    How should I go about this? I've seen other similar questions where people simply turn to lerping between two textures in a shader, but the issue here is that my wireframe material and my diffuse material have different shaders (which is probably the reason why the material.lerp example isn't working), and I don't know how to achieve a wireframe effect with a texture that actually maps correctly over the mesh's edges and vertices. The wireframe material i'm using is from this repo: https://github.com/Chaser324/unity-wireframe

    I would greatly appreciate any help with this issue, since I'm a complete beginner with Unity and coding shaders.
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,334
    I think you're right about that. According to the documentation, it sounds like it only interpolates between color fields on two materials of the same shader.

    Since you are using a specialized wire-frame shader, I think it would be difficult to lerp from that to anything else. maybe you could make two separate objects. One with the wire-frame shader, and one slightly larger that has it's final material. For the larger object, maybe you can do something like a dissolve shader except in reverse?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    From the Material.Lerp documentation:
    That statement packs a lot of information they should be far more specific about. The reality is Material.Lerp can only interpolate the color, vector, and float values and cannot interpolate textures or shaders. If you have two materials with different shaders and no shared properties, the result will simply be at the end of the lerp it snaps from one material to the other. If they have color, vector, or float properties of the same name, those will be interpolated.

    If you want to blend between two different shaders, you have to write a single custom shader that can do both things that you want. That or, similar to what @kdgalla suggested, has options to fade in / out and manually cross fade between two copies of the objects.

    There's also the question of what you mean by "fill in". There's lots of ways to accomplish that. It could fill up like a cup of water, or fade in, or the wireframe lines could just get thicker until it's fully there. You need to decide how exactly you want that to look, and then you'd need to write a custom shader to do that.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    The short version is to do the effect you want you're going to need to learn how to write shaders. The effect you're starting off looking to do is relatively advanced, so don't expect this to be something you can watch a video or two and then copy / paste some code and be done.

    I'd start here:
    https://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/

    After that there are several threads on the forum with resources for beginners.