Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Shader "Diffuse - Worldspace"
  2. {
  3. Properties
  4. {
  5. _Color ("Main Color", Color) = (1,1,1,1)
  6. _MainTex ("Base (RGB)", 2D) = "white" {}
  7. _Scale ("Texture Scale", Float) = 1.0
  8. }
  9.  
  10. SubShader
  11. {
  12. Tags { "RenderType"="Opaque" }
  13. LOD 200
  14.  
  15. CGPROGRAM
  16. #pragma surface surf Lambert
  17.  
  18. sampler2D _MainTex;
  19. fixed4 _Color;
  20. float _Scale;
  21.  
  22. struct Input
  23. {
  24. float3 worldNormal;
  25. float3 worldPos;
  26. };
  27.  
  28. void surf (Input IN, inout SurfaceOutput o)
  29. {
  30. float2 UV;
  31. fixed4 c;
  32.  
  33. if(abs(IN.worldNormal.x)>0.5)
  34. {
  35. UV = IN.worldPos.yz; // side
  36. c = tex2D(_MainTex, UV* _Scale); // use WALLSIDE texture
  37. }
  38. else if(abs(IN.worldNormal.z)>0.5)
  39. {
  40. UV = IN.worldPos.xy; // front
  41. c = tex2D(_MainTex, UV* _Scale); // use WALL texture
  42. }
  43. else
  44. {
  45. UV = IN.worldPos.xz; // top
  46. c = tex2D(_MainTex, UV* _Scale); // use FLR texture
  47. }
  48.  
  49. o.Albedo = c.rgb * _Color;
  50. }
  51. ENDCG
  52. }
  53.  
  54. Fallback "VertexLit"
  55. }
  56.  
  57. CGPROGRAM
  58. // Physically based Standard lighting model, and enable shadows on all light types
  59. #pragma surface surf Standard fullforwardshadows vertex:vert
  60.  
  61. void vert(inout appdata_full v) {
  62.  
  63. // Get the worldspace normal after transformation, and ensure it's unit length.
  64. float3 n = normalize(mul(unity_ObjectToWorld, v.normal).xyz);
  65.  
  66. // Pick a direction for our texture's vertical "v" axis.
  67. // Default for floors/ceilings:
  68. float3 vDirection = float3(0, 0, 1);
  69.  
  70. // For non-horizontal planes, we'll choose
  71. // the closest vector in the polygon's plane to world up.
  72. if(abs(n.y) < 1.0f)) {
  73. vDirection = normalize(float3(0, 1, 0) - n.y * n);
  74. }
  75.  
  76. // Get the perpendicular in-plane vector to use as our "u" direction.
  77. float3 uDirection = normalize(cross(n, vDirection));
  78.  
  79. // Get the position of the vertex in worldspace.
  80. float3 worldSpace = mul(unity_ObjectToWorld, v.vertex).xyz;
  81.  
  82. // Project the worldspace position of the vertex into our texturing plane,
  83. // and use this result as the primary texture coordinate.
  84. v.texcoord.xy = float2(dot(worldSpace, uDirection), dot(worldSpace, vDirection));
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement