Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can somebody help me?

Discussion in 'Shaders' started by Dorobo, Aug 24, 2013.

  1. Dorobo

    Dorobo

    Joined:
    Aug 24, 2013
    Posts:
    2
    My shader code can't display on phone.I want to achieve "RimLight"(Enlarge model‘s normal).I don't know why.:(
     
  2. Dorobo

    Dorobo

    Joined:
    Aug 24, 2013
    Posts:
    2
    No code No help - -!
    Code (csharp):
    1.  
    2. Shader "TrueRim" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _Color("Color",color)=(1,1,1,1)
    6.         _Width("Width",range(0.01,0.1))= 0.01
    7.         _ModeColor("Mode Color",color)=(1,1,1,1)
    8.     }
    9.     SubShader {
    10.         pass
    11.         {
    12.             Tags { "Queue" = "Transparent" }  
    13.             lighting off
    14.             ZWrite off
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             sampler2D _MainTex;
    19.             float _RandomC;
    20.             fixed4 _Color;
    21.             float _Size;
    22.             float _Width;
    23.             struct input
    24.             {
    25.                 float4 pos:position;
    26.                 float3 normal :Normal;
    27.             };
    28.             struct v2f
    29.             {
    30.                 float4 rimpos:position;
    31.             };
    32.             v2f vert(input i)
    33.             {
    34.                 v2f v;
    35.                 v.rimpos = mul(UNITY_MATRIX_MVP,i.pos);
    36.                 float3 tempNor = mul((float3x3)UNITY_MATRIX_MV,i.normal);
    37.                 float2 offset = float2(tempNor.x*UNITY_MATRIX_P[0][0], tempNor.y*UNITY_MATRIX_P[1][1]);
    38.                 v.rimpos.xy += offset*_Width;
    39.                 return v;
    40.             }
    41.             fixed4 frag(v2f v):color
    42.             {
    43.                 return _Color;
    44.             }
    45.             ENDCG
    46.         }
    47.         Pass
    48.         {  
    49.             ZWrite On  
    50.             ZTest LEqual  
    51.             lighting on
    52.             Material
    53.             {  
    54.                 Diffuse [_ModeColor]  
    55.             }    
    56.             SetTexture [_MainTex]
    57.             {  
    58.                 Combine texture  
    59.             }  
    60.             SetTexture [_MainTex]
    61.             {  
    62.                 Combine previous * primary double  
    63.             }  
    64.         }
    65.     }  
    66.     fallBack "Diffuse"
    67. }
    68.  
     
    Last edited: Aug 24, 2013