Anisotropic 2.x

From Unify Community Wiki
Jump to: navigation, search



Anisotropic 2.x is the modified upgrade to the previous shader posted by Aras Pranckevicius here. This shader has been tested with Unity 2.6. Upgraded by: Nick Davis


Default Unity scene light with anisotropic lighting applied Dual spotlight illumination with anisotropic lighting applied

Copper Lookup Example Material

Anisotropic copper lookup example material


  • Create a shader, rename it to anistropic and paste the following shader code.
  • Create a new material and select "Anisotropic" from the drop down list.
  • Apply your default diffuse texture to the Base(RGB) property
  • Apply the Anisotropic copper lookup material to the Aniso lookup property.
  • Apply the material to a game object.

Anisotropic 2.x

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 "Anisotropic" { 

Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _AnisoTex ("Aniso lookup (RGBA)", 2D) = "white" {}

Category {
    Lod 0
    Blend AppSrcAdd AppDstAdd
    Fog { Color [_AddFog] }
    SubShader {
        // Ambient pass
        Pass {
            Name "BASE"
            Tags {"LightMode" = "PixelOrNone"}
            Color [_PPLAmbient]
            // Make it respond less to ambient color just to make it look better - no DOUBLE part here
            SetTexture [_MainTex] {constantColor [_Color] Combine texture * primary, texture * constant}
        // Vertex lights
        Pass { 
            Name "BASE"
            Tags {"LightMode" = "Vertex"}
            Lighting On
            Material {
                Diffuse [_Color]
                Emission [_PPLAmbient]
            SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
        // Pixel lights
        Pass {
            Name "PPL"
            Tags { "LightMode" = "Pixel" }
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin  

#include "UnityCG.cginc" 
#include "AutoLight.cginc" 

struct v2f {
    float2 uv[2];
v2f vert (appdata_base v) {
    v2f o;
    PositionFog( v.vertex, o.pos, o.fog );
    o.uv[0] = TRANSFORM_UV(0);
    float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    float3 lightDir = normalize(ObjSpaceLightDir(v.vertex));
    float3 halfAngle = normalize(viewDir + lightDir);
    o.uv[1].x = dot(lightDir,v.normal);
    o.uv[1].y = dot(halfAngle,v.normal);

    return o;

sampler2D _MainTex;
sampler2D _AnisoTex;

float4 frag (v2f i) : COLOR
    float4 texcol = tex2D( _MainTex, i.uv[0]);
    float4 aniso = tex2D( _AnisoTex, i.uv[1] );
    texcol.rgb *= _ModelLightColor0.rgb;
    texcol.rgb *= aniso.rgb * (aniso.a * LIGHT_ATTENUATION(i) * 2);
    return float4( texcol.rgb, 0 );


            SetTexture[_MainTex] {}
            SetTexture[_AnisoTex] {}
            SetTexture [_LightTexture0] {}
            SetTexture [_LightTextureB0] {}

Fallback " VertexLit", 1 

Personal tools