Virtual three-dimensional scene construction method
Through polygon topology analysis, normal optimization and parallel computing technology, the model detail level is dynamically adjusted, solving the problem of insufficient polygon optimization performance in virtual 3D scene construction, and achieving efficient rendering performance improvement on resource-constrained platforms.
Patent Information
- Application Number
- CN202410753356.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-12
AI Technical Summary
Existing virtual 3D scene construction technology has insufficient performance in polygon optimization, resulting in low rendering performance, especially on resource-constrained platforms, where it is difficult to achieve smooth application operation.
By obtaining the geometric data of the object, perform polygon topology analysis and merging, optimize normal information, dynamically adjust the model detail level, and use parallel computing to accelerate the rendering process, reduce the number of polygons and redundant calculations, and improve rendering performance.
Dramatically improves rendering performance, allowing applications to run smoothly on lower-performance hardware and reducing memory usage and data transfer overhead, especially for resource-constrained platforms such as mobile devices and virtual reality headsets.
Smart Images

Figure CN118628654A
Abstract
Description
Technical Field
[0001] The 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 sense 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 virtual three-dimensional scene construction method.
[0004] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0005] The method for constructing a virtual three-dimensional scene comprises 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 model in the scene based on the viewpoint distance, viewing angle, object importance, current rendering load, and curvature;
[0011] Step 6: Use parallel computing to speed up the scene rendering process.
[0012] Further: Step 1 comprises:
[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 the normal vector N i ={n xi ,n yi ,n zi};
[0017] Use the normal information of vertices 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 comprises:
[0024] Create a polygon adjacency matrix A, where A ij =1 indicates 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 vertices, 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 a polygon adjacency graph G = (V, E), where vertex v i Represents polygon f i , edge 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 , then they can be merged;
[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 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 Fluctuation:
[0045]
[0046] Where λ is the smoothing coefficient and N(i) is the vertex v i The set of adjacent vertices of ;
[0047] Compute the curvature of 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 comprises:
[0057] In the LOD management step, this embodiment dynamically adjusts the model's level of detail according to the 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 rendering system load, calculated as Among them 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 of the two triangles around the edge (i, j), V i and V j Represents vertex v i and v j location.
[0066] Further: Step 6 comprises:
[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, represents 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] The present invention can significantly improve rendering performance by optimizing polygons in the scene, thereby making the application smoother. Optimizing polygons enables the application to run on lower-performance hardware, so it is particularly important for resource-constrained platforms such as mobile devices and virtual reality head-mounted displays. After optimization, fewer polygons will be generated, and fewer polygons mean less memory usage, because each polygon needs to store vertices and other related data, which is particularly critical for mobile devices and applications that require a large number 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 picture:
[0076] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0077] The following specific embodiments may 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 in conjunction with 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 obtains the geometric data of objects in the scene through mathematical representation methods, including the vertex coordinates and normal information of the objects, for subsequent polygon optimization.
[0080] Step 2: Polygonal topology analysis: For each object, perform polygonal 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 calculation 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: Use LOD to manage models at different levels so that simplified models can be used when observing 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 the virtual environment and provide the original data for subsequent polygon optimization. Polygon topology analysis establishes the relationship between polygons based on the geometric data and provides the basis of the topological structure for polygon optimization. Polygon quantity control and merging optimize the number of polygons by merging adjacent polygons on the basis of topological analysis, thereby reducing the computational burden of subsequent processing. Lighting and normal optimization optimizes the normals based on the merged polygons to ensure 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 quantity to maintain rendering performance at different viewpoint distances. Texture compression and optimization further optimizes texture data, reduces memory usage and data transmission overhead, and provides a more streamlined input for GPU parallel computing. GPU parallel computing optimization makes full use of the optimized data structure and texture to improve the rendering performance of the scene 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. Suppose the vertex set of the object surface is:
[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 the 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 indicates polygon f i With f j Adjacent, A ij =0 means polygon f i With f j Not adjacent, by traversing the polygon set F, checking whether each pair of polygons shares vertices, the adjacent relationship of the polygons is determined:
[0101]
[0102] For each polygon f i , record its boundary information, including the indices 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 a polygon adjacency graph G = (V, E), where vertex v i Represents polygon f i , edge 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, which provides a basis for subsequent polygon optimization.
[0107] Specifically, step 3 includes:
[0108] In the step 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 center points of the polygons 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 set of vertices and edges in the original polygon adjacency graph G, V' and E' respectively represent the set 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} indicates adding 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 impact 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 reducing the calculation load and improving the overall performance.
[0123] Specifically, step 4 includes:
[0124] In the step of lighting and normal optimization, this embodiment optimizes the lighting effect of the scene by smoothing the normal vector:
[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 to be calculated.i ) represents the vertex v i The neighborhood of v i A collection 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 magnitude (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 By 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 of .
[0132] For vertex v i , its original normal vector n i The normal vector n of its adjacent vertex j Perform a weighted average 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 effect 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 of the two triangles around the 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 edge (i, j) and add them together with (V i -V j ) and finally divided by the vertex v i The area of the mixed region A i , so we can get the vertex v i The curvature K i , which is 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] Among them, 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 preliminary smoothing result; γ: 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 of K is used to calculate the normal vector and curvature of the adjacent vertices; j : Vertex v j The curvature of is used to weight the normal vectors of adjacent vertices; n 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 curvature K used j For adjacent vertices v jThe normal vector n j The weighted average is performed and normalized, so that the results of vector field smoothing and curvature optimization can be balanced, which not only ensures the consistency of the normal vector in adjacent areas, but also retains the 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, i.e. 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 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 magnitude of a vector:
[0150] ||n″ i || is the vector n″ i The modulus is calculated as:
[0151]
[0152] in, Respectively represent 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] So obtained The length is 1 and the direction is n″ i same.
[0157] By normalizing the normal vector, it can be ensured that the updated normal vector is standardized to 1 in length, so that it is 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 effects.
[0159] Specifically, step 5 includes:
[0160] In the LOD management step, this embodiment dynamically adjusts the model's level of detail according to the 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. The viewpoint distance directly affects the audience's perception of object details. When the object is closer to the viewpoint, the human eye can distinguish more details, and vice versa. Therefore, adjusting the detail level according to the viewpoint distance can reduce the details of 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. The viewing angle determines the prominence of an object in the field of vision. Objects facing forward require higher details than objects facing sideways or backwards. Therefore, by considering the viewing angle, the allocation of rendering resources can be optimized to ensure that the areas that the audience pays attention to have a higher level of detail, while the areas that are not of interest have lower details, thereby improving the overall rendering performance.
[0166] I f : Importance factor, a pre-set weight value. In a scene, different objects have different importance. For example, main characters or key props usually require higher details. Therefore, dynamically adjusting the detail level of objects according to their importance can effectively highlight key elements and ensure that the core part of the scene always has high-quality rendering effects.
[0167] L f : Load factor, the current rendering system load, calculated as Where L current is the current load, l max is the maximum load. The performance of real-time rendering will be affected by the current system load. Therefore, dynamically adjusting the level of detail according to the real-time load can balance visual quality and rendering performance to ensure 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 of the two triangles around the edge (i, j), V i and V j Represents vertex v i and v j location.
[0169] Curvature reflects the complexity of the surface of an object. High-curvature areas usually require more details to accurately express their shapes and features. Therefore, the introduction of the curvature factor can more finely control the level of detail of the surface of the object. 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 recognized by the audience. The curvature factor can be used to retain high details in these key areas and enhance 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 capability 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 incident light direction, Indicates the direction of reflected light, represents the viewpoint direction, Represents a half-angle 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 if the FBO is complete and make sure all attachments are bound correctly;
[0186] When rendering the scene, set the FBO as the current framebuffer;
[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 the 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 is only a preferred embodiment of the present invention and is 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 can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein with equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in 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 the realism of the lighting effect and improve the lighting effect of the scene; Step 5: Dynamically adjust the level of detail of the object model in the scene based on the viewpoint distance, viewing angle, object importance, current rendering load, and curvature; Step 6: Use parallel computing to speed up the scene rendering process.
2. The method for constructing a virtual three-dimensional scene according to claim 1, characterized in that: 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 the normal vector N i ={n xi , n yi , n zi }; Use the normal information of vertices 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 i1 ,v i2 ,…,v ik }。 3. The method for constructing a virtual three-dimensional scene according to claim 2, characterized in that: The step 2 comprises: Create a polygon adjacency matrix A, where A ij =1 indicates 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 vertices, and determine the adjacent relationship of the polygons: For each polygon fi, record 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 a polygon adjacency graph G = (V, E), where vertex v i Represents polygon f i , edge ij Represents polygon f i With f j There is an adjacent relationship between them: E={(v i ,v j )|A ij =1}。 4. The method for constructing a virtual three-dimensional scene according to claim 3, characterized in that: 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 can be merged. If Dist(f i , f j )<D threshold , then they can be merged; 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 ; 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 : G′=V′,E′ V′=V-{v i ,v j }∪{v merged } E′=E-{(v i ,v j )}∪{(v i ,v merged ),(v j ,v merged )}。 5. The method for constructing a virtual three-dimensional scene according to claim 4, characterized in that: The step 4 comprises: 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 : Among them, N(v i ) is the vertex v i The set of polygons in the neighborhood of f is the area of polygon f, n f is the normal vector of polygon f; Use Laplace smoothing to reduce the normal vector n i Fluctuation: Where λ is the smoothing coefficient and N(i) is the vertex v i The set of adjacent vertices of ; Compute the curvature of each vertex to preserve feature detail: 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; Update the normal vector: Among them, γ is the control parameter; Normalize the updated normal vector: Apply the normalized normal vector information to each vertex v i .
6. The method for constructing a virtual three-dimensional scene according to claim 5, characterized in that: The step 5 comprises: In the LOD management step, this embodiment dynamically adjusts the model's level of detail according to the 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 rendering system load, calculated as Among them 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.
7. The method for constructing a virtual three-dimensional scene according to claim 7, characterized in that: The step 6 comprises: Define the following rendering equation: 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 incident light direction, Indicates the direction of reflected light, represents 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
Power grid three-dimensional scene data rendering method and system
CN113989458A
Rendering optimization method, electronic equipment and computer readable storage medium
CN117557703A
Self-adaptive detail level model construction method and system for three-dimensional end rendering
CN117593435A
Indoor scene virtual roaming method based on reflection decomposition
US20240169674A1
