并将其作为结果 解决方案我不确定您如何在链接到的Github存储库中应用脚本.看起来轮廓着色器仅适用于您发布的3D模型上的叶子材质,但是我认为,此轮廓效果旨在作为后期处理或替换着色器运行.我认为您应该在将脚本或引用附加到树上的叶子时,将其附加到摄像机上. 更新:我下载了该存储库,并更改了"UnityOutlineFX.cs"脚本以使用多种材料(问题是该脚本最初仅概述了索引0中的材料).该修复程序位于RecreateCommandBuffer()函数中,我添加了以下代码(请注意不同材料的for循环): // render selected objects into a mask buffer, with different colors for visible vs occluded onesfloat 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 thisI tried to use this script https://github.com/michaelcurtiss/UnityOutlineFXAnd 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 onesfloat 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编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 16:49