Advertisement
Guest User

BasicTessellation.shader

a guest
Jun 27th, 2022
1,955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. // This shader adds tessellation in URP
  2. Shader "Example/URPUnlitShaderTessallated"
  3. {
  4.  
  5. // The properties block of the Unity shader. In this example this block is empty
  6. // because the output color is predefined in the fragment shader code.
  7. Properties
  8. {
  9. _Tess("Tessellation", Range(1, 32)) = 20
  10. _MaxTessDistance("Max Tess Distance", Range(1, 32)) = 20
  11. _Noise("Noise", 2D) = "gray" {}
  12.  
  13. _Weight("Displacement Amount", Range(0, 1)) = 0
  14. }
  15.  
  16. // The SubShader block containing the Shader code.
  17. SubShader
  18. {
  19. // SubShader Tags define when and under which conditions a SubShader block or
  20. // a pass is executed.
  21. Tags{ "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
  22.  
  23. Pass
  24. {
  25. Tags{ "LightMode" = "UniversalForward" }
  26.  
  27.  
  28. // The HLSL code block. Unity SRP uses the HLSL language.
  29. HLSLPROGRAM
  30. // The Core.hlsl file contains definitions of frequently used HLSL
  31. // macros and functions, and also contains #include references to other
  32. // HLSL files (for example, Common.hlsl, SpaceTransforms.hlsl, etc.).
  33. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  34. #include "CustomTessellation.hlsl"
  35.  
  36. // This line defines the name of the hull shader.
  37. #pragma hull hull
  38. // This line defines the name of the domain shader.
  39. #pragma domain domain
  40. // This line defines the name of the vertex shader.
  41. #pragma vertex TessellationVertexProgram
  42. // This line defines the name of the fragment shader.
  43. #pragma fragment frag
  44.  
  45. sampler2D _Noise;
  46. float _Weight;
  47.  
  48. // pre tesselation vertex program
  49. ControlPoint TessellationVertexProgram(Attributes v)
  50. {
  51. ControlPoint p;
  52.  
  53. p.vertex = v.vertex;
  54. p.uv = v.uv;
  55. p.normal = v.normal;
  56. p.color = v.color;
  57.  
  58. return p;
  59. }
  60.  
  61. // after tesselation
  62. Varyings vert(Attributes input)
  63. {
  64. Varyings output;
  65.  
  66. float4 Noise = tex2Dlod(_Noise, float4(input.uv + (_Time.x * 0.1), 0, 0));
  67.  
  68. input.vertex.xyz += normalize(input.normal) * Noise.r * _Weight;
  69. output.vertex = TransformObjectToHClip(input.vertex.xyz);
  70. output.color = input.color;
  71. output.normal = input.normal;
  72. output.uv = input.uv;
  73.  
  74. return output;
  75. }
  76.  
  77. [UNITY_domain("tri")]
  78. Varyings domain(TessellationFactors factors, OutputPatch<ControlPoint, 3> patch, float3 barycentricCoordinates : SV_DomainLocation)
  79. {
  80. Attributes v;
  81. // interpolate the new positions of the tessellated mesh
  82. Interpolate(vertex)
  83. Interpolate(uv)
  84. Interpolate(color)
  85. Interpolate(normal)
  86.  
  87. return vert(v);
  88. }
  89.  
  90. // The fragment shader definition.
  91. half4 frag(Varyings IN) : SV_Target
  92. {
  93. float4 Noise = tex2D(_Noise, IN.uv + (_Time.x * 0.1));
  94. return Noise;
  95. }
  96. ENDHLSL
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement