user73786
user73786

Reputation: 35

Outline shader unity similar to the gizmo Editor

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

Upvotes: 2

Views: 5045

Answers (1)

Nicholas Bucher
Nicholas Bucher

Reputation: 440

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.

Upvotes: 5

Related Questions