Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. Shader "Tri-Planar World" {
  2. Properties {
  3. _Tint("Tint", Color) = (1, 1, 1, 1)
  4. _Atlas("Atlas 3D", 3D) = "clear" {}
  5. _Bump("Bump Atlas 3D", 3D) = "clear" {}
  6. _BumpMultX ("Bump Multiplier X", range(-0.3,0.3)) = 0
  7. _BumpMultY ("Bump Multiplier Y", range(-0.3,0.3)) = 0
  8. _BumpMultZ ("Bump Multiplier Z", range(-0.3,0.3)) = 0
  9.  
  10. }
  11.  
  12. SubShader {
  13. Tags {
  14. "Queue"="Geometry"
  15. "IgnoreProjector"="False"
  16. "RenderType"="Opaque"
  17. }
  18.  
  19. Cull Back
  20. ZWrite On
  21.  
  22.  
  23. CGPROGRAM
  24. #pragma target 3.0
  25. #pragma surface surf Lambert vertex:vert fullforwardshadows
  26. #pragma exclude_renderers flash
  27. #pragma debug
  28.  
  29. #include "UnityCG.cginc"
  30.  
  31. sampler3D _Atlas, _Bump;
  32. float4 _Tint;
  33. float _BumpMultX, _BumpMultY, _BumpMultZ;
  34.  
  35. struct Input {
  36. float3 worldNormal;
  37. float4 color;
  38. };
  39.  
  40. void vert(inout appdata_full v, out Input o){
  41. UNITY_INITIALIZE_OUTPUT (Input, o);
  42. o.color = v.color;
  43. o.color.r = v.vertex.z + 0.5f;
  44. o.color.g = v.vertex.x + 0.5f;
  45. o.color.b = v.vertex.y + 0.5f;
  46. }
  47.  
  48.  
  49. void surf (Input IN, inout SurfaceOutput o) {
  50. float3 projNormal = saturate(pow(IN.worldNormal * 1.4, 4));
  51.  
  52. // SIDE X
  53. float3 x = tex3D(_Atlas, IN.color.rba) * abs(IN.worldNormal.x);
  54. float3 xb = tex3D(_Bump, IN.color.rba) * abs(IN.worldNormal.x);
  55.  
  56. // TOP / BOTTOM
  57. float3 y = 0;
  58. float3 yb = 0;
  59. if (IN.worldNormal.y > 0) {
  60. y = tex3D(_Atlas, IN.color.rga) * abs(IN.worldNormal.y);
  61. yb = tex3D(_Bump, IN.color.rga) * abs(IN.worldNormal.y);
  62. } else {
  63. y = tex3D(_Atlas, IN.color.rga) * abs(IN.worldNormal.y);
  64. yb = tex3D(_Bump, IN.color.rga) * abs(IN.worldNormal.y);
  65. }
  66.  
  67. // SIDE Z
  68. float3 z = tex3D(_Atlas, IN.color.gba) * abs(IN.worldNormal.z);
  69. float3 zb = tex3D(_Bump, IN.color.gba) * abs(IN.worldNormal.z);
  70.  
  71. o.Albedo = _Tint * lerp(o.Albedo, z * lerp(z,zb,_BumpMultZ), projNormal.z);
  72. o.Albedo = _Tint * lerp(o.Albedo, x * lerp(x,xb,_BumpMultX), projNormal.x);
  73. o.Albedo = _Tint * lerp(o.Albedo, y * lerp(y,yb,_BumpMultY), projNormal.y);
  74.  
  75.  
  76. }
  77. ENDCG
  78. }
  79. Fallback "Diffuse"
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement