subd_dice.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __SUBD_DICE_H__
  17. #define __SUBD_DICE_H__
  18. /* DX11 like EdgeDice implementation, with different tessellation factors for
  19. * each edge for watertight tessellation, with subpatch remapping to work with
  20. * DiagSplit. For more algorithm details, see the DiagSplit paper or the
  21. * ARB_tessellation_shader OpenGL extension, Section 2.X.2. */
  22. #include "util/util_types.h"
  23. #include "util/util_vector.h"
  24. CCL_NAMESPACE_BEGIN
  25. class Camera;
  26. class Mesh;
  27. class Patch;
  28. struct SubdParams {
  29. Mesh *mesh;
  30. bool ptex;
  31. int test_steps;
  32. int split_threshold;
  33. float dicing_rate;
  34. int max_level;
  35. Camera *camera;
  36. Transform objecttoworld;
  37. SubdParams(Mesh *mesh_, bool ptex_ = false)
  38. {
  39. mesh = mesh_;
  40. ptex = ptex_;
  41. test_steps = 3;
  42. split_threshold = 1;
  43. dicing_rate = 1.0f;
  44. max_level = 12;
  45. camera = NULL;
  46. }
  47. };
  48. /* EdgeDice Base */
  49. class EdgeDice {
  50. public:
  51. SubdParams params;
  52. float3 *mesh_P;
  53. float3 *mesh_N;
  54. size_t vert_offset;
  55. size_t tri_offset;
  56. explicit EdgeDice(const SubdParams &params);
  57. void reserve(int num_verts);
  58. int add_vert(Patch *patch, float2 uv);
  59. void add_triangle(Patch *patch, int v0, int v1, int v2);
  60. void stitch_triangles(Patch *patch, vector<int> &outer, vector<int> &inner);
  61. };
  62. /* Quad EdgeDice
  63. *
  64. * Edge tessellation factors and subpatch coordinates are as follows:
  65. *
  66. * tu1
  67. * P01 --------- P11
  68. * | |
  69. * tv0 | | tv1
  70. * | |
  71. * P00 --------- P10
  72. * tu0
  73. */
  74. class QuadDice : public EdgeDice {
  75. public:
  76. struct SubPatch {
  77. Patch *patch;
  78. float2 P00;
  79. float2 P10;
  80. float2 P01;
  81. float2 P11;
  82. };
  83. struct EdgeFactors {
  84. int tu0;
  85. int tu1;
  86. int tv0;
  87. int tv1;
  88. };
  89. explicit QuadDice(const SubdParams &params);
  90. void reserve(EdgeFactors &ef, int Mu, int Mv);
  91. float3 eval_projected(SubPatch &sub, float u, float v);
  92. float2 map_uv(SubPatch &sub, float u, float v);
  93. int add_vert(SubPatch &sub, float u, float v);
  94. void add_corners(SubPatch &sub);
  95. void add_grid(SubPatch &sub, int Mu, int Mv, int offset);
  96. void add_side_u(SubPatch &sub,
  97. vector<int> &outer,
  98. vector<int> &inner,
  99. int Mu,
  100. int Mv,
  101. int tu,
  102. int side,
  103. int offset);
  104. void add_side_v(SubPatch &sub,
  105. vector<int> &outer,
  106. vector<int> &inner,
  107. int Mu,
  108. int Mv,
  109. int tv,
  110. int side,
  111. int offset);
  112. float quad_area(const float3 &a, const float3 &b, const float3 &c, const float3 &d);
  113. float scale_factor(SubPatch &sub, EdgeFactors &ef, int Mu, int Mv);
  114. void dice(SubPatch &sub, EdgeFactors &ef);
  115. };
  116. CCL_NAMESPACE_END
  117. #endif /* __SUBD_DICE_H__ */