Search Unity

iphone shader question

Discussion in 'Shaders' started by DrFromTheLab, Nov 22, 2010.

  1. DrFromTheLab

    DrFromTheLab

    Joined:
    May 21, 2009
    Posts:
    108
    Hello every one.
    I'm pretty bad in writing code especially shaders... maybe someone of you wrote such a shader like this in splintercell on the iphone:

    I mean the character looks like normal vertexlit but he has some "light" glow around the edges (like look on his right leg)
    I've tryed to make something like this but it was a total disaster... if someone has wrote something similar could you please share this with us :) ?
    Thanks in advanced!!

    cheers
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    So that's either the shader doing it (usually called "rim lighting"), or actually just one extra per-vertex directional light, parented to the camera (almost looking into it), and affecting only the characters (via layer masks).
     
  3. DrFromTheLab

    DrFromTheLab

    Joined:
    May 21, 2009
    Posts:
    108
    Is there any way to achieve this with the default unity shaders? as said - I'm really bad in writing shader :( (okok to call it simply - I can't it :) )
     
  4. DrFromTheLab

    DrFromTheLab

    Joined:
    May 21, 2009
    Posts:
    108
    I found this shader but it won't work on Unity Iphone Advanced... it says that this graphic card don't support this...

    Code (csharp):
    1.  
    2.  
    3. Shader "RimLight" {
    4.    
    5.     Properties {
    6.         _Color ("Main Color", Color) = (1,1,1,1)
    7.         _RimColor ("Rim Color", Color) = (1, 1, 1, 1)
    8.         _MainTex ("Base (RGB)", 2D) = "white" {}
    9.     }
    10.    
    11.     SubShader {
    12.        
    13.         Pass {
    14.            
    15.             CGPROGRAM
    16.                
    17.                 #pragma vertex vert
    18.                 #pragma fragment frag
    19.                 #include "UnityCG.cginc"
    20.                 struct appdata {
    21.                     float4 vertex : POSITION;
    22.                     float3 normal : NORMAL;
    23.                     float2 texcoord : TEXCOORD0;
    24.                 };
    25.                
    26.                 struct v2f {
    27.                     float4 pos : SV_POSITION;
    28.                     float2 uv : TEXCOORD0;
    29.                     float3 color : COLOR;
    30.                 };
    31.                
    32.                 uniform float4 _MainTex_ST;
    33.                 uniform float4 _RimColor;
    34.                
    35.                 v2f vert (appdata_base v) {
    36.                     v2f o;
    37.                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    38.                    
    39.                     float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    40.                     float dotProduct = 1 - dot(v.normal, viewDir);
    41.                     float rimWidth = 0.7;
    42.                     o.color = smoothstep(1 - rimWidth, 1.0, dotProduct);
    43.                    
    44.                     o.color *= _RimColor;
    45.                    
    46.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    47.                    
    48.                     return o;
    49.                 }
    50.                
    51.                 uniform sampler2D _MainTex;
    52.                 uniform float4 _Color;
    53.                
    54.                 float4 frag(v2f i) : COLOR {
    55.                     float4 texcol = tex2D(_MainTex, i.uv);
    56.                     texcol *= _Color;
    57.                     texcol.rgb += i.color;
    58.                     return texcol;
    59.                 }
    60.                
    61.             ENDCG
    62.         }
    63.     }
    64. }
    any idea how to make this run on iphone?

    cheers
     
  5. DrFromTheLab

    DrFromTheLab

    Joined:
    May 21, 2009
    Posts:
    108
    or let me ask the other way - can I fake this with any of the standard unity shader ???

    hope you can help me :) thanks
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Like Aras said, just add an extra directional light that only affects your main character. Attach it to the camera so that it is always coming from the right. From the look of the screen shot, they have a slightly darker, slightly bluer light coming from the left, too.