Virtual 3D scene construction method
Patent Information
- Application Number
- CN202410753356.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2044-06-12
AI Technical Summary
In the construction of virtual three-dimensional scenes, the excessive number of polygons leads to insufficient rendering performance, especially on platforms with limited resources, which is particularly obvious, affecting the smoothness of the application.
Through polygon topology analysis, merging and normal optimization, the model detail level is dynamically adjusted in combination with viewpoint distance, view angle, object importance and curvature, and the rendering process is accelerated by using GPU parallel calculations to optimize the number of polygons and lighting effects.
Significantly improve rendering performance, allowing applications to run smoothly on lower-performance hardware and reduce memory usage, especially for mobile devices and virtual reality head-mounted displays.
Smart Images

Figure CN118628654B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer graphics, and in particular to a method for constructing a virtual three-dimensional scene. Background Art
[0002] Virtual 3D scene construction refers to the creation and presentation of a virtual environment with a three-dimensional feel through computer technology and graphics principles. Such an environment can be used in various applications, such as game development, virtual reality (VR) and augmented reality (AR) applications, simulation training, etc. Virtual 3D scene construction mainly includes: modeling, lighting and rendering, scene design, camera settings and perspective control, etc. At the same time, virtual 3D scene construction must also consider polygon optimization. Polygon optimization is a key step in virtual 3D scene construction, which aims to ensure that the number and complexity of polygons in the scene are moderate to maintain good performance. In computer graphics, each object is composed of many polygons, which present the shape and surface of the object on the screen. Optimizing these polygons is crucial to improving rendering performance. Summary of the Invention
[0003] In order to solve the above problems, the present invention provides a method for constructing a virtual three-dimensional scene.
[0004] To achieve the above object, the technical solutions adopted by the present invention are as follows:
[0005] A method for constructing a virtual three-dimensional scene includes the following steps:
[0006] Step 1: Get the geometric data of the objects in the scene, including the vertex coordinates and normal information of the objects;
[0007] Step 2: For each object, perform polygon topology analysis to determine the relationship between polygons;
[0008] Step 3: Reduce the total number of polygons in the scene by controlling the number of polygons and merging adjacent polygons into a larger polygon.
[0009] Step 4: Perform normal optimization to ensure the realism of the lighting effect and improve the lighting effect of the scene;
[0010] Step 5: Dynamically adjust the level of detail of the object models in the scene based on the viewpoint distance, viewing angle, object importance, current rendering load, and curvature;
[0011] Step 6: Use parallel computing to accelerate the rendering process of the scene.
[0012] Further: Step 1 includes:
[0013] The surface of the object is represented as a set of vertices. Let the vertex set of the object surface be:
[0014] V={v1,v2,...,v n}
[0015] Where n is the number of vertices;
[0016] For each vertex v i , get its spatial coordinates P i ={x i ,y i ,z i} and normal vector N i ={n xi ,n yi ,n zi};
[0017] Use the normal information of the vertex to construct the normal of the object surface;
[0018] Divide the surface of a three-dimensional object into multiple polygons to form a polygon set:
[0019] F={f1,f2,...,f m}
[0020] Where m is the number of polygons;
[0021] For each polygon f j , record its vertex index to determine the topological structure of the object surface:
[0022] f j ={v i1 ,v i2 ,...,v ik}
[0023] Further: Step 2 includes:
[0024] Create a polygon adjacency matrix A, where A ij =1 means polygon f i With f j Adjacent, A ij =0 means polygon f i With f j Not adjacent, traverse the polygon set F, check whether each pair of polygons shares a vertex, and determine the adjacent relationship of the polygons:
[0025]
[0026] For each polygon f i , recording its boundary information, including the indices of adjacent polygons and shared edges:
[0027] Boundary(f j )={(f j ,ek )|Shared edge e k with f j}
[0028] Use the polygon adjacency matrix A to construct the polygon adjacency graph G = (V, E), where vertex v i Represents polygon f i , side e ij Represents polygon f i With f j There is an adjacent relationship between them:
[0029] E={(v i ,v j )|A ij =1}
[0030] Further: Step 3 includes:
[0031] For every pair of adjacent polygons f i and f j , calculate the distance between the two:
[0032] Dist(f i ,f j )=||Centroid(f i )-Centroid(f j )||
[0033] Among them, Centroid (f i ) represents the center point of the polygon;
[0034] Set the distance threshold D threshold , used to determine whether two adjacent polygons can be merged. If Dist(f i ,f j ) <D threshold , you can merge;
[0035] Traverse the polygon adjacency graph G, for each pair of adjacent polygons v i and v j , check the distance between the two, if Dist(f i ,f j )>D theshold , then merge them into a new polygon v merged ;
[0036] After the merge operation, update the polygon adjacency graph G and remove the original polygon v i and v j , add the newly merged polygon v merged :
[0037] G′=V′,E′
[0038] V′=V-{v i ,v j}∪{v merged}
[0039] E'=E-{(v i ,v j )}∪{(v i ,v merged ),(v j ,v merged )}
[0040] Further: Step 4 includes:
[0041] Through the vertex v i The initial normal vector n is obtained by weighted average of the normals of the polygons in the neighborhood i :
[0042]
[0043] Among them, N(v i ) is the vertex v i The set of polygons in the neighborhood of A f is the area of polygon f, n f is the normal vector of polygon f;
[0044] Use Laplace smoothing to reduce the normal vector n i Fluctuations:
[0045]
[0046] Where λ is the smoothing coefficient, N(i) is the vertex v i The set of adjacent vertices of ;
[0047] Compute the curvature at each vertex to preserve feature detail:
[0048]
[0049] Among them, α ij and β ij is the diagonal angle of the two triangles around the edge (i, j), A i is the vertex v i mixed areas;
[0050] Update the normal vector:
[0051]
[0052] Among them, γ is the control parameter;
[0053] Normalize the updated normal vector:
[0054]
[0055] Apply the normalized normal vector information to each vertex v i .
[0056] Further: Step 5 includes:
[0057] In the LOD management step, this embodiment dynamically adjusts the model's level of detail based on viewpoint distance, viewing angle, object importance, current rendering load, and curvature. The calculation formula is as follows:
[0058] L i =αD f +βS f +γI f +δL f +∈K i
[0059] in:
[0060] L i : LOD level of model i;
[0061] D f : Viewpoint distance factor, calculated as Among them, d i is the distance from model i to the viewpoint, d min and d max are the minimum and maximum distances, d i =||p i -p v ||, where p i is the position vector of model i, p v is the viewpoint position vector;
[0062] S f : View factor, calculated as Where V i is the direction vector from the viewpoint to model i, N i is the normal vector of model i;
[0063] I f : Importance factor, pre-set weight value;
[0064] L f : Load factor, the current load of the rendering system, calculated as where l current is the current load, l max is the maximum load;
[0065] K i : curvature factor, calculated as Among them, K i Represents vertex v i The curvature, A i Represents vertex v i The area of the mixed region, N(i) represents the vertex v i The set of adjacent vertices, α ij and β ij represents the diagonal angle between two triangles around edge (i, j), V i and V j Represents vertex v i and v j location.
[0066] Further: Step 6 includes:
[0067] Define the following rendering equation:
[0068]
[0069] Among them, I represents the final color, L represents the incident light, R represents the reflected light, A represents the ambient light intensity, and k d 、k s 、k t Represents the material coefficients of diffuse reflection, specular reflection and transmission respectively, L d 、L s 、L t Represent the light intensity of diffuse reflection, specular reflection and transmission respectively, represents the normal vector, represents the direction of incident light, Indicates the direction of reflected light, Indicates the viewpoint direction, represents a half-angle vector;
[0070] Apply the rendering equation to each polygon calculation;
[0071] Cache rendering results in video memory to reduce data transmission overhead.
[0072] Compared with the prior art, the present invention has the following technical advances:
[0073] By optimizing the polygons in a scene, this method significantly improves rendering performance, resulting in smoother applications. Polygon optimization enables applications to run on lower-performance hardware, making it particularly important for resource-constrained platforms such as mobile devices and virtual reality head-mounted displays. Optimization results in fewer polygons, which means less memory usage, as each polygon requires storing vertices and other associated data. This is particularly critical for mobile devices and applications that require large numbers of models. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0075] In the attached figure:
[0076] Figure 1 Flowchart of the present invention. DETAILED DESCRIPTION
[0077] The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. The embodiments of the present invention will be described below with reference to the accompanying drawings.
[0078] like Figure 1 As shown, the present invention discloses a method for constructing a virtual three-dimensional scene, comprising the following steps:
[0079] Step 1: Scene modeling and geometric data acquisition: The first step in constructing a virtual three-dimensional scene. This embodiment uses mathematical representation methods to obtain the geometric data of objects in the scene, including the vertex coordinates and normal information of the objects, for subsequent polygon optimization.
[0080] Step 2: Polygon topology analysis: For each object, perform polygon topology analysis to determine the relationship between polygons, including adjacency and connection. This step is to establish a topological relationship diagram between polygons to provide a basis for subsequent optimization.
[0081] Step 3: Polygon number control and merging: By controlling the number of polygons, close polygons are merged into a larger polygon to reduce the total number of polygons in the scene. The optimization goal of this step is to reduce the computational load and improve overall performance.
[0082] Step 4: Lighting and normal optimization: Considering the impact of lighting on scene rendering performance, normal optimization is performed to ensure the realism of the lighting effect. By smoothing the normals and optimizing the calculation of the normal vectors, the lighting effect of the scene is improved while reducing redundant calculations.
[0083] Step 5: LOD (Level of Detail) Management: LOD is used to manage models at different levels, so that simplified models can be used when viewed from a distance, further reducing the rendering load and improving the frame rate.
[0084] Step 6 GPU parallel computing optimization: Make full use of the parallel computing capabilities of the graphics processing unit (GPU), use parallel computing technology to accelerate the rendering process of the scene, improve rendering performance, and ensure parallel processing of polygons.
[0085] Scene modeling and geometric data acquisition provide the basic geometric data for building virtual environments and provide the original data for subsequent polygon optimization. Polygon topology analysis establishes the relationship between polygons based on geometric data, providing a topological structure basis for polygon optimization. Polygon number control and merging, based on topological analysis, optimize the number of polygons by merging adjacent polygons, reducing the computational burden of subsequent processing. Lighting and normal optimization optimizes normals based on the merged polygons, ensuring the authenticity of the lighting effect while reducing redundant calculations. LOD management adjusts the model's level of detail according to the scene's geometric data and polygon number to maintain rendering performance at different viewpoint distances. Texture compression and optimization further optimize texture data, reduce memory usage and data transmission overhead, and provide a more streamlined input for GPU parallel computing. GPU parallel computing optimization makes full use of the optimized data structure and texture, and improves the scene's rendering performance through parallel computing technology.
[0086] Specifically, step 1 includes:
[0087] In the scene modeling and geometric data acquisition steps, this embodiment adopts the following modeling method:
[0088] The surface of an object is represented as a set of vertices. An object surface is composed of multiple triangles or other polygons connected together. Let the vertex set of the object surface be:
[0089] V={v1,v2,...,v n}
[0090] Where n is the number of vertices;
[0091] For each vertex v i , get its spatial coordinates P i ={x i ,y i ,z i} and normal vector N i ={n xi ,n yi ,n zi}, this information constitutes the geometric data of the object, and the normals of the object surface are constructed using the normal information of the vertices.
[0092] Divide the surface of a three-dimensional object into multiple polygons, such as triangles, to form a polygon set:
[0093] F={f1,f2,...,f m}
[0094] Where m is the number of polygons;
[0095] For each polygon f j, record its vertex index to determine the topological structure of the object surface:
[0096] f j ={v i1 ,v i2 ,...,v ik}
[0097] Through the above steps, this embodiment completes the modeling of objects in the virtual three-dimensional scene and obtains geometric data for subsequent polygon optimization, laying the foundation for the optimization process.
[0098] Specifically, step 2 includes:
[0099] In the polygon topology analysis step, this embodiment uses the polygon set F and vertex indexes obtained during the modeling process to establish the topological relationship between polygons:
[0100] Create a polygon adjacency matrix A, where A ij =1 means polygon f i With f j Adjacent, A ij =0 means polygon f i With f j Non-adjacent, by traversing the polygon set F and checking whether each pair of polygons shares a vertex, the adjacent relationship of the polygons is determined:
[0101]
[0102] For each polygon f i , record its boundary information, including the index of adjacent polygons and shared edges, which can be used in the subsequent polygon optimization process:
[0103] Boundary(f j )={(f j ,e k )|Shared edge e k with f j
[0104] Use the polygon adjacency matrix to construct the polygon adjacency graph G = (V, E), where vertex v i Represents polygon f i , side e ij Represents polygon f i With f j There is an adjacent relationship between them:
[0105] E={(v i ,v j )|A ij =1}
[0106] Through the above steps, this embodiment establishes a topological relationship diagram between polygons, providing a basis for subsequent polygon optimization.
[0107] Specifically, step 3 includes:
[0108] In the steps of controlling and merging the number of polygons, this embodiment uses the polygon adjacency graph G and topological relationship information to reduce the number of polygons.
[0109] For every pair of adjacent polygons f i and f j , calculate the distance between the two. In this embodiment, the Euclidean distance between the polygon center points is selected, that is:
[0110] Dist(f i ,f j )=||Centroid(f i )-Centroid(f j )||
[0111] Among them, Centroid (f i ) represents the center point of the polygon.
[0112] Set a distance threshold D threshold , used to determine whether two adjacent polygons can be merged. If Dist(f i ,f j ) <D threshold , they are considered to be mergeable.
[0113] Traverse the polygon adjacency graph G, for each pair of adjacent polygons v i and v j , check the distance between the two, if Dist(f i ,f j ) <D threshold , then merge them into a new polygon v merged ;
[0114] After the merge operation, update the polygon adjacency graph G and remove the original polygon v i and v j , add the newly merged polygon v merged :
[0115] G′=V′,E′
[0116] V′=V-{v i ,v j}∪{v merged}
[0117] E'=E-{(v i ,v j)}∪{(v i ,v merged ),(v j ,v merged )}
[0118] In this embodiment, V and E respectively represent the sets of vertices and edges in the original polygon adjacency graph G, and V' and E' respectively represent the sets of vertices and edges in the updated graph G' after the merge operation, that is, G'=V', E' is the updated graph.
[0119] {v i ,v j} means removing the original polygon v from the adjacency graph i and v j , because in the merge operation, the original two polygons v i and v j have been merged into a new polygon that no longer exists in its original form.
[0120] {v merged} represents the addition of the newly merged polygon v merged , is to add the newly merged polygon to the adjacency graph to reflect its adjacency relationship with other polygons.
[0121] That is, after the merge operation, the merged polygon v is removed from the original adjacency graph. i and v j , then add the new polygon v merged , to update the polygon adjacency graph, ensuring that the adjacency graph reflects the new topology, where the neighbor relationships have been adjusted to accommodate the effects of the merge operation.
[0122] Through the above steps, this embodiment can implement polygon merging operations based on distance and topological relationships, which can reduce the total number of polygons in the scene, thereby alleviating the computing load and improving overall performance.
[0123] Specifically, step 4 includes:
[0124] In the lighting and normal optimization step, this embodiment optimizes the lighting effect of the scene by smoothing the normal vectors:
[0125] Initial normal calculation, first, calculate each vertex v i The initial normal vector n i , in this embodiment, is obtained by weighted averaging of the normals of the polygons in the vertex neighborhood:
[0126]
[0127] Among them, v i Indicates the vertex whose normal vector is currently to be calculated, N(vi ) represents the vertex v i The neighborhood of v i A set of connected polygons, A f Represents the area of polygon f, used to weight the normal vector of the polygon, n f represents the normal vector of polygon f, and ||·|| represents the modulus (length) of the vector.
[0128] By the vertex v i The normal vector n of each polygon f in the neighborhood of f Perform weighted averaging to obtain vertex v i The initial normal vector n i , where the normal vector n of each polygon is f Its area A f The weighting can ensure that polygons with larger areas contribute more to the normal vector, thereby obtaining a more accurate vertex normal vector.
[0129] Vector field smoothing is to smooth the normal vector field to reduce the fluctuation of the normal vector in adjacent areas. In this embodiment, the Laplace smoothing method is used:
[0130]
[0131] Among them, n' i Represents vertex v i The smoothed normal vector, n i Represents vertex v i The original normal vector of ,λ represents the smoothing coefficient, which controls the degree of smoothing, and N(i) represents the vertex v i The set of adjacent vertices.
[0132] For vertex v i , its original normal vector n i The normal vector n of its adjacent vertex j Perform weighted averaging and then add the average result to the original normal vector to get the smoothed normal vector n' i , the smoothing coefficient λ controls the amplitude of smoothing. When λ is larger, the smoothing effect is more significant, and when λ is smaller, the smoothing effect is weaker.
[0133] Curvature optimization considers the impact of curvature on the normal vector and retains feature edges and details, that is, calculates the curvature of each vertex:
[0134]
[0135] Among them, K i Represents vertex v i The curvature, A i Represents vertex vi The area of the mixed region, N(i) represents the vertex v i The set of adjacent vertices, α ij and β ij represents the diagonal angle between two triangles around edge (i, j), V i and V j Represents vertex v i and v j location.
[0136] For vertex v i , first calculate its adjacent vertex v j The angle α between ij and β ij , then calculate the sum of the cotangent values of the edge angles on the side (i, j) and add it to (V i -V j ) and finally divided by the vertex v i The area of the mixing region A i , so we can get the vertex v i The curvature K i , used in the subsequent optimization process when updating the normal vector.
[0137] Normal update, using curvature information to update the normal vector, combining vector field smoothing results and curvature optimization:
[0138]
[0139] Where n i : represents vertex v i Updated normal vector; n' i : The normal vector after the vector field is smoothed, representing the vertex v i The initial smoothing result of γ: control parameter, ranging from 0 to 1, used to adjust the weight between vector field smoothing and curvature optimization; N(i): vertex v i The neighborhood vertex set is used to calculate the normal vector and curvature of the adjacent vertices; K j : Vertex v j The curvature of n is used to weight the normal vectors of adjacent vertices; j : Vertex v j The normal vector of , participates in the calculation of weighted average.
[0140] Among them, (1-γ)n' i Represents the result of vector field smoothing, reflecting the vertex v i The smoothed normal vector of Represents the normal vector update result based on curvature optimization, Indicates the use of curvature K j For adjacent vertices v jThe normal vector n j By performing weighted averaging and normalizing it, we can balance the results of vector field smoothing and curvature optimization, ensuring the consistency of normal vectors in adjacent areas while retaining detailed features, making the final normal vector more consistent with the actual situation.
[0141] Normalize the normal vector: Normalize the updated normal vector to ensure it is a unit vector:
[0142]
[0143] The purpose of normalization is to ensure that the updated normal vector has a length of 1, that is, to convert it to a unit vector, where:
[0144] Represents vertex v i The final normalized normal vector;
[0145] n″ i : represents vertex v i Updated normal vector;
[0146] ||n″ i ||: represents vector n″ i The modulus (length).
[0147] The purpose of normal vector normalization is to normalize the updated normal vector n″ i Normalize to a unit vector of length 1. This is very important for the use of normal vectors, because many calculations (such as lighting calculations) rely on the unit length property of normal vectors, and the normalization operation only changes the length of the vector, not its direction, which ensures that the updated normal vector is still correct in direction, but the length is adjusted to 1.
[0148] The specific standardization process is as follows:
[0149] 1. Calculate the modulus of a vector:
[0150] ||n″ i || is the vector n″ i The modulus is calculated as:
[0151]
[0152] in, Represents vector n″ i The x, y, and z components of .
[0153] 2. Divide a vector by its modulus:
[0154] The vector n″ i Divide by its modulus || n″i ||, get the unit vector
[0155]
[0156] This is obtained The length is 1 and the direction is n″ i same.
[0157] By normalizing the normal vector, it is possible to ensure that the updated normal vector is standardized to 1 in length, making it suitable for subsequent lighting calculations and rendering processes, maintaining the consistency and accuracy of the calculations.
[0158] Apply the normalized normal vector information to each vertex v i , which can ensure the consistency of normal vectors in the lighting model and improve the realism of the lighting effect.
[0159] Specifically, step 5 includes:
[0160] In the LOD management step, this embodiment dynamically adjusts the model's level of detail based on viewpoint distance, viewing angle, object importance, current rendering load, and curvature. The calculation formula is as follows:
[0161] L i =αD f +βS f +γI f +δL f +∈K i
[0162] in:
[0163] L i : LOD level of model i.
[0164] D f : Viewpoint distance factor, calculated as Among them, d i is the distance from model i to the viewpoint, d min and d max are the minimum and maximum distances, d i =||p i -p v ||, where p i is the position vector of model i, p v is the viewpoint position vector. Viewpoint distance directly affects the viewer's perception of object detail. When objects are closer to the viewpoint, the human eye can discern more detail, while closer objects require less detail. Therefore, adjusting the level of detail based on viewpoint distance can reduce detail in distant objects without affecting the visual experience, thereby saving computing resources.
[0165] S f : View factor, calculated as Where V i is the direction vector from the viewpoint to model i, N i is the normal vector of model i. Viewing angle determines the saliency of an object in the field of view. Objects facing forward require higher levels of detail than those facing sideways or from behind. Therefore, by considering viewing angle, we can optimize the allocation of rendering resources, ensuring a higher level of detail in areas of interest to the viewer, while reducing detail in areas of non-interest, improving overall rendering performance.
[0166] I f Importance factor: A pre-set weighting value. Different objects in a scene have varying degrees of importance. For example, key characters or props typically require higher levels of detail. Therefore, dynamically adjusting the level of detail of objects based on their importance effectively highlights key elements and ensures consistently high-quality rendering of the core of the scene.
[0167] L f : Load factor, the current load of the rendering system, calculated as Among them L current is the current load, l max is the maximum load. Real-time rendering performance is affected by the current system load. Therefore, dynamically adjusting the level of detail based on the real-time load can balance visual quality and rendering performance, ensuring a smooth user experience.
[0168] K i : curvature factor, calculated as Among them, K i Represents vertex v i The curvature, A i Represents vertex v i The area of the mixed region, N(i) represents the vertex v i The set of adjacent vertices, α ij and β ij represents the diagonal angle between two triangles around edge (i, j), V i and V j Represents vertex v i and v j location.
[0169] Curvature reflects the complexity of an object's surface. High-curvature areas usually require more details to accurately represent their shapes and features. Therefore, the introduction of the curvature factor can more finely control the level of detail of the object's surface. For areas with high curvature, more polygons are retained to make the details richer and more realistic. For flat areas with low curvature, the number of polygons is reduced to optimize rendering efficiency. In areas with high curvature, such as the edges, corners or feature points of an object, details are more easily noticed and identified by the audience. The curvature factor can be used to retain high details in these key areas, enhancing the realism of the object. For areas with low curvature, such as large flat surfaces, reducing the number of unnecessary polygons can significantly reduce rendering overhead without affecting visual quality, thereby improving overall rendering efficiency.
[0170] At the same time, the curvature factor helps ensure that the adjustment of the detail level is not only based on geometric and positional factors, but also takes into account the shape characteristics of the object itself, making the change of the detail level more natural and reasonable. While maintaining visual details, it minimizes unnecessary waste of computing resources and improves rendering efficiency.
[0171] α, β, γ, δ, ∈: weight coefficients used to adjust the influence of each factor.
[0172] Assume there are N LOD levels, use L i Select the specific LOD model accordingly:
[0173]
[0174] Among them LOD i Indicates the LOD level selected by model i, Indicates rounding down.
[0175] Specifically, step 6 includes:
[0176] In the step of GPU parallel computing optimization, this embodiment fully utilizes the parallel computing capabilities of the graphics processing unit (GPU) to improve rendering performance:
[0177] The following rendering equation is used:
[0178]
[0179] Among them, I represents the final color, L represents the incident light, R represents the reflected light, A represents the ambient light intensity, and k d 、k s 、k t Represents the material coefficients of diffuse reflection, specular reflection and transmission respectively, L d , L s , L t Represent the light intensity of diffuse reflection, specular reflection and transmission respectively, represents the normal vector, represents the direction of incident light, Indicates the direction of reflected light, Indicates the viewpoint direction, Represents a half-width vector.
[0180] Applying the rendering equation to the calculation of each polygon can be achieved through GPU Shader in this implementation. In the Shader, the final color of each pixel is calculated by writing code. For each pixel, the final color of the pixel can be obtained by calculating according to the material coefficients of its diffuse reflection, specular reflection and transmission, as well as the incident light, reflected light, transmitted light and ambient light factors according to the rendering equation.
[0181] Caching rendering results in video memory reduces data transfer overhead, helps improve frame rates, and alleviates data transfer bottlenecks between the CPU and GPU, including:
[0182] When initializing the rendering environment, create an FBO object. FBO is a virtual frame buffer used to store rendering results.
[0183] Create an attachment for FBO, which can be a texture attachment to store the rendered color information;
[0184] Also create a depth buffer attachment;
[0185] After setting up the FBO, check whether the FBO is complete and make sure all attachments are bound correctly;
[0186] When rendering the scene, set the FBO as the current frame buffer;
[0187] Render the scene to an FBO instead of the default frame buffer, and the rendering results are saved in the FBO's attachment.
[0188] Through the above steps, this embodiment caches the rendering results in the video memory, which can alleviate the data transmission bottleneck between the CPU and GPU and improve the frame rate. When the rendering results are needed, they can be directly accessed in the video memory without expensive data transmission.
[0189] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art will be able to modify the technical solutions described in the aforementioned embodiments or substitute equivalents for some of the technical features. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the claims of the present invention.
Claims
1. A method for constructing a virtual three-dimensional scene, characterized in that: The steps include: Step 1: Get the geometric data of the objects in the scene, including the vertex coordinates and normal information of the objects; Step 2: For each object, perform polygon topology analysis to determine the relationship between polygons; Step 3: Reduce the total number of polygons in the scene by controlling the number of polygons and merging adjacent polygons into a larger polygon. Step 4: Perform normal optimization to ensure realistic lighting effects and improve the lighting effects of the scene, including: Calculate each vertex v i The initial normal vector n i , obtained by weighted averaging of the normals of polygons in the vertex neighborhood: Among them, v i Indicates the vertex whose normal vector is currently to be calculated, N(v i ) represents the vertex v i The neighborhood of v i A set of connected polygons, A f Represents the area of polygon f, used to weight the normal vector of the polygon, n f represents the normal vector of polygon f, ‖·‖ represents the modulus of the vector; By the vertex v i The normal vector n of each polygon f in the neighborhood of f Perform weighted averaging to obtain vertex v i The initial normal vector n i , where the normal vector n of each polygon is f Its area A f weighted; Use the Laplace smoothing method to smooth the normal vector field to reduce the fluctuation of the normal vector in adjacent areas: Among them, n i ′ Represents vertex v i The smoothed normal vector, n i Represents vertex v i The original normal vector of ,λ represents the smoothing coefficient, which controls the degree of smoothing, and N(i) represents the vertex v i The set of adjacent vertices of ; For vertex v i , its original normal vector n i The normal vector n of its adjacent vertex j Perform weighted averaging and then add the average result to the original normal vector to obtain the smoothed normal vector n i ′ , the smoothing coefficient λ controls the amplitude of smoothing; Considering the effect of curvature on the normal vector, retaining feature edges and details, that is, calculating the curvature of each vertex: Among them, K i Represents vertex v i The curvature, A i Represents vertex v i The area of the mixed region, N(i) represents the vertex v i The set of adjacent vertices, α ij and β ij represents the diagonal angle between two triangles around edge (i, j), V i and V j Represents vertex v i and v j location; For vertex v i , first calculate its adjacent vertex v j The angle α between ij and β ij , then calculate the sum of the cotangent values of the edge angles on the side (i, j) and add it to (V i -V j ) and finally divided by the vertex v i The area of the mixing region A i , get vertex v i The curvature K i ; Use curvature information to update the normal vector, combining the vector field smoothing results and curvature optimization: Where n i : represents vertex v i Updated normal vector; n′ i : The normal vector after the vector field is smoothed, representing the vertex v i The initial smoothing result of γ: control parameter, ranging from 0 to 1, used to adjust the weight between vector field smoothing and curvature optimization; N(i): vertex v i The neighborhood vertex set is used to calculate the normal vector and curvature of the adjacent vertices; K j : Vertex v j The curvature of n is used to weight the normal vectors of adjacent vertices; j : Vertex v j The normal vector of , participates in the calculation of weighted average; Among them, (1-γ)n i ′ Represents the result of vector field smoothing, reflecting the vertex v i The smoothed normal vector of Represents the normal vector update result based on curvature optimization, Indicates the use of curvature K j For adjacent vertices v j The normal vector n j Perform weighted averaging; Step 5: Dynamically adjust the level of detail of the object models in the scene based on the viewpoint distance, viewing angle, object importance, current rendering load, and curvature; Step 6: Use parallel computing to accelerate the rendering process of the scene.
2. The method for constructing a virtual three-dimensional scene according to claim 1, wherein: The step 1 comprises: The surface of the object is represented as a set of vertices. Let the vertex set of the object surface be: V={v1,v2,...,v n } Where n is the number of vertices; For each vertex v i , get its spatial coordinates P i ={x i ,y i ,z i } and normal vector N i ={n xi ,n yi ,n zi }; Use the vertex normal information to construct the normal of the object surface; Divide the surface of a three-dimensional object into multiple polygons to form a polygon set: F={F1,f2,...,f m } Where m is the number of polygons; For each polygon f j , record its vertex index to determine the topological structure of the object surface: f j ={v j1 ,v j2 ,...,v jk }。 3. The method for constructing a virtual three-dimensional scene according to claim 2, wherein: The step 2 includes: Create a polygon adjacency matrix A, where A ij =1 means polygon f i With f j Adjacent, A ij =0 means polygon f i With f j Not adjacent, traverse the polygon set F, check whether each pair of polygons shares a vertex, and determine the adjacent relationship of the polygons: For each polygon f i , recording its boundary information, including the indices of adjacent polygons and shared edges: Boundary(f j )={(f j ,e k )|Shared edge e k with f j } Use the polygon adjacency matrix A to construct the polygon adjacency graph G = (F, E), edge e ij Represents polygon f i With f j There is an adjacent relationship between them: E={(f i ,f j )|A ij =1}。 4. The method for constructing a virtual three-dimensional scene according to claim 3, wherein: The step 3 comprises: For every pair of adjacent polygons f i and f j , calculate the distance between the two: Dist(f i ,f j )=||Centroid(f i )-Centroid(f j )|| Among them, Centroid (f i ) represents the center point of the polygon; Set the distance threshold D threshold , used to determine whether two adjacent polygons are merged. If Dist(f i ,f j ) <D threshold , then merge; Traverse the polygon adjacency graph G, for each pair of adjacent polygons f i and f j , check the distance between the two, if Dist(f i ,f j ) <D threshold , then merge them into a new polygon v merged ; After the merge operation, update the polygon adjacency graph G and remove the original adjacent polygon f i and f j , add the newly merged polygon f merged : G ′ =F,E ′ F ′ =F-{f i ,f j }∪{f merged } E ′ =E-{(f i ,f j )}∪[(f i ,f merged ),(f j ,f merged )}。 5. The method for constructing a virtual three-dimensional scene according to claim 4, wherein: The step 5 comprises: In the LOD management step, this embodiment dynamically adjusts the model's level of detail based on viewpoint distance, viewing angle, object importance, current rendering load, and curvature. The calculation formula is as follows: L i =αD f +βS f +γI f +δL f +∈K i in: L i : LOD level of model i; D f : Viewpoint distance factor, calculated as Among them, d i is the distance from model i to the viewpoint, d min and d max are the minimum and maximum distances, d i =‖p i -p v ‖, where p i is the position vector of model i, p v is the viewpoint position vector; S f : View factor, calculated as Where V i is the direction vector from the viewpoint to model i, N i is the normal vector of model i; I f : Importance factor, pre-set weight value; L f : Load factor, the current load of the rendering system, calculated as where l current is the current load, l max is the maximum load; K i : curvature factor, calculated as Among them, K i Represents vertex v i The curvature, A i Represents vertex v i The area of the mixed region, N(i) represents the vertex v i The set of adjacent vertices, α ij and β ij represents the diagonal angle between two triangles around edge (i, j), V i and V j Represents vertex v i and v j location.
6. The method for constructing a virtual three-dimensional scene according to claim 5, wherein: The step 6 comprises: Define the following rendering equation: Among them, I represents the final color, L represents the incident light, T represents the reflected light, Lx represents the ambient light intensity, k d 、k s 、k t Represents the material coefficients of diffuse reflection, specular reflection and transmission respectively, L d 、L s 、L t Represent the light intensity of diffuse reflection, specular reflection and transmission respectively, represents the normal vector, represents the direction of incident light, Indicates the direction of reflected light, Indicates the viewpoint direction, represents a half-angle vector; Apply the rendering equation to each polygon calculation; Cache rendering results in video memory to reduce data transmission overhead.
Citation Information
Patent Citations
Indoor scene three-dimensional modeling method based on structure
CN113112600A