A method for realizing motion blur based on 3D engine

By using motion blur technology in the 3D engine, combined with shaders and texture information, the problem of stiff lens switching is solved, achieving smoother visual transitions and realism, and improving the visual experience of lens switching in the 3D engine.

CN118429595BActive Publication Date: 2024-10-11YANTAI JIERUI NETWORK TRADING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410888220.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-10-11
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

The lens switching process in the existing 3D engine is stiff, the scene transition is not smooth, and the sense of reality is weak, resulting in a poor visual experience.

Method used

Using a motion blur implementation method based on a 3D engine, by creating a shader and defining the blur degree and texture information, the motion vector and texture UV coordinates between consecutive frames are obtained, the image sampling results are calculated, and the texture UV is updated based on the motion vector and blur degree. Coordinates, configure weights to combine the sampling results of different frames, and apply motion blur effects to the screen.

Benefits of technology

It improves the image quality, avoids image tearing caused by fast movement, achieves smooth visual transition when switching lenses, reduces the sense of mutation, and makes the visual experience smoother.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118429595B_ABST
    Figure CN118429595B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for implementing motion blur based on a three-dimensional engine, comprising the following steps: step S1, creating a shader and defining the blur degree and texture information of the shader; step S2, obtaining the motion vector and texture UV coordinates between consecutive frames according to the texture information; step S3, calculating the image sampling result of the current frame according to the texture information and the texture UV coordinates, and updating the texture UV coordinates according to the motion vector and the blur degree; step S4, repeating step S3, respectively calculating the image sampling results of the previous frames in sequence; step S5, configuring different weights to combine the sampling results of the current frame and the previous frames to obtain a motion blur effect; step S6, applying the motion blur effect to the screen. When the three-dimensional engine lens switches, the motion blur effect can smooth the visual transition, reduce the sense of mutation, and make the visual experience smoother.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of three-dimensional engine lens technology, and in particular to a method for realizing motion blur based on a three-dimensional engine. Background Art

[0002] In a 3D engine, the lens is an important tool for users to observe and interact with the virtual world. The lens not only determines the part of the scene that the user sees, but also affects the emotion and narrative of the scene. In a 3D scene, the switching of the 3D engine lens refers to the rapid and smooth transition from one specific observation perspective (i.e., lens) to another. It involves changing the parameters of the virtual camera, such as position, orientation, focal length, etc., to present different scene views.

[0003] In the traditional shot switching process of the existing 3D engine, the shot switching is abrupt, the scene transition is not smooth and natural, and the sense of reality is weak. Summary of the invention

[0004] In order to enhance the realism of fast-moving scenes and make the transition between the previous scene and the next scene smooth and natural, the present invention provides a method for implementing motion blur based on a three-dimensional engine.

[0005] In a first aspect, the present invention provides a method for implementing motion blur based on a three-dimensional engine, which adopts the following technical solution:

[0006] A method for implementing motion blur based on a three-dimensional engine comprises the following steps:

[0007] Step S1, creating a shader and defining the blur level and texture information of the shader;

[0008] Step S2, obtaining motion vectors and texture UV coordinates between consecutive frames according to the texture information;

[0009] Step S3, calculating the image sampling result of the current frame according to the texture information and the texture UV coordinates, and updating the texture UV coordinates according to the motion vector and the blur degree;

[0010] Step S4, repeating step S3, respectively calculating the image sampling results of the first 100 frames;

[0011] Step S5, configuring different weights to combine the sampling results of the current frame and the previous 100 frames to obtain a motion blur effect;

[0012] Step S6, applying the motion blur effect to the screen.

[0013] By adopting the above technical solution, image sampling results of different frames are obtained by continuously superimposing texture UV coordinates of motion and blur degree, and all image sampling results are configured with different weights and combined, so as to improve image quality and avoid image tearing caused by rapid motion. Finally, a motion blur effect is obtained, so that when the 3D engine lens is switched, the motion blur effect can smooth the visual transition, reduce the sense of mutation, and make the visual experience smoother.

[0014] Optionally, the texture information includes a main texture and a depth texture, and both the main texture and the depth texture are set as two-dimensional textures. In step S2, the motion vector is obtained according to the depth texture, and the texture UV coordinate is obtained according to the main texture.

[0015] Optionally, in step S2, obtaining the motion vector includes:

