Search Unity

convert Surface Shader to Fragment Shader

Discussion in 'Scripting' started by namba02250, May 28, 2015.

  1. namba02250

    namba02250

    Joined:
    Feb 6, 2015
    Posts:
    19
    heeeey, guys, i need some help! pleasee can some one help me, i need this surface shader written as a fragment shader, or a shader for doing chroma

    Code (csharp):
    1.  
    2. Shader "Unlit/Transparent Chroma" {
    3.         Properties {
    4.                 _MainTex ("Base (RGB)", 2D) = "white" {}
    5.                 _MaskCol ("Mask Color", Color)  = (1.0, 0.0, 0.0, 1.0)
    6.                 _Sensitivity ("Threshold Sensitivity", Range(0,1)) = 0.5
    7.                 _Smooth ("Smoothing", Range(0,1)) = 0.5
    8.         }
    9.         SubShader {
    10.                 Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    11.                 LOD 100
    12.                 ZTest Always Cull Back ZWrite On Lighting Off Fog { Mode off }
    13.                 CGPROGRAM
    14.                 #pragma surface surf Lambert alpha
    15.  
    16.                 struct Input {
    17.                     float2 uv_MainTex;
    18.                 };
    19.  
    20.                 sampler2D _MainTex;
    21.                 float4 _MaskCol;
    22.                 float _Sensitivity;
    23.                 float _Smooth;
    24.  
    25.                 void surf (Input IN, inout SurfaceOutput o) {
    26.                         half4 c = tex2D (_MainTex, IN.uv_MainTex);
    27.  
    28.                         float maskY = 0.2989 * _MaskCol.r + 0.5866 * _MaskCol.g + 0.1145 * _MaskCol.b;
    29.                         float maskCr = 0.7132 * (_MaskCol.r - maskY);
    30.                         float maskCb = 0.5647 * (_MaskCol.b - maskY);
    31.  
    32.                         float Y = 0.2989 * c.r + 0.5866 * c.g + 0.1145 * c.b;
    33.                         float Cr = 0.7132 * (c.r - Y);
    34.                         float Cb = 0.5647 * (c.b - Y);
    35.  
    36.                         float blendValue = smoothstep(_Sensitivity, _Sensitivity + _Smooth, distance(float2(Cr, Cb), float2(maskCr, maskCb)));
    37.                         o.Alpha = 1.0 * blendValue;
    38.                         o.Emission = c.rgb * blendValue;            
    39.                 }
    40.                 ENDCG
    41.         }
    42.         FallBack "Diffuse"  
    43. }
    44.