Image rendering method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202211609840.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2042-12-12
AI Technical Summary
[0004]有鉴于此,本发明的目的在于提供一种图像渲染方法、装置、电子设备及存储介质,其能够改善传统的二维图像绘制技术的视觉效果差的问题
[0038] The image rendering method, apparatus, electronic device, and storage medium provided in this invention obtain a target transformation matrix for spatial transformation and three-dimensional perspective projection. Based on the target transformation matrix, a two-dimensional image is transformed to obtain a three-dimensional perspective image of the two-dimensional image. The two-dimensional image is then processed based on a set cropping region to determine the display area of the two-dimensional image. Thus, only the area corresponding to the display area in the three-dimensional perspective image is displayed, thereby realizing the rendering and display of the two-dimensional image in a three-dimensional spatial perspective projection manner, which can greatly improve the visual effect of the image.
Smart Images

Figure CN115779418B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more specifically, to an image rendering method, apparatus, electronic device, and storage medium. Background Technology
[0002] A game interface refers to the user interface of game software, including game design elements that users directly or indirectly interact with, such as buttons, animations, text, sounds, and windows. The game interface is an important means of information transmission, and its user interaction significantly impacts the overall game visual presentation and user experience.
[0003] Currently, two-dimensional user interface rendering technology is commonly used to present the game's user interface on the target device screen in a two-dimensional format, conveying important information about the game to players through graphics or text. However, the visual effects of two-dimensional user interface rendering technology are poor. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide an image rendering method, apparatus, electronic device and storage medium that can improve the problem of poor visual effect of traditional two-dimensional image rendering technology.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows:
[0006] In a first aspect, embodiments of the present invention provide an image rendering method, the method comprising:
[0007] Obtain the target transformation matrix; wherein, the target transformation matrix is a transformation matrix used for spatial transformation and three-dimensional perspective projection;
[0008] Based on the target transformation matrix, the two-dimensional image is transformed to obtain a three-dimensional perspective image of the two-dimensional image;
[0009] Based on the set cropping area, the two-dimensional image is colored to determine the display area of the two-dimensional image, and the area corresponding to the display area in the three-dimensional perspective image is colored.
[0010] The step of obtaining the target transformation matrix includes:
[0011] A three-dimensional reference mapping space is established based on the camera space;
[0012] Based on the target projection screen, calculate the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space;
[0013] Obtain the mapping point corresponding to the pre-selected point in the two-dimensional plane space in the reference mapping space, and construct a second transformation matrix for three-dimensional rotation around the mapping point in the reference mapping space;
[0014] The target transformation matrix is calculated based on the first transformation matrix, the second transformation matrix, and the perspective projection matrix.
[0015] Furthermore, the step of establishing a three-dimensional reference mapping space based on camera space includes:
[0016] A reference mapping space is established with the origin at a position in the camera orientation direction of the camera space at a set distance from the origin of the camera space. The three-axis directions are consistent with the three-axis directions of the camera space, and the unit size is consistent with the unit size of the camera space.
[0017] Further, the step of calculating the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space based on the target projection screen includes:
[0018] Based on the width and height of the target projection screen, condition points in the two-dimensional plane space of the two-dimensional image are determined; wherein, the horizontal coordinate of the condition point is half the width of the target projection screen, and the vertical coordinate of the condition point is half the height of the target projection screen.
[0019] Using the overlap between the condition point and the origin of the reference mapping space as the mapping condition, a first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space is determined.
[0020] Furthermore, the target transformation matrix includes:
[0021] AMat=ProjectMat*RMat*UMat*LMat
[0022] Where AMat represents the target transformation matrix, ProjectMat represents the perspective projection matrix, RMat represents the second transformation matrix, UMat represents the first transformation matrix, and LMat represents the translation, rotation, and scaling matrix in the two-dimensional plane space.
[0023] Further, the step of performing color processing on the two-dimensional image based on the set cropping region to determine the display area of the two-dimensional image includes:
[0024] The input two-dimensional transformation matrix is received, and the cropping information of the two-dimensional image and the two-dimensional transformation matrix are passed to the vertex shading stage.
[0025] During the vertex shading stage, the position coordinates of each vertex of the two-dimensional image in the two-dimensional plane space are calculated using the two-dimensional transformation matrix, and the scale value of each vertex is obtained based on the position coordinates and the cropping information;
[0026] The scale values of all vertices are passed to the pixel shading stage, and the scale value of each fragment of the two-dimensional image is calculated by linear interpolation of the GPU.
[0027] The display area of the two-dimensional image is determined based on the scale value of each fragment.
[0028] Furthermore, the cropping information includes the starting point, height, and width of the cropping area;
[0029] The step of obtaining the proportional value of each vertex based on the position coordinates and the clipping information includes:
[0030] For each vertex, subtract the starting point of the clipping region from the vertex's position coordinates to obtain the vertex's relative position with respect to the clipping region;
[0031] Calculate the product between the width and height of the clipping region, and use the ratio between the relative position and the product as the ratio value of the vertex.
[0032] Secondly, embodiments of the present invention provide an image rendering apparatus, including a spatial transformation module, a perspective projection module, and a coloring and drawing module:
[0033] The spatial transformation module is used to obtain the target transformation matrix; wherein, the target transformation matrix is a transformation matrix used for spatial transformation and three-dimensional perspective projection;
[0034] The perspective projection module is used to transform the two-dimensional image based on the target transformation matrix to obtain a three-dimensional perspective image of the two-dimensional image.
[0035] The coloring and drawing module is used to color the two-dimensional image based on a set cropping area, determine the display area of the two-dimensional image, and color the area corresponding to the display area in the three-dimensional perspective image.
[0036] Thirdly, embodiments of the present invention provide an electronic device, including a graphics processor and a memory, wherein the memory stores a computer program executable by the graphics processor, and the graphics processor can execute the computer program to implement the image rendering method as described in the first aspect.
[0037] Fourthly, embodiments of the present invention provide a storage medium having a computer program stored thereon, wherein the computer program, when executed by a graphics processor, implements the image rendering method as described in the first aspect.
[0038] The image rendering method, apparatus, electronic device, and storage medium provided in this invention obtain a target transformation matrix for spatial transformation and three-dimensional perspective projection. Based on the target transformation matrix, a two-dimensional image is transformed to obtain a three-dimensional perspective image of the two-dimensional image. The two-dimensional image is then processed based on a set cropping region to determine the display area of the two-dimensional image. Thus, only the area corresponding to the display area in the three-dimensional perspective image is displayed, thereby realizing the rendering and display of the two-dimensional image in a three-dimensional spatial perspective projection manner, which can greatly improve the visual effect of the image.
[0039] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 A block diagram of an image rendering system provided in an embodiment of the present invention is shown.
[0042] Figure 2 This is a schematic flowchart of an image rendering method provided in an embodiment of the present invention.
[0043] Figure 3 It shows Figure 2 A flowchart illustrating some sub-steps of step S11.
[0044] Figure 4 It shows Figure 3 A flowchart illustrating some sub-steps of step S112.
[0045] Figure 5 It shows Figure 2 A flowchart illustrating some sub-steps of step S15.
[0046] Figure 6 A block diagram of an image rendering apparatus provided in an embodiment of the present invention is shown.
[0047] Figure 7 A block diagram of an electronic device provided in an embodiment of the present invention is shown.
[0048] Reference numerals: 100-Image rendering system; 110-Server; 120-Client; 130-Image rendering device; 140-Spatial transformation module; 150-Perspective projection module; 160-Shaping and drawing module; 170-Electronic device. Detailed Implementation
[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0050] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0051] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0052] In video games, the user interface is typically displayed in a two-dimensional format on the client's screen to convey important information to the player through graphics or text. The user interface is a crucial means of information delivery, and an aesthetically pleasing interactive interface significantly impacts the overall visual presentation and user experience of the game.
[0053] Currently, the commonly used user interface rendering technology is as follows: write the clipping region into the stencil buffer, and use orthographic projection in camera space to draw the user interface in screen pixels onto the projection screen to draw the user interface. Fragments outside the clipping region in the drawn user interface will not pass the stencil test stage and will not be displayed.
[0054] However, this user interface rendering technology has the following drawbacks: it cannot achieve a 3D perspective visual effect, resulting in poor visual effects; region clipping leads to additional drawing overhead and template testing overhead, resulting in significant resource consumption.
[0055] Based on the above considerations, embodiments of the present invention provide an image rendering method that can render images in a three-dimensional perspective, improving visual effects and reducing resource consumption. The image rendering method is described below.
[0056] The image rendering method provided in this embodiment of the invention can be applied to, for example... Figure 1 The image rendering system 100 shown includes a server 110 and a client 120. The server 110 can communicate with the client 120 via a network.
[0057] Server 110 is used to send two-dimensional images to client 120. The two-dimensional image can be a two-dimensional image of a game screen, such as a game user interface, or a two-dimensional image of any other screen.
[0058] Client 120 is used to receive two-dimensional images and implement the image rendering method provided in the embodiments of the present invention to draw and display the two-dimensional images in a perspective projection manner with a three-dimensional spatial sense.
[0059] Server 110 can be a standalone server or a cluster of servers 110. Client 120 includes, but is not limited to, smart terminals such as personal computers, laptops, tablets, smartphones, and wearable devices. Client 120 includes a graphics processing unit (GPU) and memory.
[0060] In this embodiment, a fragment refers to the set of information about pixels in 3D space obtained by the GPU graphics pipeline through triangular rasterization calculations and projected onto the screen. Shading stage: a programmable stage in the GPU graphics pipeline. Camera space: an abstract space in the 3D graphics transformation pipeline, referring to a three-dimensional coordinate system constructed using the camera origin and orientation, based on a left-handed or right-handed coordinate system. Typically, a 3D graphics transformation pipeline can include local space, world space, camera space, and screen space (projected screen space).
[0061] In one possible implementation, embodiments of the present invention provide an image rendering method, referring to... Figure 2 This may include the following steps. In this embodiment, the image rendering method is applied to... Figure 1 Let's take client 120 as an example to illustrate.
[0062] S11, Obtain the target transformation matrix. The target transformation matrix is used for spatial transformation and 3D perspective projection.
[0063] S13, based on the target transformation matrix, transforms the two-dimensional image to obtain a three-dimensional perspective image of the two-dimensional image.
[0064] S15, based on the set cropping area, perform color processing on the two-dimensional image, determine the display area of the two-dimensional image, and color the area corresponding to the display area in the three-dimensional perspective image.
[0065] After receiving the 2D image from the server 110, the client 120 obtains the target transformation matrix for spatial transformation and 3D perspective projection. The GPU on the client 120 uses this target transformation matrix to transform the 2D image, performing spatial transformation and 3D perspective projection to draw a 3D perspective image of the 2D image. Simultaneously, based on the clipping region defined on the 2D image, the GPU enters the coloring stage, coloring the 2D image to determine the display area. Thus, the GPU on the client 120 colors the area corresponding to the display area in the 3D perspective image.
[0066] Compared with traditional user interface rendering techniques, the image rendering method provided in this embodiment of the invention realizes the drawing and display of two-dimensional images in a three-dimensional spatial perspective projection manner, producing a three-dimensional effect and greatly improving the visual effect of the image.
[0067] Considering that the 2D image (which could be a user interface) needs to be displayed on the screen permanently, camera space is chosen as the primary coordinate system for the 2D user interface transformation. Based on this, to enable the target transformation matrix to render the 2D image using a perspective projection with a 3D spatial feel, refer to... Figure 3 The above step S11 can be further implemented as the following steps S111-S114.
[0068] S111 establishes a three-dimensional reference mapping space based on camera space.
[0069] The method for establishing the reference mapping space can be flexibly chosen. For example, it can be established according to preset rules, or it can be established as the same reference mapping space as the camera space. In this embodiment, no specific limitation is made.
[0070] Taking the camera space as a three-dimensional coordinate system constructed using a right-handed coordinate system, and the camera orientation in the camera space as the Z-axis, we can establish a reference mapping space with the same three-axis directions and unit size as the camera space, using a position at a set distance from the origin in the camera orientation direction as the origin. The resulting reference mapping space is identical to the camera space except for the origin position.
[0071] S112, calculate the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space based on the target projection screen.
[0072] It should be understood that the aspect ratio of the target projection screen is consistent with the resolution (i.e., aspect ratio) of the client 120's display screen.
[0073] It should be noted that the two-dimensional planar space of the two-dimensional image and the space of the target projection screen satisfy the following conditions: their X-axis and Y-axis directions are the same, their unit size is the same, and both are in pixels. When the scaling mapping rules from the two-dimensional image to the reference mapping space are different, the corresponding first transformation matrix will be different.
[0074] S113, obtain the mapping point corresponding to the pre-selected point in the two-dimensional plane space in the reference mapping space, and construct the second transformation matrix that performs three-dimensional rotation around the mapping point in the reference mapping space.
[0075] It should be noted that the pre-selected point can be any point in a two-dimensional plane space.
[0076] S114. Calculate the target transformation matrix based on the first transformation matrix, the second transformation matrix, and the perspective projection matrix.
[0077] Through the above steps S111-S114, the obtained target transformation matrix can transform the two-dimensional image from a two-dimensional planar space to a reference mapping space, and after performing a standard 3D spatial transformation in the reference mapping space, it is projected onto the target projection screen through perspective to produce the effect of a three-dimensional perspective image.
[0078] Since the two-dimensional image is ultimately projected onto the target projection screen, in one possible implementation, to improve the compatibility of the final three-dimensional perspective image with the client's display screen, step S112 can be further implemented as follows: based on the width and height of the target projection screen, determine the condition points in the two-dimensional planar space of the two-dimensional image; using the overlap between the condition points and the origin of the reference mapping space as the mapping condition, determine the first transformation matrix from the two-dimensional planar space of the two-dimensional image to the reference mapping space.
[0079] The x-coordinate of the condition point is half the width of the target projection screen, and the y-coordinate of the condition point is half the height of the target projection screen.
[0080] Assuming the target projection screen has a width of pw and a height of ph, and a = pw / ph, then the mapping condition is: the condition point (pw / 2, ph / 2) coincides with the origin of the reference mapping space. It should be understood that the width of the target projection screen can be the same as the width of the client 120's display screen, and the height of the target projection screen can also be the same as the height of the client 120's display screen.
[0081] Assume the distance between the origin of the reference mapping space and the origin of the camera space is d, where the default value of d can be -1. The width of the client's display screen is pw, and the height is ph. The camera's field of view in camera space is FOV in radians. Define tan_FOV as tan(FOV / 2), which is the trigonometric tangent of half the FOV. Define the symbol a = pw / ph, representing the aspect ratio of the client's display screen. Since the aspect ratio of the target projection screen is the same as that of the client's display screen, a is also the aspect ratio of the target projection screen.
[0082] To further improve the adaptation of the 3D perspective image of the 2D image to the client's display screen, the aspect ratio of the target projection screen and the distance between the origin of the reference mapping space and the origin of the camera space are introduced into the first transformation matrix calculated from the 2D screen to the reference mapping space. Figure 4 The method for determining the first transformation matrix from the two-dimensional plane space of a two-dimensional image to the reference mapping space can be further implemented as follows:
[0083] S1121, based on the distance between the origin of the reference mapping space and the origin of the camera space, calculate the height scaling ratio of the two-dimensional image from the two-dimensional plane space to the XY plane of the reference mapping space.
[0084] S1122, based on the aspect ratio of the target projection screen, calculate the width scaling ratio of the two-dimensional image from the two-dimensional plane space to the reference mapping space XY plane.
[0085] The height scaling ratio in the above steps can be expressed as: h = tan_FOV * d. The width scaling ratio can be expressed as: w = h * a.
[0086] S1123, based on the height scaling ratio and the height scaling ratio, calculate the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space.
[0087] Considering that traditional 2D user interfaces are half in a 2D coordinate system with the X-axis pointing to the right and the Y-axis pointing down, which is opposite to the Y-axis of the standard right-handed coordinate system, the scaling mapping rule can be: divide the 2D image by the product of the width and height of the target projection screen, scale it along the XY axis, magnify it by a factor of 2, and then offset it by one unit length in the negative X-axis direction and the positive Y-axis direction. The Z-axis adopts the same scaling as the Y-axis.
[0088] Since the unit size of the reference mapping space is the same as that of the camera space, the unit size of the reference mapping space changes with the camera parameters. Therefore, during the scaling process, the unit ratio between the two-dimensional screen space and the reference mapping space of the two-dimensional image is dynamically calculated based on the camera parameters.
[0089] Under the above scaling mapping rules, the first transformation matrix can be expressed as:
[0090]
[0091] To achieve a three-dimensional effect for the user interface, step S113 uses a three-dimensional rotation of a pre-selected point in the two-dimensional plane space of the two-dimensional image around a point in the three-dimensional pixel space. Assuming the pre-selected point is point p, step S113 can be further implemented as follows: transform point p in the two-dimensional plane space to point P in the reference mapping space, and construct a second transformation matrix in the reference mapping space to perform a 3D transformation around point P.
[0092] When the coordinates of point P are represented as P(px, py, pz), the second transformation matrix can be expressed as: Where BMat represents the translation, rotation, and scaling matrix in the reference mapping space. Since the translation, rotation, and scaling matrix in three-dimensional space is common knowledge, it will not be elaborated in this embodiment.
[0093] Based on the above, the target transformation matrix in step S114 can be expressed as: AMat=ProjectMat*RMat*UMat*LMat.
[0094] Where AMat represents the target transformation matrix, ProjectMat represents the perspective projection matrix, RMat represents the second transformation matrix, UMat represents the first transformation matrix, and LMat represents the translation, rotation, and scaling matrix of the two-dimensional plane. Since the perspective projection matrix and the translation, rotation, and scaling matrix of the two-dimensional plane are common knowledge in spatial transformations, they will not be described in detail in this embodiment.
[0095] To address the issue that current region clipping leads to additional rendering and stencil testing overhead, resulting in high resource consumption and low efficiency, one possible implementation is to refer to... Figure 5Regarding step S15, the method of coloring the two-dimensional image based on the set cropping area to determine the display area of the two-dimensional image can be further implemented as follows:
[0096] S151: Receive the input two-dimensional transformation matrix and pass the cropping information of the two-dimensional image and the two-dimensional transformation matrix into the vertex shading stage.
[0097] S152, In the vertex coloring stage, the position coordinates of each vertex of the two-dimensional image in the two-dimensional plane space are calculated by the two-dimensional transformation matrix, and the ratio value of each vertex is obtained based on the position coordinates and the cropping information.
[0098] S153, the scale values of all vertices are passed to the pixel shading stage, and the scale value of each fragment of the two-dimensional image is calculated by GPU linear interpolation.
[0099] S154, determine the display area of the two-dimensional image based on the ratio value of each fragment.
[0100] When client 120 receives the 2D image sent by server 110, the central processing unit (CPU) of client 120 transmits the 2D image, including the clipping region, and the 2D transformation matrix to the graphics processor. The 2D transformation matrix is a conventional transformation matrix used in the vertex shading stage and will not be further described in this embodiment. The clipping region is a pre-defined area, and the clipping information may include the starting point, height, and width of the clipping region.
[0101] The graphics processing unit (GPU) receives a 2D transformation matrix and a 2D image including the cropped region from the central processing unit (CPU). It then passes the cropping information and the 2D transformation matrix to the vertex shading stage. In the vertex shading stage, the GPU calculates the position coordinates of each vertex in the 2D plane using the 2D transformation matrix, and for each vertex, determines its scale value based on the cropping information, its position coordinates, and the vertex's proportions.
[0102] To obtain the scale value of each vertex in the 2D image more accurately, in one possible implementation, the method of obtaining the scale value of each vertex based on the position coordinates and the cropping information in S152 can be further implemented as follows: for each vertex, subtract the starting point of the cropping region from the vertex's position coordinates to obtain the vertex's relative position with respect to the cropping region, then calculate the product between the width and height of the cropping region, and use the ratio between the vertex's relative position and this product as the vertex's scale value. In this way, the scale values of all vertices in the 2D image are obtained.
[0103] The graphics processor (GPU) inputs the scale values of all vertices of the 2D image into the pixel shading stage. Through linear interpolation by the GPU, it calculates the scale value of each fragment in the 2D image. For each fragment, if its scale value is between 0 and 1, it is determined that the fragment is located in the clipping region; otherwise, it is. Fragments not located in the clipping region are then not displayed, thus determining the display area. The GPU then performs pixel shading on the region corresponding to this display area in the 3D perspective image and performs stencil and depth tests on each pixel after shading to ultimately display it on the client's screen.
[0104] In traditional image rendering methods, all fragments need to undergo stencil testing, and fragments that fail the stencil test will not be displayed. Compared with traditional image rendering methods, the image rendering method provided in this embodiment of the invention, through the above steps S151-S154, determines the display area through vertex shading and pixel shading stages. Therefore, in subsequent stencil testing, only fragments located within the display area need to be stencil tested, which can greatly reduce rendering overhead and stencil testing overhead, and improve clipping efficiency.
[0105] The image rendering method provided in this invention converts a two-dimensional image to 3D and projects the transformed image onto a target projection screen to obtain a three-dimensional perspective image. Simultaneously, during the coloring stage, fragments located in the clipping region of the two-dimensional image are identified to determine the display area. This allows coloring only the area corresponding to the display area in the three-dimensional perspective image, enabling subsequent testing only on the colored fragment templates within the display area. This significantly reduces rendering overhead and target testing overhead, reduces resource consumption, and improves efficiency.
[0106] Based on the inventive concept of the above-described image rendering method, in one possible implementation, the present invention also provides an image rendering apparatus 130, which can be applied to... Figure 1 Client 120 in the middle. (Refer to...) Figure 6 The image rendering device 130 may include a spatial transformation module 140, a perspective projection module 150, and a coloring and drawing module 160.
[0107] The spatial transformation module 140 is used to obtain the target transformation matrix. The target transformation matrix is used for spatial transformation and 3D perspective projection.
[0108] The perspective projection module 150 is used to transform a two-dimensional image based on a target transformation matrix to obtain a three-dimensional perspective image of the two-dimensional image.
[0109] The coloring and drawing module 160 is used to color the two-dimensional image based on the set cropping area, determine the display area of the two-dimensional image, and color the area corresponding to the display area in the three-dimensional perspective image.
[0110] In the image rendering apparatus 130 described above, through the coordinated action of the spatial transformation module 140, the perspective projection module 150, and the coloring and drawing module 160, the two-dimensional image is transformed based on the target transformation matrix used for spatial transformation and three-dimensional perspective projection to obtain a three-dimensional perspective image of the two-dimensional image. Based on the set clipping region, the two-dimensional image is processed to determine the display area of the two-dimensional image. Thus, only the area corresponding to the display area in the three-dimensional perspective image is colored, realizing the drawing and display of the two-dimensional image in a three-dimensional spatial perspective projection mode, which can greatly improve the visual effect of the image.
[0111] Specific limitations regarding the image rendering apparatus 130 can be found in the limitations of the image rendering method described above, and will not be repeated here. Each module in the image rendering apparatus 130 can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the electronic device 170 in hardware form, or stored in the memory of the electronic device 170 in software form, so that the processor can call and execute the operations corresponding to each module.
[0112] In one embodiment, an electronic device 170 is provided, which can be a client, and its internal structure diagram can be as follows: Figure 7 As shown, the electronic device 170 includes a processor, memory, communication interface, display screen, and input device connected via a system bus. The processor of the electronic device 170 provides computing and control capabilities. The memory of the electronic device 170 includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The communication interface of the electronic device 170 is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, near-field communication (NFC), or other technologies. When the computer program is executed by the processor, it implements the image rendering method provided in the above embodiment.
[0113] Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the electronic device 170 to which the present invention is applied. The specific electronic device 170 may include, but is not limited to, the following: Figure 7 The diagram shows more or fewer components, or combinations of certain components, or different component arrangements.
[0114] In one embodiment, the image rendering apparatus 130 provided by the present invention can be implemented as a computer program, which can be implemented in, for example... Figure 7 The electronic device 170 shown operates on this device. The memory of the electronic device 170 can store various program modules that make up the image rendering apparatus 130, for example, Figure 6 The spatial transformation module 140, perspective projection module 150, and color rendering module 160 are shown. The computer program composed of these various program modules causes the processor to execute the steps in the image rendering method described in this specification.
[0115] For example, Figure 7 The electronic device 170 shown can be used as follows Figure 6 The spatial transformation module 140 in the image rendering apparatus 130 executes step S11. The electronic device 170 can execute step S13 through the perspective projection module 150. The electronic device 170 can execute step S15 through the shading and drawing module 160.
[0116] In one embodiment, an electronic device 170 is provided, including a memory and a graphics processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: obtaining a target transformation matrix; transforming a two-dimensional image based on the target transformation matrix to obtain a three-dimensional perspective image of the two-dimensional image; coloring the two-dimensional image based on a set cropping region to determine the display area of the two-dimensional image, and coloring the region corresponding to the display area in the three-dimensional perspective image.
[0117] In one embodiment, a storage medium is provided storing a computer program that, when executed by a graphics processor, performs the following steps: obtaining a target transformation matrix; transforming a two-dimensional image based on the target transformation matrix to obtain a three-dimensional perspective image of the two-dimensional image; coloring the two-dimensional image based on a set cropping region to determine the display area of the two-dimensional image, and coloring the region corresponding to the display area in the three-dimensional perspective image.
[0118] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0119] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0120] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0121] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An image rendering method, characterized in that, The method includes: Obtain the target transformation matrix; wherein, the target transformation matrix is a transformation matrix used for spatial transformation and three-dimensional perspective projection; the step of obtaining the target transformation matrix includes: A three-dimensional reference mapping space is established based on the camera space; Based on the target projection screen, calculate the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space; Obtain the mapping point corresponding to the pre-selected point in the two-dimensional plane space in the reference mapping space, and construct a second transformation matrix for three-dimensional rotation around the mapping point in the reference mapping space; The target transformation matrix is calculated based on the first transformation matrix, the second transformation matrix, and the perspective projection matrix; Based on the target transformation matrix, the two-dimensional image is transformed to obtain a three-dimensional perspective image of the two-dimensional image; Based on the set cropping area, the two-dimensional image is colored to determine the display area of the two-dimensional image, and the area corresponding to the display area in the three-dimensional perspective image is colored. The step of coloring the two-dimensional image based on a set cropping region to determine the display area of the two-dimensional image includes: The input two-dimensional transformation matrix is received, and the cropping information of the two-dimensional image and the two-dimensional transformation matrix are passed to the vertex shading stage. During the vertex shading stage, the position coordinates of each vertex of the two-dimensional image in the two-dimensional plane space are calculated using the two-dimensional transformation matrix, and the scale value of each vertex is obtained based on the position coordinates and the cropping information; The scale values of all vertices are passed to the pixel shading stage, and the scale value of each fragment of the two-dimensional image is calculated by linear interpolation of the GPU. The display area of the two-dimensional image is determined based on the scale value of each fragment.
2. The image rendering method according to claim 1, characterized in that, The step of establishing a three-dimensional reference mapping space based on camera space includes: A reference mapping space is established with the origin at a position in the camera orientation direction of the camera space at a set distance from the origin of the camera space. The three-axis directions are consistent with the three-axis directions of the camera space, and the unit size is consistent with the unit size of the camera space.
3. The image rendering method according to claim 1, characterized in that, The step of calculating the first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space based on the target projection screen includes: Based on the width and height of the target projection screen, condition points in the two-dimensional plane space of the two-dimensional image are determined; wherein, the horizontal coordinate of the condition point is half the width of the target projection screen, and the vertical coordinate of the condition point is half the height of the target projection screen. Using the overlap between the condition point and the origin of the reference mapping space as the mapping condition, a first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space is determined.
4. The image rendering method according to claim 1, characterized in that, The target transformation matrix includes: in, Represents the target transformation matrix. Represents the perspective projection matrix. Denotes the second transformation matrix. Denotes the first transformation matrix. This represents the translation, rotation, and scaling matrix in a two-dimensional planar space.
5. The image rendering method according to claim 1, characterized in that, The cropping information includes the starting point, height, and width of the cropping area; The step of obtaining the proportional value of each vertex based on the position coordinates and the clipping information includes: For each vertex, subtract the starting point of the clipping region from the vertex's position coordinates to obtain the vertex's relative position with respect to the clipping region; Calculate the product between the width and height of the cropped area, and use the ratio between the relative position and the product as the ratio value of the vertex.
6. An image rendering apparatus, characterized in that, Includes a spatial transformation module, a perspective projection module, and a coloring and drawing module: The spatial transformation module is used to obtain a target transformation matrix; wherein, the target transformation matrix is a transformation matrix used for spatial transformation and three-dimensional perspective projection; the spatial transformation module is also used to: establish a three-dimensional reference mapping space based on camera space; calculate a first transformation matrix from the two-dimensional plane space of the two-dimensional image to the reference mapping space according to the target projection screen; obtain the mapping point corresponding to the pre-selected point in the two-dimensional plane space in the reference mapping space, and construct a second transformation matrix for three-dimensional rotation around the mapping point in the reference mapping space; calculate the target transformation matrix according to the first transformation matrix, the second transformation matrix, and the perspective projection matrix; The perspective projection module is used to transform the two-dimensional image based on the target transformation matrix to obtain a three-dimensional perspective image of the two-dimensional image. The coloring and rendering module is used to color the two-dimensional image based on a set clipping region, determine the display area of the two-dimensional image, and color the area corresponding to the display area in the three-dimensional perspective image. The coloring and rendering module is used to: receive an input two-dimensional transformation matrix and pass the clipping information of the two-dimensional image and the two-dimensional transformation matrix to the vertex coloring stage; in the vertex coloring stage, calculate the position coordinates of each vertex of the two-dimensional image in the two-dimensional plane space using the two-dimensional transformation matrix, and obtain the scale value of each vertex based on the position coordinates and the clipping information; pass the scale values of all vertices to the pixel coloring stage, calculate the scale value of each fragment of the two-dimensional image using GPU linear interpolation; and determine the display area of the two-dimensional image based on the scale value of each fragment.
7. An electronic device, characterized in that, It includes a graphics processor and a memory, the memory storing a computer program that can be executed by the graphics processor to implement the image rendering method as described in any one of claims 1 to 5.
8. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the graphics processor, it implements the image rendering method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Drawing control device, drawing control method, computer program of the same, and recording medium with the program recorded thereon
JP2011186930A