3SideProjDiffuse1.1

From Unify Community Wiki
Jump to: navigation, search


Author: Nils Dauman. Additional work: WarpedAxiom.

Description

A model using this shader

An only slight modification to Nils Daumann's handy shader (who did 99% of the work and deserve as much credit), which adds control of what textures are projected onto the material. I'm sure there are plenty of times this could come in handy. The example image is only on possibility. With flatter terrain and sharper slopes, you could get a neat 2D RPG look.

Visit the original shader for more information about usage. 3SideProjDiffuse


ShaderLab - WorldTextureDiffuse.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 "World Texture Diffuse 1.1"
{
	Properties
	{
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex1("Texture", 2D) = "white" {}
		_MainTex2("Texture", 2D) = "white" {}
		_MainTex3("Texture", 2D) = "white" {}
		
		_TileFac("Tile factor", Float) = 5
	}
	
	SubShader
	{
		Pass {
			Name "BASE"
			Tags {"LightMode" = "None"}
			Blend AppSrcAdd AppDstAdd
			Fog { Color [_AddFog] }
			
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				
				#pragma multi_compile_builtin
				#pragma fragmentoption ARB_fog_exp2
				#pragma fragmentoption ARB_precision_hint_fastest
				
				#include "UnityCG.cginc"
				#include "AutoLight.cginc"
				
				uniform sampler2D _MainTex1;
				uniform sampler2D _MainTex2;
				uniform sampler2D _MainTex3;
				
				uniform float _TileFac;
				
				struct v2f
				{
					V2F_POS_FOG;
					float3 worldnormal;
					float3 worldpos;
				}; 

				v2f vert(appdata_base v)
				{
					v2f o;
					
					PositionFog( v.vertex, o.pos, o.fog );
					
					o.worldnormal = mul(_Object2World, float4(v.normal, 0.0f)).xyz;
					o.worldpos = mul(_Object2World, v.vertex);
					
					return o;
				}
			   
				float4 frag(v2f i) : COLOR
				{
					float2 s = float2(_TileFac, -_TileFac);
					
					float2 tex0 = i.worldpos.xy/s;
					float2 tex1 = i.worldpos.zx/s;
					float2 tex2 = i.worldpos.zy/s;
					
					float4 color0_ = tex2D(_MainTex1, tex0);
					float4 color1_ = tex2D(_MainTex2, tex1);
					float4 color2_ = tex2D(_MainTex3, tex2);
					
					i.worldnormal = normalize(i.worldnormal);
					float3 projnormal = saturate(pow(i.worldnormal*1.5, 4));
					
					float3 color = lerp(color1_, color0_, projnormal.z);
					color = lerp(color, color2_, projnormal.x);
					
					return float4(color.rgb*_PPLAmbient, 1.0);
				}
			ENDCG
		}
		Pass {
			Name "BASE"
			Tags {"LightMode" = "VertexOrPixel"}
			Blend AppSrcAdd AppDstAdd
			Fog { Color [_AddFog] }
			
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				
				#pragma multi_compile_builtin
				#pragma fragmentoption ARB_fog_exp2
				#pragma fragmentoption ARB_precision_hint_fastest
				
				#include "UnityCG.cginc"
				#include "AutoLight.cginc"
				
				uniform sampler2D _MainTex1;
				uniform sampler2D _MainTex2;
				uniform sampler2D _MainTex3;
				
				uniform float _TileFac;
				
				struct v2f
				{
					V2F_POS_FOG;
					float3 worldnormal;
					float3 worldpos;
				}; 

				v2f vert(appdata_base v)
				{
					v2f o;
					
					PositionFog( v.vertex, o.pos, o.fog );
					
					o.worldnormal = mul(_Object2World, float4(v.normal, 0.0f)).xyz;
					o.worldpos = mul(_Object2World, v.vertex);
					
					return o;
				}
			   
				float4 frag(v2f i) : COLOR
				{
					float2 s = float2(_TileFac, -_TileFac);
					
					float2 tex0 = i.worldpos.xy/s;
					float2 tex1 = i.worldpos.zx/s;
					float2 tex2 = i.worldpos.zy/s;
					
					float4 color0_ = tex2D(_MainTex1, tex0);
					float4 color1_ = tex2D(_MainTex2, tex1);
					float4 color2_ = tex2D(_MainTex3, tex2);
					
					i.worldnormal = normalize(i.worldnormal);
					float3 projnormal = saturate(pow(i.worldnormal*1.5, 4));
					
					float3 color = lerp(color1_, color0_, projnormal.z);
					color = lerp(color, color2_, projnormal.x);
					
					return float4(color.rgb*_PPLAmbient, 1.0);
				}
			ENDCG
		}
		Pass
		{
			Name "PPL"
			Tags { "LightMode" = "Pixel" }
			
			Blend AppSrcAdd AppDstAdd
			Fog { Color [_AddFog] }
		
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				
				#pragma multi_compile_builtin
				#pragma fragmentoption ARB_fog_exp2
				#pragma fragmentoption ARB_precision_hint_fastest
				
				#include "UnityCG.cginc"
				#include "AutoLight.cginc"
				
				uniform sampler2D _MainTex1;
				uniform sampler2D _MainTex2;
				uniform sampler2D _MainTex3;
								
				uniform float _TileFac;
				
				struct v2f
				{
					V2F_POS_FOG;
					LIGHTING_COORDS
					float3 normal;
					float3 worldnormal;
					float3 worldpos;
					float3 lightDir;
				}; 

				v2f vert(appdata_base v)
				{
					v2f o;
					
					PositionFog( v.vertex, o.pos, o.fog );
					o.normal = v.normal;
					
					o.worldnormal = mul(_Object2World, float4(v.normal, 0.0f)).xyz;
					o.worldpos = mul(_Object2World, v.vertex);
					
					o.lightDir = ObjSpaceLightDir(v.vertex);
					TRANSFER_VERTEX_TO_FRAGMENT(o);
					
					return o;
				}
			   
				float4 frag(v2f i) : COLOR
				{
					float2 s = float2(_TileFac, -_TileFac);
					
					float2 tex0 = i.worldpos.xy/s;
					float2 tex1 = i.worldpos.zx/s;
					float2 tex2 = i.worldpos.zy/s;
					
					float4 color0_ = tex2D(_MainTex1, tex0);
					float4 color1_ = tex2D(_MainTex2, tex1);
					float4 color2_ = tex2D(_MainTex3, tex2);
					
					i.normal = normalize(i.normal);
					
					i.worldnormal = normalize(i.worldnormal);
					float3 projnormal = saturate(pow(i.worldnormal*1.5, 4));
					
					float3 color = lerp(color1_, color0_, projnormal.z);
					color = lerp(color, color2_, projnormal.x);
					
					return DiffuseLight(i.lightDir, i.normal, float4(color.rgb, 1.0), LIGHT_ATTENUATION(i));
				}
			ENDCG
		}
	}
	
	FallBack "Diffuse"
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools