Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. Shader "Custom/Triplanar"
  2. {
  3. Properties
  4. {
  5. _HighlightedColor ("Circle Highlighed Color", Color) = (1,1,1,1)
  6. _NormalColor("Circle Color", Color) = (1,1,1,1)
  7. _WallTex ("Wall texture", 2D) = "white" {}
  8. _FloorTex ("Floor texture", 2D) = "white" {}
  9. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  10. _Metallic ("Metallic", Range(0,1)) = 0.0
  11. }
  12. SubShader
  13. {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 200
  16.  
  17. CGPROGRAM
  18. // Upgrade NOTE: excluded shader from DX11, OpenGL ES 2.0 because it uses unsized arrays
  19. #pragma exclude_renderers d3d11 gles
  20. // Physically based Standard lighting model, and enable shadows on all light types
  21. #pragma surface surf Standard fullforwardshadows
  22.  
  23. // Use shader model 3.0 target, to get nicer looking lighting
  24. #pragma target 3.0
  25.  
  26. sampler2D _WallTex;
  27. sampler2D _FloorTex;
  28.  
  29. struct Input
  30. {
  31. float3 worldPos;
  32. float3 worldNormal;
  33. };
  34.  
  35. half _Glossiness;
  36. half _Metallic;
  37. fixed4 _HighlightedColor;
  38. fixed4 _NormalColor;
  39.  
  40. //int _ArgCount = 0;
  41. //float4 _Positions[100];
  42. //float _Radii[100];
  43.  
  44.  
  45. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  46. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  47. // #pragma instancing_options assumeuniformscaling
  48. UNITY_INSTANCING_BUFFER_START(Props)
  49. // put more per-instance properties here
  50. UNITY_INSTANCING_BUFFER_END(Props)
  51.  
  52. //credit to @minionsart on twitter for her triplanar shading implementation
  53. void surf (Input IN, inout SurfaceOutputStandard o)
  54. {
  55. float3 xCol = tex2D(_WallTex, IN.worldPos.yz);
  56. float3 yCol = tex2D(_FloorTex, IN.worldPos.xz);
  57. float3 zCol = tex2D(_WallTex, IN.worldPos.xy);
  58.  
  59. //for (int i = 0; i < _ArgCount; i++)
  60. //{
  61. // float distanceToCircle = length(IN.worldPos.xz - _Positions[i].xz);
  62. // yCol += (distanceToCircle < _Radii[i]) * _NormalColor * distanceToCircle / _Radii[i];
  63. //}
  64.  
  65. float3 blendedNormal = saturate(pow(IN.worldNormal*1.4, 4.));
  66.  
  67. fixed3 endColor = lerp(zCol, yCol, blendedNormal.y);
  68. endColor = lerp(endColor, xCol, blendedNormal.x);
  69. o.Albedo = float3(1.0f,1.0f,1.0f);
  70.  
  71.  
  72. o.Metallic = _Metallic;
  73. o.Smoothness = _Glossiness;
  74. o.Alpha = 1.0;
  75. }
  76. ENDCG
  77. }
  78. FallBack "Diffuse"
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement