暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorldSpaceGrid.shader 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. Shader "PlaceHolder/WorldSpaceGrid"
  2. {
  3. Properties
  4. {
  5. [Toggle] _EnableWorldSpace("Enable World Space", int) = 1
  6. _Color ("Color", Color) = (0.61,0.61,0.61,1)
  7. _MainTex ("Albedo (RGB)", 2D) = "white" {}
  8. _Scale("Scale", float) = 1.0
  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. CGPROGRAM
  17. // Physically based Standard lighting model, and enable shadows on all light types
  18. #pragma surface surf Standard fullforwardshadows
  19. // Use shader model 3.0 target, to get nicer looking lighting
  20. #pragma target 3.0
  21. sampler2D _MainTex;
  22. struct Input
  23. {
  24. float4 color : COLOR;
  25. float2 uv_MainTex;
  26. float3 worldPos;
  27. float3 worldNormal;
  28. };
  29. half _Glossiness;
  30. half _Metallic;
  31. int _EnableWorldSpace;
  32. fixed4 _Color;
  33. half _Scale;
  34. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  35. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  36. // #pragma instancing_options assumeuniformscaling
  37. UNITY_INSTANCING_BUFFER_START(Props)
  38. // put more per-instance properties here
  39. UNITY_INSTANCING_BUFFER_END(Props)
  40. void surf (Input IN, inout SurfaceOutputStandard o)
  41. {
  42. float2 UV;
  43. fixed4 c;
  44. if (_EnableWorldSpace == 1)
  45. {
  46. if (abs(IN.worldNormal.x) > 0.5)
  47. {
  48. UV = IN.worldPos.yz; // side
  49. c = tex2D(_MainTex, UV* _Scale);
  50. }
  51. else if (abs(IN.worldNormal.z) > 0.5)
  52. {
  53. UV = IN.worldPos.xy; // front
  54. c = tex2D(_MainTex, UV* _Scale);
  55. }
  56. else
  57. {
  58. UV = IN.worldPos.xz; // top
  59. c = tex2D(_MainTex, UV* _Scale);
  60. }
  61. o.Albedo = c.rgb * _Color;
  62. }
  63. else
  64. {
  65. fixed4 c = tex2D(_MainTex, IN.uv_MainTex*_Scale) * _Color;
  66. o.Albedo = c.rgb * _Color;
  67. }
  68. // Metallic and smoothness come from slider variables
  69. o.Metallic = _Metallic;
  70. o.Smoothness = _Glossiness;
  71. o.Alpha = c.a;
  72. }
  73. ENDCG
  74. }
  75. FallBack "Diffuse"
  76. }