[0016] Get the NDC coordinates of the previous frame and the NDC coordinates of the current frame according to the depth texture;

[0017] The speed direction is calculated as the motion vector by taking the difference between the NDC coordinates of the previous frame and the current frame.

[0018] Optionally, in step S1, defining the shader further includes defining a previous frame VP matrix and a current frame VP inverse matrix of the shader;

[0019] The steps of obtaining the NDC coordinates of the previous frame and the NDC coordinates of the current frame include:

[0020] Get the depth value according to the depth texture;

[0021] Get the NDC coordinate H mapped from [0,1] to [-1,1] according to the texture UV coordinate and depth value;

[0022] Transform H into world coordinates according to the current frame VP inverse matrix;

[0023] Get the NDC coordinate of the previous frame as H;

[0024] Get the NDC coordinates of the current frame based on the VP matrix of the previous frame and the world coordinates.

[0025] Optionally, the specific steps of calculating the image sampling results of the first few frames in sequence include:

[0026] According to the texture information and the updated texture UV coordinates, the image sampling result of the previous frame is calculated, and the texture UV coordinates are updated for the second time according to the motion vector and blur degree;

[0027] According to the texture information and the updated texture UV coordinates, the image sampling results of the previous two frames are calculated, and the texture UV coordinates are updated for the third time according to the motion vector and the blur degree;

[0028] According to the texture information and the updated texture UV coordinates, the image sampling results of the previous n frames are calculated, and the texture UV coordinates are updated for the n+1th time according to the motion vector and the blur degree.

[0029] Optionally, the sampling result includes: obtaining color values ​​from the main texture according to texture UV coordinates of different frames.

[0030] Optionally, configuring the weights in step S5 includes: configuring the weight values ​​from the current frame to previous frames to decrease in sequence, and the sum of the weight values ​​of the current frame and the previous frames is 1.

[0031] Optionally, the sampling results of the current frame, the previous frame and the previous two frames are calculated respectively, and the weight value of the current frame is configured to be 0.6, the weight value of the previous frame is configured to be 0.3, and the weight value of the previous two frames is configured to be 0.1.

[0032] Optionally, in step S6, the step of applying the motion blur effect to the screen includes:

[0033] Creating a material and assigning the shader to the created material;

[0034] Setting the properties of the material as required by the shader;

[0035] Apply the configured material to the screen.

[0036] Optionally, set the matrix properties for the created material by:

[0037] Initialize the VP matrix of the previous frame and set it to the material's properties;

[0038] Calculate the VP matrix of the current frame and save it;

[0039] Set the current frame's inverse VP matrix to the material's properties.

[0040] In summary, the present invention has the following beneficial technical effects:

[0041] The present invention obtains image sampling results of different frames by continuously superimposing texture UV coordinates of motion and blur degree, and combines all image sampling results after configuring different weights, so as to improve image quality and avoid image tearing caused by rapid motion. Finally, a motion blur effect is obtained, so that when the 3D engine lens is switched, the motion blur effect can smooth the visual transition, reduce the sense of mutation, and make the visual experience smoother. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 The present invention is a flowchart of a method for implementing motion blur based on a three-dimensional engine according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] The following is combined with Figure 1 The present invention is described in further detail.

[0044] Reference Figure 1 , a method for realizing motion blur based on a three-dimensional engine, comprising the following steps:

[0045] Step S1, create a shader and define the blur level _BlurSize and texture information of the shader; the texture information includes the main texture _MainTex and the depth texture _CameraDepthTexture, and the definition of the shader also includes defining the previous frame VP matrix _PreViewMatrix and the current frame VP inverse matrix _CurViewInserseMatrix of the shader.

[0046] In computer graphics, shaders are used to determine the visual appearance of surfaces in a three-dimensional scene. Shaders typically run on the GPU, and they are key components in the rendering pipeline responsible for generating the pixel colors of the final image. There are many types of shaders, including vertex shaders, fragment shaders, and more. The shader definition provides the necessary input and output interfaces for subsequent shader logic, as well as variables for calculations and texture sampling.

[0047] Step S2, obtaining motion vectors and texture UV coordinates between consecutive frames according to texture information; the motion vector is obtained according to the depth texture, and the texture UV coordinates are obtained according to the main texture.

