有没有办法在纹理/片段着色器中进行多次传递?

时间:2018-04-19 20:08:43

标签: unity3d shader

有没有办法在片段着色器中进行多次传递?我需要在第一步中转换纹理,然后在第二步中修改部分受到第一步的影响。有没有办法用一个着色器做到这一点?我写了一个例子,我想怎么做,但第一遍似乎完全被忽略了:

Shader "Test/FragmentShaderWithMemory" {
     Properties {
         _MainTex ("MainTexture", 2D) = "white" {}
     }
     SubShader {

         Pass {
             CGPROGRAM
             #pragma vertex vert_img
             #pragma fragment frag
             #include "UnityCG.cginc"

             uniform sampler2D _MainTex;

             float3 frag(v2f_img i) : COLOR {
                 float3 pixelColor = tex2D(_MainTex, i.uv);
                 // the red channel to 0 as a test:
                 pixelColor.x = 0; 
                 return pixelColor;
             }
             ENDCG
         }

         Pass {
             CGPROGRAM
             #pragma vertex vert_img
             #pragma fragment frag
             #include "UnityCG.cginc"

             uniform sampler2D _MainTex;

             float3 frag(v2f_img i) : COLOR {
                 float3 pixelColor = tex2D(_MainTex, i.uv);
                 // all pixels should now have red to 0, test by setting all green channels to 1:
                 if (pixelColor.x==0) pixelColor.y = 1; 
                 return pixelColor;
             }
             ENDCG
         }

     }
 }

0 个答案:

没有答案