Outline shader unity similar to the gizmo Editor

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 07:56:41

问题


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:


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.



来源:https://stackoverflow.com/questions/56023443/outline-shader-unity-similar-to-the-gizmo-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!