TerrainFourLayer2Pass

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<shaderlab>" to "<syntaxhighlight lang="shaderlab">")
m (Text replace - "</shaderlab>" to "</syntaxhighlight>")
 
Line 104: Line 104:
 
         }
 
         }
 
     }
 
     }
}</shaderlab>
+
}</syntaxhighlight>

Latest revision as of 23:56, 17 January 2012

Author: Eric Haines (Eric5h5) - Based on the TerrainFourLayer shader

[edit] Description

This is similar to the above referenced shader, with these differences: 1) It should work properly on all graphics cards from the 5200FX and later 2) It has fog 3) It uses 2 passes, so it's slower 4) It has a _Base texture, which is used as a fallback for really old cards like the Radeon 8500 and older. This should be like the mixing mask, but with colors, so you can at least get a flat-shaded version of the texture colors...otherwise you'd just get a single texture which wouldn't be representative of the mixed texture at all. If you don't care about old cards like that, then you can skip it.

[edit] Usage

Place this shader somewhere in your Assets folder hierarchy, create a material which uses it and apply it to the relevant objects.

[edit] ShaderLab - FourLayerVertexLit2Pass.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 "Terrain/Four Layer VertexLit 2Pass" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Color 1 (RGB)", 2D) = "white" {}
    _MainTex2 ("Color 2 (RGB)", 2D) = "white" {}
    _MainTex3 ("Color 3 (RGB)", 2D) = "white" {}
    _MainTex4 ("Color 4 (RGB)", 2D) = "white" {}
    _Mask ("Mixing Mask (RGBA)", 2D) = "gray" {}
    _Base ("Base Color (RGB)", 2D) = "white" {}
}
Category {
    Lighting On
    Cull Back
    Fog { Color [_AddFog] }
    Subshader {
        Material {
            Diffuse [_Color]
            Ambient [_Color]
        }
        
        Pass {
CGPROGRAM
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
 
sampler2D _MainTex;
sampler2D _MainTex2;
sampler2D _MainTex3;
sampler2D _Mask;
 
struct v2f {
    V2F_POS_FOG;
    float4 uv[4] : TEXCOORD0;
    float4 diffuse : COLOR;
};
 
half4 frag( v2f i ) : COLOR
{
    // get the first three layer colors
    half4 color1 = tex2D( _MainTex, i.uv[0].xy );
    half4 color2 = tex2D( _MainTex2, i.uv[1].xy );
    half4 color3 = tex2D( _MainTex3, i.uv[2].xy );
    // get the mixing mask texture
    half4 mask = tex2D( _Mask, i.uv[3].xy );
    // mix the three layers
    half4 color = color1 * mask.r + color2 * mask.g + color3 * mask.b;
    // multiply and double by the lighting
    return color * i.diffuse * 2.0;
}
ENDCG
        }
        
        Pass {
            Blend One One
CGPROGRAM
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#include "UnityCG.cginc"
 
sampler2D _MainTex4;
sampler2D _Mask;
 
struct v2f {
    V2F_POS_FOG;
    float4 uv[2] : TEXCOORD0;
    float4 diffuse : COLOR;
};
 
half4 frag( v2f i ) : COLOR
{
    // Finish the last texture mix in the second pass...some cards don't have enough registers to do it in one pass
    half4 color1 = tex2D( _MainTex4, i.uv[0].xy );
    half4 mask = tex2D( _Mask, i.uv[1].xy );
    half4 color = color1 * mask.a;
    return color * i.diffuse * 2.0;
}
ENDCG        
        }
    }
} 
    // ------------------------------------------------------------------
    // Radeon 7000 / 9000
    
    SubShader {
        Pass {
            Material {
                Diffuse [_Color]
                Ambient [_Color]
            } 
            Lighting On
            SetTexture [_Base] {
                Combine texture * primary DOUBLE, texture * primary
            }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox