Three-dimensional scene rendering method, system, device and storage medium
By dividing the three-dimensional scene into fixed and changing parts, and using texture pictures to cache the rendering data of the changed parts, the problem of low rendering performance of three-dimensional scenes in the existing technology is solved, efficient rendering effect is achieved, and interactive fluency is improved.
Patent Information
- Application Number
- CN202111304819.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-11-05
AI Technical Summary
Existing 3D scene rendering methods require adding vertices of all models to OpenGL per frame, resulting in poor rendering performance, especially in the case of larger scene sizes.
By dividing the three-dimensional model scene data, dividing the scene into fixed parts and changing parts, creating the camera and using texture pictures to cache the rendering data of the changed parts, multiplexing the rendering data of the fixed parts, and mixing the rendering results to improve efficiency.
It significantly reduces the rendering content of each frame of the scene and improves the fluency of the interaction, especially in commonly used interactions in element drawing and scene layout, which can ensure a frame rate of more than 60 frames.
Smart Images

Figure CN114241101B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision technology, and specifically relates to a three-dimensional scene rendering method, system, device and storage medium. Background Art
[0002] With the continuous development and in-depth application of 3D design technology, more and more zero-engineering designs are designed and stored in the form of 3D models. In industrial CAD / CAE design, a design project often contains multiple 3D models with business significance. Taking CAD design software as an example, in common interactions such as primitive drawing and scene layout, if the scene scale is large, the rendering performance is poor because each frame of the scene rendering needs to add the vertices of all models to OpenGL (Open Graphics Library) for rendering.
[0003] Since all current 3D models are composed of 3D points in space. One point generates a point, two points generate a line, and three or more points generate a triangle or polygon. The drawing provided by OpenGL also confirms the drawing content through the vertex array. The vertex is a set of points representing the current 3D model. The drawing of points, lines and surfaces can be realized with the link method. However, through analysis, when the primitives are drawn and the scene is arranged, the main body of the scene does not change, only the part that is currently dynamically drawn is changing.
[0004] Therefore, it is necessary to provide an efficient rendering method for three-dimensional scenes, which can cache the rendering data of the current subject, reuse and synthesize the dynamically modified parts in each subsequent frame of scene rendering, and greatly reduce the rendering content of the current frame scene. Summary of the invention
[0005] In order to solve the problem in the prior art that each frame of scene rendering requires adding the vertices of all models to OpenGL for rendering, resulting in poor rendering performance, the present invention provides a three-dimensional scene rendering method, system, device and storage medium. By caching the rendering data of the current subject and reusing and synthesizing the dynamically modified parts in each subsequent frame of scene rendering, the rendering content of the current frame scene can be greatly reduced, thereby improving the smoothness of interaction.
[0006] The present invention is implemented by the following technical solutions:
[0007] A three-dimensional scene rendering method, comprising:
[0008] 1. Divide the 3D model scene data;
[0009] Define the current rendering scene as S, and divide the current rendering scene S into fixed partial scenes S fand a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ;
[0010] 2. Create a 3D scene camera;
[0011] Create camera C as the main camera of the current rendering scene S, and create three slave cameras C under the main camera C f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering;
[0012] 3. Scene rendering;
[0013] Render the scene with data changes to the texture image of the changing part for cache; f Render to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
[0014] As a further solution of the present invention, the current rendering scene S defined in the divided three-dimensional model scene data and the fixed part scene S after division f , transparent part scene S t And the opaque part scene S c The relationship satisfies: S = S f ∪S c ∪S t , where U represents the union operation.
[0015] Furthermore, in the divided three-dimensional model scene data, each component model in the scene is called an element, and the fixed part scene S f (Fix Scene) represents a generally fixed set of elements in the scene, usually the model data of the scene. The modification is triggered only when the model data is added, deleted or modified;
[0016] The opaque part scene S c (Changing Scene) represents a collection of frequently changing elements in the scene, usually JIG dynamic drawing data, and the model will change in real time depending on the current mouse position;
[0017] The transparent part scene St (Transparent Scene) represents a collection of transparent elements in the scene, usually drawing auxiliary data, and the primitives have transparency.
[0018] As a further solution of the present invention, when creating a three-dimensional scene camera, when rendering each frame of the scene, the camera matrix of the created master camera C and the slave camera C f , slave camera C c , slave camera C t The camera matrix is consistent.
[0019] Furthermore, when creating the three-dimensional scene camera, two texture pictures of the current window pixel size for rendering are created for each camera, including a texture picture CT (Color Texture) and a texture picture DT (Depth Texture).
[0020] Furthermore, when creating a three-dimensional scene camera, it also includes: creating a rectangular HUD camera C that always fills the screen under the main camera C h , used to fill the rectangular screen with textures to render scene data; among them, the HUD camera C h The creation method is: according to the fixed viewport matrix M v With the projection matrix M p In HUD Camera C h Next, add a corresponding rectangle and obtain the list of rectangle vertices;
[0021] The fixed viewport matrix M v for The projection matrix M p for The rectangle vertex list is (-1, -1, 0), (-1, 1, 0), (1, 1, 0), (1, -1, 0).
[0022] As a further solution of the present invention, when rendering the scene, OpenGL (Open Graphics Library) is called to perform scene rendering, and case-by-case processing is performed when drawing to a specified camera node; wherein the scene of the data-changed part is rendered into a texture picture of the changed part for caching, including:
[0023] Update the camera posture of the master camera C to the slave camera C c and slave camera C t The camera posture is composed of a viewport transformation matrix, a projection matrix, and a viewport matrix, which are used to determine the viewing direction and imaging size of the current camera;
[0024] Use OpenGL's glBindFramebufferEXT method to bind the slave camera C c and slave camera C t The depth buffer and color buffer are rendered to the texture image CT respectively c , Texture image DT c and texture image CT t , Texture image DT t wherein the texture image CT c , Texture image DT c For slave camera C c The corresponding opaque part of the scene S c The corresponding texture image CT and texture image DT, the texture image CT t , Texture image DT t For slave camera C t The corresponding transparent part scene S t The corresponding texture image CT and texture image DT.
[0025] Furthermore, the fixed part of the scene S f Render to the frame scene cache object, reuse the texture image of the previous frame scene, including:
[0026] Record the current slave camera C f Compare the camera posture of the main camera C with that of the main camera C, record whether it has changed, and record the variable B c ;
[0027] Compare the current scene element with the scene element of the previous frame to see if it has changed, and record the variable B s ;
[0028] According to variable B c With variable B s Decide whether the slave camera C needs to be re-rendered f The depth buffer and color buffer are rendered to the texture image CT respectively f , Texture image DT f , otherwise reuse the texture of the previous frame.
[0029] Furthermore, the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered in the fixed part are mixed to obtain a rendering result, including:
[0030] Based on the texture image CT c , Texture image DT c , Texture Image CT t , Texture image DT t , Texture Image CT f and texture images DT fBy calling the OpenGL glBindTexture function, all textures are bound to the HUD camera C h In the HUD camera C h The rectangle below is rendered fragment by fragment using OpenGL's custom rendering pipeline (shader). The OpenGL rendering pipeline splits the rendering content into pixels (rasterization), and each fragment represents a corresponding pixel.
[0031] Furthermore, the rendering of each fragment adopts a fragment shader, and the fragment shader determines the texture coordinates (x, y) of the current rendering through gl_TexCoord, returns the fragment color value of the current texture coordinate through calculation and fills it into FrameBuffer, providing subsequent applications.
[0032] Furthermore, the algorithm expression of the fragment shader is as follows:
[0033]
[0034] Among them, CT(x,y) means getting the color value RGBA of the x,y coordinates of the current color texture, DT(x,y) means getting the depth value of the x,y coordinates in the current depth texture, and mix means mixing the two RGBA colors; the subscripts f, c, and t in CT(x,y) and DT(x,y) represent the slave camera C respectively. f , slave camera C c , slave camera C t The corresponding texture image.
[0035] As a further solution of the present invention, the rendering result is obtained by performing scene rendering through glSwapBuffer provided by OpenGL, and the rendering result is submitted to interface rendering, and the above scene rendering operation is repeated to start rendering of the next frame.
[0036] The present invention also includes a three-dimensional scene rendering system, which uses the above-mentioned three-dimensional scene rendering method to realize the rendering content of the current frame scene; the three-dimensional scene rendering system includes:
[0037] The scene division module is used to define the current rendering scene as S and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ;
[0038] The camera creation module is used to create a camera C as the main camera of the current rendering scene S, and to create three slave cameras C under the main camera C.f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering; and
[0039] The scene rendering module is used to render the scene with changing data into the texture image of the changing part for caching; f Render to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
[0040] The present invention also includes a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the three-dimensional scene rendering method when executing the computer program.
[0041] The present invention also includes a storage medium storing a computer program, which implements the steps of the three-dimensional scene rendering method when executed by a processor.
[0042] The technical solution provided by the present invention has the following beneficial effects:
[0043] The present invention analyzes from the perspective of three-dimensional design. The scene only needs to be fully rendered when the viewport changes. In most cases, only the changed part needs to be processed. Taking the drawing in three-dimensional design as an example, most of the scenes are unchanged, and only the drawn part needs to be redrawn, and the currently drawn part is generally only a small part of the scene. By caching the rendering data of the current subject, the dynamically modified part is reused and synthesized in each subsequent frame of scene rendering, the rendering content of the current frame scene can be greatly reduced, thereby improving the smoothness of interaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0045] Figure 1 This is a flowchart of a three-dimensional scene rendering method according to Embodiment 1 of the present invention.
[0046] Figure 2 This is a rendering flow chart of the three-dimensional scene rendering method in Example 1 of the present invention.
[0047] Figure 3 This is a flow chart of scene rendering in a three-dimensional scene rendering method according to embodiment 1 of the present invention.
[0048] Figure 4 This is a flow chart of obtaining rendering results in the three-dimensional scene rendering method in embodiment 1 of the present invention.
[0049] Figure 5 This is a system block diagram of a three-dimensional scene rendering system in Embodiment 2 of the present invention.
[0050] Figure 6 It is a schematic diagram of a scenario where the present invention is applied to an example of placing a guard room in an entire substation scenario without changing the scenario.
[0051] Figure 7 It is a schematic diagram of the changing scene when the example of placing a guard room in the entire substation scene is applied to the present invention.
[0052] Figure 8 It is a schematic diagram of the final result when the present invention is applied to an example of placing a guard room in the entire substation scenario. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0054] The present invention provides a 3D scene rendering method, system, device and storage medium. For the common interactions such as primitive drawing and scene arrangement, when the scene scale is large, because each frame of scene rendering needs to add all the vertices of the model to OpenGL for rendering, resulting in poor rendering performance. The present invention determines through analysis that when primitive drawing and scene arrangement are carried out, the main body of the scene does not change, and only the currently dynamically drawn part is changing. By caching the rendering data of the current main body, the dynamically modified part is reused and synthesized in each subsequent frame of scene rendering, the rendering content of the current frame scene can be greatly reduced, which will be explained in conjunction with specific embodiments below.
[0055] Example 1
[0056] like Figure 1 and Figure 2 As shown, this embodiment provides a three-dimensional scene rendering method, which includes the following steps:
[0057] S1. Divide the 3D model scene data.
[0058] In this embodiment, the current rendering scene is defined as S, and the current rendering scene S is divided into fixed partial scenes S fand a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c After the division, the current rendering scene S defined in the divided 3D model scene data and the fixed part scene S after the division f , transparent part scene S t And the opaque part scene S c The relationship satisfies: S = S f ∪S c ∪S t , where U represents the union operation.
[0059] In the divided 3D model scene data, each component model in the scene is called an element. f (Fix Scene) represents a generally fixed set of elements in the scene, usually the model data of the scene. The modification is triggered only when the model data is added, deleted or modified;
[0060] The opaque part scene S c (Changing Scene) represents a collection of frequently changing elements in the scene, usually JIG dynamic drawing data, and the model will change in real time depending on the current mouse position;
[0061] The transparent part scene S t (Transparent Scene) represents a collection of transparent elements in the scene, usually drawing auxiliary data, and the primitives have transparency.
[0062] S2. Create a three-dimensional scene camera.
[0063] In this embodiment, a camera C is created as the main camera for the current rendering scene S, and three slave cameras C are created under the main camera C. f , C c , C t Load scene S separately f , S c , S t When creating a 3D scene camera, two texture images of the current window pixel size for rendering are created for each camera, including a texture image CT (Color Texture) and a texture image DT (Depth Texture).
[0064] When creating a three-dimensional scene camera, when rendering each frame of the scene, the camera matrix of the created main camera C and the slave camera C f , slave camera C c, slave camera C t The camera matrix is consistent.
[0065] When creating a three-dimensional scene camera, the method further includes: creating a rectangular HUD camera C that always fills the screen under the main camera C. h , used to fill the rectangular screen with textures to render scene data; among them, the HUD camera C h The creation method is: according to the fixed viewport matrix M v With the projection matrix M p In HUD Camera C h Add a corresponding rectangle below and get a list of rectangle vertices; the rectangle is a model of the current scene, and is always the same size as the screen, so that the texture I fill in it is the data the user sees. Projection refers to the coordinate position of a point in three-dimensional space projected onto the screen, and the projection matrix is used to do this operation, that is, three-dimensional coordinate point * projection matrix = screen coordinate point.
[0066] The fixed viewport matrix M v for The projection matrix M p for The rectangle vertex list is (-1, -1, 0), (-1, 1, 0), (1, 1, 0), (1, -1, 0).
[0067] In this embodiment, the texture image in computer graphics includes both the texture of the surface of an object in the usual sense, even if the surface of the object presents uneven grooves, and the color pattern on the smooth surface of the object, which we usually call a pattern. Generally, the image that needs to be filled on the model is called texture. The purpose of texture filling here is to save the frame image of other scenes into one picture for synthesis.
[0068] In other rendering operations, not all rendering is achieved through textures. This implementation uses texture images for use in subsequent rendering.
[0069] S3. Scene rendering.
[0070] In this embodiment, OpenGL is called to perform scene rendering based on the above-divided camera information. Figure 3 As shown, when drawing to the specified camera node, different cases are processed. The steps are as follows:
[0071] S301, rendering the scene of the data-changed part into the texture image of the changed part for caching.
[0072] In this embodiment, the camera posture of the master camera C is updated to the slave camera C c and slave camera Ct The camera posture is composed of a viewport transformation matrix, a projection matrix, and a viewport matrix, which are used to determine the viewing direction and imaging size of the current camera.
[0073] Use OpenGL's glBindFramebufferEXT method to bind the slave camera C c and slave camera C t The depth buffer and color buffer are rendered to the texture image CT respectively c , Texture image DT c and texture image CT t , Texture image DT t wherein the texture image CT c , Texture image DT c For slave camera C c The corresponding opaque part of the scene S c The corresponding texture image CT and texture image DT, the texture image CT t , Texture image DT t For slave camera C t The corresponding transparent part scene S t The corresponding texture image CT and texture image DT.
[0074] S302, fix the partial scene S f Render to the frame scene cache object and reuse the texture image of the previous frame scene.
[0075] In this embodiment, see Figure 4 As shown, the fixed part of the scene S f The method of rendering to the frame scene cache object and reusing the texture image of the previous frame scene includes:
[0076] S3021, record the current slave camera C f Compare the camera posture of the main camera C with that of the main camera C, record whether it has changed, and record the variable B c ;
[0077] S3022. Compare the current scene element with the scene element of the previous frame to see if it has changed, and record the variable B s ;
[0078] S3023, according to variable B c With variable B s Decide whether the slave camera C needs to be re-rendered f The depth buffer and color buffer are rendered to the texture image CT respectively f , Texture image DT f , otherwise reuse the texture of the previous frame.
[0079] S303: Mix the cached texture image data of the changing part and the texture image data of the frame scene cache object rendered in the fixed part to obtain a rendering result.
[0080] In this embodiment, based on the texture image CT c , Texture image DT c , Texture Image CT t , Texture image DT t , Texture Image CT f and texture images DT f By calling the OpenGL glBindTexture function, all textures are bound to the HUD camera C h In the HUD camera C h The rectangle below is rendered fragment by fragment using OpenGL's custom rendering pipeline (shader). The OpenGL rendering pipeline splits the rendering content into pixels (rasterization), and each fragment represents a corresponding pixel.
[0081] The rendering of each fragment adopts a fragment shader, and the fragment shader determines the texture coordinates (x, y) of the current rendering through gl_TexCoord, returns the fragment color value of the current texture coordinate through calculation and fills it into FrameBuffer to provide subsequent applications.
[0082] The algorithm expression of the fragment shader is as follows:
[0083]
[0084] Among them, CT(x,y) means getting the color value RGBA of the x,y coordinates of the current color texture, DT(x,y) means getting the depth value of the x,y coordinates in the current depth texture, and mix means mixing the two RGBA colors; the subscripts f, c, and t in CT(x,y) and DT(x,y) represent the slave camera C respectively. f , slave camera C c , slave camera C t The corresponding texture image.
[0085] S304: Submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame of the scene.
[0086] In this embodiment, the rendering result is obtained by performing scene rendering through glSwapBuffer provided by OpenGL, and the rendering result is submitted to interface rendering, and the above scene rendering operation is repeated to start rendering of the next frame.
[0087] This embodiment caches the rendering data of the current subject, reuses and synthesizes the dynamically modified part in each subsequent frame of scene rendering, which can greatly reduce the rendering content of the current frame scene and improve the fluency of interaction.
[0088] Example 2
[0089] like Figure 5 As shown, in an embodiment of the present invention, a three-dimensional scene rendering system is provided, which includes a scene division module 100 , a camera creation module 200 and a scene rendering module 300 .
[0090] The scene division module 100 is used to define the current rendering scene as S and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ;
[0091] The camera creation module 200 is used to create a camera C as the main camera of the current rendering scene S, and to create three slave cameras C under the main camera C. f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering; and
[0092] The scene rendering module 300 is used to render the scene of the data change part into the texture image of the change part for buffering; f Render to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
[0093] In the three-dimensional model scene data divided in the scene division module 100, each component model in the scene is called an element, and the fixed part scene S f (Fix Scene) represents a generally fixed set of elements in the scene, usually the model data of the scene, and the modification is triggered only when the model data is added, deleted or modified; the opaque part scene S c (Changing Scene) represents a set of frequently changing elements in the scene, usually JIG dynamic drawing data, and the model will change in real time depending on the current mouse position; the transparent part scene S t(Transparent Scene) represents a collection of transparent elements in the scene, usually drawing auxiliary data, and the primitives have transparency.
[0094] The camera creation module 200 creates a camera matrix of the main camera C and a camera matrix of the slave camera C when rendering each frame of the scene. f , slave camera C c , slave camera C t The camera matrix is consistent with that of the main camera C, and also includes: creating a rectangular HUD camera C that always fills the screen under the main camera C h , used to fill the rectangular screen with textures to render scene data, HUD camera C h The creation method is based on the fixed viewport matrix M v With the projection matrix M p In HUD Camera C h Next, add a corresponding rectangle and obtain the list of rectangle vertices.
[0095] The scene rendering module 300 calls OpenGL (Open Graphics Library) to perform scene rendering. When drawing to a specified camera node, it performs case-by-case processing and updates the camera posture of the master camera C to the slave camera C. c and slave camera C t The camera posture is composed of the viewport transformation matrix, projection matrix, and viewport matrix, which are used to determine the current camera's viewing direction and imaging size. The slave camera C is bound to the glBindFramebufferEXT method of OpenGL. c and slave camera C t The depth buffer and color buffer are rendered to the texture image CT respectively c , Texture image DT c and texture image CT t , Texture image DT t wherein the texture image CT c , Texture image DT c For slave camera C c The corresponding opaque part of the scene S c The corresponding texture image CT and texture image DT, the texture image CT t , Texture image DT t For slave camera C t The corresponding transparent part scene S t The corresponding texture image CT and texture image DT.
[0096] Based on the texture image CT c , Texture image DT c , Texture Image CTt , Texture image DT t , Texture Image CT f and texture images DT f By calling the OpenGL glBindTexture function, all textures are bound to the HUD camera C h In the HUD camera C h The rectangle below is rendered fragment by fragment using OpenGL's custom rendering pipeline (shader). The OpenGL rendering pipeline splits the rendering content into pixels (rasterization), and each fragment represents a corresponding pixel.
[0097] The three-dimensional scene rendering system adopts the steps of the three-dimensional scene rendering method as described above during execution, and therefore, the operation process of the three-dimensional scene rendering system will not be described in detail in this embodiment.
[0098] Example 3
[0099] In an embodiment of the present invention, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiment 1 are implemented:
[0100] 1. Divide the 3D model scene data;
[0101] Define the current rendering scene as S, and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ;
[0102] 2. Create a 3D scene camera;
[0103] Create camera C as the main camera of the current rendering scene S, and create three slave cameras C under the main camera C f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering;
[0104] 3. Scene rendering;
[0105] Render the scene with data changes to the texture image of the changing part for cache; fRender to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
[0106] Example 4
[0107] In an embodiment of the present invention, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented:
[0108] 1. Divide the 3D model scene data;
[0109] Define the current rendering scene as S, and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ;
[0110] 2. Create a 3D scene camera;
[0111] Create camera C as the main camera of the current rendering scene S, and create three slave cameras C under the main camera C f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering;
[0112] 3. Scene rendering;
[0113] Render the scene with data changes to the texture image of the changing part for cache; f Render to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
[0114] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory.
[0115] For example, placing a guard room in the entire substation scene, the substation model is an unchanging model, and the placed guard room is a changing model. When placing it, you only need to re-render the guard room, and then mix the scenes together to get the final result. Figure 6 is the unchanged scene in the substation scene, Figure 7 The scene in the substation scene changes. The substation is divided into the unchanged scene (substation) and the changing scene (guard room). The corresponding texture images are rendered respectively. Figure 8 for the final result.
[0116] Taking the scale of 750kV substation with more than one million components as an example, the frame rate of commonly used interactive rendering such as primitive drawing and scene layout can be increased to more than 60 frames to ensure the smoothness of interaction.
[0117] In summary, the present invention analyzes from the perspective of 3D design that the scene only needs to be fully rendered when the viewport changes. In most cases, only the changed part needs to be processed. Taking the drawing in 3D design as an example, most of the scenes are unchanged, and only the drawn part needs to be redrawn, and the currently drawn part is generally only a small part of the scene. Based on the above analysis, the present invention can achieve efficient rendering of most 3D scenes.
[0118] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A three-dimensional scene rendering method; characterized in that: The three-dimensional scene rendering method comprises:
1. Divide the 3D model scene data; Define the current rendering scene as S, and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ; 2. Create a 3D scene camera; Create camera C as the main camera of the current rendering scene S, and create three slave cameras C under the main camera C f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering; When creating a three-dimensional scene camera, the method further includes: creating a rectangular HUD camera C that always fills the screen under the main camera C. h , used to fill the rectangular screen with textures to render scene data; among them, the HUD camera C h The creation method is: according to the fixed viewport matrix M v With the projection matrix M p In HUD Camera C h Next, add a corresponding rectangle and obtain the list of rectangle vertices; The fixed viewport matrix M v for: The projection matrix M p for: The rectangle vertex list is (-1, -1, 0), (-1, 1, 0), (1, 1, 0), (1, -1, 0); 3. Scene rendering; Render the scene with data changes to the texture image of the changing part for cache; f Rendering to a frame scene cache object, reusing the texture image of the previous frame scene; mixing the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered in the fixed part to obtain a rendering result, submitting the rendering result to the interface rendering, and repeating the above scene rendering operation to start rendering the next frame scene; when rendering the scene, calling OpenGL to perform scene rendering, and performing case-by-case processing when drawing to a specified camera node; wherein, rendering the scene of the data changing part to the texture image of the changing part for caching, including: Update the camera posture of the master camera C to the slave camera C c and slave camera C t In the camera posture; wherein the camera posture is composed of a viewport transformation matrix, a projection matrix, and a viewport matrix; Use OpenGL's glBindFramebufferEXT method to bind the slave camera C c and slave camera C t The depth buffer and color buffer are rendered to the texture image CT respectively c , Texture image DT c and texture image CT t , Texture image DT t wherein the texture image CT c , Texture image DT c For slave camera C c The corresponding opaque part of the scene S c The corresponding texture image CT and texture image DT, the texture image CT t , Texture image DT t For slave camera C t The corresponding transparent part scene S t Corresponding texture image CT and texture image DT; The fixed part of the scene S f Render to the frame scene cache object, reuse the texture image of the previous frame scene, including: Record the current slave camera C f Compare the camera posture of the main camera C with that of the main camera C, record whether it has changed, and record the variable B c ; Compare the current scene element with the scene element of the previous frame to see if it has changed, and record the variable B s ; According to variable B c With variable B s Decide whether the slave camera C needs to be re-rendered f The depth buffer and color buffer are rendered to the texture image CT respectively f , Texture image DT f , otherwise reuse the texture of the previous frame; The texture image data of the cached changing part and the texture image data of the frame scene cache object rendered in the fixed part are mixed to obtain the rendering result, including: Based on the texture image CT c , Texture image DT c , Texture Image CT t , Texture image DT t , Texture Image CT f and texture images DT f By calling the OpenGL glBindTexture function, all textures are bound to the HUD camera C h In the HUD camera C h The rectangle below is rendered fragment by fragment using OpenGL's custom rendering pipeline, where the OpenGL rendering pipeline splits the rendering content into pixels, and each fragment represents a corresponding pixel.
2. The three-dimensional scene rendering method according to claim 1, characterized in that: The current rendering scene S defined in the divided 3D model scene data and the fixed part scene S after division f , transparent part scene S t And the opaque part scene S c The relationship satisfies: S = S f ∪S c ∪S t , where U represents the union operation.
3. The three-dimensional scene rendering method according to claim 2, characterized in that: When creating the three-dimensional scene camera, two texture pictures of the current window pixel size for rendering are created for each camera, including a texture picture CT and a texture picture DT.
4. A three-dimensional scene rendering system, characterized in that: The three-dimensional scene rendering system adopts the three-dimensional scene rendering method described in any one of claims 1 to 3 to realize the rendering content of the current frame scene; The three-dimensional scene rendering system comprises: The scene division module is used to define the current rendering scene as S and divide the current rendering scene S into fixed partial scenes S f and a changing partial scene, wherein the changing partial scene is split into a transparent partial scene S t With the opaque part of the scene S c ; The camera creation module is used to create a camera C as the main camera of the current rendering scene S, and to create three slave cameras C under the main camera C. f , C c , C t Load scene S separately f , S c , S t scene data, and creates two texture images of the current window pixel size for each camera for rendering; and The scene rendering module is used to render the scene with changing data into the texture image of the changing part for caching; f Render to the frame scene cache object and reuse the texture image of the previous frame scene; mix the texture image data of the cached changing part and the texture image data of the frame scene cache object rendered with the fixed part to obtain the rendering result, submit the rendering result to the interface rendering, and repeat the above scene rendering operation to start rendering the next frame scene.
5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.
6. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Display method and system for rendering three-dimensional scene model
CN108460823A
Texture mapping generation method and device of three-dimensional model, equipment and storage medium
CN113112581A
Three-dimensional rendering method and device of geographic information system, equipment and storage medium
CN113379886A
Rendering Vector Maps in a Geographic Information System
US20150178977A1
Webgl-based progressive real-time rendering method for editable large scene
WO2021174659A1
