Skip to content

Instantly share code, notes, and snippets.

@runewake2
Created July 22, 2017 04:23
Show Gist options
  • Save runewake2/2ffbf5a6f6a7298c8013ed5ecea54d9b to your computer and use it in GitHub Desktop.
Save runewake2/2ffbf5a6f6a7298c8013ed5ecea54d9b to your computer and use it in GitHub Desktop.
World of Zero Tiling Triplanar Shader
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
Shader "Custom/TriplanarWorldShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_WallTexture("Wall Normal", 2D) = "bump" {}
_CeilingTexture("Ceiling Normal", 2D) = "bump" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _WallTexture;
sampler2D _CeilingTexture;
struct Input {
float3 worldPos;
float3 worldNormal;
INTERNAL_DATA
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_CBUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_CBUFFER_END
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed3 normal = abs(WorldNormalVector(IN, float3(0, 0, 1)));
fixed3 wallNormal = float3(0, 0, 1);
if (normal.x > normal.y && normal.x > normal.z) {
wallNormal = UnpackNormal(tex2D(_WallTexture, float2(IN.worldPos.y, IN.worldPos.z)));
} else if (normal.y > normal.x && normal.y > normal.z) {
wallNormal = UnpackNormal(tex2D(_WallTexture, float2(IN.worldPos.x, IN.worldPos.z)));
} else {
wallNormal = UnpackNormal(tex2D(_CeilingTexture, float2(IN.worldPos.x, IN.worldPos.y)));
}
o.Albedo = normal;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Normal = wallNormal;
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment