VertexColorParallaxBump
Author: Aras Pranckevicius
Description
Just like the builtin ParallaxBump/Diffuse one, only this one takes per-vertex colors into account as well.
Works on vertex/fragment program capable hardware (Radeon 9500, GeForceFX, Intel 9xx).
ShaderLab - VertexColorParallaxBump.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 "ParallaxBump/Diffuse VertexColor" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_Parallax ("Height", Range (0.005, 0.08)) = 0.02
_MainTex ("Base (RGB)", 2D) = "white" {}
_BumpMap ("Bumpmap (RGB) Height (A)", 2D) = "bump" {}
}
Category {
Blend AppSrcAdd AppDstAdd
Fog { Color [_AddFog] }
// ------------------------------------------------------------------
// ARB fragment program
SubShader {
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "PixelOrNone"}
BindChannels {
Bind "Vertex", vertex
Bind "Normal", normal
Bind "TexCoord", texcoord
Bind "Color", color
}
SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary, texture * constant}
SetTexture [_MainTex] {constantColor [_PPLAmbient] Combine previous * constant DOUBLE, previous}
}
// Vertex lights
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
Lighting On
Material {
Diffuse [_Color]
}
BindChannels {
Bind "Vertex", vertex
Bind "Normal", normal
Bind "TexCoord", texcoord
Bind "Color", color
}
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary, texture * constant}
SetTexture [_MainTex] {constantColor [_Color] Combine previous * constant DOUBLE, previous}
}
// Pixel lights
Pass {
Name "PPL"
Tags {
"LightMode" = "Pixel"
"LightTexCount" = "012"
}
CGPROGRAM
// profiles arbfp1
// fragment frag
// vertex vert
// 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 viewDirT : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float3 lightDirT : TEXCOORD3;
float4 color : COLOR0;
V2F_LIGHT_COORDS(TEXCOORD4);
};
struct v2f2 {
V2F_POS_FOG;
float2 uv : TEXCOORD0;
float3 viewDirT : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float3 lightDirT : TEXCOORD3;
float4 color : COLOR0;
};
struct appdata_tan_color {
float4 vertex;
float4 tangent;
float3 normal;
float4 texcoord;
float4 color;
};
v2f vert (appdata_tan_color v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_UV(1);
o.uv2 = TRANSFORM_UV(0);
o.color = v.color;
TANGENT_SPACE_ROTATION;
o.lightDirT = mul( rotation, ObjSpaceLightDir( v.vertex ) );
o.viewDirT = mul( rotation, ObjSpaceViewDir( v.vertex ) );
PASS_LIGHT_COORDS(2);
return o;
}
uniform sampler2D _BumpMap : register(s0);
uniform sampler2D _MainTex : register(s1);
uniform float _Parallax;
float4 frag (v2f2 i, LIGHTDECL(TEXUNIT2)) : COLOR
{
half h = tex2D( _BumpMap, i.uv2 ).w;
float2 offset = ParallaxOffset( h, _Parallax, i.viewDirT );
i.uv += offset;
i.uv2 += offset;
// get normal from the normal map
half3 normal = tex2D(_BumpMap, i.uv2).xyz * 2 - 1;
half4 texcol = tex2D(_MainTex,i.uv);
texcol *= i.color;
return DiffuseLight( i.lightDirT, normal, texcol, LIGHTATT );
}
ENDCG
SetTexture [_BumpMap] {combine texture}
SetTexture [_MainTex] {combine texture}
SetTexture [_LightTexture0] {combine texture}
SetTexture [_LightTextureB0] {combine texture}
}
}
}
FallBack " Bumped", 1
}