Multi-Model Surface Filling Method Based on Template Buffer, Terminal, and Storage Medium
Through the bit-by-bit numbering rules and template buffer sharing mechanism, the problem of insufficient utilization of template buffer resources and difficulty in controlling rendering order in multi-model scenarios is solved, and efficient multi-model cutting and face-filling processing is achieved, adapting to the parallel and delayed rendering modes of modern graphics engines, improving rendering efficiency and stability.
Patent Information
- Application Number
- CN202510409170.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2045-04-02
AI Technical Summary
In the cutting and surface filling method in multi-model scenarios, the problem of insufficient utilization of template buffer resources, insufficient processing of cutting and surface filling relationships, and difficulty in controlling parallel rendering and rendering order in the prior art, which is difficult to meet the real-time rendering needs of modern graphics engines.
The bit-by-bit corresponding numbering rules and template buffer sharing mechanism are adopted. Through double-sided rendering and bit-by-bit inversion operations, multiple models share the same template buffer. The template mask value and reference value settings are used to accurately mark the gap and fill the face.
It improves the rendering efficiency and stability of multi-model scenes, adapts to the parallel and delayed rendering modes of modern graphics engines, reduces dependence on rendering order, and improves the real-time and flexibility of rendering.
Smart Images

Figure CN119919557B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of three-dimensional graphics rendering, and in particular to a multi-model sectioning and surface filling method based on template buffering applied to three-dimensional models. Background Art
[0002] With the continuous advancement of computer graphics and 3D modeling technology, dynamic sectioning and surface generation of 3D models has been widely applied in a wide range of fields, including architectural design, virtual reality, medical imaging, geological surveying, and engineering visualization. Sectioning and surface generation can more intuitively display the internal structure of a model, helping users understand and analyze complex 3D data.
[0003] However, existing technologies still face many challenges in multi-model scenes, dynamic scenes, and real-time rendering requirements. Traditional sectioning and patching methods often require explicit sorting or multiple rendering of different models, resulting in low efficiency and difficulty in maintaining stable rendering effects. Especially in the context of the widespread adoption of parallel rendering and batch processing technologies in modern graphics engines, forcibly controlling the rendering order of models is not only costly and difficult, but also greatly affects the sectioning and patching performance in multi-model dynamic scenes. The following will introduce the limitations of existing technologies from two typical technologies: traditional geometric sectioning and patching methods and template buffer-based sectioning and patching methods.
[0004] (1) Traditional geometric sectioning method:
[0005] Chinese patent publication number CN109685914A discloses a method for automatically filling in the section contours of a triangular mesh model. This method achieves sectioning by modifying the model's geometric data (e.g., vertices and triangular facets). This method has the following issues:
[0006] 1. High computational overhead. When dealing with complex models, geometric data must be frequently reconstructed. A single section often requires dynamic updates of a large number of vertices and faces, which is computationally intensive and time-consuming, making it difficult to meet real-time rendering requirements.
[0007] 2. Complex algorithm design. Once the sectioning is completed, the gaps need to be automatically or semi-automatically filled, which typically requires geometric algorithms such as topology updates, boundary detection, and reconstruction. This process places high demands on algorithm design and can easily become a system bottleneck. If implemented improperly, the connection between the sectioned and filled surfaces will be poor, significantly reducing overall efficiency.
[0008] (2) Sectioning and patching method based on template buffer:
[0009] The existing template buffer-based sectioning and patching methods have insufficient utilization of template buffer resources. One template value can only mark one model, and the template buffer bit operation capability cannot be fully utilized, making it difficult to adapt to the needs of multi-model patching.
[0010] The relationship between sectioning and patching is not handled accurately enough, and it relies more on timing control, with sectioning performed first and patching later. There is a lack of precise management of the relationship between the two, and the effects of sectioning and patching are prone to inconsistencies, which also places high demands on the rendering mechanism.
[0011] Parallel rendering and rendering order control are difficult. Traditional stencil buffering methods often require rendering the back and front faces separately, processing the model one by one. Modern engines rely heavily on parallelism and batch processing. Forcing control over rendering order creates performance bottlenecks and hinders the full utilization of parallel computing resources.
[0012] Stencil buffer limitations. In modern graphics engines like UE5, a single rendering operation typically uses only a single stencil buffer. If multiple sections and patching are required, traditional methods rely on multiple renderings and multiple stencil buffers, making it difficult to maintain efficiency and stability in large, multi-model scenes.
[0013] For example, existing technologies (such as patents CN102013113A and CN115690378A) use a stencil buffer to mark cutout areas and update stencil values multiple times to achieve cutout and fillout. These stencil values use decimal operations, such as subtracting 1 for the front side and adding 1 for the back side, to record the number of fillouts. Consequently, a single stencil value can only represent the gap state of a single object. Fillouts must be completed immediately after rendering an object; otherwise, addition and subtraction operations on subsequent objects will destroy the previously generated information. Furthermore, frequent stencil value clearing procedures must be interspersed between multiple objects. Summary of the Invention
[0014] In order to overcome the problems of insufficient utilization of template buffer resources and inaccurate processing of the relationship between sectioning and patching in existing surface patching methods, the present invention proposes a multi-model surface patching method based on template buffer sharing, which can fully utilize the template buffer bit operation capability to achieve efficient processing of multi-model sectioning and patching.
[0015] The technical solution provided by the present invention is as follows: a multi-model face filling method based on template buffer, comprising the following steps:
[0016] Obtain several models to be processed and defined cutting planes, and generate corresponding patching planes;
[0017] Set a number n corresponding to the binary bit of the template value in the template buffer for the model to be processed, and the patch plane and its corresponding model to be processed use the same number;
[0018] Setting the rendering state of the model to be processed and the patching plane, including: setting the template mask value of the model to be processed and the patching plane to the power of 2; setting the initial value of the template value to 0;
[0019] The first rendering process is started, including: performing double-sided rendering on the model to be processed, and inverting the template value based on the template mask value each time a pixel is covered by a fragment, thereby writing the model gap information into the template value;
[0020] Start the second rendering process and perform single-sided rendering on the patch plane. Keep the fragments of the patch plane whose template value corresponds to the binary bit of 1 after the first rendering process, and discard the fragments of the patch plane whose template value corresponds to the binary bit of 0, thereby cutting off the part of the patch plane that exceeds the area to be patched, and completing the trimming of the patch plane.
[0021] Preferably, the method further includes setting the rendering state of the patch plane before starting the second rendering process, wherein the setting content includes:
[0022] Passes when the template test function is set to equality;
[0023] Set both the template mask value and the reference value to powers of 2.
[0024] Preferably, before starting the first rendering process, the method further includes setting the "template test operation" of the template buffer to bitwise inversion and setting the template test function to always pass.
[0025] Preferably, the number n starts from 0 to number the models to be processed.
[0026] Preferably, the step further includes transferring the cutting plane information to the shader to form a cutting surface, wherein the step is:
[0027] The cutting plane is defined by a general plane equation. When the coordinates of a given fragment are substituted into the plane equations of all the cutting planes and the resulting values are greater than 0, the fragment is deleted; otherwise, the fragment is retained, thereby forming a cutting plane.
[0028] Preferably, the patching plane is used to fill the gap generated after sectioning, and the step of generating the patching plane includes: traversing each model to be processed, and generating a corresponding patching plane according to the intersection position of the model with the sectioning plane.
[0029] Preferably, the setting of the rendering state of the patch plane further includes: setting the template operation to remain unchanged.
[0030] An intelligent terminal includes a processor and a memory, wherein the memory stores a computer program, the processor is in communication with the memory, and the processor executes the above-mentioned template buffer-based multi-model face filling method through the computer program.
[0031] A computer-readable storage medium stores program data, wherein the program data is used to execute the above-mentioned multi-model surface filling method based on template buffer.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] 1. For multi-model scenarios, the stencil mask values of the model to be processed and its patch planes are set to powers of 2 (n) (where n is the number of the model to be processed or the patch plane). That is, when rendering models or patch planes with different numbers, only their corresponding binary bits in the stencil value are manipulated. This allows gap markers for multiple models to be processed simultaneously within the same stencil value. Multiple models to be processed and their corresponding patch planes share the same stencil buffer, allowing a single stencil value to manage gap information for multiple models using different binary bits, eliminating the need for frequent clearing or resetting. This overcomes the limitation of traditional stencil value "addition and subtraction" operations that can only store gaps for a single model.
[0034] 2. Through double-sided rendering and parity determination, with the help of bitwise inversion and mask control mechanisms, the coverage counts for front- and back-facing fragments are marked in one go, eliminating the need for multiple rendering cycles such as "front minus 1, back plus 1." Each model only affects the binary bits it occupies, thus achieving unified processing of multiple models within a single stencil buffer flow. This eliminates the need for strict control over the order in which models are rendered, significantly improving the efficiency of parallel rendering and effectively reducing strict reliance on rendering order. This is particularly adaptable to the parallel pipelines and deferred rendering modes of modern graphics engines, significantly improving real-time efficiency in large-scale, multi-model scenarios.
[0035] 3. Set the template test function of the patching plane to EQUAL (pass if equal), and use the template mask value and reference value corresponding to the same number as the model to be processed to accurately patch the gaps. This allows the patching plane to automatically identify and fill the gaps of their respective models, eliminating the need for immediate patching or relying on complex sequential control. At the same time, you can freely change materials, control transparency or texture, and meet diverse visual needs.
[0036] 4. Adaptable to modern engine deferred rendering and batch processing, fully utilizing the deferred rendering and parallel features of modern graphics engines. Eliminating the need for forced sorting or frequent clearing of stencil values, this allows the rendering engine to simultaneously process sectioning and patching in parallel or deferred pipelines, maximizing the GPU's parallel computing capabilities and enabling true real-time and flexible dynamic sectioning and patching of multiple models. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is a flow chart of the first embodiment of the present invention;
[0038] Figure 2 This is a schematic diagram of the state of the model to be processed (geological model) before being cut and filled;
[0039] Figure 3 The state diagram after the models to be processed are numbered;
[0040] Figure 4 It is a schematic diagram of the state of the model to be processed after being cut by a single cutting plane;
[0041] Figure 5 for Figure 4 On this basis, a schematic diagram of the patch plane is generated with semi-transparent representation;
[0042] Figure 6 for Figure 5 A schematic diagram after the template value is marked in the gap;
[0043] Figure 7 Schematic diagram of the model state after pruning according to the template value;
[0044] Figure 8 This is a schematic diagram of the final filling effect after removing the template value;
[0045] Figure 9 The figure is a schematic diagram of the state of two intersecting cubes before being cut and patched as the model to be processed;
[0046] Figure 10 This is a schematic diagram of the state of two intersecting cubes after being cut and patched;
[0047] Figure 11 A schematic diagram of the state of the template values corresponding to the gap area when two intersecting cubes are cut and patched. DETAILED DESCRIPTION
[0048] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the described embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should have the common meaning understood by people with ordinary skills in the field to which the present invention belongs.
[0049] Example 1:
[0050] A multi-model face filling method based on template buffer, the specific steps are as follows.
[0051] S1, obtain the model to be processed and generate the cutting plane and the filling plane.
[0052] S11, obtain the model to be processed, the model to be processed is as follows Figure 2 As shown, this embodiment takes three models to be processed as examples.
[0053] The model to be processed can be loaded from the hard disk or generated by the program in real time. It only needs to be a closed mesh model.
[0054] S12, defining the cutting plane, that is, passing the cutting plane information to the shader.
[0055] Define one or more cutting planes as needed. This embodiment uses a single plane as an example. If multiple planes are required, the fragment will be cut only when it falls on the positive side of all planes. The cutting plane can be defined using a general plane equation, such as ax+by+cz+d=0, where (a,b,c) is the normal vector of the plane and d is a constant. The plane can be directly described by the coefficients a,b,c,d. For a given point P(x1,y1,z1), substitute its coordinates into the plane equation to obtain F=ax1+by1+cz1+d. If:
[0056] F>0, indicating that the point is on the positive side of the plane (the side to which the normal vector points);
[0057] F<0 means the point is on the negative side of the plane;
[0058] F=0 means the point lies on the plane.
[0059] In this embodiment, the front side of the plane is regarded as the area to be cut off, and the front side fragments are discarded in the fragment shader to obtain the cutting effect. Figure 5 As described above, the semi-transparent plane is a schematic diagram of the cutting plane, and the model fragments in the positive side area are deleted, while the negative side area is retained.
[0060] If you need to use multiple cutting planes, the fragment will be cut only if it is on the positive side of all planes, such as Figures 9-11 Shown is the effect of multi-plane sectioning.
[0061] The specific steps are to apply the cutting plane to the fragment shader to form the cutting surface. Specifically, the cutting plane is described as F = ax + by + cz + d, and the four coefficients a, b, c, and d are passed to the fragment shader (also known as the pixel shader). For the fragment's world coordinates (x1, y1, z1), F = ax1 + by1 + cz1 + d is calculated. If F > 0, the fragment is discarded, removing the area on the positive side of the plane; otherwise, it is retained. This way, the positive side of the model where the cutting plane intersects is "cut off," while the negative side is retained, forming a clear cutting surface.
[0062] S13, generating a patch plane.
[0063] Each model to be processed is traversed, and a corresponding patch plane is generated based on its intersection with the cutting plane. This patch plane is a renderable mesh model that fills the gap left by the sectioning. Typically, the patch plane can be rectangular, and its size can be as long as it covers the gap. By default, the patch plane's material is the same as the model to be processed to maintain visual consistency, but other materials can be changed as needed.
[0064] S2, setting a number n corresponding to the binary bits of the template value in the template buffer for the model to be processed, and the patch plane and its corresponding model to be processed use the same number.
[0065] In order to ensure that multiple models to be processed and their corresponding patch planes can correspond one-to-one in the template buffer, it is necessary to set bit-by-bit numbers for the models to be processed and the patch planes. The specific numbering rules are as follows:
[0066] Models to be processed and the patch planes are managed in a sequentially numbered manner. The numbers of multiple models to be processed start from 0 and increase one by one. For example, if there are five models to be processed in the scene, they are numbered 0, 1, 2, 3, and 4. In this implementation, there are three models to be processed, and they are numbered 0, 1, and 2.
[0067] The model to be processed in this embodiment is a geological model, such as Figure 2 As shown, it consists of multiple geological layers that fit together, and each geological layer is regarded as a model to be processed. Figure 3 In the embodiment, only the three models to be processed are assigned numbers and subsequent operations are performed.
[0068] After each model to be processed is numbered, in order to achieve a one-to-one correspondence in the subsequent template buffer, the patch plane and its corresponding model to be processed use the same number.
[0069] S3, set the rendering state of the model to be processed.
[0070] Enable stencil test. Stencil test is a common function of existing graphics engines. Configure stencil test parameters, including:
[0071] S31, setting the template mask value (ie, MASK) of the model to be processed to the power of 2, where n is the number of the model to be processed, and setting the "template test operation" of the template buffer to bitwise inversion (ie, INVERT).
[0072] S311: Set the template mask value to the nth power of 2, where n is the number of the model, that is, read and write the n+1th bit in the template value.
[0073] The number of each model to be processed and the patch plane has a one-to-one correspondence with the binary bit of the template value. Assuming that the number of the model to be processed is n, the corresponding binary bit in the template value is the n+1th bit, and the corresponding decimal expression is 2 to the power of n, for example:
[0074] 1) Model number 0 corresponds to the first digit of a binary number, which is expressed as 2 raised to the power of 0 in decimal (1 in binary and 1 in decimal).
[0075] 2) The model numbered 1 corresponds to the second digit of the binary number, expressed as 2 raised to the power of 1 in decimal (10 in binary, 2 in decimal);
[0076] 3) Model number 2 corresponds to the third digit of the binary number, expressed as 2 to the power of 2 in decimal (100 in binary, 4 in decimal);
[0077] 4) Model number 3 corresponds to the fourth digit of a binary number, expressed as 2 to the power of 3 in decimal (1000 in binary, 8 in decimal);
[0078] 5) Model number 4 corresponds to the fifth digit of a binary number, expressed as 2 to the power of 4 in decimal (10000 in binary, 16 in decimal);
[0079] Therefore, the template mask values of the model to be processed and its patching plane are set to the power of 2 (n is the number of the model or patching plane), so that the template mask values corresponding to the model to be processed and its patching plane are both the power of 2. In this way, when the models to be processed and patching planes with different numbers are rendered, only the corresponding binary bits in the template value are operated, so that the gap marks of multiple models can be processed simultaneously in the same template value.
[0080] S312, two-sided rendering (ie, Two-Sided) is turned on, and the stencil test operation (ie, StencilOp) is set to bitwise inversion (INVERT).
[0081] A fragment is a unit of data generated at a stage in the graphics rendering pipeline. It's the result of rasterizing 3D graphics and can be thought of as a fragment of graphics data corresponding to each pixel on the screen. Simply put, when we draw a geometric shape like a triangle on the screen, it undergoes a series of transformations and processing, converting the triangle into individual fragments. Each fragment contains information such as color, depth, and texture coordinates, ultimately used to determine the display effect of each pixel on the screen.
[0082] When rendering a model, you need to determine which fragments are "model gaps" and need to be filled. Model gaps are internal surfaces exposed after the model is cut. Model solids are external surfaces of the model.
[0083] In double-sided rendering, if a pixel is covered by fragments an odd number of times during the rendering process, it means that the pixel is ultimately located in a gap in the model and needs to be patched. If it is covered an even number of times, it means that the pixel is in the solid part of the model and does not need to be patched. Therefore, by determining the odd or even number of coverages, it is possible to distinguish between pixel locations that require patching and those that do not.
[0084] Specifically, during rendering, the stencil buffer's "stencil test operation" is set to INVERT (bitwise inversion). Initially, the stencil buffer's stencil value's corresponding bit value is 0. When a fragment of the model to be processed first covers that pixel, the corresponding bit is inverted to 1. The second time it covers that pixel, the corresponding bit is inverted again to 0, and so on.
[0085] When a pixel is covered an odd number of times by a fragment, the corresponding bit is set to 1, indicating a gap in the model. When the number of coverages is even, the bit is set to 0, indicating that the fragment is still part of the model. Later, when rendering the patching plane, gaps are identified by checking whether the corresponding bit in the template value is 1. The patching plane can accurately identify the locations of "gaps" in multiple models within a single template value, ultimately enabling multiple models to be patched simultaneously using the same template value.
[0086] S32 other settings, including:
[0087] Set the template test function (ie, StencilFunc) of the model to be processed: ALWAYS (ie, always pass).
[0088] Set the reference value of the model to be processed (ie REF): This can be set to any value, because the test function always passes. The key lies in the template mask and the inversion operation.
[0089] At this point, steps S1 to S3 complete the setting of the rendering state of the model to be processed.
[0090] S4, starts the first rendering process, that is, performing double-sided rendering (i.e., Two-Sided) on the model to be processed, and operates the corresponding template value to write the information of the model gap. That is, each time a pixel is covered by a fragment, the template value is inverted based on the template mask value to record the fragment at the model gap.
[0091] For double-sided rendering, when the fragment of the model being processed finally passes through the cutting plane, the binary bit corresponding to the stencil value is inverted (0→1 or 1→0) based on the stencil mask value. For an odd number of overlays, this bit is 1, indicating a gap; for an even number of overlays, this bit is 0, indicating a solid part of the model.
[0092] When performing double-sided rendering, compared with the traditional "front side minus 1, back side plus 1" method, the traditional approach requires two single-sided renderings and strictly controls the order to record whether the model has gaps; the present invention uses bitwise inversion and double-sided rendering to complete the parity judgment of the number of times the fragment is covered in one go, which is more efficient and does not require a forced model rendering order.
[0093] like Figure 6 The values in the figure are the template values written in the gap area after double-sided rendering of each model to be processed. Figure 5 From the numbers in, we can see that at this time,
[0094] The template value written into the fragment at the gap of the model to be processed with number 0 is binary 001 (decimal 1);
[0095] The template value written into model number 1 is binary 010 (decimal 2);
[0096] The template value written to model number 2 is binary 100 (decimal 4).
[0097] because Figures 2 to 8 There is no internal intersection of the model, so at this time, the template value at the gap only has the binary bit corresponding to the number as 1, and the other binary bits are 0.
[0098] Figures 9 to 11 Shown are the schematic states of each stage when two intersecting cubes (models to be processed) are cut and patched with cubes, and the template value state at the intersection of the two models to be processed is shown.
[0099] If there is an intersection between models, the binary bits corresponding to multiple models to be processed may be written into the same gap position at the same time. For example, the template value corresponding to the intersection of two cube models can be binary 011 (decimal 3), indicating that both the first and second bits are set to 1, reflecting that the position is composed of the gaps of the two models. This also shows that by applying the bit-by-bit numbering rule, when multiple models share a template value, the states will not overlap with each other.
[0100] S5. Set the rendering state of the patching plane and initiate the second rendering process, which involves single-sided rendering of the patching plane, processing the portion of the model that extends beyond the gap. The rendering state of the patching plane can also be set in advance in step S3, followed by the first and second rendering processes. This embodiment places the rendering state of the patching plane in step S5 for ease of understanding and does not represent the actual sequence of operations. After all models to be processed have been rendered and their gap information written, the patching planes at the gap locations need to be processed.
[0101] S51, enable stencil test to set the rendering state of the patch plane, including:
[0102] Set the stencil test function (StencilFunc option in the graphics engine): Set to Pass if Equal (EQUAL option in the image engine). This means that the fragment will pass the test only when "stencil value & mask" is equal to "reference value". & is the binary AND operator, which means that if the stencil value and the stencil mask have the same bit as 1, the output is 1, otherwise the output is 0.
[0103] To discard fragments with a stencil value of 0 after applying the stencil mask value, while retaining fragments with stencil values corresponding to the patch planes set to 1, set the mask (MASK) and reference value (REF): both to 2^n (2^n is 2 raised to the power of n), where n is the model number corresponding to the patch plane (consistent with the model to be processed). Set the stencil operation (StencilOp option in the graphics engine): Leave unchanged (KEEP option in the graphics engine). At this point, only the existing stencil value needs to be read to determine the gap, so no further modification of the stencil value is required.
[0104] At this point, the rendering status settings of the cutting plane, the model to be processed, and the patching plane are completed.
[0105] Because each number maps to a different binary bit in the template value, MASK=2^n means only bit n+1 is tested. In effect, when this bit is 1, it indicates that the fragment is a gap in the model to be processed, numbered n, and the corresponding fragment of the patch plane numbered n passes the test; when this bit is 0, the fragment of the patch plane numbered n is directly discarded.
[0106] S52, starts the second rendering process, including:
[0107] When the binary bit of the template value read by the fragment of the patch plane is finally 1, that is, the "template value & mask" is 2^n, which is equal to the reference value 2^n, the template test passes, and the fragment of the patch plane is retained.
[0108] In this embodiment, for ease of understanding, three models to be processed are used as examples. For example, if the final template value corresponding to a pixel is 110 in binary, it means that the pixel is located at the gap between Models 1 and 2 to be processed, or the exterior or solid part of Model 0 to be processed. At this time, the patch plane corresponding to Model 2 to be processed is being processed, so the template mask value is 100, and the reference value is 100.
[0109] Then, 110 (template value) & 100 (template mask value) is 100, which is equal to the reference value. That is, the template value binary bit corresponding to the pixel at the patch plane is finally 1, so the template test passes, and the patch plane fragment corresponding to the pixel position is retained.
[0110] When the template value binary bit corresponding to the pixel at the patch plane is finally 0, that is, the "template value & template mask" is 0, which is not equal to the reference value 2^n, the template test fails, and the patch plane fragment corresponding to the pixel position is discarded, and the part of the patch plane that exceeds the gap in the model to be processed is removed.
[0111] In this embodiment, for ease of understanding, three models to be processed are used as an example. For example, if the final template value corresponding to a pixel is 010 in binary, it means that the pixel is located at the gap of model 1 to be processed, the exterior or solid part of model 0 to be processed, and model 2 to be processed. At this time, the patch plane corresponding to model 2 to be processed is being processed, so the template mask value is 100 and the reference value is 100.
[0112] Then, 010 (template value) & 100 (template mask value) is 000, which is not equal to the reference value. That is, the template value corresponding to the pixel at the patch plane is finally 0, so the template test fails, and the fragment corresponding to the patch plane at this pixel position is discarded.
[0113] In summary, the pruning method of this embodiment is completed by setting the template mask (MASK) and the reference value (REF) to decimal 2^n and setting the template test function to pass when they are equal.
[0114] The beneficial effects of this embodiment include:
[0115] 1. The rendering order is adapted to parallel rendering, that is, all models are rendered first, and then the patch faces are rendered.
[0116] Traditional methods require immediate patching after rendering each model, and template values must be repeatedly cleared between models. This severely limits performance when dealing with a large number of models. This method, however, utilizes a "bitwise numbering rule" to allow a single template value to simultaneously record gaps in multiple models without interfering with each other. This allows batch rendering of multiple models to be processed, followed by unified rendering of the patching planes.
[0117] 2. Automatic sorting for transparent materials: In modern graphics engines (such as UE5 and Unity), setting the patch plane material to "Transparent" render mode automatically sorts it after all opaque objects, eliminating the need to manually specify the order. If you don't want the patch plane to appear transparent, simply enable the "Transparent" render pass in the material properties; the actual shading will still appear opaque.
[0118] 3. Applying Multi-Model Parallel Rendering: Because each model only modifies its own bit in the template value, it can fully utilize parallel pipelines or deferred rendering mechanisms, reducing pipeline switching and template clearing operations. For complex applications with large scenes and multiple objects (such as architectural visualization and geological exploration), this method can significantly improve rendering efficiency.
[0119] 4. The present invention can be widely applied to various graphics APIs (such as OpenGL, Vulkan, DirectX, etc.) and modern graphics engines (such as UE5, Unity, etc.), and has good cross-platform compatibility.
[0120] It should be noted that the order of the above steps is not fixed and can be changed as needed. For example, after completing all the above rendering state settings, you can batch render the scene to obtain the final sectioning and filling effect.
[0121] like Figure 8 As shown, each cutout in the model being processed is precisely filled with the corresponding patch plane, maintaining the overall visual consistency with the original model. Compared to traditional methods that rely on "front-side subtraction and back-side addition" or sequentially clearing template values, this method, with its bitwise numbering scheme and double-sided rendering, greatly simplifies the rendering process and significantly improves parallelization efficiency. This approach is particularly well-suited for modern graphics engines' deferred rendering pipelines and large-scale multi-model scenarios.
[0122] Compared to existing techniques, this embodiment uses bitwise inversion (INVERT) and a numbered mask (MASK = 2^n) to simultaneously record gaps in multiple models within the same stencil buffer value. Filled planes are rendered only when the corresponding binary bit is equal to 1, eliminating the need for additional order control and seamlessly integrating with the latency and parallel pipelines of modern rendering engines.
[0123] The present invention utilizes bitwise corresponding numbering rules, a combination of double-sided rendering and bitwise inversion, and a parallel mechanism in which multiple models share a single template value. This solves the problems of traditional methods such as frequent clearing of template values, strict reliance on sequential rendering, and insufficient support for multiple models. It also seamlessly connects with the deferred rendering pipeline of modern graphics engines, greatly improving rendering efficiency and maintainability in complex scenarios.
[0124] In a second embodiment, an intelligent terminal includes a processor and a memory, wherein the memory stores a computer program, the processor is in communication with the memory, and the processor executes the template buffer-based multi-model face filling method of the first embodiment through the computer program.
[0125] The third embodiment is a computer-readable storage medium, wherein the computer-readable storage medium stores program data, and the program data is used to execute the template buffer-based multi-model surface filling method of the first embodiment.
[0126] The preferred embodiments of the present invention are described in detail above in conjunction with the accompanying drawings. However, the present invention is not limited to the specific details in the above embodiments. Within the technical concept of the present invention, various simple modifications can be made to the technical solution of the present invention, and these simple modifications all fall within the scope of protection of the present invention.
Claims
1. A multi-model face filling method based on template buffer, characterized in that: The steps include: Obtain several models to be processed and defined cutting planes, and generate corresponding patching planes; Set a number n corresponding to the binary bit of the template value in the template buffer for the model to be processed, and the patch plane and its corresponding model to be processed use the same number; Setting the rendering state of the model to be processed and the patching plane, including: setting the template mask value of the model to be processed and the patching plane to the power of 2; setting the initial value of the template value to 0; The first rendering process is started, including: performing double-sided rendering on the model to be processed, and inverting the template value based on the template mask value each time a pixel is covered by a fragment, thereby writing the model gap information into the template value; Start the second rendering process and perform single-sided rendering on the patch plane. Keep the fragments of the patch plane whose template value corresponds to the binary bit of 1 after the first rendering process, and discard the fragments of the patch plane whose template value corresponds to the binary bit of 0, thereby cutting off the part of the patch plane that exceeds the area to be patched, and completing the trimming of the patch plane.
2. The multi-model face filling method based on template buffer according to claim 1, characterized in that: It also includes setting the rendering state of the patch plane before starting the second rendering process. The settings include: Passes when the template test function is set to equality; Set both the template mask value and the reference value to powers of 2.
3. The multi-model face filling method based on template buffer according to claim 2, characterized in that: It also includes setting the "Stencil Test Operation" of the stencil buffer to bitwise inversion and the stencil test function to always pass before starting the first rendering process.
4. The multi-model face filling method based on template buffer according to claim 1, 2 or 3, characterized in that: The number n is used to number the models to be processed starting from 0.
5. The multi-model face filling method based on template buffer according to claim 1, 2 or 3, characterized in that: It also includes passing the cutting plane information to the shader to form a cutting surface, the steps of which are: The cutting plane is defined by a general plane equation. When the coordinates of a given fragment are substituted into the plane equations of all the cutting planes and the resulting values are greater than 0, the fragment is deleted; otherwise, the fragment is retained, thereby forming a cutting plane.
6. The multi-model face filling method based on template buffer according to claim 1, 2 or 3, characterized in that: The patching plane is used to fill the gap generated after sectioning. The step of generating the patching plane includes: traversing each model to be processed and generating a corresponding patching plane according to the intersection position of the model with the sectioning plane.
7. The multi-model face filling method based on template buffer according to claim 1, 2 or 3, characterized in that: The settings for the rendering status of the patch plane also include: setting the template operation to remain unchanged.
8. An intelligent terminal, characterized in that: The intelligent terminal includes a processor and a memory, wherein the memory stores a computer program, the processor is in communication with the memory, and the processor executes the template buffer-based multi-model face filling method according to any one of claims 1 to 7 through the computer program.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program data, and the program data is used to execute the template buffer-based multi-model surface filling method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method for dynamically sectioning multiple-object model based on template buffering
CN102013113A
Solid sectioning method of three-dimensional object, terminal and storage medium
CN115690378A
A triangular mesh model-based automatic surface patching algorithm for a sectioned contour
CN109685914A
Web end three-dimensional geological model dynamic sectioning and profile filling method
CN113487718A