Search Unity

Why does this shader mirror the texture

Discussion in 'Shaders' started by atilah, Apr 16, 2015.

  1. atilah

    atilah

    Joined:
    Mar 9, 2015
    Posts:
    29
    I have the following shader and I dont understand why the texture is being mirrored in my objects. I'd like to have the texture simply applied, no mirroring or double. Can anyone please signal the part of the shader that is causing this and how to change it. Thanks

    Code (CSharp):
    1. Shader "Clouds/Cloud Color Alpha Blend" {
    2. Properties {
    3.     _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    4.     _MainTex ("Particle Texture", 2D) = "white" {}
    5.     _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    6. }
    7.  
    8. Category {
    9.     Tags { "Queue"="Transparent+1" "IgnoreProjector"="True" "RenderType"="Transparent" }
    10.     Blend SrcAlpha OneMinusSrcAlpha
    11.     AlphaTest Greater .01
    12.     ColorMask RGB
    13.     Cull Off Lighting Off ZWrite Off
    14.     BindChannels {
    15.         Bind "Color", color
    16.         Bind "Vertex", vertex
    17.         Bind "TexCoord", texcoord
    18.     }
    19.  
    20.     // ---- Fragment program cards
    21.     SubShader {
    22.         Pass {
    23.      
    24.             CGPROGRAM
    25.             #pragma vertex vert
    26.             #pragma fragment frag
    27.             #pragma fragmentoption ARB_precision_hint_fastest
    28.             #pragma multi_compile_particles
    29.          
    30.             #include "UnityCG.cginc"
    31.  
    32.             sampler2D _MainTex;
    33.             fixed4 _TintColor;
    34.          
    35.             struct appdata_t {
    36.                 float4 vertex : POSITION;
    37.                 fixed4 color : COLOR;
    38.                 float2 texcoord : TEXCOORD0;
    39.             };
    40.  
    41.             struct v2f {
    42.                 float4 vertex : POSITION;
    43.                 fixed4 color : COLOR;
    44.                 float2 texcoord : TEXCOORD0;
    45.                 #ifdef SOFTPARTICLES_ON
    46.                 float4 projPos : TEXCOORD1;
    47.                 #endif
    48.             };
    49.          
    50.             float4 _MainTex_ST;
    51.  
    52.             v2f vert (appdata_t v)
    53.             {
    54.                 v2f o;
    55.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    56.                 #ifdef SOFTPARTICLES_ON
    57.                 o.projPos = ComputeScreenPos (o.vertex);
    58.                 COMPUTE_EYEDEPTH(o.projPos.z);
    59.                 #endif
    60.                 o.color = v.color;
    61.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    62.                 return o;
    63.             }
    64.  
    65.             sampler2D _CameraDepthTexture;
    66.             float _InvFade;
    67.          
    68.             fixed4 frag (v2f i) : COLOR
    69.             {
    70.                 #ifdef SOFTPARTICLES_ON
    71.                 float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
    72.                 float partZ = i.projPos.z;
    73.                 float fade = saturate (_InvFade * (sceneZ-partZ));
    74.                 i.color.a *= fade;
    75.                 #endif
    76.              
    77.                 return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
    78.             }
    79.             ENDCG
    80.         }
    81.     }  
    82.  
    83.     // ---- Dual texture cards
    84.     SubShader {
    85.         Pass {
    86.             SetTexture [_MainTex] {
    87.                 constantColor [_TintColor]
    88.                 combine constant * primary
    89.             }
    90.             SetTexture [_MainTex] {
    91.                 combine texture * previous DOUBLE
    92.             }
    93.         }
    94.     }
    95.  
    96.     // ---- Single texture cards (does not do color tint)
    97.     SubShader {
    98.         Pass {
    99.             SetTexture [_MainTex] {
    100.                 combine texture * primary
    101.             }
    102.         }
    103.     }
    104. }
    105. }
    106.  
     
  2. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    On what do you apply the material ? plane? a complex mesh?

    Are you sure that object UV are properly set?

    That shader have backface culling off and zwrite off, that mean that some backface (so "inverted") can be drawn on top of forward facing face, leading to the illusion the object is inside out (and the textures mirrored).
     
    atilah likes this.
  3. atilah

    atilah

    Joined:
    Mar 9, 2015
    Posts:
    29
    UnityGuillaume, thanks for your kind answer. I'm applying it to a very thin and large cube. Probably waht may be happening is that I'm seeing the reversed image in the other face of it? maybe a plane can help with this. I'll give a try and come back if I need further help. You've been of great assistance.