[0048] The acquisition of motion vector includes:

[0049] ①According to the depth texture, obtain the NDC coordinates of the previous frame and the NDC coordinates of the current frame;

[0050] The steps of obtaining the NDC coordinates of the previous frame and the NDC coordinates of the current frame include:

[0051] a. Get the depth value d from the depth texture; the depth value is a value that represents the distance of an object or pixel from the observer (usually the camera) in three-dimensional space. Specifically, the depth value d is calculated by combining the zw component of the current fragment texture coordinates with the depth texture. The calculation formula for the depth d is float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv.zw);

[0052] b. Obtain the NDC coordinate H mapped from [0,1] to [-1,1] according to the texture UV coordinate and depth value; the calculation formula is: float4 H = float4(i.uv.x * 2 - 1, i.uv.y * 2 - 1, d * 2 - 1, 1); Texture coordinates are a set of two-dimensional coordinates used to map texture images to the surface of a three-dimensional model. The range of texture coordinates is usually from 0 to 1, where (0, 0) represents the lower left corner of the texture image and (1, 1) represents the upper right corner. NDC coordinates are normalized device coordinates, which are used to represent points in a standardized space. The range of NDC coordinates is usually [-1, 1]. NDC coordinates standardize the range of texture coordinates to [-1,1], making the processing of texture coordinates more consistent and convenient in different graphics systems and applications. In addition, the conversion between NDC coordinates and other graphics coordinate systems (such as screen coordinates) is simpler and more intuitive. NDC coordinates can be mapped to screen coordinates or other coordinate systems through simple linear transformations.

[0053] c. Transform H into world coordinates according to the current frame VP inverse matrix; specifically, the world coordinate worldPos is obtained by inversely transforming the current frame VP inverse matrix and dividing it by the w component, and the calculation formula is: float4 worldPos = mul(_CurViewInserseMatrix, H) / mul(_CurViewInserseMatrix, H).w;

[0054] d. Get the NDC coordinate curViewPos of the previous frame as H; the calculation formula is: float4 curViewPos =H;

[0055] ②According to the VP matrix of the previous frame and the world coordinates, the NDC coordinates preViewPos of the current frame are obtained. The calculation formula is: float4 preViewPos = mul(_PreViewMatrix, worldPos); preViewPos / =preViewPos.w. The world coordinates are needed to obtain the NDC coordinates of the current frame because the NDC coordinates are relative to the camera's perspective, and the camera's perspective is determined by the world coordinates. Since the VP matrix contains the camera's projection and view transformation information, by multiplying the world coordinate position by the VP matrix, it can be transformed from the world space to the camera space, thereby obtaining the NDC coordinates under the camera's perspective.

[0056] The velocity direction velocity is calculated as the motion vector by taking the difference between the NDC coordinates of the previous frame and the current frame; the calculation formula is as follows: float2 velocity = (curViewPos.xy - preViewPos.xy) / 10.0f;

[0057] Step S3, calculating the image sampling result of the current frame according to the texture information and the texture UV coordinates, and updating the texture UV coordinates according to the motion vector and the blur degree;

[0058] The calculation formula for texture UV coordinates is: float2 uv = i.uv.xy;

[0059] The image sampling result of the current frame is calculated as follows: tex2D(_MainTex, uv.xy);

[0060] Update the texture UV coordinates calculated as follows: uv1 = uv + velocity * _BlurSize;

[0061] Step S4, repeating step S3, respectively calculating the image sampling results of the first few frames in sequence; the sampling results include obtaining color values ​​from the main texture according to the texture UV coordinates of different frames.

[0062] The specific steps of calculating the image sampling results of the first few frames in sequence include:

[0063] According to the texture information and the updated texture UV coordinates, the image sampling result tex2D (_MainTex, uv1.xy) of the previous frame is calculated, and the texture UV coordinates are updated for the second time according to the motion vector and the blur degree; the second update of the texture UV coordinates here is based on the first update of the texture UV coordinates, and then the motion vector and the blur degree are superimposed, and the calculation is as follows: uv2 = uv1 + velocity * _BlurSize;

