Няма описание

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. // PN patch data
  5. struct PnPatch
  6. {
  7. float b210;
  8. float b120;
  9. float b021;
  10. float b012;
  11. float b102;
  12. float b201;
  13. float b111;
  14. float n110;
  15. float n011;
  16. float n101;
  17. };
  18. // tessellation levels
  19. layout (binding = 0) uniform UBO
  20. {
  21. float tessLevel;
  22. } ubo;
  23. layout(vertices=3) out;
  24. layout(location = 0) in vec3 inNormal[];
  25. layout(location = 1) in vec2 inUV[];
  26. layout(location = 0) out vec3 outNormal[3];
  27. layout(location = 3) out vec2 outUV[3];
  28. layout(location = 6) out PnPatch outPatch[3];
  29. float wij(int i, int j)
  30. {
  31. return dot(gl_in[j].gl_Position.xyz - gl_in[i].gl_Position.xyz, inNormal[i]);
  32. }
  33. float vij(int i, int j)
  34. {
  35. vec3 Pj_minus_Pi = gl_in[j].gl_Position.xyz
  36. - gl_in[i].gl_Position.xyz;
  37. vec3 Ni_plus_Nj = inNormal[i]+inNormal[j];
  38. return 2.0*dot(Pj_minus_Pi, Ni_plus_Nj)/dot(Pj_minus_Pi, Pj_minus_Pi);
  39. }
  40. void main()
  41. {
  42. // get data
  43. gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
  44. outNormal[gl_InvocationID] = inNormal[gl_InvocationID];
  45. outUV[gl_InvocationID] = inUV[gl_InvocationID];
  46. // set base
  47. float P0 = gl_in[0].gl_Position[gl_InvocationID];
  48. float P1 = gl_in[1].gl_Position[gl_InvocationID];
  49. float P2 = gl_in[2].gl_Position[gl_InvocationID];
  50. float N0 = inNormal[0][gl_InvocationID];
  51. float N1 = inNormal[1][gl_InvocationID];
  52. float N2 = inNormal[2][gl_InvocationID];
  53. // compute control points
  54. outPatch[gl_InvocationID].b210 = (2.0*P0 + P1 - wij(0,1)*N0)/3.0;
  55. outPatch[gl_InvocationID].b120 = (2.0*P1 + P0 - wij(1,0)*N1)/3.0;
  56. outPatch[gl_InvocationID].b021 = (2.0*P1 + P2 - wij(1,2)*N1)/3.0;
  57. outPatch[gl_InvocationID].b012 = (2.0*P2 + P1 - wij(2,1)*N2)/3.0;
  58. outPatch[gl_InvocationID].b102 = (2.0*P2 + P0 - wij(2,0)*N2)/3.0;
  59. outPatch[gl_InvocationID].b201 = (2.0*P0 + P2 - wij(0,2)*N0)/3.0;
  60. float E = ( outPatch[gl_InvocationID].b210
  61. + outPatch[gl_InvocationID].b120
  62. + outPatch[gl_InvocationID].b021
  63. + outPatch[gl_InvocationID].b012
  64. + outPatch[gl_InvocationID].b102
  65. + outPatch[gl_InvocationID].b201 ) / 6.0;
  66. float V = (P0 + P1 + P2)/3.0;
  67. outPatch[gl_InvocationID].b111 = E + (E - V)*0.5;
  68. outPatch[gl_InvocationID].n110 = N0+N1-vij(0,1)*(P1-P0);
  69. outPatch[gl_InvocationID].n011 = N1+N2-vij(1,2)*(P2-P1);
  70. outPatch[gl_InvocationID].n101 = N2+N0-vij(2,0)*(P0-P2);
  71. // set tess levels
  72. gl_TessLevelOuter[gl_InvocationID] = ubo.tessLevel;
  73. gl_TessLevelInner[0] = ubo.tessLevel;
  74. }