Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 统一-如何使材料双面化_Unity3d - Fatal编程技术网

Unity3d 统一-如何使材料双面化

Unity3d 统一-如何使材料双面化,unity3d,Unity3d,搜索该问题提供了许多解决方案,但由于某些原因,它们在mine Unity3D 5.4中不起作用。喜欢 我在Unity editor的材质中没有看到cull和/或边。 在C# rend=GetComponent(); 材料=趋势材料; 格式设置面剔除(“正面”、“ccw”); 主侧=三个双侧; 不提供此类setFaceCulling和side属性 如何使材质双面?您需要一个自定义着色器,通过使用剔除 最简单/最快的测试方法是在编辑器中创建一个新的标准曲面着色器,然后将其打开。在LOD 200下

搜索该问题提供了许多解决方案,但由于某些原因,它们在mine Unity3D 5.4中不起作用。喜欢

我在Unity editor的材质中没有看到
cull
和/或
边。
在C#

rend=GetComponent();
材料=趋势材料;
格式设置面剔除(“正面”、“ccw”);
主侧=三个双侧;
不提供此类
setFaceCulling
side
属性


如何使材质双面?

您需要一个自定义着色器,通过使用
剔除

最简单/最快的测试方法是在编辑器中创建一个新的
标准曲面着色器
,然后将其打开。在
LOD 200
下面添加行
Cull Off


现在有一件事要考虑的是闪电不会正确地渲染背面。如果您需要,我建议您使用双面模型。

使用或创建带有消隐功能的着色器。 简单的双面着色器:

Shader "Custom/NewSurfaceShader" {
    Properties {

    }
    SubShader {
         Cull off   
         Pass {
             ColorMaterial AmbientAndDiffuse
         }

    }
}

也许我对您的Unity版本的回答不起作用,但在下图中,它是HDRP中较新版本的解决方案

您可以使用带有消隐功能的自定义曲面着色器,但相反的面将无法获得正确的灯光,因为法线仅对正面有效,而对背面,法线与面相对。如果希望将背面视为与正面类似,并且不希望使用双面网格制作模型以消耗双内存,则可以绘制2个过程,1个过程用于正面,1个过程用于背面,其中可以为顶点着色器中的每个顶点反转法线。您可以使用后消隐前消隐

SubShader
{
     //Here start first Pass, if you are using standard surface shader passes are created automated, 
     //else you should specify Pass {  }
     Tags { ... }
     LOD 200
     Cull Back

     ...
     struct Input 
     {
         ...
     }
     ...

     ...
     //or vert & frag shaders
     void surf(Input IN, inout SurfaceOutputStandard p)
     {
           //processing front face, culling back face
           ...
     }
     ...

     //Here start second pass put automated by unity
     Tags {...}
     LOD 200
     Cull Front

     #pragma vertex vert
     #pragma surface ...

     ...
     struct Input 
     {
         ...
     }
     ...

     void vert(inout appdata_full v)
     {
           v.normal = -v.normal;//flip
     }

     void surf(Input IN, inout SurfaceOutputStandard p)
     {
           //processing back face, culling front face
           ...
     }
}

谢谢分享!在我的尝试中,它给了背面一种透视的、几乎透明的感觉,它后面的每一种颜色都是倒转的。是的,这不会正确地渲染灯光,也就是说,灯光必须被镜像!如果仅将视图方向应用于法线,则照明将正常工作。ie:基于法线点viewdir,翻转法线。其思想是法线仅在单个方向上是正确的,但您基本上需要从前视图和后视图进行照明。基本上与前面的答案相同,但从默认着色器开始可能更有用。
SubShader
{
     //Here start first Pass, if you are using standard surface shader passes are created automated, 
     //else you should specify Pass {  }
     Tags { ... }
     LOD 200
     Cull Back

     ...
     struct Input 
     {
         ...
     }
     ...

     ...
     //or vert & frag shaders
     void surf(Input IN, inout SurfaceOutputStandard p)
     {
           //processing front face, culling back face
           ...
     }
     ...

     //Here start second pass put automated by unity
     Tags {...}
     LOD 200
     Cull Front

     #pragma vertex vert
     #pragma surface ...

     ...
     struct Input 
     {
         ...
     }
     ...

     void vert(inout appdata_full v)
     {
           v.normal = -v.normal;//flip
     }

     void surf(Input IN, inout SurfaceOutputStandard p)
     {
           //processing back face, culling front face
           ...
     }
}