Winz00e (ver 6.0)
Would you like to react to this message? Create an account in a few clicks or log in to continue.

RGB Color Swap and Grayscale Shader (Unity Engine)

Go down

RGB Color Swap and Grayscale Shader (Unity Engine) Empty RGB Color Swap and Grayscale Shader (Unity Engine)

Post by InfinitasImpetum Fri Jan 02, 2015 4:10 pm

Color swap shader
Code:
Shader "Custom/ColorSwap" {
   Properties {
      _MainTex ("Base (RGB)", 2D) = "white" {}
      _Color1 ("Base Color", Color) = (1,1,1,1)
      _Color2 ("Color2", Color) = (1,1,1,1)
      _Color3 ("Color3", Color) = (1,1,1,1)
      _Color4 ("Color4", Color) = (1,1,1,1)
      
   }
   SubShader {
      Tags { "RenderType"="Opaque" }
      LOD 200
      
      CGPROGRAM
      #pragma surface surf Lambert

      sampler2D _MainTex;
      
      float4 _Color1,_Color2,_Color3,_Color4;
      
      
      struct Input {
         float2 uv_MainTex;
         
      };

      void surf (Input IN, inout SurfaceOutput o) {
         half4 c = tex2D (_MainTex, IN.uv_MainTex);
         
         if (c.r >= .1 && c.g >= .1 && c.b >= .1) c = _Color1;
         else if (c.r >= .1) c = _Color2;
         else if (c.g >= .1) c = _Color3;
         else if (c.b >= .1) c = _Color4;
         
         o.Albedo = c.rgb;
         o.Alpha = c.a;
         
      }
      ENDCG
   } 
   
}

replaces white with color 1, red with color 2, green with color 3, and blue with color 4. 

Grayscale shader
was easy to write but i did it for fun. takes in an texture and grayscale it.

RGB Color Swap and Grayscale Shader (Unity Engine) 10620651_349967475169633_3618684398180492157_n

Code:

Shader "Custom/Grayscale" {
   Properties {
      _MainTex ("Base (RGB)", 2D) = "white" {}
   }
   SubShader {
      Tags { "RenderType"="Opaque" }
      LOD 200
      
      CGPROGRAM
      #pragma surface surf Lambert

      sampler2D _MainTex;

      struct Input {
         float2 uv_MainTex;
      };

      void surf (Input IN, inout SurfaceOutput o) {
         half4 c = tex2D (_MainTex, IN.uv_MainTex);
         half4 f = c;
         f.r = (c.r + c.g + c.b) / 3;
         f.g = f.r;
         f.b = f.r;
         c = f;
         o.Albedo = c.rgb;
         o.Alpha = c.a;
      }
      ENDCG
   } 
   FallBack "Diffuse"
}
InfinitasImpetum
InfinitasImpetum
(0%)-Lv8
(0%)-Lv8

Posts : 2162
Join date : 2012-05-30
Age : 34

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum