CalmWater_Tessellation.cginc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifdef DX11
  2. #ifdef UNITY_CAN_COMPILE_TESSELLATION
  3. struct TessVertex {
  4. float4 vertex : INTERNALTESSPOS;
  5. float3 normal : NORMAL;
  6. float4 tangent : TANGENT;
  7. float2 texcoord : TEXCOORD0;
  8. #ifdef UNITY_PASS_FORWARDADD
  9. float2 texcoord1 : TEXCOORD1;
  10. #endif
  11. //float4 color : COLOR;
  12. };
  13. struct OutputPatchConstant {
  14. float edge[3] : SV_TessFactor;
  15. float inside : SV_InsideTessFactor;
  16. };
  17. TessVertex tessvert(appdata v) {
  18. TessVertex o;
  19. o.vertex = v.vertex;
  20. o.normal = v.normal;
  21. o.tangent = v.tangent;
  22. o.texcoord = v.texcoord;
  23. #ifdef UNITY_PASS_FORWARDADD
  24. o.texcoord1 = v.texcoord1;
  25. #endif
  26. //o.color = v.color;
  27. return o;
  28. }
  29. float4 Tessellation(TessVertex v, TessVertex v1, TessVertex v2) {
  30. return UnityEdgeLengthBasedTess(v.vertex, v1.vertex, v2.vertex, 32 - _Tess);
  31. }
  32. OutputPatchConstant hullconst(InputPatch<TessVertex, 3> v) {
  33. OutputPatchConstant o;
  34. float4 ts = Tessellation(v[0], v[1], v[2]);
  35. o.edge[0] = ts.x;
  36. o.edge[1] = ts.y;
  37. o.edge[2] = ts.z;
  38. o.inside = ts.w;
  39. return o;
  40. }
  41. [domain("tri")]
  42. [partitioning("fractional_odd")]
  43. [outputtopology("triangle_cw")]
  44. [patchconstantfunc("hullconst")]
  45. [outputcontrolpoints(3)]
  46. TessVertex hs_surf(InputPatch<TessVertex, 3> v, uint id : SV_OutputControlPointID) {
  47. return v[id];
  48. }
  49. [domain("tri")]
  50. v2f ds_surf(OutputPatchConstant tessFactors, const OutputPatch<TessVertex, 3> vi, float3 bary : SV_DomainLocation) {
  51. appdata v = (appdata)0;
  52. v.vertex = vi[0].vertex * bary.x + vi[1].vertex * bary.y + vi[2].vertex * bary.z;
  53. v.texcoord = vi[0].texcoord * bary.x + vi[1].texcoord * bary.y + vi[2].texcoord * bary.z;
  54. #ifdef UNITY_PASS_FORWARDADD
  55. v.texcoord1 = vi[0].texcoord1 * bary.x + vi[1].texcoord1 * bary.y + vi[2].texcoord1 * bary.z;
  56. #endif
  57. //v.color = vi[0].color*bary.x + vi[1].color*bary.y + vi[2].color*bary.z;
  58. v.tangent = vi[0].tangent * bary.x + vi[1].tangent * bary.y + vi[2].tangent * bary.z;
  59. v.normal = vi[0].normal * bary.x + vi[1].normal * bary.y + vi[2].normal * bary.z;
  60. v2f o = vert(v);
  61. return o;
  62. }
  63. #endif
  64. #endif // End DX11