2014-12-04 71 views
1

我试图建立一个统一的WebIS使用统一5测试版WebGL。 我写的自定义着色器(或从现有的着色器更准确地编辑)不再适用于Unity 5. 继承人着色器应该做什么。创建一个圆球曲线中的阿尔法斜线的元球效果。 着色器打开这个.. enter image description here 到这个..(通过渲染纹理) enter image description here自定义着色器不再工作在Unity 5

继承人的整个事情..

//Water Metaball Shader effect by Rodrigo Fernandez Diaz-2013 
//Visit http://codeartist.info/ for more!! 
Shader "Custom/Metaballs" { 
Properties { 


    _MyColor ("Some Color", Color) = (1,1,1,1) 
    _MainTex ("Texture", 2D) = "white" { } 

    _botmcut ("bottom cutoff", Range(0,1)) = 0.1 
    _topcut ("top cutoff", Range(0,4)) = 0.8 
    _constant ("curvature constant", Range(0,5)) = 1 
} 
SubShader { 
    Tags {"Queue" = "Transparent" } 
    Pass { 
    Blend SrcAlpha OneMinusSrcAlpha  
    CGPROGRAM 
    #pragma vertex vert 
    #pragma fragment frag 
    #include "UnityCG.cginc"  
    float4 _MyColor; 
    float4 _Color; 
    sampler2D _MainTex; 
    float _botmcut,_topcut,_constant; 

    struct v2f { 
     float4 pos : SV_POSITION; 
     float2 uv : TEXCOORD0; 
    }; 
    float4 _MainTex_ST; 

    v2f vert (appdata_base v){ 
     v2f o; 
     o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 
     o.uv = TRANSFORM_TEX (v.texcoord, _MainTex); 
     return o; 
    } 

    half4 frag (v2f i) : COLOR{  
     half4 texcol,finalColor; 
     texcol = tex2D (_MainTex, i.uv);   
     //finalColor=_Color*texcol; 
     finalColor=_MyColor; 
     if(texcol.a<_botmcut) 
     { 
      finalColor.a= 0; 
     } 
     else if((texcol.a>_topcut)) 
     { 
      finalColor.a= 0; 
     } 
     else 
     { 
      float r = _topcut-_botmcut; 
      float xpos = _topcut - texcol.a; 

      finalColor.a= 1-(_botmcut + sqrt((xpos*xpos)-(r*r)))/_constant; 
     }   
     return finalColor; 
    } 
    ENDCG 

    } 
} 
Fallback "VertexLit" 
} 

我在Unity 5时遇到的问题是,所产生的纹理是空白的。即。 0 alpha。 似乎是导致问题的位是这一个。

else 
    { 
     float r = _topcut-_botmcut; 
     float xpos = _topcut - texcol.a; 

     finalColor.a= 1-(_botmcut + sqrt((xpos*xpos)-(r*r)))/_constant; 
    } 

如果我注释掉这个“finalCOlor ......等等等等”的最后一行,然后我看到东西 这是通常创建圆形alpha曲线线,但在统一五是始终似乎解决为0。 API有没有变化?因为这个数学应该和它在团结中的工作方式一样。 Ps。我不太了解着色器!

回答

2

在跟踪着色器问题时,我通常会做一些事情。

选项1 尝试使用PIX或其他标准程序调试着色器。你只需要捕捉帧并右键单击像素并点击调试。我会密切关注每个值是什么,确保没有设置为0不应该是。同时在这个工具中验证正在使用正确的纹理。

选项2 如果您将finalColor.a设置为0.5,这是否会执行任何操作?如果这是你知道的问题是你的变量之一是0.应该_constant甚至允许范围0?我认为这应该是从0到5诚实。同时验证你没有覆盖材料上的任何常量或变量,确保它们仍然都设置为默认值。你甚至可能只想在着色器中设置它们来查看是否解决了这个问题。

最后,解决着色器问题并不容易,但它在Unity 4中工作而不在5中的事实告诉我,您可能只是将某些东西解析为0,所以我会先检查它。

0

我不知道why..But改变这一行..

finalColor.a= 1-(_botmcut + sqrt((xpos*xpos)-(r*r)))/_constant; 

到这个..

finalColor.a= 1-(_botmcut + sqrt((r*r)-(xpos*xpos)))/_constant; 

合作。 它没有任何意义!

+1

这使我相信在xpos nfirvine 2015-03-20 00:38:54