Outline shader unity similar to the gizmo Editor

2020-05-09 18:15发布

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 result

1条回答
我欲成王,谁敢阻挡
2楼-- · 2020-05-09 18:39

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 original problem (only one material was being outlined, with the blue and orange objects in this picture being part of one mesh)

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

查看更多
登录 后发表回答