[0064] According to the texture information and the updated texture UV coordinates, the image sampling results tex2D (_MainTex, uv2.xy) of the previous two frames are calculated, and the texture UV coordinates are updated for the third time according to the motion vector and the blur degree; the third update of the texture UV coordinates here is based on the second update of the texture UV coordinates, and then the motion vector and blur degree are superimposed, and the calculation is as follows: uv3 = uv2 + velocity * _BlurSize;

[0065] According to the texture information and the updated texture UV coordinates, the image sampling results tex2D (_MainTex, uvn.xy) of the previous n frames are calculated, and the texture UV coordinates are updated for the n+1th time according to the motion vector and the degree of blur; the n+1th update of the texture UV coordinates here is based on the second update of the texture UV coordinates, and then the motion vector and the degree of blur are superimposed, and the calculation is as follows: uv(n+1) = uvn + velocity * _BlurSize.

[0066] In this embodiment, the current frame, the previous frame and the previous two frames are used to calculate the sampling results.

[0067] Step S5, configure different weights to combine the sampling results of the current frame and the previous frames to obtain a motion blur effect; the significance of configuring weights is to achieve a motion blur effect by adjusting the contribution of different sampling results to the final pixel color. The weight values ​​are configured to decrease in sequence from the current frame to the previous frames, that is, the weight values ​​decrease in sequence from the current frame, the previous frame, the previous two frames...the previous n frames, and the sum of all weight values ​​of the current frame and the previous frames is 1. In this embodiment, the weight value of the current frame is configured to be 0.6, the weight value of the previous frame is configured to be 0.3, and the weight value of the previous two frames is configured to be 0.1. The configuration calculation is as follows: float velColRate[3] = { 0.6,0.3,0.1};

[0068] Combining the weights gives:

[0069] The sampling result col of the current frame is calculated as: fixed4 col = tex2D(_MainTex, uv) *velColRate[0];

[0070] The sampling result col2 of the previous frame is calculated as: fixed4 col2= tex2D(_MainTex, uv1.xy) *velColRate[it];

[0071] The sampling result col3 of the first two frames is calculated as: fixed4 col3= tex2D(_MainTex, uv2.xy) *velColRate[it];

[0072] The final sampling result is obtained by adding the sampling result col of the current frame, the sampling result col2 of the previous frame, and the sampling result col3 of the previous two frames.

[0073] Step S6, applying the motion blur effect to the screen. The steps include:

[0074] Create a material and assign a shader to the created material; this enables the material to use the shader's rendering logic to determine its appearance on the screen.

[0075] Set the material properties according to the needs of the shader; set the parameters required by the shader, such as texture, matrix, color, etc., into the material object, and this parameter can be passed to the shader through the material object.

[0076] Apply the configured material to the screen. Apply the configured material to the corresponding object in the 3D scene. In this way, when the object is rendered, the shader program will determine its appearance based on the properties of the material. During the rendering process, the GPU will use the shader program and material properties to render all objects that have the material applied.

[0077] The steps of setting matrix attributes for the created material according to requirements include:

[0078] Turn on the depth camera mode; the depth camera mode allows the camera to capture depth information for each pixel in the scene, rather than just a two-dimensional image; and through the depth information, the three-dimensional structure of the scene can be better understood, which is crucial for three-dimensional reconstruction and environmental perception.

[0079] Initialize the VP matrix preViewMatrix of the previous frame and set it to the material's properties; the calculation for initializing the VP matrix of the previous frame is as follows: Matrix4x4 preViewMatrix = Camera.projectionMatrix*Camera.worldToCameraMatrix; set the VP matrix of the previous frame to the material's properties as follows: Material.SetMatrix("_PreViewMatrix", preViewMatrix).

[0080] Calculate the VP matrix curViewMatrix of the current frame and save it; the VP matrix of the current frame is calculated as follows: Matrix4x4 curViewMatrix = MyCamera.projectionMatrix *MyCamera.worldToCameraMatrix; save and set the VP matrix of the current frame as follows: preViewMatrix = curViewMatrix.

[0081] Set the current frame's VP inverse matrix CurViewInserseMatrix to the material's properties as follows: Material.SetMatrix("_CurViewInserseMatrix", curViewMatrix.inverse).

[0082] In the material, the VP matrix and VP inverse matrix of each frame are continuously updated so that the shader can process each frame appropriately to obtain the motion vector and generate the final rendering result.

