Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Shader "TriplanarTutorial/Triplanar_Final"
  2. {
  3. Properties
  4. {
  5. _DiffuseMap ("Diffuse Map ", 2D) = "white" {}
  6. _TextureScale ("Texture Scale",float) = 1
  7. _TriplanarBlendSharpness ("Blend Sharpness",float) = 1
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType"="Opaque" }
  12. LOD 200
  13.  
  14. CGPROGRAM
  15. #pragma target 3.0
  16. #pragma surface surf Lambert
  17.  
  18. sampler2D _DiffuseMap;
  19. float _TextureScale;
  20. float _TriplanarBlendSharpness;
  21.  
  22. struct Input
  23. {
  24. float3 worldPos;
  25. float3 worldNormal;
  26. };
  27.  
  28. void surf (Input IN, inout SurfaceOutput o)
  29. {
  30. // Find our UVs for each axis based on world position of the fragment.
  31. half2 yUV = IN.worldPos.xz / _TextureScale;
  32. half2 xUV = IN.worldPos.zy / _TextureScale;
  33. half2 zUV = IN.worldPos.xy / _TextureScale;
  34. // Now do texture samples from our diffuse map with each of the 3 UV set's we've just made.
  35. half3 yDiff = tex2D (_DiffuseMap, yUV);
  36. half3 xDiff = tex2D (_DiffuseMap, xUV);
  37. half3 zDiff = tex2D (_DiffuseMap, zUV);
  38. // Get the absolute value of the world normal.
  39. // Put the blend weights to the power of BlendSharpness, the higher the value,
  40. // the sharper the transition between the planar maps will be.
  41. half3 blendWeights = pow (abs(IN.worldNormal), _TriplanarBlendSharpness);
  42. // Divide our blend mask by the sum of it's components, this will make x+y+z=1
  43. blendWeights = blendWeights / (blendWeights.x + blendWeights.y + blendWeights.z);
  44. // Finally, blend together all three samples based on the blend mask.
  45. o.Albedo = xDiff * blendWeights.x + yDiff * blendWeights.y + zDiff * blendWeights.z;
  46. }
  47. ENDCG
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement