轮廓着色器统一,类似于Gizmo编辑器 [英] Outline shader unity similar to the gizmo Editor

查看:111
本文介绍了轮廓着色器统一,类似于Gizmo编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我能否获得与编辑器中相同的轮廓.

我尝试使用此脚本 https://github.com/michaelcurtiss/UnityOutlineFX

将其作为结果

解决方案

我不确定您如何在链接到的Github存储库中应用脚本.看起来轮廓着色器仅适用于您发布的3D模型上的叶子材质,但是我认为,此轮廓效果旨在作为后期处理或替换着色器运行.我认为您应该在将脚本或引用附加到树上的叶子时,将其附加到摄像机上.


更新:我下载了该存储库,并更改了"UnityOutlineFX.cs"脚本以使用多种材料(问题是该脚本最初仅概述了索引0中的材料).该修复程序位于RecreateCommandBuffer()函数中,我添加了以下代码(请注意不同材料的for循环):

 // 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);
        }
    }
}
 

最初的问题(仅勾勒出一种材料,该图片中的蓝色和橙色对象是一个网格的一部分)

在具有三个子网格和两种不同材质的网格(橙色和蓝色网格)上工作的轮廓.

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

解决方案

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.

这篇关于轮廓着色器统一,类似于Gizmo编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