[0083] In summary, the present invention first creates a shader and sets the shader; then creates a material and assigns the shader to the material; finally, the material is copied to the screen and converted into pixels of the screen to present the final motion blur effect. Among them, the speed direction is obtained according to the NDC coordinates of the current frame and the previous frame at different times, and the motion and blur degree of the current frame and the previous frames are continuously superimposed on the texture UV coordinates at different times to obtain the image sampling results of different frames. After configuring different weights for all the image sampling results and combining them, the image quality can be improved, and the image tearing caused by rapid motion can be avoided. Finally, a better motion blur effect is obtained, and then copied to the screen through material rendering, so that when the three-dimensional engine lens switches, the motion blur effect can smooth the visual transition, reduce the sense of mutation, and make the visual experience smoother.

[0084] The above are all preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Therefore, any equivalent changes made based on the structure, shape, and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for implementing motion blur based on a three-dimensional engine, characterized in that: The following steps are involved: Step S1, creating a shader and defining the blur level and texture information of the shader; Step S2, obtaining motion vectors and texture UV coordinates between consecutive frames according to the texture information; Step S3, calculating the image sampling result of the current frame according to the texture information and the texture UV coordinates, and updating the texture UV coordinates according to the motion vector and the blur degree; Step S4, repeating step S3, respectively calculating the image sampling results of the first n frames in sequence, where n represents a positive integer; Step S5, configuring different weights to combine the sampling results of the current frame and the previous n frames to obtain a motion blur effect; Step S6, applying a motion blur effect to the screen; The texture information includes a main texture and a depth texture, both of which are set as two-dimensional textures. In step S2, the motion vector is obtained according to the depth texture, and the texture UV coordinate is obtained according to the main texture.

2. The method according to claim 1, characterized in that In step S2, obtaining the motion vector includes: Get the NDC coordinates of the previous frame and the NDC coordinates of the current frame according to the depth texture; The speed direction is calculated as the motion vector by taking the difference between the NDC coordinates of the previous frame and the current frame.

3. The method according to claim 2, characterized in that In step S1, the definition of the shader further includes defining the previous frame VP matrix and the current frame VP inverse matrix of the shader; The steps of obtaining the NDC coordinates of the previous frame and the NDC coordinates of the current frame include: Get the depth value according to the depth texture; Get the NDC coordinate H mapped from [0,1] to [-1,1] according to the texture UV coordinate and depth value; Transform H into world coordinates according to the current frame VP inverse matrix; Get the NDC coordinate of the previous frame as H; Get the NDC coordinates of the current frame based on the VP matrix of the previous frame and the world coordinates.

4. The method according to claim 1, characterized in that: The specific steps of calculating the image sampling results of the first n frames in sequence include: According to the texture information and the updated texture UV coordinates, the image sampling result of the previous frame is calculated, and the texture UV coordinates are updated for the second time according to the motion vector and blur degree; According to the texture information and the updated texture UV coordinates, the image sampling results of the previous two frames are calculated, and the texture UV coordinates are updated for the third time according to the motion vector and the blur degree; According to the texture information and the updated texture UV coordinates, the image sampling results of the previous n frames are calculated, and the texture UV coordinates are updated for the n+1th time according to the motion vector and the blur degree.

5. The method according to claim 1, characterized in that The sampling result includes: obtaining color values ​​from the main texture according to texture UV coordinates of different frames.

6. The method according to claim 1, characterized in that Configuring the weights in step S5 includes configuring the weight values ​​from the current frame to the previous n frames to decrease in sequence, and configuring the sum of the weight values ​​of the current frame and the previous n frames to be 1.

7. The method according to claim 6, characterized in that The sampling results of the current frame, the previous frame and the previous two frames are calculated respectively. The weight value of the current frame is configured as 0.6, the weight value of the previous frame is configured as 0.3, and the weight value of the previous two frames is configured as 0.

1.

8. The method according to claim 1, characterized in that In step S6, the step of applying the motion blur effect to the screen includes: Creating a material and assigning the shader to the created material; Setting the properties of the material as required by the shader; Apply the configured material to the screen.

9. The method according to claim 7, characterized in that: To set the matrix properties for the created material, the steps include: Initialize the VP matrix of the previous frame and set it to the material's properties; Calculate the VP matrix of the current frame and save it; Set the current frame's inverse VP matrix to the material's properties.