2016-08-03 128 views
-5

我如何添加一个Texture由魔环API给出以下着色器衰减:添加纹理熄灭透明色着色

Shader "Oculus/Unlit Transparent Color" { 
Properties { 
    _Color ("Main Color", Color) = (1,1,1,1) 
    _MainTex ("Texture", 2D) = "white" {} // I added this property to apply Texture. Where can I use it? 
} 

SubShader { 
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} 
    LOD 100 
    Fog {Mode Off} 
    Cull Off 
    ZWrite Off 
    Blend SrcAlpha OneMinusSrcAlpha 
    Color [_Color] 

    Pass {} 
} 
} 
+11

**关于所有downvoters **如果您确信_this问题不显示的研究工作;它不清楚,也没有用处。那么你应该通过添加适当的评论来证明这一点。如果您因为_meta效应而拒绝投票回答问题,并且您不能因为不想失去声誉而降低答案,那么这样的羊群行为是不可接受的。 –

回答

1

由于xyLe_建议在他的post,在Pass{}块我添加以下代码,它的工作:

SetTexture [_MainTex] { 
      constantColor [_Color] 
      Combine texture * primary DOUBLE, texture * constant 
     } 
+22

你应该标明他的答案是正确的。如果它缺少任何你只需要告诉他,或者在编辑中添加它。 – Will

+1

这个答案已经在讨论荟萃:https://meta.stackoverflow.com/questions/332723/answer-your-question-copying-an-answer-and-mark-yours-as-accepted – user000001

29

您可以使用您在Pass {}加入其中应至少包含一个属性顶点和片段着色器(或者表面着色器)。

在通过定义一个sampler2D具有相同的名称,你的财产,所以你可以在你的着色器的功能使用。

有一些例子着色器unitys文档: https://docs.unity3d.com/Manual/ShaderTut2.html
https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

编辑
另外还有一点的构成就像你的着色器的例子:
https://docs.unity3d.com/Manual/ShaderTut1.html
根据这一点,你可以添加类似

SetTexture [_MainTex] { 
    // some properties 
} 

因此以类似的方式设置颜色。 (对不起,我没有使用着色器的结构一样,然而,只有顶点/片段着色,所以你必须尝试,如果它的工作原理和/或读了由统一提供的例子或等待别人有更多的专业知识的另一种答案: ))