Advertisement
443eb9

Untitled

Sep 27th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. Shader "443eb9/Ground"
  2. {
  3. Properties
  4. {
  5. _BaseColor ("BaseColor", Color) = (1, 1, 1, 1)
  6. _Smoothness ("Smoothness", Range(0, 1)) = 0.5
  7.  
  8. _RippleTexture ("RippleTexture", 2D) = "bump" {}
  9. _RippleStrength ("RippleStrength", Float) = 1
  10. _RippleAnimSpeed ("RippleAnimSpeed", Float) = 1
  11. }
  12. SubShader
  13. {
  14. Tags
  15. {
  16. "Pipeline"="UniversalPipeline"
  17. "RenderType"="Opaque"
  18. "RenderType"="Opaque"
  19. }
  20. LOD 100
  21.  
  22. Pass
  23. {
  24. HLSLPROGRAM
  25. #pragma vertex vert;
  26. #pragma fragment frag;
  27. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  28. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  29. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  30. #pragma multi_compile_instancing
  31. #pragma instancing_options renderinglayer
  32.  
  33. CBUFFER_START(UnityPerMaterial)
  34. float4 _BaseColor;
  35. float _Smoothness;
  36.  
  37. float4 _RippleTexture_ST;
  38. float _RippleStrength;
  39. float _RippleAnimSpeed;
  40. CBUFFER_END
  41.  
  42.  
  43. #if defined(UNITY_DOTS_INSTANCING_ENABLED)
  44. UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
  45. UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)
  46. UNITY_DOTS_INSTANCED_PROP(float, _Smoothness)
  47. UNITY_DOTS_INSTANCED_PROP(float4, _RippleTexture_ST)
  48. UNITY_DOTS_INSTANCED_PROP(float, _RippleStrength)
  49. UNITY_DOTS_INSTANCED_PROP(float, _RippleAnimSpeed)
  50. UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
  51. #define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _BaseColor)
  52. #define _Smoothness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _Smoothness)
  53. #define _RippleTexture_ST UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _RippleTexture_ST)
  54. #define _RippleStrength UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _RippleStrength)
  55. #define _RippleStrength UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _RippleAnimSpeed)
  56. #endif
  57.  
  58. TEXTURE2D(_RippleTexture);
  59. SAMPLER(sampler_RippleTexture);
  60.  
  61. struct Attributes
  62. {
  63. float3 positionOS : POSITION;
  64. float3 normalOS : NORMAL;
  65. UNITY_VERTEX_INPUT_INSTANCE_ID
  66. };
  67.  
  68. struct Varyings
  69. {
  70. float4 positionHCS : SV_POSITION;
  71. float3 positionWS : TEXCOORD0;
  72. float3x3 ttw : TEXCOORD1;
  73. UNITY_VERTEX_INPUT_INSTANCE_ID
  74. };
  75.  
  76. static const float totalFrames = 16.0;
  77.  
  78. Varyings vert(Attributes IN)
  79. {
  80. Varyings OUT;
  81. VertexPositionInputs vpi = GetVertexPositionInputs(IN.positionOS);
  82. OUT.positionHCS = vpi.positionCS;
  83. OUT.positionWS = vpi.positionWS;
  84.  
  85. VertexNormalInputs vni = GetVertexNormalInputs(IN.normalOS);
  86.  
  87. OUT.ttw = float3x3(vni.tangentWS, vni.bitangentWS, vni.normalWS);
  88. UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
  89. return OUT;
  90. }
  91.  
  92. float3 frag(Varyings IN) : SV_Target
  93. {
  94. UNITY_SETUP_INSTANCE_ID(IN);
  95. float2 uv = float2
  96. (
  97. IN.positionWS.x / _RippleTexture_ST.x,
  98. frac(IN.positionWS.z / _RippleTexture_ST.y) / totalFrames + floor(_Time.w * _RippleAnimSpeed) / totalFrames
  99. );
  100. float3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_RippleTexture, sampler_RippleTexture, uv));
  101. float3 normalWS = mul(normalTS, IN.ttw);
  102. normalWS.xz *= _RippleStrength;
  103.  
  104. Light mainLight = GetMainLight();
  105. float3 viewWS = GetWorldSpaceNormalizeViewDir(IN.positionWS);
  106.  
  107. BRDFData data;
  108. InitializeBRDFData(_BaseColor.rgb, 0, 1, _Smoothness, _BaseColor.a, data);
  109. float3 color = LightingPhysicallyBased(data, mainLight, normalWS, viewWS);
  110.  
  111. return color;
  112. }
  113. ENDHLSL
  114. }
  115.  
  116. UsePass "Universal Render Pipeline/Lit/DEPTHNORMALS"
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement