DesaturatedDarks
Author: Aras Pranckevicius
Description
This shader desaturates unlit areas (whereas in traditional shaders unlit areas are black, with this one they are only grayscale). This is a pixel lit shader.
This shader requires a fragment program card to work (GeForce FX and up, Radeon 9500 and up, Intel 9xx and up). On older cards it will fallback to Diffuse.
ShaderLab - DesaturatedDarks.shader
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic
Shader "Desaturated Darks" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Darkening ("Darkening", Range (0,1)) = 0.5
}
Category {
Blend AppSrcAdd AppDstAdd
Fog { Color [_AddFog] }
SubShader {
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "PixelOrNone"}
CGPROGRAM
// profiles arbfp1
// fragment frag
// fragmentoption ARB_fog_exp2
// fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _Darkening;
uniform float4 _Color;
half4 frag( v2f_vertex_lit i ) : COLOR
{
// texture
half4 texcol = tex2D( _MainTex, i.uv ) * _Color;
half unlit = Luminance( texcol.xyz ) * (1.0 - _Darkening);
texcol.xyz = unlit;
return texcol;
}
ENDCG
SetTexture [_MainTex] {}
}
// Vertex lit pass
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
Material {
Diffuse [_Color]
Ambient (0,0,0,0)
}
Lighting On
CGPROGRAM
// profiles arbfp1
// fragment frag
// fragmentoption ARB_fog_exp2
// fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _Darkening;
uniform float4 _Color;
half4 frag( v2f_vertex_lit i ) : COLOR
{
// texture
half4 texcol = tex2D( _MainTex, i.uv );
// intensity of the lighting
half brightness = saturate(Luminance( i.diff.xyz ) * 2);
// color of completely unlit & desaturated areas
half unlit = Luminance(
lerp( texcol.xyz, texcol.xyz * i.diff.xyz, _Darkening ) );
// final color based on lighting intensity
half4 c;
c.xyz = lerp( half3(unlit), texcol.xyz * i.diff.xyz * 2.0, brightness );
c.w = texcol.w * i.diff.w;
return c;
}
ENDCG
SetTexture [_MainTex] {}
}
// Pixel lit pass
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
// This lighting is not additive, instead it must
// blend over existing grayscale into saturated.
// So we output light's intensity into alpha
// and blend.
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
CGPROGRAM
// profiles arbfp1
// vertex vert
// fragment frag
// autolight 7
// fragmentoption ARB_fog_exp2
// fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 normal : TEXCOORD1;
float3 lightDir : TEXCOORD2;
V2F_LIGHT_COORDS(TEXCOORD3);
};
struct v2f2 {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 normal : TEXCOORD1;
float3 lightDir : TEXCOORD2;
};
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.normal = v.normal;
o.uv = TRANSFORM_UV(0);
o.lightDir = ObjSpaceLightDir( v.vertex );
PASS_LIGHT_COORDS(1);
return o;
}
uniform sampler2D _MainTex : register(s0);
uniform float _Darkening;
uniform float4 _Color;
half4 frag( v2f2 i, LIGHTDECL(TEXUNIT1) ) : COLOR
{
// texture
half4 texcol = tex2D( _MainTex, i.uv );
// intensity of the lighting
half brightness = Luminance( DiffuseLight( i.lightDir, i.normal, _ModelLightColor[0], LIGHTATT ).rgb );
half4 c;
c.rgb = texcol.rgb * _ModelLightColor[0].rgb;
c.a = brightness;
return c;
}
ENDCG
SetTexture [_MainTex] {}
SetTexture [_LightTexture0] {}
SetTexture [_LightTextureB0] {}
}
}
}
Fallback " Diffuse", 1
}