Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Tri-Planar World" {
- Properties {
- _Tint("Tint", Color) = (1, 1, 1, 1)
- _Atlas("Atlas 3D", 3D) = "clear" {}
- _Bump("Bump Atlas 3D", 3D) = "clear" {}
- _BumpMultX ("Bump Multiplier X", range(-0.3,0.3)) = 0
- _BumpMultY ("Bump Multiplier Y", range(-0.3,0.3)) = 0
- _BumpMultZ ("Bump Multiplier Z", range(-0.3,0.3)) = 0
- }
- SubShader {
- Tags {
- "Queue"="Geometry"
- "IgnoreProjector"="False"
- "RenderType"="Opaque"
- }
- Cull Back
- ZWrite On
- CGPROGRAM
- #pragma target 3.0
- #pragma surface surf Lambert vertex:vert fullforwardshadows
- #pragma exclude_renderers flash
- #pragma debug
- #include "UnityCG.cginc"
- sampler3D _Atlas, _Bump;
- float4 _Tint;
- float _BumpMultX, _BumpMultY, _BumpMultZ;
- struct Input {
- float3 worldNormal;
- float4 color;
- };
- void vert(inout appdata_full v, out Input o){
- UNITY_INITIALIZE_OUTPUT (Input, o);
- o.color = v.color;
- o.color.r = v.vertex.z + 0.5f;
- o.color.g = v.vertex.x + 0.5f;
- o.color.b = v.vertex.y + 0.5f;
- }
- void surf (Input IN, inout SurfaceOutput o) {
- float3 projNormal = saturate(pow(IN.worldNormal * 1.4, 4));
- // SIDE X
- float3 x = tex3D(_Atlas, IN.color.rba) * abs(IN.worldNormal.x);
- float3 xb = tex3D(_Bump, IN.color.rba) * abs(IN.worldNormal.x);
- // TOP / BOTTOM
- float3 y = 0;
- float3 yb = 0;
- if (IN.worldNormal.y > 0) {
- y = tex3D(_Atlas, IN.color.rga) * abs(IN.worldNormal.y);
- yb = tex3D(_Bump, IN.color.rga) * abs(IN.worldNormal.y);
- } else {
- y = tex3D(_Atlas, IN.color.rga) * abs(IN.worldNormal.y);
- yb = tex3D(_Bump, IN.color.rga) * abs(IN.worldNormal.y);
- }
- // SIDE Z
- float3 z = tex3D(_Atlas, IN.color.gba) * abs(IN.worldNormal.z);
- float3 zb = tex3D(_Bump, IN.color.gba) * abs(IN.worldNormal.z);
- o.Albedo = _Tint * lerp(o.Albedo, z * lerp(z,zb,_BumpMultZ), projNormal.z);
- o.Albedo = _Tint * lerp(o.Albedo, x * lerp(x,xb,_BumpMultX), projNormal.x);
- o.Albedo = _Tint * lerp(o.Albedo, y * lerp(y,yb,_BumpMultY), projNormal.y);
- }
- ENDCG
- }
- Fallback "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement