Image rendering method, device, equipment, storage medium and program product
By homogenizing the vertex coordinates of virtual objects and using vector multiplication and addition operations to perform coordinate conversion, the problem of wasted storage and computing resources in graphics image rendering is solved, and the display efficiency is improved.
Patent Information
- Application Number
- CN202210053376.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-18
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-01-18
AI Technical Summary
The prior art in graphic image rendering consumes a large amount of storage space and computing resources, which affects the user experience.
By homogenizing the vertex coordinates of virtual objects and using vector multiplication and addition operations to perform coordinate conversion, the calculation amount and storage requirements are reduced.
Effectively save storage space and computing resources, and improve the display efficiency of virtual objects.
Smart Images

Figure CN114399580B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer graphics technology, and in particular to an image rendering method, device, electronic device, computer-readable storage medium, and computer program product. Background Art
[0002] Display technology based on graphics processing hardware has expanded the channels for perceiving the environment and obtaining information. In particular, display technology for virtual scenes can achieve diversified interactions between virtual objects controlled by users or artificial intelligence according to actual application needs. It has various typical application scenarios. For example, in virtual scenes such as games, it can simulate the real battle process between virtual objects.
[0003] In related technologies, the coordinate transformation of the vertices is achieved by multiplying the four-dimensional matrix twice with multiple vertices of the virtual object to be rendered, and image rendering is performed based on the vertices after coordinate transformation. This solution requires a large number of vertex calculations, which will waste a lot of storage space and computing resources, thereby affecting the user experience. Summary of the Invention
[0004] The embodiments of the present application provide an image rendering method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can fully and effectively utilize vector multiplication and addition, saving related storage space and computing resources.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present invention provides an image rendering method, including:
[0007] Obtain multiple vertices of the virtual object to be rendered, where each vertex corresponds to a vertex coordinate;
[0008] Performing homogenization processing on the vertex coordinates of each vertex to obtain homogeneous coordinates of each vertex;
[0009] Performing vector multiplication and addition processing on the homogeneous coordinates of each vertex based on the coordinate transformation matrix to obtain the transformed coordinates of each vertex;
[0010] Image rendering processing is performed on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain a rendered virtual object.
[0011] An embodiment of the present application provides an image rendering device, comprising:
[0012] An acquisition module, configured to acquire a plurality of vertices of a virtual object to be rendered, wherein each vertex corresponds to a vertex coordinate;
[0013] A homogenization module, configured to perform homogenization processing on the vertex coordinates of each vertex to obtain homogeneous coordinates of each vertex;
[0014] A conversion module, configured to perform vector multiplication and addition processing on the homogeneous coordinates of each vertex based on a coordinate conversion matrix to obtain a conversion coordinate of each vertex;
[0015] A rendering module is used to perform image rendering processing on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain a rendered virtual object.
[0016] In the above technical solution, the vertex coordinates of each vertex are a three-dimensional coordinate vector, and the homogeneous coordinates are a four-dimensional coordinate vector; the homogenization module is further used to concatenate the three-dimensional coordinate vector of each vertex with a constant to obtain the four-dimensional coordinate vector of each vertex;
[0017] The constant is the fourth-dimensional value of the four-dimensional coordinate vector.
[0018] In the above technical solution, the conversion module is further used to perform column vector segmentation processing on the coordinate conversion matrix to obtain multiple column vectors of the coordinate conversion matrix;
[0019] Vector multiplication and addition processing is performed on the multiple column vectors and the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex.
[0020] In the above technical solution, when the coordinate transformation matrix is a model matrix, before performing column vector segmentation processing on the coordinate transformation matrix, the conversion module is further used to determine the rotation orthogonal matrix, translation matrix and scaling matrix corresponding to each vertex;
[0021] The rotation orthogonal matrix, the translation matrix, and the scaling matrix are multiplied to obtain a model matrix corresponding to each vertex.
[0022] In the above technical solution, when the coordinate transformation matrix includes a view projection matrix, before performing column vector segmentation processing on the coordinate transformation matrix, the conversion module is further used to determine the view space matrix and the projection matrix corresponding to each vertex;
[0023] The view space matrix and the projection matrix are multiplied to obtain the view projection matrix corresponding to each vertex.
[0024] In the above technical solution, when the coordinate transformation matrix includes a model matrix and a view projection matrix, the transformation module is further used to perform column vector segmentation processing on the model matrix to obtain multiple first column vectors of the model matrix;
[0025] Performing column vector segmentation processing on the view projection matrix to obtain a plurality of second column vectors of the view projection matrix;
[0026] Performing vector multiplication and addition processing on the plurality of first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex;
[0027] Vector multiplication and addition processing is performed on the multiple second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex.
[0028] In the above technical solution, when the vertex coordinates are position coordinate vectors, the conversion module is further configured to perform a first product processing on a first first column vector of the multiple first column vectors and a first-dimensional coordinate value of the homogeneous coordinates of each vertex, and add the first product result to a fourth first column vector of the multiple first column vectors to obtain first coordinate transformation information;
[0029] Performing a second product process on a second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second product result to the first coordinate transformation information to obtain second coordinate transformation information;
[0030] Perform a third multiplication process on the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the world space coordinates of each vertex.
[0031] In the above technical solution, the conversion module is further configured to perform a first product processing on the first three-dimensional values of the first first column vector of the multiple first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the first product result to the first three-dimensional values of the fourth first column vector of the multiple first column vectors to obtain the three-dimensional first coordinate transformation information;
[0032] Performing a second product process on the first three-dimensional values of the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex;
[0033] Perform a third multiplication process on the first three-dimensional values of the third column vector of the multiple column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, add the third product result to the second coordinate transformation information to obtain three-dimensional third coordinate transformation information, and splice the third coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
[0034] In the above technical solution, when the vertex coordinates are position coordinate vectors, the conversion module is further configured to perform a first product processing on a first second column vector of the plurality of second column vectors and a first-dimensional coordinate value of the world space coordinates of each vertex, and add the first product result to a fourth second column vector of the plurality of second column vectors to obtain fourth coordinate transformation information;
[0035] Performing a second product process on the second second column vector of the plurality of second column vectors and the second-dimensional coordinate value of the world space coordinate of each vertex, and adding the second product result to the fourth coordinate transformation information to obtain fifth coordinate transformation information;
[0036] Perform a third multiplication process on the third second column vector of the multiple second column vectors and the fifth-dimensional coordinate value of the world space coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the transformed coordinates of each vertex.
[0037] In the above technical solution, when the vertex coordinates are direction coordinate vectors, the conversion module is further used to perform a first product process on the first first column vector of the multiple first column vectors and the first dimension coordinate value of the homogeneous coordinates of each vertex to obtain sixth coordinate transformation information;
[0038] Performing a second product process on a second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second product result to the sixth coordinate transformation information to obtain seventh coordinate transformation information;
[0039] Perform a third multiplication process on the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the seventh coordinate transformation information to obtain the world space coordinates of each vertex.
[0040] In the above technical solution, the conversion module is further used to perform a first product processing on the first three-dimensional values of the first first column vector of the multiple first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex;
[0041] Performing a second product process on the first three-dimensional values of the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex;
[0042] Perform a third multiplication process on the first three-dimensional values of the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, add the third product result to the seventh coordinate transformation information to obtain three-dimensional eighth coordinate transformation information, and splice the eighth coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
[0043] In the above technical solution, the rendering module is further used to perform rasterization processing on the transformed coordinates of each vertex to obtain the pixels corresponding to each vertex;
[0044] Performing coloring on the pixels corresponding to each vertex to obtain the color corresponding to each pixel;
[0045] The colors corresponding to each pixel are mixed to obtain the rendered virtual object.
[0046] An embodiment of the present application provides an electronic device for image rendering, the electronic device comprising:
[0047] a memory for storing executable instructions;
[0048] The processor is used to implement the image rendering method provided in the embodiment of the present application when executing the executable instructions stored in the memory.
[0049] An embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute and implement the image rendering method provided in the embodiment of the present application.
[0050] An embodiment of the present application provides a computer program product, including a computer program or instructions, characterized in that when the computer program or instructions are executed by a processor, the image rendering method provided in the embodiment of the present application is implemented.
[0051] The embodiments of the present application have the following beneficial effects:
[0052] The homogeneous coordinates of each vertex are vector-multiplied and added through the coordinate transformation matrix to obtain the transformed coordinates of each vertex, and image rendering processing is performed based on the transformed coordinates of each vertex, so as to fully and effectively utilize vector multiplication and addition for coordinate transformation, save related storage space and computing resources, and thus improve the display efficiency of virtual objects. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1A-1B Schematic diagram of an application mode of the image rendering method provided in an embodiment of the present application;
[0054] Figure 2 is a structural diagram of an electronic device for image rendering provided by an embodiment of the present application;
[0055] Figure 3-Figure 5 Schematic diagram of the image rendering method provided in the embodiment of the present application;
[0056] Figure 6 is a schematic diagram of an unlit shader provided in an embodiment of the present application;
[0057] Figure 7 is a schematic diagram of the material resources of the newly created and modified shader provided in an embodiment of the present application;
[0058] Figure 8 This is a schematic diagram of the material resource application provided in the embodiment of the present application;
[0059] Figure 9 It is a flowchart of the rendering pipeline provided by related technologies;
[0060] Figure 10 This is a flowchart of the vertex shading calculation provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0062] In the following description, the terms "first\second" are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0064] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0065] 1) In response to: used to indicate the conditions or states on which the executed operations depend. When the dependent conditions or states are met, one or more operations executed can be in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations executed are executed.
[0066] 2) Client: An application running in a terminal to provide various services, such as a video player client, a game client, etc.
[0067] 3) Virtual scene: A virtual game scene displayed (or provided) when the game program is running on the terminal. The virtual scene can be a simulation of the real world, a semi-simulation and semi-fictitious virtual environment, or a purely fictitious virtual environment. The virtual scene can be any of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, or a three-dimensional virtual scene. The embodiment of the present application does not limit the dimensions of the virtual scene. For example, the virtual scene may include the sky, land, ocean, etc., and the land may include environmental elements such as deserts and cities. The user can control the movement of virtual objects in the virtual scene.
[0068] 4) Virtual Objects: These are the images of various people and objects that can interact in a virtual scene, or movable objects within the virtual scene. These movable objects can be virtual people, virtual animals, animated characters, etc., such as people or animals displayed within the virtual scene. A virtual object can be a virtual avatar that represents the user within the virtual scene. A virtual scene can include multiple virtual objects, each with its own unique shape and volume, occupying a portion of the space within the virtual scene.
[0069] 5) Scene data: This data represents the characteristics of the virtual scene, such as the area of the construction area in the virtual scene, the current architectural style of the virtual scene, etc.; it can also include the location of the virtual building in the virtual scene, and the area occupied by the virtual building, etc.
[0070] 6) Graphics Processing Unit (GPU): A dedicated chip used in modern personal computers, servers, mobile devices, game consoles, etc. specifically for graphics and image processing.
[0071] 7) Rendering Pipeline: The graphics rendering process that runs on the GPU, including vertex shaders, rasterizers, and pixel shaders. By writing code in shaders, you can flexibly control the GPU to render the rendering components.
[0072] 8) Vertex Shader: A required part of the GPU rendering pipeline. The vertex shader program calculates the vertices of the model one by one according to the code and outputs the results to the next stage.
[0073] 9) Coordinate transformation: The process of transforming the coordinates of one spatial coordinate system to another spatial coordinate system. The transformation relationship between coordinate systems is represented by a matrix. The coordinate vector is placed on the left side of the matrix, and the value obtained is the transformed coordinate.
[0074] 10) Fragment shader: A required part of the GPU rendering pipeline. The fragment shader program will perform shading calculations on the rasterized pixels according to the code, output them to the frame buffer after testing, and complete a rendering pipeline process.
[0075] 11) Graphics Application Programming Interface (API): When the central processing unit (CPU) communicates with the GPU, it follows a standard graphics API. Graphics APIs include OpenGL, OpenGL ES, Direct X, Metal, Vulkan, etc. When developing graphics, you can call the GPU according to the methods defined by the interface.
[0076] In the related art, in the field of graphics and image rendering and industry applications, when a three-dimensional scene is rendered in a graphics processing unit (GPU), it will go through a series of calculations in the GPU rendering pipeline. Among them, when performing coordinate transformation, the vertex coordinates of each vertex need to be homogenized and then multiplied by the matrix twice. In the Open Graphics Library (OpenGL) graphics application programming interface (API, Application Programming Interface), the corresponding shader language (GLSL, OpenGL Shading Language) is used for implementation. The constant 1 needs to be used as the fourth dimension of the vertex to form a homogeneous coordinate vector, and then the four-dimensional matrix and the four-dimensional vector (i.e., the homogeneous coordinate vector) are multiplied twice.
[0077] In 3D rendering, coordinate transformations are a unified computational process, supported by the game engine itself. As the scene's models become more detailed, meaning the number of vertices increases, the computational cost of the vertex shader increases as a percentage of the entire rendering pipeline.
[0078] To address the above-mentioned issues, embodiments of the present application provide an image rendering method, apparatus, electronic device, computer-readable storage medium, and computer program product that can fully and effectively utilize vector multiplication and addition, saving related storage space and computing resources. To facilitate easier understanding of the image rendering method provided by embodiments of the present application, an exemplary implementation scenario of the image rendering method provided by embodiments of the present application is first described. The virtual objects in the image rendering method provided by embodiments of the present application can be output entirely based on the terminal, or based on the coordinated output of the terminal and the server.
[0079] In some embodiments, the virtual scene can be an environment for game characters to interact. For example, it can be an environment for game characters to fight in the virtual scene. By controlling the actions of the game characters, both parties can interact in the virtual scene, allowing users to relieve life stress during the game.
[0080] In one implementation scenario, see Figure 1A , Figure 1A This is a schematic diagram of the application mode of the image rendering method provided in an embodiment of the present application, which is suitable for some application modes that completely rely on the graphics processing hardware computing power of the terminal 400 to complete the relevant data calculation of the virtual scene 100, such as stand-alone / offline mode games, and complete the output of the virtual scene through various types of terminals 400 such as smartphones, tablets and virtual reality / augmented reality devices.
[0081] As an example, types of graphics processing hardware include a central processing unit (CPU) and a graphics processing unit (GPU).
[0082] When forming the visual perception of the virtual scene 100, the terminal 400 calculates the data required for display through the graphics computing hardware, and completes the loading, parsing and rendering of the display data, and outputs the video frames that can form the visual perception of the virtual scene on the graphics output hardware, for example, presenting two-dimensional video frames on the display screen of a smartphone, or projecting video frames on the lenses of augmented reality / virtual reality glasses to achieve a three-dimensional display effect; in addition, in order to enrich the perception effect, the terminal 400 can also use different hardware to form one or more of auditory perception, tactile perception, motion perception and taste perception.
[0083] As an example, a client 410 (e.g., a stand-alone game application) is running on the terminal 400. During the operation of the client 410, a virtual scene including role-playing is output. The virtual scene can be an environment for game characters to interact, such as a plain, street, valley, etc. for game characters to fight. Taking the first-person perspective display of the virtual scene 100 as an example, a rendered virtual object 110 is displayed in the virtual scene 100. The rendered virtual object 110 can be a game character controlled by a user (or player), which will operate in the virtual scene in response to the real user's operation on buttons (including joystick buttons, attack buttons, defense buttons, etc.). For example, when the real user moves the joystick button to the left, the virtual object will move to the left in the virtual scene, and can also remain stationary, jump, and use various functions (such as skills and props). The rendered virtual object 110 can also be an artificial intelligence (AI) set in the virtual scene battle through training. The rendered virtual object 110 can also be a non-user character (NPC) set in the virtual scene interaction. The rendered virtual object 110 may also be an inactive object or an active object in the virtual scene 100.
[0084] For example, taking the first-person perspective display of the virtual scene 100 as an example, a virtual object to be rendered is displayed in the virtual scene 100. Before the battle game starts, the player customizes the display position 120 of the virtual object to be rendered in the virtual scene. Through the image rendering method of the embodiment of the present application, multiple vertices of the virtual object to be rendered are obtained, and the vertex coordinates of each vertex are homogenized to obtain the homogeneous coordinates of each vertex. Based on the coordinate transformation matrix corresponding to the display position 120, vector multiplication and addition are performed on the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex. Based on the transformed coordinates of each vertex, image rendering processing is performed on the virtual object to be rendered to obtain the rendered virtual object 110, and human-computer interaction of the virtual scene, such as game confrontation, is performed at the display position 120 based on the rendered virtual object 110.
[0085] In another implementation scenario, see Figure 1B , Figure 1B It is a schematic diagram of the application mode of the image rendering method provided in an embodiment of the present application, which is applied to the terminal 400 and the server 200, and is suitable for an application mode that relies on the computing power of the server 200 to complete the virtual scene calculation and output the virtual scene at the terminal 400.
[0086] Taking the visual perception of the virtual scene 100 as an example, the server 200 calculates the virtual scene-related display data (such as scene data) and sends it to the terminal 400 through the network 300. The terminal 400 relies on the graphics computing hardware to complete the loading, parsing and rendering of the calculated display data, and relies on the graphics output hardware to output the virtual scene to form visual perception. For example, a two-dimensional video frame can be presented on the display screen of a smartphone, or a video frame with a three-dimensional display effect can be projected on the lenses of augmented reality / virtual reality glasses. As for the perception of the form of the virtual scene, it can be understood that the corresponding hardware output of the terminal 400 can be used, such as using a microphone to form auditory perception, using a vibrator to form tactile perception, and so on.
[0087] As an example, a client 410 (e.g., an online version of a game application) runs on the terminal 400, which interacts with other users in a game by connecting to a server 200 (e.g., a game server). The terminal 400 outputs a virtual scene 100 of the client 410. Taking the first-person perspective display of the virtual scene 100 as an example, a rendered virtual object 110 is displayed in the virtual scene 100. The rendered virtual object 110 can be a game character controlled by a user (or player), which will operate in the virtual scene in response to the real user's operation on buttons (including joystick buttons, attack buttons, defense buttons, etc.). For example, when the real user moves the joystick button to the left, the virtual object will move to the left in the virtual scene, and can also remain stationary, jump, and use various functions (such as skills and props); the rendered virtual object 110 can also be an artificial intelligence (AI) set in a virtual scene battle through training; the rendered virtual object 110 can also be a non-user character (NPC, Non-Player) set in the virtual scene interaction. The rendered virtual object 110 may also be an inactive object or an active object in the virtual scene 100.
[0088] For example, taking the first-person perspective display of the virtual scene 100 as an example, a virtual object to be rendered is displayed in the virtual scene 100. Before the battle game starts, the player customizes the display position 120 of the virtual object to be rendered in the virtual scene. Through the image rendering method of the embodiment of the present application, multiple vertices of the virtual object to be rendered are obtained, and the vertex coordinates of each vertex are homogenized to obtain the homogeneous coordinates of each vertex. Based on the coordinate transformation matrix corresponding to the display position 120, vector multiplication and addition are performed on the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex. Based on the transformed coordinates of each vertex, image rendering processing is performed on the virtual object to be rendered to obtain the rendered virtual object 110, and human-computer interaction of the virtual scene, such as game confrontation, is performed at the display position 120 based on the rendered virtual object 110.
[0089] In some embodiments, the terminal 400 can implement the image rendering method provided in the embodiments of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, APPlication), that is, a program that needs to be installed in the operating system to run, such as a dress-up game APP (i.e., the above-mentioned client 410); it can also be a small program, that is, a program that can be run only by downloading it into a browser environment; it can also be a game small program that can be embedded in any APP. In short, the above-mentioned computer program can be an application, module or plug-in in any form.
[0090] Taking a computer program as an application, in actual implementation, terminal 400 installs and runs an application that supports a virtual scene. This application can be any of a first-person shooter (FPS), a third-person shooter, a virtual reality application, a three-dimensional map program, or a multiplayer shooter survival game. A user uses terminal 400 to manipulate virtual objects in the virtual scene to perform activities, including but not limited to: adjusting body posture, crawling, walking, running, riding, jumping, driving, picking up, shooting, attacking, throwing, and constructing virtual buildings. Illustratively, the virtual object can be a virtual character, such as a simulated human character or an anime character.
[0091] In some embodiments, the embodiments of the present application can also be implemented with the help of cloud technology. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network within a wide area network or local area network to realize data calculation, storage, processing, and sharing.
[0092] Cloud technology is a general term for network, information, integration, management platform, and application technologies used in the cloud computing business model. It can form a resource pool that can be used flexibly and conveniently on demand. Cloud computing technology will become a key support. The backend services of technical network systems require a large amount of computing and storage resources.
[0093] For example, Figure 1BThe server 200 in the example can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal 400 can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to these. The terminal 400 and the server 200 can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0094] See also Figure 2 , Figure 2 4 is a schematic diagram of the structure of an electronic device for image rendering provided by an embodiment of the present application, and is described by taking the electronic device as a terminal 400 as an example. Figure 2 The electronic device 400 shown includes: at least one processor 420, a memory 460, at least one network interface 430 and a user interface 440. The various components in the terminal 400 are coupled together via a bus system 450. It is understood that the bus system 450 is used to achieve connection and communication between these components. In addition to including a data bus, the bus system 450 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 450 is not shown in FIG. Figure 2 Various buses are labeled as bus system 450 .
[0095] The processor 420 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0096] The user interface 440 includes one or more output devices 441 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 440 also includes one or more input devices 442, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0097] The memory 460 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 460 may optionally include one or more storage devices that are physically remote from the processor 420.
[0098] The memory 460 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 460 described in the embodiments of the present application is intended to include any suitable type of memory.
[0099] In some embodiments, the memory 460 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.
[0100] Operating system 461, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;
[0101] A network communication module 462 for reaching other computing devices via one or more (wired or wireless) network interfaces 430 , exemplary network interfaces 430 including Bluetooth, WiFi, and USB;
[0102] a presentation module 463 for enabling presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 441 (e.g., a display screen, a speaker, etc.) associated with the user interface 440;
[0103] The input processing module 464 is configured to detect one or more user inputs or interactions from one of the one or more input devices 442 and to translate the detected inputs or interactions.
[0104] In some embodiments, the image rendering device provided by the embodiments of the present application can be implemented in software. Figure 2 An image rendering device 465 stored in the memory 460 is shown, which can be software in the form of a program and plug-in, etc., including the following software modules: an acquisition module 4651, a homogenization module 4652, a second conversion module 4653, and a rendering module 4654. These modules are logical and can therefore be arbitrarily combined or further split according to the functions implemented.
[0105] In other embodiments, the image rendering device provided in the embodiments of the present application can be implemented in hardware. As an example, the image rendering device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the image rendering method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0106] The image rendering method provided by the embodiment of the present application will be described in detail below with reference to the accompanying drawings. Figure 1A The terminal 400 in the Figure 1B The terminal 400 and the server 200 cooperate to execute.
[0107] Below, by Figure 1A The terminal 400 in the embodiment of the present application alone performs the image rendering method provided by the embodiment of the present application as an example for explanation. Figure 3 , Figure 3 This is a flow chart of the image rendering method provided by the embodiment of the present application, which will be combined with Figure 3 The steps shown are explained.
[0108] It should be noted that Figure 3 The method shown can be executed by various forms of computer programs running on the terminal 400, and is not limited to the above-mentioned client 410, but can also be the above-mentioned operating system 461, software modules and scripts. Therefore, the client should not be regarded as a limitation on the embodiments of the present application.
[0109] In step 101 , a plurality of vertices of a virtual object to be rendered are obtained, wherein each vertex corresponds to a vertex coordinate.
[0110] For example, in a 3D rendering scene, the virtual object to be rendered includes multiple vertices. The more detailed the virtual object to be rendered, the more vertices there are, and the greater the computational effort required to render the vertex-based image. Each vertex corresponds to a vertex coordinate, which is a 3D coordinate vector consisting of the vertex's x, y, and z coordinate values.
[0111] In step 102, the vertex coordinates of each vertex are homogenized to obtain homogeneous coordinates of each vertex.
[0112] For example, before performing coordinate transformation, the three-dimensional vertex coordinates need to be homogenized to obtain the four-dimensional homogeneous coordinates of each vertex, so as to perform matrix multiplication based on the four-dimensional homogeneous coordinates.
[0113] In some embodiments, the vertex coordinates of each vertex are a three-dimensional coordinate vector, and the homogeneous coordinates are a four-dimensional coordinate vector; the vertex coordinates of each vertex are homogenized to obtain the homogeneous coordinates of each vertex, including: concatenating the three-dimensional coordinate vector of each vertex with a constant to obtain a four-dimensional coordinate vector of each vertex; wherein the constant is the fourth-dimensional value of the four-dimensional coordinate vector.
[0114] For example, the vertex coordinates of a vertex are [x, y, z]. The three-dimensional coordinate vector of the vertex is concatenated with a constant to obtain the four-dimensional coordinate vector of the vertex [x, y, z, w]. Here, w represents a constant. When the vertex coordinates are position coordinate vectors, w is 1, that is, the four-dimensional coordinate vector of the vertex is [x, y, z, 1]. When the vertex coordinates are direction coordinate vectors, w is 0, that is, the four-dimensional coordinate vector of the vertex is [x, y, z, 0].
[0115] In step 103 , vector multiplication and addition processing is performed on the homogeneous coordinates of each vertex based on the coordinate transformation matrix to obtain the transformed coordinates of each vertex.
[0116] For example, in the coordinate transformation stage, multiplication and addition instructions are used to optimize the matrix multiplication process of vectors, thereby improving the efficiency of vertex coordinate transformation while maintaining the output results and accuracy unchanged, thereby improving the overall image rendering performance.
[0117] See also Figure 4 , Figure 4 This is an optional flowchart of the image rendering method provided in the embodiment of the present application. Figure 4 Show Figure 3 Step 103 in the figure can be implemented through steps 1031 and 1032: in step 1031, the coordinate transformation matrix is split into column vectors to obtain multiple column vectors of the coordinate transformation matrix; in step 1032, the multiple column vectors and the homogeneous coordinates of each vertex are multiplied and added to obtain the transformed coordinates of each vertex.
[0118] For example, the coordinate transformation matrix is M, Among them, split M into c1 T 、c2 T 、c3 T 、c4 T column vector, and c1 T 、c2T 、c3 T 、c4 t and homogeneous vector v = [v1,v2,v3,v4] T Perform vector multiplication and addition to obtain the transformed coordinates of each vertex.
[0119] It should be noted that, according to actual needs, the coordinate transformation matrix can also be divided into row vectors to obtain multiple row vectors of the coordinate transformation matrix; multiple row vectors and the homogeneous coordinates of each vertex are multiplied and added to obtain the transformed coordinates of each vertex. For example, the coordinate transformation matrix is M, Among them, M is split into column vectors r1, r2, r3, and r4, and r1, r2, r3, and r4 are multiplied and added with the homogeneous vector v = [v1, v2, v3, v4] to obtain the transformed coordinates of each vertex.
[0120] In some embodiments, when the coordinate transformation matrix is a model matrix, before performing column vector segmentation processing on the coordinate transformation matrix, the rotation orthogonal matrix, translation matrix and scaling matrix corresponding to each vertex are determined; the rotation orthogonal matrix, translation matrix and scaling matrix are multiplied to obtain the model matrix corresponding to each vertex.
[0121] For example, the scaling matrix Among them, s1, s2, and s3 represent the scaling coefficients of the x, y, and z axes respectively, and the translation matrix Among them, Tx, Ty, and Tz are the translation amounts of the x, y, and z axes respectively, and the scaling matrix Where α, β, and γ are the Euler angles of roll, pitch, and yaw, respectively. Multiply the rotation orthogonal matrix, translation matrix, and scaling matrix to get the model matrix corresponding to each vertex.
[0122] In some embodiments, when the coordinate transformation matrix includes a view projection matrix, before performing column vector segmentation processing on the coordinate transformation matrix, the view space matrix and the projection matrix corresponding to each vertex are determined; the view space matrix and the projection matrix are multiplied to obtain the view projection matrix corresponding to each vertex.
[0123] For example, when the vertex coordinates are homogenized from the three-dimensional coordinate vector of the local coordinate system to obtain four-dimensional homogeneous coordinates, and then converted to homogeneous coordinates in the world space (i.e., world space coordinates), and then converted to four-dimensional coordinates in the projection space, it is necessary to obtain the view-projection matrix corresponding to each vertex. The view-projection matrix is obtained by multiplying the view space matrix and the projection matrix.
[0124] In some embodiments, when the coordinate transformation matrix includes a model matrix and a view projection matrix, the coordinate transformation matrix is subjected to column vector splitting processing to obtain multiple column vectors of the coordinate transformation matrix, including: performing column vector splitting processing on the model matrix to obtain multiple first column vectors of the model matrix; performing column vector splitting processing on the view projection matrix to obtain multiple second column vectors of the view projection matrix; performing vector multiplication and addition processing on the multiple column vectors and the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex, including: performing vector multiplication and addition processing on the multiple first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex; performing vector multiplication and addition processing on the multiple second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex.
[0125] For example, after splitting the model matrix and the view-projection matrix into column vectors, you first need to use the column vectors of the model matrix to convert the homogeneous coordinates from the three-dimensional coordinate vectors of the local coordinate system to the homogeneous coordinates in the world space (i.e., world space coordinates). Then, use the column vectors of the view-projection matrix to convert the world space coordinates to the four-dimensional coordinates in the projection space, i.e., the converted coordinates.
[0126] In some embodiments, when the vertex coordinates are position coordinate vectors, vector multiplication and addition are performed on multiple first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex, including: performing a first multiplication of the first first column vector of the multiple first column vectors with the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the first multiplication result to the fourth first column vector of the multiple first column vectors to obtain first coordinate transformation information; performing a second multiplication of the second first column vector of the multiple first column vectors with the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second multiplication result to the first coordinate transformation information to obtain second coordinate transformation information; performing a third multiplication of the third first column vector of the multiple first column vectors with the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the second coordinate transformation information to obtain the world space coordinates of each vertex.
[0127] For example, when the vertex coordinates are position coordinate vectors, that is, the homogeneous coordinates of the vertex are [x, y, z, 1], the process of converting the homogeneous coordinates from the three-dimensional coordinate vector of the local coordinate system to the homogeneous coordinates in the world space (that is, the world space coordinates) is as follows:
[0128] Instruction a1:
[0129] 1.r1.xyzw=Mt[0].xyzw*v.xxxx+Mt[3].xyzw;
[0130] 2.r1.xyzw=Mt[1].xyzw*v.yyyy+r1.xyzw;
[0131] 3.r1.xyzw=Mt[2].xyzw*v.zzzz+r1.xyzw;
[0132] 4.return r1.xyzw;
[0133] Among them, Mt[0].xyzw represents the first column vector c1 T , Mt[1].xyzw represents the second first column vector c2 T , Mt[2].xyzw represents the third first column vector c3 T , Mt[3].xyzw represents the fourth first column vector c4 T , v.xxxx means [x,x,x,x], v.yyyy means [y,y,y,y], v.zzzz means [z,z,z,z], and r1 represents a temporary variable in the calculation.
[0134] Therefore, the computational effort of the above instruction is 3 vector multiplications and additions, which takes 3 cycles.
[0135] In some embodiments, a first first column vector of a plurality of first column vectors is subjected to a first product process with a first-dimensional coordinate value of the homogeneous coordinate of each vertex, and the first product result is added to a fourth first column vector of the plurality of first column vectors to obtain first coordinate transformation information, including: a first product process is performed on the first three-dimensional values of the first first column vector of the plurality of first column vectors with the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and the first product result is added to the first three-dimensional values of the fourth first column vector of the plurality of first column vectors to obtain three-dimensional first coordinate transformation information; a second first column vector of the plurality of first column vectors is subjected to a second product process with a second-dimensional coordinate value of the homogeneous coordinate of each vertex, including: a first product process is performed on the first three-dimensional values of the first first column vector of the plurality of first column vectors with the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and the first product result is added to the first three-dimensional values of the fourth first column vector of the plurality of first column vectors to obtain three-dimensional first coordinate transformation information. Performing a second multiplication of the first three-dimensional values of the second first column vector of the first column vector with the second dimensional coordinate value of the homogeneous coordinate of each vertex; performing a third multiplication of the third first column vector of the multiple first column vectors with the third dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the second coordinate transformation information to obtain the world space coordinate of each vertex, including: performing a third multiplication of the first three-dimensional values of the third column vector of the multiple column vectors with the third dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the second coordinate transformation information to obtain three-dimensional third coordinate transformation information, and splicing the third coordinate transformation information with a constant to obtain the world space coordinate of each vertex.
[0136] For example, since the model matrix M itself is formed by multiplying the rotation orthogonal matrix R, the scaling matrix S and the translation matrix T, the conversion of the homogeneous coordinates from the three-dimensional coordinate vector of the local coordinate system to the homogeneous coordinates in the world space is simplified to
[0137] Therefore, based on the model matrix The above instruction a1 can complete the calculation in three dimensions. The above instruction a1 is optimized into instruction a2 as shown below:
[0138] Instruction a2:
[0139] 1.r1.xyz=Mt[0].xyz*v.xxx+Mt[3].xyz;
[0140] 2.r1.xyz=Mt[1].xyz*v.yyy+r1.xyz;
[0141] 3.r1.xyz=Mt[2].xyz*v.zzz+r1.xyz;
[0142] 4.return r1.xyz;
[0143] Therefore, the calculation result r1.xyz of the above instruction a2 is still a three-dimensional vector. Finally, based on r1.xyz, it is spliced with the constant 1 to obtain the world space coordinates of each vertex, where the constant 1 serves as the fourth dimension value of the world space coordinates.
[0144] In some embodiments, when the vertex coordinates are position coordinate vectors, vector multiplication and addition are performed on multiple second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex, including: performing a first multiplication of the first second column vector of the multiple second column vectors with the first-dimensional coordinate value of the world space coordinate of each vertex, and adding the first multiplication result to the fourth second column vector of the multiple second column vectors to obtain fourth coordinate transformation information; performing a second multiplication of the second second column vector of the multiple second column vectors with the second-dimensional coordinate value of the world space coordinate of each vertex, and adding the second multiplication result to the fourth coordinate transformation information to obtain fifth coordinate transformation information; performing a third multiplication of the third second column vector of the multiple second column vectors with the fifth-dimensional coordinate value of the world space coordinate of each vertex, and adding the third multiplication result to the second coordinate transformation information to obtain the transformed coordinates of each vertex.
[0145] For example, when the vertex coordinates are position coordinate vectors, that is, the homogeneous coordinates of the vertex are [x, y, z, 1], the process of converting the homogeneous coordinates from the homogeneous coordinates in the world space (that is, the world space coordinates) to the homogeneous coordinates in the projection space (that is, the conversion coordinates) is as follows:
[0146] Instruction b1:
[0147] 1.r2.xyzw=PVt[0].xyzw*r1.xxxx+PVt[3].xyzw;
[0148] 2.r2.xyzw=PVt[1].xyzw*r1.yyyy+r2.xyzw;
[0149] 3.r2.xyzw=PVt[2].xyzw*r1.zzzz+r2.xyzw;
[0150] 4.return r2.xyzw;
[0151] Among them, r1 represents the world space coordinate, PVt[].xyzw represents the transposed matrix of the projection matrix PV, PVt[0].xyzw represents the first second column vector, PVt[1].xyzw represents the second second column vector, PVt[2].xyzw represents the third second column vector, and PVt[3].xyzw represents the fourth second column vector.
[0152] Therefore, the computational effort of the above instruction is 3 vector multiplications and additions, which takes 3 cycles.
[0153] In some embodiments, when the vertex coordinates are direction coordinate vectors, vector multiplication and addition are performed on multiple first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex, including: performing a first multiplication of the first first column vector of the multiple first column vectors with the first dimensional coordinate value of the homogeneous coordinate of each vertex to obtain sixth coordinate transformation information; performing a second multiplication of the second first column vector of the multiple first column vectors with the second dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second multiplication result to the sixth coordinate transformation information to obtain seventh coordinate transformation information; performing a third multiplication of the third first column vector of the multiple first column vectors with the third dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the seventh coordinate transformation information to obtain the world space coordinates of each vertex.
[0154] For example, when the vertex coordinates are direction coordinate vectors (such as normals and tangents), that is, the homogeneous coordinates of the vertex are [x, y, z, 0], the fourth dimension value of the direction coordinate vector is 0 and the model matrix corresponding to the direction coordinate vector has no translation characteristics, that is, the fourth first column vector is [0, 0, 0, 1] T The process of converting homogeneous coordinates from the three-dimensional coordinate vector of the local coordinate system to homogeneous coordinates in the world space (i.e., world space coordinates) is as follows:
[0155] 1.r1.xyzw=Mt[0].xyzw*n.xxxx;
[0156] 2.r1.xyzw=Mt[1].xyzw*n.yyyy+r1.xyzw;
[0157] 3.r1.xyzw=Mt[2].xyzw*n.zzzz+r1.xyzw;
[0158] 4.return r1.xyzw;
[0159] Among them, Mt[0].xyzw represents the first column vector c1 T , Mt[1].xyzw represents the second first column vector c2 T , Mt[2].xyzw represents the third first column vector c3 T , Mt[3].xyzw represents the fourth first column vector c4 T , n.xxxx means [x,x,x,x], n.yyyy means [y,y,y,y], n.zzzz means [z,z,z,z], and r1 represents a temporary variable in the calculation.
[0160] Therefore, the computational effort of the above instruction is 3 vector multiplications and additions, which takes 3 cycles.
[0161] In some embodiments, a first first column vector of a plurality of first column vectors is multiplied for the first time with the first dimension coordinate value of the homogeneous coordinate of each vertex to obtain sixth coordinate transformation information, including: performing a first product processing on the first three-dimensional values of the first first column vector of the plurality of first column vectors and the first dimension coordinate value of the homogeneous coordinate of each vertex; performing a second product processing on the second first column vector of the plurality of first column vectors and the second dimension coordinate value of the homogeneous coordinate of each vertex, including: performing a second product processing on the first three-dimensional values of the second first column vector of the plurality of first column vectors and the second dimension coordinate value of the homogeneous coordinate of each vertex; performing a third product processing on the third first column vector of the plurality of first column vectors and the third dimension coordinate value of the homogeneous coordinate of each vertex, and adding the third product result to the seventh coordinate transformation information to obtain three-dimensional eighth coordinate transformation information, and splicing the eighth coordinate transformation information with a constant to obtain the world space coordinate of each vertex.
[0162] For example, since the model matrix M itself is formed by multiplying the rotation orthogonal matrix R, the scaling matrix S and the translation matrix T, the conversion of the homogeneous coordinates from the three-dimensional coordinate vector of the local coordinate system to the homogeneous coordinates in the world space is simplified to
[0163] Therefore, based on the model matrix The above instruction c1 can complete the calculation in three dimensions. The above instruction c1 is optimized into instruction c2 as shown below:
[0164] Instruction c2:
[0165] 1.r1.xyz=Mt[0].xyz*n.xxx;
[0166] 2.r1.xyz=Mt[1].xyz*n.yyy+r1.xyz;
[0167] 3.r1.xyz=Mt[2].xyz*n.zzz+r1.xyz;
[0168] 4.return r1.xyz;
[0169] Therefore, the calculation result r1.xyz of the above instruction c2 is still a three-dimensional vector. Finally, based on r1.xyz, it is spliced with the constant 0 to obtain the world space coordinates of each vertex, where the constant 0 serves as the fourth dimension value of the world space coordinates.
[0170] In step 104 , image rendering processing is performed on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain a rendered virtual object.
[0171] For example, after the coordinates of the vertices are transformed, subsequent image rendering operations are performed based on the transformed coordinates of the vertices to obtain a virtual object that is rendered and displayed corresponding to the transformed coordinates in the virtual scene.
[0172] See also Figure 5 , Figure 5 This is an optional flowchart of the image rendering method provided in the embodiment of the present application. Figure 5 Show Figure 3 Step 104 in the figure can be implemented through steps 1041 to 1043: in step 1041, the transformed coordinates of each vertex are rasterized to obtain the pixels corresponding to each vertex; in step 1042, the pixels corresponding to each vertex are shaded to obtain the color corresponding to each pixel; in step 1043, the colors corresponding to each pixel are mixed to obtain the rendered virtual object.
[0173] For example, the GPU rendering pipeline is the stage when a rendering call occurs. The GPU rendering pipeline takes vertex coordinates as input, then performs vertex shader calculations based on the vertex information. After obtaining the transformed coordinates, the vertex shader is passed to the rasterization stage for rasterization calculations to obtain the pixels corresponding to each vertex. Pixel shading calculations are then performed on the pixels corresponding to each vertex to obtain the color corresponding to each pixel. Finally, the colors corresponding to each pixel are tested and blended, and the results of the test and blending (i.e., the rendered virtual object) are output to the frame buffer for display.
[0174] The following describes an exemplary application of the embodiments of the present application in a practical application scenario.
[0175] The embodiments of the present application can be applied to rendering scenarios of various games, such as competitive games, racing games, dress-up games, etc.
[0176] The following uses a virtual scene as an example to illustrate:
[0177] In related technologies, coordinate transformations in 3D rendering scenes are a unified computational process, supported by the game engine itself. As the scene model becomes more detailed, meaning the number of vertices increases, the computational cost of the vertex shader in the entire rendering pipeline also increases.
[0178] In order to solve the above problems, an embodiment of the present application proposes a coordinate transformation instruction optimization method (i.e., an image rendering method) applied to the GPU rendering pipeline, which applies the GPU's multiplication and addition instructions to optimize matrix-vector multiplication, so that the GPU can complete the image rendering more efficiently.
[0179] The following is an example of how to implement the shader application:
[0180] The embodiment of the present application applies shader code in the rendering engine and creates corresponding materials, and applies the materials to the model rendering of the scene, so that the rendering results of the model can be seen during rendering.
[0181] First, create a new shader resource in the rendering engine.
[0182] like Figure 6 As shown, taking the unlit shader as an example, a new unlit shader resource 601 is created in the rendering engine.
[0183] Then, trigger the shader resource, open the shader editor, and modify the shader code as shown below.
[0184] The shader originally referenced the UnityObjectToClip method to implement two coordinate transformation instructions for vertices from local space to view projection space.
[0185] The modified shader originally manually implemented the two coordinate transformation instructions from local space to view projection space of the vertex by referencing the FastObjectToClip method. The FastObjectToClip method is as follows:
[0186]
[0187] Save the shader code changes and exit the editor to return to the rendering engine.
[0188] Then, create a new material asset in the rendering engine based on the modified shader.
[0189] like Figure 7 As shown, the material resource is created in the rendering engine 701 through a manual new creation operation.
[0190] Finally, apply the material resource to the model renderer of the scene.
[0191] like Figure 8 As shown, drag the material resource 801 to the game object 802 in the outline view, or the model 803 in the scene view, or the material 804 of the model renderer component of the game object.
[0192] After applying the shader code provided in the embodiment of the present application, compared with the rendering method of the related technology, the rendering performance can be improved while maintaining the accuracy of the scene rendering results unchanged, so that the number of vertices that the GPU can draw per unit time can be increased.
[0193] During the image rendering process, when the rendering is initialized, the vertex information is passed to the GPU through the graphics interface. When the rendering call occurs, the vertex information is calculated by the GPU rendering pipeline and finally output to the screen buffer for image presentation.
[0194] like Figure 9 As shown in the figure, the GPU rendering pipeline is the stage when a rendering call occurs. The GPU rendering pipeline takes vertex information as input, then performs vertex shader calculations based on the vertex information. After obtaining unified device coordinates, it is passed to the rasterization stage for rasterization calculations, followed by pixel shading calculations, and finally test and blending. The test and blending results are output to the frame buffer for display.
[0195] Among them, the detailed process of vertex shading calculation is as follows Figure 10 As shown in the figure, the GPU rendering pipeline takes vertex information as input, transforms the vertex coordinates into world space coordinates, then transforms the world space coordinates into the view projection coordinate system, and outputs the transformation results to the rasterizer for rasterization.
[0196] It should be noted that the vertex coordinates are homogenized from the three-dimensional vector of the local coordinate system to obtain four-dimensional homogenized coordinates, and then the model matrix is multiplied on the vector to obtain the homogeneous coordinates in the world space (i.e., world space coordinates), and then the view projection matrix is multiplied on the world space coordinates to obtain the four-dimensional coordinates in the projection space, and the four-dimensional coordinates in the projection space are output to the subsequent steps of the rendering pipeline for rendering operations.
[0197] In this process, there are two matrix-vector left multiplication operations. Let the model matrix be M, as shown in the following formula (1):
[0198]
[0199] The coordinate vector of the vertex is v = [v1, v2, v3, v4] T , then the model matrix M is multiplied by v on the left as shown in the following formula (2):
[0200]
[0201] The computing units in GPU hardware are mostly vector-based. Matrix-vector multiplication is actually equivalent to splitting it into multiple vectors for calculation. There are two ways to achieve this:
[0202] Method 1:
[0203]
[0204] Method 2:
[0205] M×v=[c1 T c2 T c3 T c4 T ]×v=c1 T ×v1+c2 T ×v2+c3 T ×v3+c4 T ×v4
[0206] According to the storage methods of the graphics interface matrix in the GPU, there are two types: row-major order and column-major order. The multiplication between the matrix and the vector includes pre-multiplication and post-multiplication. The storage method and multiplication method need to be matched according to the actual needs. In the Unity engine, the matrix multiplication by the vector is uniformly adopted. It is implemented by the above method 2, which is divided into the following instructions 1:
[0207] Instruction 1:
[0208] 1.r1.xyzw=Mt[0].xyzw*v.xxxx;
[0209] 2.r2.xyzw=Mt[1].xyzw*v.yyyy;
[0210] 3.r3.xyzw=Mt[2].xyzw*v.zzzz;
[0211] 4.r4.xyzw=Mt[3].xyzw*v.wwww;
[0212] 5.r5.xyzw=r1.xyzw+r2.xyzw;
[0213] 6.r6.xyzw=r3.xyzw+r4.xyzw;
[0214] 7.r7.xyzw=r5.xyzw+r6.xyzw;
[0215] 8.return r7.xyzw;
[0216] Among them, Mt[0].xyzw represents c1 T , Mt[1].xyzw represents c2 T , Mt[2].xyzw represents c3 T , Mt[3].xyzw represents c4 T , v.xxxx means [v1,v1,v1,v1], v.yyyy means [v2,v2,v2,v2], v.zzzz means [v3,v3,v3,v3], v.wwww means [v4,v4,v4,v4], and r1~r7 represent temporary variables in the calculation.
[0217] The computational effort of instruction 1 above is a total of 4 vector multiplications and 3 vector additions. In the GPU, the computation unit provides multiplication-addition instructions, allowing vector multiplication, vector addition, and mixed vector multiplication-addition operations to be completed in the same GPU cycle. Simplifying instruction 1 above into instruction 2 below:
[0218] Instruction 2:
[0219] 1.r1.xyzw=Mt[0].xyzw*v.xxxx;
[0220] 2.r1.xyzw=Mt[1].xyzw*v.yyyy+r1.xyzw;
[0221] 3.r1.xyzw=Mt[2].xyzw*v.zzzz+r1.xyzw;
[0222] 4.r1.xyzw=Mt[3].xyzw*v.wwww+r1.xyzw;
[0223] 5.return r1.xyzw;
[0224] The computational complexity of instruction 2 is one vector multiplication and three vector multiplication-additions, taking four cycles. During this calculation, the vertex coordinates are four-dimensional homogeneous coordinates. The first three dimensions, v1, v2, and v3, represent the x, y, and z coordinates of the vertex, respectively. The fourth dimension, v4, is always 1, meaning v.wwww is represented as [1,1,1,1]. Therefore, instruction 2 can be optimized to the following instruction 3:
[0225] Instruction 3:
[0226] 1.r1.xyzw=Mt[0].xyzw*v.xxxx+Mt[3].xyzw;
[0227] 2.r1.xyzw=Mt[1].xyzw*v.yyyy+r1.xyzw;
[0228] 3.r1.xyzw=Mt[2].xyzw*v.zzzz+r1.xyzw;
[0229] 4.return r1.xyzw;
[0230] The calculation result does not change at this time, but the calculation amount of the above instruction 3 is reduced to 3 vector multiplications and additions, which takes 3 cycles.
[0231] Since the model matrix M itself is formed by multiplying the rotation orthogonal matrix R, the scaling matrix S and the translation matrix T, the above formula (2) can be simplified to formula (3):
[0232]
[0233] Among them, the scaling matrix Among them, s1, s2, and s3 represent the scaling coefficients of the x, y, and z axes respectively, and the translation matrix Among them, Tx, Ty, and Tz are the translation amounts of the x, y, and z axes respectively, and the scaling matrix Where α, β, and γ are the Euler angles of roll, pitch, and yaw, respectively.
[0234] Therefore, based on the model matrix The above instruction 3 can complete the calculation in three dimensions, as shown in instruction 4:
[0235] Instruction 4:
[0236] 1.r1.xyz=Mt[0].xyz*v.xxx+Mt[3].xyz;
[0237] 2.r1.xyz=Mt[1].xyz*v.yyy+r1.xyz;
[0238] 3.r1.xyz=Mt[2].xyz*v.zzz+r1.xyz;
[0239] 4.return r1.xyz;
[0240] The result of the calculation of instruction 4 is still a three-dimensional vector. When calculating the view projection space coordinate transformation, you can continue to use the above method for optimization. Let the view projection matrix be PV. Then the instructions for all coordinate transformations are shown in instruction 5:
[0241] Directive 5:
[0242] 1.r1.xyz=Mt[0].xyz*v.xxx+Mt[3].xyz;
[0243] 2.r1.xyz=Mt[1].xyz*v.yyy+r1.xyz;
[0244] 3.r1.xyz=Mt[2].xyz*v.zzz+r1.xyz;
[0245] 4.r2.xyzw=PVt[0].xyzw*r1.xxxx+PVt[3].xyzw;
[0246] 5.r2.xyzw=PVt[1].xyzw*r1.yyyy+r2.xyzw;
[0247] 6.r2.xyzw=PVt[2].xyzw*r1.zzzz+r2.xyzw;
[0248] 7.return r2.xyzw;
[0249] Among them, PVt[].xyzw represents the transposed matrix of the projection matrix PV.
[0250] For directional vectors such as normals and tangents, the embodiment of the present application can also utilize the characteristic of v4=0 for optimization. For example, the instruction for converting the normal n from the local space to the world space is shown in instruction 6:
[0251] Directive 6:
[0252] 1.r1.xyz=Mt[0].xyz*n.xxx;
[0253] 2.r1.xyz=Mt[1].xyz*n.yyy+r1.xyz;
[0254] 3.r1.xyz=Mt[2].xyz*n.zzz+r1.xyz;
[0255] 4.return r1.xyz;
[0256] Therefore, in the vertex shader, the workload is concentrated on the coordinate transformation of these coordinate vectors and direction vectors. Using the embodiment of the present application can reduce the amount of calculation that originally required 8 cycles to 6 cycles without introducing additional errors. The optimized efficiency reaches 25%, and it is compatible with different platforms and different calculation precisions.
[0257] In summary, the embodiment of the present application proposes a coordinate transformation instruction optimization method applied to the GPU rendering pipeline, which uses multiplication-add instructions to optimize the matrix multiplication vector process in the vertex shader stage, thereby improving the efficiency of vertex coordinate transformation while keeping the output results and accuracy unchanged. It is widely used in three-dimensional scene rendering scenarios to improve the overall rendering performance.
[0258] The embodiment of the present application optimizes the computational efficiency of the vertex coordinate transformation process without changing the vertex calculation accuracy. Compared with the GPU rendering pipeline process of the related technology, the number of instructions for vertex coordinate transformation is reduced from 8 to 6, which can bring a 25% improvement in vertex processing performance. It is compatible with most graphics production processes and can be applied to different graphics rendering products in the industry.
[0259] The embodiment of the present application optimizes a problem that the industry cannot optimize: achieving efficient coordinate transformation in the vertex shader, thereby optimizing the efficiency of the entire GPU rendering pipeline. The embodiment of the present application tests the created Shader and compares the vertex shader with the optimized vertex shader. In the Mali-G72 GPU, the number of cycles of the mathematical calculation unit is reduced from 2.33 to 1.75, and the efficiency is improved by 25%; in the Mali-G76 GPU, the number of cycles of the mathematical calculation unit is reduced from 1.17 to 0.88, and the efficiency is improved by 25%; in the Mali-G78 GPU, the number of cycles of the multiplication and addition unit is reduced from 0.50 to 0.33, and the efficiency is improved by 33%. This enables the GPU rendering pipeline to complete tasks faster when performing large-scale vertex shading calculations.
[0260] So far, the image rendering method provided by the embodiment of the present application has been described in combination with the exemplary application and implementation of the terminal or server provided by the embodiment of the present application. The following will continue to describe the cooperation of various modules in the image rendering device 465 provided by the embodiment of the present application to implement the image rendering solution.
[0261] The acquisition module 4651 is used to obtain multiple vertices of the virtual object to be rendered, wherein each vertex corresponds to a vertex coordinate; the homogenization module 4652 is used to homogenize the vertex coordinates of each vertex to obtain the homogeneous coordinates of each vertex; the conversion module 4653 is used to perform vector multiplication and addition processing on the homogeneous coordinates of each vertex based on the coordinate conversion matrix to obtain the converted coordinates of each vertex; the rendering module 4654 is used to perform image rendering processing on the virtual object to be rendered based on the converted coordinates of each vertex to obtain the rendered virtual object.
[0262] In some embodiments, the vertex coordinates of each vertex are a three-dimensional coordinate vector, and the homogeneous coordinates are a four-dimensional coordinate vector; the homogenization module 4652 is also used to concatenate the three-dimensional coordinate vector of each vertex with a constant to obtain the four-dimensional coordinate vector of each vertex; wherein the constant is the fourth-dimensional value of the four-dimensional coordinate vector.
[0263] In some embodiments, the conversion module 4653 is also used to perform column vector segmentation processing on the coordinate conversion matrix to obtain multiple column vectors of the coordinate conversion matrix; and perform vector multiplication and addition processing on the multiple column vectors and the homogeneous coordinates of each vertex to obtain the conversion coordinates of each vertex.
[0264] In some embodiments, when the coordinate transformation matrix is a model matrix, before the coordinate transformation matrix is subjected to column vector segmentation processing, the transformation module 4653 is also used to determine the rotation orthogonal matrix, translation matrix and scaling matrix corresponding to each vertex; and multiply the rotation orthogonal matrix, the translation matrix and the scaling matrix to obtain the model matrix corresponding to each vertex.
[0265] In some embodiments, when the coordinate transformation matrix includes a view projection matrix, before performing column vector segmentation processing on the coordinate transformation matrix, the transformation module 4653 is also used to determine the view space matrix and projection matrix corresponding to each vertex; multiply the view space matrix and the projection matrix to obtain the view projection matrix corresponding to each vertex.
[0266] In some embodiments, when the coordinate transformation matrix includes a model matrix and a view projection matrix, the transformation module 4653 is further used to perform column vector splitting processing on the model matrix to obtain multiple first column vectors of the model matrix; perform column vector splitting processing on the view projection matrix to obtain multiple second column vectors of the view projection matrix; perform vector multiplication and addition processing on the multiple first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex; perform vector multiplication and addition processing on the multiple second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex.
[0267] In some embodiments, when the vertex coordinates are position coordinate vectors, the conversion module 4653 is further used to perform a first multiplication process on the first first column vector of the multiple first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the first multiplication result to the fourth first column vector of the multiple first column vectors to obtain first coordinate transformation information; perform a second multiplication process on the second first column vector of the multiple first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the second multiplication result to the first coordinate transformation information to obtain second coordinate transformation information; perform a third multiplication process on the third first column vector of the multiple first column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the world space coordinates of each vertex.
[0268] In some embodiments, the conversion module 4653 is also used to perform a first multiplication of the first three-dimensional values of the first first column vector of the multiple first column vectors with the first dimensional coordinate value of the homogeneous coordinate of each vertex, and add the first multiplication result to the first three-dimensional values of the fourth first column vector of the multiple first column vectors to obtain the three-dimensional first coordinate transformation information; perform a second multiplication of the first three-dimensional values of the second first column vector of the multiple first column vectors with the second dimensional coordinate value of the homogeneous coordinate of each vertex; perform a third multiplication of the first three-dimensional values of the third column vector of the multiple column vectors with the third dimensional coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain three-dimensional third coordinate transformation information, and concatenate the third coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
[0269] In some embodiments, when the vertex coordinates are position coordinate vectors, the conversion module 4653 is further used to perform a first multiplication process on the first second column vector of the multiple second column vectors and the first-dimensional coordinate value of the world space coordinate of each vertex, and add the first multiplication result to the fourth second column vector of the multiple second column vectors to obtain fourth coordinate transformation information; perform a second multiplication process on the second second column vector of the multiple second column vectors and the second-dimensional coordinate value of the world space coordinate of each vertex, and add the second multiplication result to the fourth coordinate transformation information to obtain fifth coordinate transformation information; perform a third multiplication process on the third second column vector of the multiple second column vectors and the fifth-dimensional coordinate value of the world space coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the transformed coordinates of each vertex.
[0270] In some embodiments, when the vertex coordinates are direction coordinate vectors, the conversion module 4653 is further used to perform a first multiplication process on the first first column vector of the multiple first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex to obtain sixth coordinate transformation information; perform a second multiplication process on the second first column vector of the multiple first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the second multiplication result to the sixth coordinate transformation information to obtain seventh coordinate transformation information; perform a third multiplication process on the third first column vector of the multiple first column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the seventh coordinate transformation information to obtain the world space coordinates of each vertex.
[0271] In some embodiments, the conversion module 4653 is also used to perform a first multiplication of the first three-dimensional values of the first first column vector of the multiple first column vectors with the first-dimensional coordinate value of the homogeneous coordinate of each vertex; perform a second multiplication of the first three-dimensional values of the second first column vector of the multiple first column vectors with the second-dimensional coordinate value of the homogeneous coordinate of each vertex; perform a third multiplication of the first three-dimensional values of the third first column vector of the multiple first column vectors with the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the seventh coordinate transformation information to obtain three-dimensional eighth coordinate transformation information, and splice the eighth coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
[0272] In some embodiments, the rendering module 4654 is also used to perform rasterization processing on the transformed coordinates of each vertex to obtain the pixels corresponding to each vertex; perform shading processing on the pixels corresponding to each vertex to obtain the color corresponding to each pixel; and perform blending processing on the colors corresponding to each pixel to obtain the rendered virtual object.
[0273] The present invention provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the image rendering method described above in the present invention.
[0274] The embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the image rendering method provided by the embodiment of the present application, for example, Figure 3-Figure 5 The image rendering method is shown.
[0275] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or various devices including one or any combination of the above memories.
[0276] In some embodiments, executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0277] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0278] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0279] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.
Claims
1. An image rendering method, characterized in that: The method comprises: Obtain multiple vertices of the virtual object to be rendered, where each vertex corresponds to a vertex coordinate; Performing homogenization processing on the vertex coordinates of each vertex to obtain homogeneous coordinates of each vertex; Performing a column vector splitting process on a coordinate transformation matrix to obtain a plurality of column vectors of the coordinate transformation matrix, wherein when the coordinate transformation matrix includes a model matrix and a view projection matrix, performing a column vector splitting process on the coordinate transformation matrix to obtain a plurality of column vectors of the coordinate transformation matrix includes: performing a column vector splitting process on the model matrix to obtain a plurality of first column vectors of the model matrix; performing a column vector splitting process on the view projection matrix to obtain a plurality of second column vectors of the view projection matrix; Performing vector multiplication and addition processing on the multiple column vectors and the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex; Image rendering processing is performed on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain a rendered virtual object.
2. The method according to claim 1, characterized in that The vertex coordinates of each vertex are a three-dimensional coordinate vector, and the homogeneous coordinates are a four-dimensional coordinate vector; The homogenizing the vertex coordinates of each vertex to obtain the homogenous coordinates of each vertex includes: Concatenate the three-dimensional coordinate vector of each vertex with a constant to obtain a four-dimensional coordinate vector of each vertex; The constant is the fourth-dimensional value of the four-dimensional coordinate vector.
3. The method according to claim 1, characterized in that When the coordinate conversion matrix is a model matrix, before performing column vector segmentation processing on the coordinate conversion matrix, the method further includes: Determine the rotation orthogonal matrix, translation matrix and scaling matrix corresponding to each vertex; The rotation orthogonal matrix, the translation matrix, and the scaling matrix are multiplied to obtain a model matrix corresponding to each vertex.
4. The method according to claim 1, wherein When the coordinate conversion matrix includes a view projection matrix, before performing column vector segmentation processing on the coordinate conversion matrix, the method further includes: Determine the view space matrix and projection matrix corresponding to each vertex; The view space matrix and the projection matrix are multiplied to obtain the view projection matrix corresponding to each vertex.
5. The method according to claim 1, characterized in that When the coordinate transformation matrix includes a model matrix and a view projection matrix, performing vector multiplication and addition processing on the plurality of column vectors and the homogeneous coordinates of each vertex to obtain the transformed coordinates of each vertex includes: Performing vector multiplication and addition processing on the plurality of first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex; Vector multiplication and addition processing is performed on the multiple second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex.
6. The method according to claim 5, characterized in that When the vertex coordinates are position coordinate vectors, performing vector multiplication and addition processing on the plurality of first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex includes: Performing a first product process on a first first column vector of the plurality of first column vectors and a first-dimensional coordinate value of the homogeneous coordinates of each vertex, and adding the first product result to a fourth first column vector of the plurality of first column vectors to obtain first coordinate transformation information; Performing a second product process on a second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second product result to the first coordinate transformation information to obtain second coordinate transformation information; Perform a third multiplication process on the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the world space coordinates of each vertex.
7. The method according to claim 6, characterized in that The step of performing a first product process on a first first column vector of the plurality of first column vectors and a first-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the first product result to a fourth first column vector of the plurality of first column vectors to obtain first coordinate transformation information includes: performing a first product processing on the first three-dimensional values of a first first column vector of the plurality of first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the first product result to the first three-dimensional values of the fourth first column vector of the plurality of first column vectors to obtain the first three-dimensional coordinate transformation information; The performing a second product process on the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex includes: Performing a second product process on the first three-dimensional values of the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex; The step of performing a third multiplication process on the third first column vector of the plurality of first column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the second coordinate transformation information to obtain the world space coordinates of each vertex includes: Perform a third multiplication process on the first three-dimensional values of the third column vector of the multiple column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, add the third product result to the second coordinate transformation information to obtain three-dimensional third coordinate transformation information, and splice the third coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
8. The method according to claim 5, characterized in that When the vertex coordinates are position coordinate vectors, performing vector multiplication and addition processing on the plurality of second column vectors and the world space coordinates of each vertex to obtain the transformed coordinates of each vertex includes: Performing a first product process on a first second column vector of the plurality of second column vectors and a first-dimensional coordinate value of the world space coordinate of each vertex, and adding the first product result to a fourth second column vector of the plurality of second column vectors to obtain fourth coordinate transformation information; Performing a second product process on the second second column vector of the plurality of second column vectors and the second-dimensional coordinate value of the world space coordinate of each vertex, and adding the second product result to the fourth coordinate transformation information to obtain fifth coordinate transformation information; A third product process is performed on the third second column vector of the multiple second column vectors and the fifth-dimensional coordinate value of the world space coordinate of each vertex, and the third product result is added to the second coordinate transformation information to obtain the transformed coordinates of each vertex.
9. The method according to claim 5, characterized in that When the vertex coordinates are direction coordinate vectors, performing vector multiplication and addition processing on the plurality of first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex includes: Performing a first product process on a first first column vector of the plurality of first column vectors and a first-dimensional coordinate value of the homogeneous coordinate of each vertex to obtain sixth coordinate transformation information; Performing a second product process on a second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and adding the second product result to the sixth coordinate transformation information to obtain seventh coordinate transformation information; Perform a third multiplication process on the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the seventh coordinate transformation information to obtain the world space coordinates of each vertex.
10. The method according to claim 9, characterized in that The step of performing a first multiplication process on a first first column vector of the plurality of first column vectors and a first-dimensional coordinate value of the homogeneous coordinate of each vertex to obtain sixth coordinate transformation information includes: Performing a first product process on the first three-dimensional values of the first first column vector of the plurality of first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex; The performing a second product process on the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex includes: Performing a second product process on the first three-dimensional values of the second first column vector of the plurality of first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex; The step of performing a third multiplication process on the third first column vector of the plurality of first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, and adding the third multiplication result to the seventh coordinate transformation information to obtain the world space coordinates of each vertex includes: Perform a third multiplication process on the first three-dimensional values of the third first column vector of the multiple first column vectors and the third coordinate value of the homogeneous coordinate of each vertex, add the third product result to the seventh coordinate transformation information to obtain three-dimensional eighth coordinate transformation information, and splice the eighth coordinate transformation information with a constant to obtain the world space coordinates of each vertex.
11. The method according to claim 1, wherein The performing image rendering processing on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain the rendered virtual object includes: Performing rasterization processing on the transformed coordinates of each vertex to obtain pixels corresponding to each vertex; Performing coloring on the pixels corresponding to each vertex to obtain the color corresponding to each pixel; The colors corresponding to each pixel are mixed to obtain the rendered virtual object.
12. An image rendering device, characterized in that: The device comprises: An acquisition module, configured to acquire a plurality of vertices of a virtual object to be rendered, wherein each vertex corresponds to a vertex coordinate; A homogenization module, configured to perform homogenization processing on the vertex coordinates of each vertex to obtain homogeneous coordinates of each vertex; A conversion module is configured to perform column vector segmentation processing on a coordinate conversion matrix to obtain a plurality of column vectors of the coordinate conversion matrix, wherein when the coordinate conversion matrix includes a model matrix and a view projection matrix, the column vector segmentation processing on the coordinate conversion matrix to obtain a plurality of column vectors of the coordinate conversion matrix comprises: performing column vector segmentation processing on the model matrix to obtain a plurality of first column vectors of the model matrix; performing column vector segmentation processing on the view projection matrix to obtain a plurality of second column vectors of the view projection matrix; and performing vector multiplication and addition processing on the plurality of column vectors and the homogeneous coordinates of each vertex to obtain the conversion coordinates of each vertex; A rendering module is used to perform image rendering processing on the virtual object to be rendered based on the transformed coordinates of each vertex to obtain a rendered virtual object.
13. The device according to claim 12, characterized in that When the coordinate transformation matrix includes a model matrix and a view projection matrix, the apparatus further includes: The conversion module is further used to perform vector multiplication and addition processing on the multiple first column vectors and the homogeneous coordinates of each vertex to obtain the world space coordinates of each vertex; and to perform vector multiplication and addition processing on the multiple second column vectors and the world space coordinates of each vertex to obtain the converted coordinates of each vertex.
14. The device according to claim 12, characterized in that When the vertex coordinates are position coordinate vectors, the device further includes: The conversion module is further used to perform a first multiplication process on the first first column vector of the multiple first column vectors and the first-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the first multiplication result to the fourth first column vector of the multiple first column vectors to obtain first coordinate transformation information; perform a second multiplication process on the second first column vector of the multiple first column vectors and the second-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the second multiplication result to the first coordinate transformation information to obtain second coordinate transformation information; perform a third multiplication process on the third first column vector of the multiple first column vectors and the third-dimensional coordinate value of the homogeneous coordinate of each vertex, and add the third multiplication result to the second coordinate transformation information to obtain the world space coordinate of each vertex.
15. An electronic device, characterized in that: The electronic device comprises: a memory for storing executable instructions; A processor, configured to implement the image rendering method according to any one of claims 1 to 11 when executing the executable instructions stored in the memory.
16. A computer-readable storage medium, characterized in that Executable instructions are stored, and are used to implement the image rendering method according to any one of claims 1 to 11 when executed by a processor.
17. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the image rendering method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
System, method, and computer program product for rendering at variable sampling rates using projective geometric distortion
CN107392988A
Method and apparatus for implementing volumetric light
CN109544674A