fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
//max(R, G, B) + min(R, G, B)) / 2.
col = (max(max(col.r,col.g),col.b) + min(min(col.r,col.g),col.b))/2;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
right click your shader code >> create the material
your directory of your shader code
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
//average
//(R + G + B) / 3.
col = (col.r+col.g+col.b)/3;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
//0.21 R + 0.72 G + 0.07 B.
col = 0.21*col.r + 0.72*col.g + 0.07*col.b;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_threshold("threshold", Range(0,1)) = 0.5
}
sampler2D _MainTex;
float4 _MainTex_ST;
float _threshold;
add float _threshold;
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col = 0.21*col.r + 0.72*col.g + 0.07*col.b;
if(col.r>_threshold)
col = 1;
else
col = 0;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
Full code for threshold
Shader "Unlit/threshold"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_threshold("threshold", Range(0,1)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _threshold;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col = 0.21*col.r + 0.72*col.g + 0.07*col.b;
if(col.r>_threshold)
col = 1;
else
col = 0;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Shader "Unlit/brightness"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_brightness("Brightness",Range(-1,1))=0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _brightness;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col+=_brightness;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Shader "Unlit/brightness"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_brightness("Brightness",Range(-1,1))=0.1
_contrast("Contrast", Range(-5,5))=0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _brightness;
float _contrast;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col+=_brightness;
//new_value = (old_value - 0.5) × contrast + 0.5
col = (col-0.5)*_contrast+0.5;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Shader "Unlit/brightness"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_brightness("Brightness",Range(-1,1))=0.1
_contrast("Contrast", Range(-5,5))=0.5
[ToggleOff] _invert("Invert", Float) =0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _brightness;
float _contrast;
float _invert;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col+=_brightness;
//new_value = (old_value - 0.5) × contrast + 0.5
col = (col-0.5)*_contrast+0.5;
if(_invert==1)
{
col = 1- col;
}
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Shader "Unlit/gamma"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_gamma("Gamma", Range(-5,5)) = 0.5
_brightness("Brightness",Range(-1,1))=0.1
_contrast("Contrast", Range(-5,5))=0.5
[ToggleOff] _invert("Invert", Float) =0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _gamma;
float _brightness;
float _contrast;
float _invert;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
col+=_brightness;
//new_value = (old_value - 0.5) × contrast + 0.5
col = (col-0.5)*_contrast+0.5;
if(_invert==1)
{
col = 1- col;
}
col = pow(col,_gamma);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Shader "Unlit/CannyEdge"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Threshold ("Edge Threshold", Range(0, 1)) = 0.2
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize; // Unity provides 1/width,1/height
float _Threshold;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// Convert to grayscale
fixed3 tc = tex2D(_MainTex, i.uv).rgb;
float gray = dot(tc, float3(0.299, 0.587, 0.114));
// Sobel kernel offsets
float2 texel = _MainTex_TexelSize.xy;
float gx =
-1.0 * tex2D(_MainTex, i.uv + texel * float2(-1,-1)).r
+ -2.0 * tex2D(_MainTex, i.uv + texel * float2(-1, 0)).r
+ -1.0 * tex2D(_MainTex, i.uv + texel * float2(-1, 1)).r
+ 1.0 * tex2D(_MainTex, i.uv + texel * float2( 1,-1)).r
+ 2.0 * tex2D(_MainTex, i.uv + texel * float2( 1, 0)).r
+ 1.0 * tex2D(_MainTex, i.uv + texel * float2( 1, 1)).r;
float gy =
-1.0 * tex2D(_MainTex, i.uv + texel * float2(-1,-1)).r
+ -2.0 * tex2D(_MainTex, i.uv + texel * float2(0,-1)).r
+ -1.0 * tex2D(_MainTex, i.uv + texel * float2( 1,-1)).r
+ 1.0 * tex2D(_MainTex, i.uv + texel * float2(-1, 1)).r
+ 2.0 * tex2D(_MainTex, i.uv + texel * float2(0, 1)).r
+ 1.0 * tex2D(_MainTex, i.uv + texel * float2( 1, 1)).r;
float edgeStrength = sqrt(gx * gx + gy * gy);
// Threshold
float edge = edgeStrength > _Threshold ? 1.0 : 0.0;
return float4(edge.xxx, 1.0);
}
ENDCG
}
}
}
Shader "Unlit/WoodTexture"
{
Properties
{
_LightColor ("Light Wood Color", Color) = (0.8, 0.6, 0.3, 1)
_DarkColor ("Dark Wood Color", Color) = (0.4, 0.2, 0.05, 1)
_RingFrequency ("Ring Frequency", Range(1, 20)) = 8
_NoiseScale ("Noise Scale", Range(0, 10)) = 2
_Distortion ("Distortion", Range(0, 1)) = 0.3
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
float4 _LightColor;
float4 _DarkColor;
float _RingFrequency;
float _NoiseScale;
float _Distortion;
// Simple pseudo-random noise
float hash(float2 p)
{
return frac(sin(dot(p, float2(12.9898,78.233))) * 43758.5453);
}
float noise(float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
float a = hash(i);
float b = hash(i + float2(1,0));
float c = hash(i + float2(0,1));
float d = hash(i + float2(1,1));
float2 u = f*f*(3.0-2.0*f);
return lerp(lerp(a,b,u.x), lerp(c,d,u.x), u.y);
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv * 5; // scale uv for tiling
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// Convert uv to polar distance (like tree rings)
float2 pos = i.uv;
float dist = length(pos);
// Add noise-based distortion
float n = noise(pos * _NoiseScale);
dist += n * _Distortion;
// Create ring pattern
float rings = sin(dist * _RingFrequency * 3.14159);
// Map rings into 0-1
float t = smoothstep(-0.2, 0.2, rings);
// Lerp between light and dark colors
return lerp(_DarkColor, _LightColor, t);
}
ENDCG
}
}
}
Shader "Unlit/OldFilm"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_SepiaStrength ("Sepia Strength", Range(0,1)) = 0.8
_GrainStrength ("Grain Strength", Range(0,1)) = 0.2
_VignetteStrength ("Vignette Strength", Range(0,1)) = 0.5
_FlickerStrength ("Flicker Strength", Range(0,1)) = 0.1
_ScratchStrength ("Scratch Strength", Range(0,1)) = 0.2
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float _SepiaStrength;
float _GrainStrength;
float _VignetteStrength;
float _FlickerStrength;
float _ScratchStrength;
// Simple hash for random
float rand(float2 co)
{
return frac(sin(dot(co.xy ,float2(12.9898,78.233))) * 43758.5453);
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// 1. Sepia tone
// 1. Sepia tone
float gray = dot(col.rgb, float3(0.3, 0.59, 0.11)); // grayscale is a single float
float3 sepia = float3(gray * 1.2, gray, gray * 0.8); // expand into RGB
col.rgb = lerp(col.rgb, sepia, _SepiaStrength);
// 2. Film grain (random noise per-pixel, animated by _Time)
float grain = rand(i.uv * _Time.y) * _GrainStrength;
col.rgb += grain;
// 3. Flicker (simulate old film brightness jumps)
float flicker = (rand(float2(_Time.y, _Time.y * 2)) - 0.5) * _FlickerStrength;
col.rgb += flicker;
// 4. Vignette
float2 center = i.uv - 0.5;
float vignette = 1.0 - _VignetteStrength * length(center) * 1.5;
col.rgb *= vignette;
// 5. Vertical scratches (random lines over time)
float scratch = step(0.99, rand(float2(i.uv.y * 10, floor(_Time.y * 5)))) * _ScratchStrength;
col.rgb -= scratch;
return col;
}
ENDCG
}
}
}