Created
February 14, 2014 04:33
-
-
Save bcatcho/8995855 to your computer and use it in GitHub Desktop.
World Tiling example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shader created with Shader Forge Beta 0.23 | |
// Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/ | |
// Note: Manually altering this data may prevent you from opening it in Shader Forge | |
/*SF_DATA;ver:0.23;sub:START;pass:START;ps:lgpr:1,nrmq:1,limd:1,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,uamb:True,mssp:True,ufog:True,aust:True,igpj:False,qofs:0,lico:1,qpre:1,flbk:,rntp:1,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,hqsc:True,hqlp:False,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.7098039,fgcg:0.7098039,fgcb:0.7098039,fgca:1,fgde:0.01,fgrn:41.4,fgrf:400,ofsf:0,ofsu:0;n:type:ShaderForge.SFN_Final,id:1,x:32411,y:32654|diff-3-RGB,amdfl-12-RGB;n:type:ShaderForge.SFN_Tex2dAsset,id:2,x:33131,y:32604,ptlb:node_2,tex:8993b617f08498f43adcbd90697f1c5d;n:type:ShaderForge.SFN_Tex2d,id:3,x:32767,y:32694,tex:8993b617f08498f43adcbd90697f1c5d,ntxv:0,isnm:False|UVIN-23-OUT,TEX-2-TEX;n:type:ShaderForge.SFN_FragmentPosition,id:11,x:33302,y:32976;n:type:ShaderForge.SFN_AmbientLight,id:12,x:32764,y:32983;n:type:ShaderForge.SFN_Append,id:23,x:33055,y:32992|A-11-X,B-11-Z;proporder:2;pass:END;sub:END;*/ | |
Shader "Shader Forge/worldspacetiling" { | |
Properties { | |
_node2 ("node_2", 2D) = "white" {} | |
} | |
SubShader { | |
Tags { | |
"RenderType"="Opaque" | |
} | |
Pass { | |
Name "ForwardBase" | |
Tags { | |
"LightMode"="ForwardBase" | |
} | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_FORWARDBASE | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
#pragma multi_compile_fwdbase_fullshadows | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform float4 _LightColor0; | |
uniform sampler2D _node2; uniform float4 _node2_ST; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float4 posWorld : TEXCOORD0; | |
float3 normalDir : TEXCOORD1; | |
LIGHTING_COORDS(2,3) | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz; | |
o.posWorld = mul(_Object2World, v.vertex); | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
TRANSFER_VERTEX_TO_FRAGMENT(o) | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
/////// Normals: | |
float3 normalDirection = i.normalDir; | |
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); | |
////// Lighting: | |
float attenuation = LIGHT_ATTENUATION(i); | |
float3 attenColor = attenuation * _LightColor0.xyz; | |
/////// Diffuse: | |
float NdotL = dot( normalDirection, lightDirection ); | |
float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.xyz; | |
float3 finalColor = 0; | |
float3 diffuseLight = diffuse; | |
diffuseLight += UNITY_LIGHTMODEL_AMBIENT.rgb; // Diffuse Ambient Light | |
float4 node_11 = i.posWorld; | |
float2 node_23 = float2(node_11.r,node_11.b); | |
finalColor += diffuseLight * tex2D(_node2,TRANSFORM_TEX(node_23, _node2)).rgb; | |
/// Final Color: | |
return fixed4(finalColor,1); | |
} | |
ENDCG | |
} | |
Pass { | |
Name "ForwardAdd" | |
Tags { | |
"LightMode"="ForwardAdd" | |
} | |
Blend One One | |
Fog { Color (0,0,0,0) } | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#define UNITY_PASS_FORWARDADD | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
#pragma multi_compile_fwdadd_fullshadows | |
#pragma exclude_renderers xbox360 ps3 flash | |
#pragma target 3.0 | |
uniform float4 _LightColor0; | |
uniform sampler2D _node2; uniform float4 _node2_ST; | |
struct VertexInput { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
}; | |
struct VertexOutput { | |
float4 pos : SV_POSITION; | |
float4 posWorld : TEXCOORD0; | |
float3 normalDir : TEXCOORD1; | |
LIGHTING_COORDS(2,3) | |
}; | |
VertexOutput vert (VertexInput v) { | |
VertexOutput o; | |
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz; | |
o.posWorld = mul(_Object2World, v.vertex); | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
TRANSFER_VERTEX_TO_FRAGMENT(o) | |
return o; | |
} | |
fixed4 frag(VertexOutput i) : COLOR { | |
i.normalDir = normalize(i.normalDir); | |
/////// Normals: | |
float3 normalDirection = i.normalDir; | |
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); | |
////// Lighting: | |
float attenuation = LIGHT_ATTENUATION(i); | |
float3 attenColor = attenuation * _LightColor0.xyz; | |
/////// Diffuse: | |
float NdotL = dot( normalDirection, lightDirection ); | |
float3 diffuse = max( 0.0, NdotL) * attenColor; | |
float3 finalColor = 0; | |
float3 diffuseLight = diffuse; | |
float4 node_11 = i.posWorld; | |
float2 node_23 = float2(node_11.r,node_11.b); | |
finalColor += diffuseLight * tex2D(_node2,TRANSFORM_TEX(node_23, _node2)).rgb; | |
/// Final Color: | |
return fixed4(finalColor * 1,0); | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
CustomEditor "ShaderForgeMaterialInspector" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment