Advertisement
SebastianLague

Triplanar shader

Apr 8th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Shader "Custom/Triplanar" {
  2. Properties {
  3. colour("Texture", 2D) = "white"{}
  4. scale("Scale", Float) = 1
  5.  
  6. }
  7. SubShader {
  8. Tags { "RenderType"="Opaque" }
  9. LOD 200
  10.  
  11. CGPROGRAM
  12. // Physically based Standard lighting model, and enable shadows on all light types
  13. #pragma surface surf Standard fullforwardshadows
  14.  
  15. // Use shader model 3.0 target, to get nicer looking lighting
  16. #pragma target 3.0
  17.  
  18.  
  19. sampler2D colour;
  20. float scale;
  21.  
  22. struct Input {
  23. float3 worldPos;
  24. float3 worldNormal;
  25. };
  26.  
  27.  
  28. float3 triplanar(float3 scaledWorldPos, float3 blendAxes) {
  29. float3 xProjection = tex2D(colour, scaledWorldPos.yz) * blendAxes.x;
  30. float3 yProjection = tex2D(colour, scaledWorldPos.xz) * blendAxes.y;
  31. float3 zProjection = tex2D(colour, scaledWorldPos.xy) * blendAxes.z;
  32. return xProjection + yProjection + zProjection;
  33. }
  34.  
  35. void surf (Input IN, inout SurfaceOutputStandard o) {
  36. float3 blendAxes = abs(IN.worldNormal);
  37. blendAxes /= blendAxes.x + blendAxes.y + blendAxes.z;
  38.  
  39. o.Albedo = triplanar(IN.worldPos/scale, blendAxes);
  40.  
  41.  
  42. }
  43.  
  44. ENDCG
  45. }
  46. FallBack "Diffuse"
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement