Outline shader unity similar to the gizmo Editor

后端 未结 1 1307
别跟我提以往
别跟我提以往 2021-01-28 10:18

I wonder if I can get the same outline as in the Editor. Like this

I tried to use this script https://github.com/michaelcurtiss/UnityOutlineFX

And get this as a

相关标签:
1条回答
  • 2021-01-28 10:59

    I'm not sure how you applied the scripts in the Github repo you linked to. It looks like the outline shader is only applied to the leaf material on the 3D model you posted, however I believe that this outline effect is meant to run as a post processing or replacement shader. I think that you're attaching a script or reference to the tree's leaves when you should be attaching it to the camera.


    Update: I downloaded the repo and changed the "UnityOutlineFX.cs" script to work with multiple materials (the problem was that the script was originally only outlining the material in index 0). The fix is in the RecreateCommandBuffer() function, and I added the following code (note the for-loop through the different materials):

    // render selected objects into a mask buffer, with different colors for visible vs occluded ones 
    float id = 0f;
    foreach (var collection in _objectRenderers)
    {
        id += 0.25f;
        _commandBuffer.SetGlobalFloat("_ObjectId", id);
    
        foreach (var render in collection)
        {
            for(var i=0; i<render.sharedMaterials.Length; i++) {
                _commandBuffer.DrawRenderer(render, _outlineMaterial, i, 1);
                _commandBuffer.DrawRenderer(render, _outlineMaterial, i, 0);
            }
        }
    }
    

    The original problem (only one material was being outlined, with the blue and orange objects in this picture being part of one mesh)

    The outline working on a mesh (the orange and blue mesh) with three submeshes and two different materials.

    0 讨论(0)
提交回复
热议问题