RGB Color Swap and Grayscale Shader (Unity Engine)

Post new topic   Reply to topic

View previous topic View next topic Go down

RGB Color Swap and Grayscale Shader (Unity Engine)

Post by InfinitasImpetum on 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.



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
(0%)-Lv8
(0%)-Lv8

Posts : 2160
Join date : 2012-05-30
Age : 27

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Post new topic   Reply to topic
 
Permissions in this forum:
You can reply to topics in this forum