WO2023202254A1 - 图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 - Google Patents
图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 Download PDFInfo
- Publication number
- WO2023202254A1 WO2023202254A1 PCT/CN2023/080513 CN2023080513W WO2023202254A1 WO 2023202254 A1 WO2023202254 A1 WO 2023202254A1 CN 2023080513 W CN2023080513 W CN 2023080513W WO 2023202254 A1 WO2023202254 A1 WO 2023202254A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- shadow
- vertex
- coordinates
- depth
- rendering
- Prior art date
Links
- 238000009877 rendering Methods 0.000 title claims abstract description 161
- 238000000034 method Methods 0.000 title claims abstract description 80
- 238000004590 computer program Methods 0.000 title claims abstract description 30
- 238000003860 storage Methods 0.000 title claims abstract description 19
- 238000005266 casting Methods 0.000 claims abstract description 149
- 238000006243 chemical reaction Methods 0.000 claims abstract description 27
- 238000012545 processing Methods 0.000 claims description 59
- 239000011159 matrix material Substances 0.000 claims description 46
- 239000013598 vector Substances 0.000 claims description 46
- 230000015654 memory Effects 0.000 claims description 25
- 230000008569 process Effects 0.000 claims description 25
- 230000009466 transformation Effects 0.000 claims description 24
- 238000004040 coloring Methods 0.000 claims description 8
- 238000009966 trimming Methods 0.000 abstract 1
- 239000012634 fragment Substances 0.000 description 57
- 238000004364 calculation method Methods 0.000 description 26
- 238000005516 engineering process Methods 0.000 description 24
- 230000006870 function Effects 0.000 description 15
- 230000000007 visual effect Effects 0.000 description 13
- 238000010586 diagram Methods 0.000 description 9
- 230000003993 interaction Effects 0.000 description 8
- 238000012360 testing method Methods 0.000 description 8
- 230000008447 perception Effects 0.000 description 7
- 238000013473 artificial intelligence Methods 0.000 description 6
- 238000004891 communication Methods 0.000 description 5
- 230000000694 effects Effects 0.000 description 5
- 239000008186 active pharmaceutical agent Substances 0.000 description 4
- 238000013519 translation Methods 0.000 description 4
- 230000016776 visual perception Effects 0.000 description 4
- 230000003190 augmentative effect Effects 0.000 description 3
- 238000013515 script Methods 0.000 description 3
- 238000005520 cutting process Methods 0.000 description 2
- 230000007123 defense Effects 0.000 description 2
- 239000011521 glass Substances 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000004088 simulation Methods 0.000 description 2
- 238000012549 training Methods 0.000 description 2
- 241001465754 Metazoa Species 0.000 description 1
- 241000699670 Mus sp. Species 0.000 description 1
- 230000009471 action Effects 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000009193 crawling Effects 0.000 description 1
- 230000001419 dependent effect Effects 0.000 description 1
- 238000006073 displacement reaction Methods 0.000 description 1
- 230000007613 environmental effect Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000010354 integration Effects 0.000 description 1
- 230000009191 jumping Effects 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 239000002184 metal Substances 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 230000014860 sensory perception of taste Effects 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000004083 survival effect Effects 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
- 230000001131 transforming effect Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/10—Geometric effects
- G06T15/20—Perspective computation
- G06T15/205—Image-based rendering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/10—Geometric effects
- G06T15/20—Perspective computation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/50—Lighting effects
- G06T15/60—Shadow generation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T19/00—Manipulating 3D models or images for computer graphics
- G06T19/20—Editing of 3D images, e.g. changing shapes or colours, aligning objects or positioning parts
Definitions
- the present application relates to computer graphics and image technology, and in particular, to an image rendering method, device, electronic equipment, computer-readable storage medium and computer program product.
- Display technology based on graphics processing hardware expands the channels for perceiving the environment and obtaining information, especially the display technology of virtual scenes, which can realize diversified interactions between virtual objects controlled by users or artificial intelligence according to actual application requirements. It has various typical application scenarios, such as in virtual scenes such as games, and can simulate the real battle process between virtual objects.
- the fragment discard function when performing shadow rendering, is used to clip at fragment granularity during the stage of calling shaders for shading, making the fragment output of the rendering pipeline unpredictable. This solution will waste a lot of storage space and computing resources. , thus affecting the user experience.
- Embodiments of the present application provide an image rendering method, device, electronic device, computer-readable storage medium, and computer program product, which can save related storage space and computing resources.
- the embodiment of the present application provides an image rendering method, including:
- An embodiment of the present application provides an image rendering device, including:
- An acquisition module configured to acquire multiple vertices of the shadow casting object in the virtual scene, where each vertex corresponds to a vertex coordinate
- a conversion module configured to perform coordinate conversion processing on the vertex coordinates of each of the vertices to obtain the conversion coordinates of each of the vertices;
- An offset module configured to perform depth offset processing on the conversion coordinates of each vertex to obtain the depth offset coordinates of each vertex
- a cropping module configured to crop the shadow casting object based on the depth offset coordinates of each vertex to obtain the cropped shadow casting object
- a rendering module configured to perform shadow rendering processing on the cropped shadow casting object to obtain the cast shadow of the shadow casting object.
- An embodiment of the present application provides an electronic device for image rendering.
- the electronic device includes:
- Memory used to store computer programs or executable instructions
- the processor is configured to implement the image rendering method provided by the embodiment of the present application when executing the computer program or executable instructions stored in the memory.
- Embodiments of the present application provide a computer-readable storage medium that stores computer programs or executable instructions for causing a processor to implement the image rendering method provided by embodiments of the present application when executed.
- Embodiments of the present application provide a computer program product, which includes a computer program or executable instructions.
- the computer program or executable instructions are executed by a processor, the image rendering method provided by the embodiment of the present application is implemented.
- the embodiment of the present application avoids the uncertainty of discarding and accurately discards the parts that need to be discarded, thus saving the storage space and computing resources occupied by the parts that need to be discarded. , thereby improving shadow rendering efficiency.
- FIGS. 1A-1B are schematic diagrams of application modes of the image rendering method provided by embodiments of the present application.
- Figure 2 is a schematic structural diagram of an electronic device for image rendering provided by an embodiment of the present application
- Figures 3-5 are schematic flow charts of the image rendering method provided by embodiments of the present application.
- FIGS 6-7 are schematic diagrams of shadow-casting scenes provided by embodiments of the present application.
- Figure 8 is a flow chart of a rendering pipeline provided by related technologies
- FIG. 9 is a schematic diagram of a shadow-casting scene provided by an embodiment of the present application.
- first ⁇ second involved are only used to distinguish similar objects and do not represent a specific ordering of objects. It is understandable that “first ⁇ second” can be used where permitted. The specific order or sequence is interchanged so that the embodiments of the application described herein can be practiced in other than that illustrated or described herein.
- Client Application programs running in the terminal to provide various services, such as video playback clients, game clients, etc.
- Virtual scene The virtual game scene displayed (or provided) when the game program is running on the terminal.
- the virtual scene can be a simulation environment of the real world, a semi-simulation and semi-fictitious virtual environment, or a purely fictitious virtual environment.
- the virtual scene may be any one of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, or a three-dimensional virtual scene.
- the embodiments of this application do not limit the dimensions of the virtual scene.
- the virtual scene can include the sky, land, ocean, etc.
- the land can include environmental elements such as deserts and cities, and the user can control virtual objects to move in the virtual scene.
- Virtual objects images of various people and objects that can interact in the virtual scene, or movable objects in the virtual scene.
- the movable object may be a virtual character, a virtual animal, an animation character, etc., such as a character, animal, etc. displayed in a virtual scene.
- the virtual object may be a virtual avatar representing the user in the virtual scene.
- the virtual scene may include multiple virtual objects. Each virtual object has its own shape and volume in the virtual scene and occupies a part of the space in the virtual scene.
- the shadow casting object is the virtual object that generates shadow casting
- the shadow receiving object is the virtual object that receives shadow casting.
- the virtual character is the shadow casting object
- the ground is the shadow receiving object.
- Scene data represents the characteristic data of the virtual scene, for example, it can be the area of the construction area in the virtual scene, the architectural style of the virtual scene currently located, etc.; it can also include the location of the virtual building in the virtual scene, and the virtual building of floor space, etc.
- GPU Graphics Processing Unit
- Rendering pipeline The graphics rendering process running in the GPU, including vertex shaders, rasterization, pixel shaders, etc. By writing code in the shader, you can flexibly control the GPU to draw and render the rendering components.
- Vertex shader A required link in the GPU rendering pipeline. The vertex shader program will calculate the vertices of the model one by one according to the code and output the results to the next stage.
- Coordinate transformation The process of transforming coordinates in one spatial coordinate system to another spatial coordinate system.
- the transformation relationship between coordinate systems is represented by a matrix.
- the matrix is left multiplied by the coordinate vector, and the obtained value is the transformed coordinate.
- Fragment shader A required link in the GPU rendering pipeline.
- the fragment shader program will perform shading calculations on the rasterized pixels based on the code. After passing the test, it will be output to the frame buffer to complete a rendering pipeline process.
- View frustum culling A function of the rasterization stage in the GPU rendering pipeline, used to eliminate fragments outside the view frustum.
- Frustum refers to the visible cone range in the direction of the camera in the virtual scene, including 6 surfaces: upper, lower, left, right, near, and far. Objects within the view frustum are visible, and vice versa are invisible. , to improve rendering performance, only objects that intersect with the view frustum are drawn.
- Standard equipment space coordinate system A three-dimensional coordinate system that has nothing to do with electronic equipment. For example, even if electronic equipment uses different resolutions, the coordinates of the same object in the standard equipment space coordinate system are the same. Perform perspective division on the four-dimensional clipping coordinate system to obtain the standard device space coordinate system. For example, the four-dimensional coordinates in the clipping coordinate system are divided by the fourth-dimensional homogeneous coordinate component, which is the standard device space coordinate system obtained.
- Fragment discarding In the fragment shader, the instruction to discard fragments based on conditions can prevent the fragments discarded by the fragment shader from being output to the screen. For example, during the rendering process of models with transparent edges, the fragment discarding function will be used.
- Graphics application programming interface (API, Application Programming Interface): When the central processing unit (CPU, Central Processing Unit) communicates with the GPU, it follows the standard graphics API.
- the graphics API includes OpenGL, OpenGL ES, Direct X, Metal , Vulkan, etc., when developing graphics, press Just call the GPU according to the method defined by the interface.
- Local coordinate system A coordinate system with the object's own position as the origin.
- the local coordinate system is used to represent the relative position and direction between objects, and will rotate according to the rotation of the object itself.
- shadow rendering includes several rendering methods such as shadow mapping, shadow offline baking and cast shadow.
- shadow maps are widely used and can cover most complex scene rendering needs.
- the 32-bit buffer required for shadow rendering will put pressure on transmission bandwidth.
- the shadow casting technology can be used to replace the shadow map technology and can achieve the same dynamic shadow rendering in an 8-bit buffer. The purpose is to improve rendering performance. For example, in a chessboard scene, the chess pieces act as shadow casters but not as shadow receivers (i.e., shadow receiving objects).
- the chessboard acts as a shadow receiver but not as a shadow caster, which meets the requirements for the use of cast shadows.
- the cast shadow technology does not have the depth comparison function, when the shadow caster's part is hidden under the shadow receiver, the shadow caster needs to be cropped according to the geometric model of the shadow receiver.
- embodiments of the present application provide an image rendering method, device, electronic device, computer-readable storage medium and computer program product, which can avoid using the fragment discarding function to save related storage space and computing resources.
- an exemplary implementation scenario of the image rendering method provided by the embodiment of the present application is first described.
- the virtual object in the image rendering method provided by the embodiment of the present application can be completely based on terminal output. , or based on terminal and server collaborative output.
- the virtual scene may be an environment for game characters to interact.
- it may be for game characters to compete in the virtual scene.
- two parties can interact in the virtual scene, thereby enabling the user to Relieve the stress of life during the game.
- Figure 1A is a schematic diagram of the application mode of the image rendering method provided by the embodiment of the present application. It is suitable for some related data that completely relies on the graphics processing hardware computing power of the terminal 400 to complete the virtual scene 100.
- Computing application modes such as stand-alone or offline mode games, complete the output of virtual scenes through various different types of terminals 400 such as smartphones, tablets, and virtual reality or augmented reality devices.
- graphics processing hardware examples include central processing units (CPU, Central Processing Unit) and graphics processing units (GPU, Graphics Processing Unit).
- CPU central processing units
- GPU Graphics Processing Unit
- the terminal 400 calculates the data required for display through the graphics computing hardware, completes the loading, parsing and rendering of the display data, and outputs video frames capable of forming the visual perception of the virtual scene through the graphics output hardware.
- video frames capable of forming the visual perception of the virtual scene through the graphics output hardware.
- two-dimensional video frames are presented on the display screen of a smartphone, or video frames that achieve a three-dimensional display effect are projected on the lenses of augmented reality or virtual reality glasses; 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.
- a client 410 (for example, a stand-alone version of a game application) is run on the terminal 400.
- a virtual scene including role-playing is output.
- the virtual scene may be an environment for game characters to interact, for example. It is a plain, street, valley, etc.
- the projected object 110 may be a game character controlled by the user (or player), and will operate in the virtual scene in response to the real user's operation of buttons (including rocker buttons, attack buttons, defense buttons, etc.), for example, when the real user When the joystick button is moved to the left, the shadow-casting object 110 with cast shadow will move to the left in the virtual scene, and can also stay still, jump, and use various functions (such as skills and props);
- the shadow-casting object 110 that casts shadows can also be an artificial intelligence (AI, Artificial Intelligence) set in the virtual scene battle through training; the shadow-casting object 110 with cast shadows can also be a non-user character set in the virtual scene interaction. (NPC, Non-Player Character); the shadow-casting object 110 with cast shadow can also be an inactive object or a
- the shadow casting object 120 to be projected is displayed in the virtual scene 100, and multiple shadow casting objects 120 to be projected are obtained through the image rendering method of the embodiment of the present application.
- Vertices perform coordinate conversion processing on the vertex coordinates of each vertex to obtain the conversion coordinates of each vertex, perform depth offset processing on the conversion coordinates of each vertex, and obtain the depth offset coordinates of each vertex, based on the
- the depth offset coordinates are clipped on the shadow casting object 120 to be cast to obtain a clipped shadow casting object, and shadow rendering processing is performed on the clipped shadow casting object to obtain a cast shadow 130 of the shadow casting object to form a cast shadow.
- the shadow casting object 110 with the cast shadow is used to perform human-computer interaction in the virtual scene, such as game confrontation based on the shadow casting object 110 with the cast shadow.
- Figure 1B is a schematic diagram of the application mode of the image rendering method provided by the embodiment of the present application. It is applied to the terminal 400 and the server 200 and is suitable for completing virtual scene calculations relying on the computing power of the server 200. And the application mode of the virtual scene is output on the terminal 400.
- 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 and analysis of the calculated display data. and rendering, which relies on graphics output hardware to output virtual scenes to form visual perceptions.
- two-dimensional video frames can be presented on the display screen of a smartphone, or a video that achieves a three-dimensional display effect can be projected on the lenses of augmented reality or virtual reality glasses.
- Frame for the perception of the form of the virtual scene, it can be understood that 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.
- the terminal 400 runs a client 410 (for example, a network version of a game application), and interacts with other users by connecting to the server 200 (for example, a game server).
- the terminal 400 outputs the virtual scene 100 of the client 410 in the first person perspective.
- a shadow-casting object 110 with a cast shadow is displayed in the virtual scene 100.
- the shadow-casting object 110 with a cast shadow may be a game character controlled by the user (or player), and will respond to The real user operates in the virtual scene for the operation of buttons (including rocker buttons, attack buttons, defense buttons, etc.).
- the shadow-casting object 110 with cast shadow will be in the virtual scene.
- the shadow-casting object 110 with cast shadows can also be an artificial intelligence set in the virtual scene battle through training (AI, Artificial Intelligence);
- the shadow-casting object 110 with cast shadows can also be a non-user character (NPC, Non-Player Character) set in the virtual scene interaction;
- the shadow-casting object 110 with cast shadows can also be Immovable objects or movable objects in the virtual scene 100.
- the shadow casting object 120 to be projected is displayed in the virtual scene 100, and multiple shadow casting objects 120 to be projected are obtained through the image rendering method of the embodiment of the present application.
- Vertices perform coordinate conversion processing on the vertex coordinates of each vertex to obtain the conversion coordinates of each vertex, perform depth offset processing on the conversion coordinates of each vertex, and obtain the depth offset coordinates of each vertex, based on the
- the depth offset coordinates are clipped on the shadow casting object 120 to be cast to obtain a clipped shadow casting object, and shadow rendering processing is performed on the clipped shadow casting object to obtain a cast shadow 130 of the shadow casting object to form a cast shadow.
- the shadow casting object 110 with the cast shadow is used to perform human-computer interaction in the virtual scene, such as game confrontation based on the shadow casting object 110 with the cast shadow.
- the terminal 400 can implement the image rendering method provided by the embodiments of the present application by running a computer program.
- the computer program can be a native program or software module in the operating system; it can be a native application program (APP, APplication), that is, a program that needs to be installed in the operating system to run,
- APP native application program
- APplication native application program
- it can be a game APP (that is, the above-mentioned client 410); it can also be an applet, that is, a program that only needs to be downloaded to the browser environment to run; it can also be a game applet that can be embedded in any APP.
- the computer program described above can be any form of application, module or plug-in.
- the terminal 400 installs and runs an application program that supports virtual scenes.
- the application can be any one of a first-person shooting game (FPS, First-Person Shooting game), a third-person shooting game, a virtual reality application, a three-dimensional map program, or a multiplayer gunfight survival game.
- the user uses the terminal 400 to operate shadow-casting objects located in the virtual scene to perform activities, which activities include but are not limited to: adjusting body posture, crawling, walking, running, riding, jumping, driving, picking up, shooting, attacking, throwing, and building virtual At least one of the buildings.
- the shadow casting object may be a virtual character, such as a simulated character or an anime character.
- Cloud Technology refers to the unification of a series of resources such as hardware, software, and networks within a wide area network or a local area network to realize data calculation, storage, and A hosting technology for processing and sharing.
- Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, and application technology based on the cloud computing business model. It can form a resource pool and use it on demand, which is flexible and convenient. Cloud computing technology will become an important support. The background services of technical network systems require a large amount of computing and storage resources.
- the server 200 in Figure 1B can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or it can provide cloud services, cloud databases, cloud computing, cloud functions, and cloud storage. , network services, cloud communications, middleware services, domain name services, security services, CDN, and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
- the terminal 400 can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.
- the terminal 400 and the server 200 can be connected directly or indirectly through wired or wireless communication methods, which are not limited in the embodiments of this application.
- FIG. 2 is a schematic structural diagram of an electronic device for image rendering provided by an embodiment of the present application.
- the electronic device is a terminal 400.
- the electronic device 400 shown in Figure 2 includes: at least one processor 420 , memory 460, at least one network interface 430 and user interface 440.
- the various components in terminal 400 are coupled together by bus system 450 .
- bus system 450 is used to implement connection communication between these components.
- the bus system 450 also includes a power bus, a control bus and a status signal bus.
- the various buses are labeled bus system 450 in FIG. 2 .
- the processor 420 may be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware Components, etc., wherein the general processor can be a microprocessor or any conventional processor, etc.
- DSP Digital Signal Processor
- User interface 440 includes one or more output devices 441 that enable the presentation of media content, including one or more speakers and/or one or more visual displays.
- User interface 440 also includes one or more input devices 442, including user interface components that facilitate user input, such as keyboards, mice, microphones, touch screen displays, cameras, and other input buttons and controls.
- Memory 460 may be removable, non-removable, or a combination thereof.
- Exemplary hardware devices include solid state memory, hard disk drives, optical disk drives, etc.
- Memory 460 optionally includes one or more storage devices physically located remotely from processor 420 .
- Memory 460 includes volatile memory or non-volatile memory, and may include both volatile and non-volatile memory.
- the non-volatile memory may be a read-only memory (ROM, Read Only Memory), and the volatile memory may be a random-access memory (RAM, Random Access Memory).
- ROM read-only memory
- RAM Random Access Memory
- the memory 460 described in the embodiments of this application is intended to include any suitable type of memory.
- the memory 460 is capable of storing data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplarily described below.
- the operating system 461 includes system programs used to process various basic system services and perform hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., which are used to implement various basic services and process hardware-based tasks;
- Network communication module 462 for reaching other electronic devices via one or more (wired or wireless) network interfaces 430.
- Exemplary network interfaces 430 include: Bluetooth, Wireless Compliance Certification (WiFi), and Universal Serial Bus ( USB, Universal Serial Bus), etc.;
- Presentation module 463 for enabling the 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., display screens, speakers, etc.) associated with user interface 440 );
- information e.g., a user interface for operating peripheral devices and displaying content and information
- output devices 441 e.g., display screens, speakers, etc.
- An input processing module 464 for detecting one or more user inputs or interactions from one or more input devices 442 and translating the detected inputs or interactions.
- the image rendering device provided by the embodiment of the present application can be implemented in software.
- Figure 2 shows the image rendering device 465 stored in the memory 460, which can be software in the form of programs, plug-ins, etc., including the following Software modules: acquisition module 4651, conversion module 4652, offset module 4653, cropping module 4654 and rendering module 4655. These modules are logical, so they can be arbitrarily combined or further split according to the functions implemented.
- the image rendering method provided by the embodiment of the present application will be described in detail below with reference to the accompanying drawings.
- the image rendering method provided by the embodiment of the present application can be executed individually by the terminal 400 in Figure 1A, or can be executed collaboratively by the terminal 400 and the server 200 in Figure 1B.
- Figure 3 is a schematic flowchart of an image rendering method provided by an embodiment of the present application, which will be described in conjunction with the steps shown in Figure 3.
- the method shown in Figure 3 can be executed by various forms of computer programs running on the terminal 400, and is not limited to the above-mentioned client 410. It can also be the above-mentioned operating system 461, software modules and scripts. , therefore the client should not be regarded as limiting the embodiments of this application.
- step 101 multiple vertices of the shadow casting object in the virtual scene are obtained, where each vertex corresponds to a vertex coordinate.
- the shadow casting object includes multiple vertices.
- the finer the shadow casting object the greater the number of vertices, and the greater the calculation of vertex-based image rendering.
- each vertex corresponds to a vertex coordinate, which is a three-dimensional coordinate vector, including the coordinate values of the x, y, and z axes of the vertex.
- step 102 perform coordinate conversion processing on the vertex coordinates of each vertex to obtain the converted coordinates of each vertex.
- coordinate conversion processing can be implemented in the following manner: homogenizing the vertex coordinates of each vertex to obtain the homogeneous coordinates of each vertex; converting the homogeneous coordinates of each vertex to world space, Obtain the world space coordinates of each vertex; convert the world space coordinates of each vertex to the visual projection space, obtain the coordinates of each vertex in the visual projection space, and use them as converted coordinates.
- the vertex coordinates of each vertex are a three-dimensional coordinate vector
- the homogeneous coordinates are a four-dimensional coordinate vector.
- the three-dimensional coordinate vector of each vertex is spliced with the homogeneous value (the value of the homogeneous component) to obtain
- the four-dimensional coordinate vector of each vertex is used to achieve coordinate homogeneity, where the homogeneous value is the fourth-dimensional value of the four-dimensional coordinate vector.
- the vertex coordinates of the vertex are v(vx,vy,vz).
- the three-dimensional coordinate vector of the vertex is spliced with the homogeneous value to obtain the four-dimensional coordinate vector v1(vx,vy,vz,vw) of the vertex.
- vw represents a homogeneous value.
- the vertex coordinate is a position coordinate vector
- vw is 1, that is, the four-dimensional coordinate vector of the vertex is v1 (vx, vy, vz, 1).
- the rotation orthogonal matrix, translation matrix and scaling matrix corresponding to each vertex are multiplied to obtain the model matrix corresponding to each vertex.
- the visual projection matrix is obtained by multiplying the visual space matrix and the projection matrix.
- the scaling matrix Among them s1, s2, and s3 respectively represent the scaling coefficients of the x, y, and z axes
- the translation matrix Among them Tx, Ty, and Tz are the translation amounts of the three axes of x, y, and z respectively
- the scaling matrix Among them ⁇ , ⁇ and ⁇ are roll angle (roll), pitch angle (pitch) and yaw angle (yaw) respectively.
- step 103 depth offset processing is performed on the transformation coordinates of each vertex to obtain the depth offset coordinates of each vertex.
- the depth of the vertices of the shadow projection object is offset (that is, the transformation coordinates of the vertices are depth offset), and the depth culling function of the rendering pipeline is used to cleverly and automatically discard the hidden fragments of the shadow projection object. Avoid using fragment discarding and enable geometry clipping to support cast shadow rendering pass without additional overhead for efficient rendering.
- Figure 4 is an optional flow diagram of the image rendering method provided by the embodiment of the present application.
- step 103 in Figure 3 can be implemented through steps 1031 to 1032:
- step 1031 each step is obtained.
- the depth component in the transformed coordinates of each vertex is obtained, and the world space coordinate of each vertex is obtained;
- step 1032 based on the world space coordinate of each vertex, the depth component in the transformed coordinate of each vertex is updated, and
- the updated depth components serve as the depth offset coordinates of each vertex.
- step 1032 Since the rendering object used to cast shadows (i.e., the shadow casting object) does not need to be compared in depth, the shadow casting object outputs a fixed color value during the rendering process, and there is no distinction between before and after.
- the z value i.e., the depth component
- the transformation coordinates i.e., the coordinates of the vertex in the visual projection space, referred to as the visual projection space coordinates
- the visual projection space coordinates is only used for clipping.
- the z value (that is, the depth component) of the visual projection space coordinate of the shadow casting object can be updated in the following manner: so that the z value of the vertex is exactly at the clipping boundary point. You can use pipeline clipping to clip shadow casting objects.
- v3.x/v3.w and v3.y/v3.w respectively represent the standard device space coordinates (i.e. The abscissa and ordinate coordinates of the vertex in the standard device space coordinate system, while v3.z/v3.w represents the depth value, and v3.z represents the depth component in the converted coordinates.
- Figure 5 is an optional flow diagram of the image rendering method provided by the embodiment of the present application.
- Figure 5 shows that step 1032 in Figure 4 can be implemented through steps 10321 to 10323.
- step 10321 obtain the shadow receiving object of the shadow casting object.
- the shadow receiving object is based on the world space coordinates of each vertex and the shadow casting object, Determines the relative height of each vertex relative to the shadow-receiving object.
- step 10322 can be implemented in the following manner: determining the plane parameter vector of the shadow receiving object; converting the plane parameter vector of the shadow receiving object to world space, and obtaining the position of the shadow receiving object in The plane parameter vector of the world space; the product of the plane parameter vector of the shadow receiving object in the world space and the world space coordinates of each vertex is used as the relative height of each vertex relative to the shadow receiving object.
- the plane parameter vector of the shadow receiving object needs to be converted into the world space, and the plane parameter vector of the shadow receiving object in the world space needs to be converted. multiplied with the world space coordinates of each vertex as the relative height of each vertex relative to the shadow receiving object, thereby accurately calculating the relative height of each vertex relative to the shadow receiving object for subsequent calculations based on the relative height of each vertex relative to the shadow receiving object
- the relative height of the object updated with the depth component in each vertex's transformed coordinates.
- the above-mentioned conversion of the plane parameter vector of the shadow receiving object into world space to obtain the plane parameter vector of the shadow receiving object in world space can be achieved by: obtaining the model matrix of the shadow receiving object; converting the model matrix The inverse matrix of the transpose matrix is multiplied by the plane parameter vector of the shadow receiving object to obtain the plane parameter vector of the shadow receiving object in the world space.
- record the plane parameter vector as P (A,B,C,D).
- the model matrix is M'
- step 10322 may be implemented in the following manner: using the ordinate in the world space coordinates of each vertex as the relative height of each vertex relative to the shadow receiving object.
- the shadow receiving object is a horizontal plane
- the world space of each vertex is directly The ordinate in the coordinates is used as the relative height of each vertex relative to the shadow receiving object, then each vertex will save one point multiplication calculation (ie P' ⁇ v2).
- step 10323 the depth component in the converted coordinates of each vertex is updated based on the relative height of each vertex relative to the shadow receiving object, and the updated depth component is used as the depth offset coordinate of each vertex.
- the relative height of each vertex relative to the shadow receiving object is calculated, and based on the relative height of each vertex relative to the shadow receiving object, the depth component in the transformation coordinates of each vertex is updated. Processing to avoid projection errors when the shadow casting object projects to the shadow receiving object.
- step 10323 can be implemented in the following manner: based on the relative position of each vertex relative to the shadow receiving object. Height and homogeneous components, update the depth component in the transformation coordinates of each vertex, and use the updated depth component as the depth offset coordinate of each vertex.
- the update processing of the depth component in the transformation coordinates of each vertex can be implemented in the following manner: obtaining the maximum display height of the virtual scene ; Multiply the relative height of each vertex relative to the shadow receiving object by the reciprocal of the maximum display height to obtain the second product result; multiply the difference between the second product result and the clipping threshold by the homogeneous component to obtain the third product result, and updates the depth component in each vertex's transformed coordinates to the third product result.
- step 10323 can be implemented in the following manner Now: Obtain the maximum display height of the virtual scene; multiply the relative height of each vertex relative to the shadow receiving object by the reciprocal of the maximum display height to obtain the first product result; determine the difference between the first product result and the clipping threshold, and Update the depth component in each vertex's transformed coordinates to the difference.
- the z value of the standard device space coordinates and the y value of the world space coordinates have the following relationship: the vertex with a y value greater than 0 in the world space coordinates is at v3.z/v3 in the standard device space coordinates. w will be greater than -1, and the v3.z/v3.w of a vertex with a y value less than 0 in world space coordinates will be less than -1 in standard device space coordinates.
- the standard device space coordinates of the fragments are linearly interpolated with the standard device space coordinates of the vertices, if the z value of the standard device space coordinates and the y value of the world space coordinates maintain the above relationship, in After clipping, fragments with a y value less than 0 in world space coordinates will be completely eliminated and will not be sent to the fragment shader, so that the parts of the shadow casting object that are obscured by the shadow receiving object will not be rendered.
- step 104 the shadow casting object is clipped based on the depth offset coordinates of each vertex to obtain a clipped shadow casting object.
- step 104 can be implemented in the following manner: standardizing the depth offset coordinates of the shadow casting object to obtain standardized depth offset coordinates; when the normalized depth offset coordinates are in the clipping range, retain The shadow casting object corresponding to the standardized depth offset coordinates; when the normalized depth offset coordinates exceed the cropping range, the shadow casting object corresponding to the standardized depth offset coordinates is cropped to obtain the cropped shadow casting object.
- normalizing the depth offset coordinates of the shadow-casting object can be achieved by dividing the depth offset coordinates of the shadow-casting object by the homogeneous component of the view-projection coordinate (i.e., the homogeneous component of the transformed coordinate), to obtain the normalized
- the depth offset coordinates v3.z/v3.w after When .z/v3.w exceeds the cropping range [-1,1], crop out part of the shadow casting object corresponding to v3.z/v3.w to obtain the cropped shadow casting object, and then use the cropped shadow casting object Perform shadow rendering processing to obtain the cast shadow of the shadow casting object.
- step 105 shadow rendering processing is performed on the clipped shadow casting object to obtain the cast shadow of the shadow casting object.
- shadow rendering processing is performed on the cropped shadow casting object to obtain the cast shadow of the shadow casting object, so as to normally display the shadow casting model 601 (ie, the shadow casting object).
- performing shadow rendering processing on the cropped shadow casting object to obtain the cast shadow of the shadow casting object can be implemented in the following manner: performing shadow map rendering processing on the cropped shadow casting object to obtain the cropped shadow.
- the shadow map of the cast object ; perform basic coloring processing on the clipped shadow cast object based on the shadow map to obtain the cast shadow of the shadow cast object.
- a clipped shadow-casting object when rendered to a shadow map (i.e., shadow map rendering), it will not include the part with a world coordinate y value less than 0, as shown in Figure 7.
- a shadow map When the shadow map is projected to a shadow-receiving object (i.e., shadow map rendering) Basic shading) you can see that no shadow will appear on the shadow receiving object in the part below the shadow receiving object.
- the shadow rendering in scene rendering (that is, the process of rendering a virtual scene including shadow casting objects) includes the shadow stage (that is, the shadow map rendering process) and the basic shading stage (that is, the basic shading process).
- the shadow stage the clipped shadow-casting object will be transformed into the light space coordinate system (the coordinate system with the light source as the origin) through matrix transformation, and the depth value of the clipped shadow-casting object in the light space coordinate system will be rendered into a shadow map.
- the clipped shadow-casting object will be matrix transformed into the final rendered projection space coordinate system, rasterized and then colored.
- the process of determining whether the current pixel is within the shadow is as follows: traverse the pixels in the shadow map, and when the depth value of the traversed current pixel is within the shadow range, determine that the current pixel is within the shadow; when the depth of the traversed current pixel is within the shadow range, When the value exceeds the shadow range, it is determined that the current pixel is not within the shadow.
- both stages will use the complete GPU rendering pipeline, including vertex shading, rasterization calculation and pixel shading calculation, but the drawing perspective is different, the target buffer drawn to is different, and the shading method used for drawing is different.
- the GPU rendering pipeline includes the following processing: rasterize the transformation coordinates of each vertex to obtain the pixels corresponding to each vertex, perform coloring processing on the pixels corresponding to each vertex, obtain the color corresponding to each pixel, and obtain the color corresponding to each pixel.
- the colors corresponding to each pixel are tested and mixed to obtain the rendering result.
- the rendering result may be the output of the above two stages, such as the shadow map of the clipped shadow-casting object in the shadow stage, and the cast shadow in the basic shading stage.
- vertex information (that is, the vertex coordinates of the vertices) is transmitted to the GPU through the graphics interface.
- the vertices are calculated by the GPU rendering pipeline and finally output to the screen buffer for picture rendering.
- the GPU rendering pipeline takes vertex information as input, and then performs vertex shader calculations based on the vertex information. After obtaining unified transformation coordinates, it is passed to the rasterization stage for rasterization calculation, then pixel shading calculation, and finally testing and mixing. Get the rendering result, output the rendering result to the frame buffer, and display the picture.
- the testing process includes in-depth testing and template testing.
- Embodiments of the present application can be applied to rendering scenarios of various games, such as confrontation games, racing games, cross-dressing games, etc.
- the following description takes the virtual scene as a game as an example.
- the model of the three-dimensional scene (that is, the shadow projection object) needs to read data on the CPU side and transfer it to the GPU, and call the GPU for rendering.
- the vertex shader is used to determine the projection space coordinates of the vertices
- the rasterizer is used to rasterize the primitives converted to the standard device space coordinate system into multiple pixels. , and submit multiple pixels to the fragment shader for final color determination.
- the model needs to be geometrically cropped in real time during rendering interaction.
- the fragment discarding function is used in the GPU fragment shader, but because all fragments need to be tested for geometric clipping, it brings additional shader calculation overhead, and turning on fragment discarding will invalidate the Early-Z function of the rendering pipeline, causing the rendering pipeline to efficiency is reduced.
- the embodiment of the present application modifies the depth in the vertex shader based on the frustum clipping characteristics of the rasterizer, thereby achieving the purpose of geometric clipping. It can achieve geometric cropping without incurring additional performance consumption, and can be widely used in cast shadow rendering of 3D models to improve the overall rendering performance.
- the left part of Figure 6 is an outline view of the scene.
- the scene includes the rendering main camera (Main Camera), directional light source (Directional Light), model (Model) and shadow receiving plane (Plane).
- the directional light source has two child nodes, which are the shadow camera component (Shadow Camera) used to render cast shadows and the projector component (Projector) used to project the shadow results to the shadow receiving surface.
- the model includes six shadow casting models 601 (ie, shadow casting objects), each with different displacement and rotation.
- the shadow casting model will be lower than the receiving plane 602 (that is, blocked by the receiving plane). part) is also rendered and projected onto the shadow receiving plane, causing incorrect shadow rendering results.
- vert represents the vertex shader, which is used to transform the coordinates of the model and output clipping space coordinates
- frag represents the fragment shader, which is used to output a shadow color value of 0.04 for all fragments.
- the shader file is rewritten according to the following content:
- the shadow rendering result returns to normal.
- the shadows of the six shadow casting models 601 are displayed normally.
- the part of the shadow casting model 601 lower than the receiving plane that is, the shadow casting model 601 is lower than the receiving plane).
- the part receiving plane occlusion will not be rendered. Without additional overhead, the cast shadow is compatible with the intersection of the shadow caster and the shadow receiver, with both high performance and applicability.
- the rendering performance can be improved while maintaining the accuracy of the shadow rendering result. This increases the number of vertices that the GPU can draw per unit time.
- vertex information is transferred to the GPU through the graphics interface.
- the vertex information is calculated by the GPU rendering pipeline and finally output to the screen buffer for drawing. face presented.
- the stage when a rendering call occurs is the GPU rendering pipeline.
- the GPU rendering pipeline takes vertex information as input, and then performs vertex shader calculations based on the vertex information. After obtaining unified transformation coordinates, it is passed to the rasterization stage for rasterization calculation, then pixel shading calculation, and finally testing and mixing. Get the rendering result, output the rendering result to the frame buffer, and display the picture.
- the vertices need to be homogenized from the three-dimensional vector of the local coordinate system to obtain the four-dimensional homogeneous coordinates, and then the model matrix is left multiplied by the four-dimensional homogeneous coordinates to obtain the homogeneous coordinates in the world space. Then left-multiply the homogeneous coordinates in the world space by the visual projection matrix to obtain the four-dimensional coordinates in the projection space, and output the four-dimensional coordinates in the projection space (that is, the projection space coordinates) for rasterization calculation.
- the projection space coordinates are subjected to perspective division, that is, divided by the w component to obtain the standard device space coordinates. Then the triangles in the shadow projection model are rasterized into fragments (including multiple pixels), and the coordinate range is intercepted. A collection of fragments from (-1,-1,-1) to (1,1,1), and the intercepted fragments are sent to the fragment shader for coloring.
- the x and y components represent the abscissa and ordinate of the fragment in the buffer respectively, and the z component is used to represent the depth relationship.
- this z component will be compared with the corresponding depth value in the depth buffer to determine whether Needs to be rendered, for example, when the z component is greater than the corresponding depth value in the depth buffer, it is determined that the fragment does not need to be rendered; when the z component is less than or equal to the corresponding depth value in the depth buffer, it is determined that the fragment needs to be rendered.
- the shadow casting model Since the rendering object used for casting shadows does not require depth comparison, the shadow casting model outputs a fixed color value during the rendering process, without distinction between before and after. Therefore, during the casting shadow rendering process, the z component is only used for clipping. Based on the clipping space and z component of the rendering pipeline, the z component of the projection space coordinate of the shadow casting model can be offset so that the z component of the vertex is just at the clipping boundary point -1 or 1, and pipeline clipping (i.e. raster The view frustum clipping feature of the optimizer) clips the shadow casting model.
- pipeline clipping i.e. raster The view frustum clipping feature of the optimizer
- v3 VP ⁇ v2.
- v3.x/v3.w and v3.y/v3.w respectively represent the sum of the abscissas of the standard device space coordinates.
- the ordinate, while v3.z/v3.w represents the depth value.
- the w component is 1.
- the w component is not 1.
- the shadow rendering of a directional light source can be regarded as an orthogonal projection.
- v2.y represents the y value of the world space coordinate of the vertex
- k represents a fixed coefficient (used to control v3.z/v3.w between (-1, 1)), which is set to the maximum height of the virtual scene
- the z value of a vertex with a y value greater than 0 in the world space coordinates will be greater than -1 in the standard device space coordinates, and the z value of a vertex with a y value less than 0 in the world space coordinates will be greater than -1 in the standard device space coordinates.
- the z value will be less than -1.
- the shadow projection model when the shadow projection model is rendered to the shadow map, it will not include the part with the world coordinate y value less than 0.
- the shadow map when the shadow map is projected to the shadow receiver, you can see the shadow below the ground plane. No shadow will appear on the ground (i.e. the shadow receiver) on the part (i.e. the part occluded by the shadow receiver).
- the clipped shadow casting model In the shadow stage, the clipped shadow casting model will be transformed into the light space coordinate system through matrix transformation, and the clipped shadow projection object will be cast in the light space.
- the depth value of the coordinate system is rendered into a shadow map to obtain the shadow map of the clipped shadow casting object; in the basic shading stage, the clipped shadow casting object will be matrix transformed into the final rendered projection space coordinate system and rasterized After that, coloring is performed. During coloring, it is judged according to the depth value of the shadow map whether the current pixel is within the shadow, so as to perform lighting coloring.
- both stages will use the complete GPU rendering pipeline, including vertex shading, rasterization calculation and pixel shading calculation, but the drawing perspective is different, the target buffer drawn to is different, and the shading method used for drawing is different.
- ((M') T ) -1 represents the inverse of the transpose of the model matrix.
- P’ ⁇ v2 represents the plane equation parameter vector P’ multiplied by the world space coordinate v2 of the vertex, that is, the distance from the vertex to the plane in world space.
- the shadow projection model will not include the part below the plane when it is rendered into the shadow map.
- plane 901 is not a horizontal plane and has an inclination. This can be seen when the shadow map is projected onto plane 901. No shadow will appear on the ground below the plane.
- the clipping range of the standard device space coordinate system is different.
- One is the DirectX class, the clipping range is 0 to 1, and the other is the OpenGL class, the clipping range is -1 to 1. Therefore, when considering multiple platforms, the following rewriting is required:
- the additional calculation required by the embodiment of the present application is one multiply-accumulate instruction for each vertex (during orthogonal projection).
- each vertex requires an additional point multiplication. Calculation (i.e. P' ⁇ v2), this calculation amount can be ignored in GPU calculations.
- the world space coordinates are transferred to the fragment shader and clipped using the fragment discard instruction, and then the vertex shader transmits a set of interpolation vectors to the fragment shader, and performs clipping testing and fragment discarding on the fragment.
- the embodiment of the present application offsets the vertex depth of the shadow caster in the vertex shader, and uses the depth culling function of the rendering pipeline to cleverly remove the fragments that intersect behind the shadow receiver (that is, the fragments that are occluded by the shadow receiver). Fragment) is automatically discarded, avoiding the use of fragment discarding, and achieving geometric clipping that supports the cast shadow rendering process without additional overhead to achieve efficient rendering, and also has compatibility and usability, which can further reduce the overall cost of cast shadows. .
- the acquisition module 4651 is configured to acquire multiple vertices of the shadow casting object in the virtual scene, where each vertex corresponds to a vertex coordinate; the conversion module 4652 is configured to perform coordinate conversion processing on the vertex coordinates of each vertex to obtain each vertex.
- the cropping module 4654 is configured to perform depth offset processing based on each vertex.
- the depth offset coordinates of each of the vertices are used to clip the shadow casting object to obtain the clipped shadow casting object; the rendering module 4655 is used to perform shadow rendering processing on the clipped shadow casting object to obtain The shadow caster casts the shadow of the object.
- the offset module 4653 is further configured to obtain the depth component in the transformed coordinates of each of the vertices, and obtain the world space coordinates of each of the vertices; based on the world space of each of the vertices coordinates, update the depth component in the converted coordinates of each vertex, and use the updated depth component as the depth offset coordinate of each vertex.
- the offset module 4653 is further configured to obtain a shadow receiving object of the shadow casting object; based on the world space coordinates of each vertex and the shadow receiving object of the shadow casting object, determine each The relative height of the vertex relative to the shadow receiving object; based on the relative height of each vertex relative to the shadow receiving object, update the depth component in the transformation coordinates of each vertex to obtain each The depth offset coordinates of the vertices.
- the offset module 4653 is further configured to use the ordinate in the world space coordinates of each vertex as the relative position of each vertex relative to the shadow when the shadow receiving object is a horizontal plane. Receives the relative height of the object.
- the offset module 4653 is further configured to determine the plane parameter vector of the shadow receiving object when the shadow receiving object is a non-horizontal plane; convert the plane parameter vector of the shadow receiving object to the world space to obtain the plane parameter vector of the shadow receiving object in the world space; multiply the product of the plane parameter vector of the shadow receiving object in the world space and the world space coordinates of each vertex as each The relative height of the vertex relative to the shadow receiving object.
- the offset module 4653 is further configured to obtain the model matrix of the shadow receiving object; multiply the inverse matrix of the transposed matrix of the model matrix by the plane parameter vector of the shadow receiving object , obtain the plane parameter vector of the shadow receiving object in the world space.
- the offset module 4653 is further configured to obtain the maximum display height of the virtual scene; The height is multiplied by the reciprocal of the maximum display height to obtain a first product result; the difference between the first product result and the clipping threshold is calculated, and the depth component in the converted coordinates of each vertex is updated to the difference.
- the depth component in the transformed coordinates of each vertex is updated based on the relative height of each vertex relative to the shadow receiving object.
- the offset module 4653 was also configured to obtain the homogeneous components in the transformation coordinates of each vertex; based on the relative height of each vertex relative to the shadow receiving object and the homogeneous components, for each The depth component in the transformed coordinates of the vertex is updated.
- the offset module 4653 is further configured to obtain the maximum display height of the virtual scene; compare the relative height of each vertex with respect to the shadow receiving object with the reciprocal of the maximum display height. Multiply to obtain the second product result; multiply the difference between the second product result and the clipping threshold by the homogeneous component to obtain the third product result, and add the depth component in the transformed coordinates of each vertex Updated to the third product result.
- the cropping module 4654 is further configured to normalize the depth offset coordinates of the shadow casting object to obtain the standardized depth offset coordinates; when the normalized depth offset coordinates When in the cropping range, retain the shadow casting object corresponding to the normalized depth offset coordinates; when the normalized depth offset coordinates exceed the cropping range, crop out the normalized depth offset The coordinates corresponding to the shadow casting object.
- the rendering module 4655 is further configured to perform shadow map rendering processing on the cropped shadow casting object to obtain a shadow map of the cropped shadow casting object;
- the shadow casting object is subjected to basic shading processing to obtain the cast shadow of the shadow casting object.
- Embodiments of the present application provide a computer program product.
- the computer program product includes a computer program or executable instructions, and the computer program or executable instructions are stored in a computer-readable storage medium.
- the processor of the electronic device reads the computer program or executable instructions from the computer-readable storage medium, and the processor executes the computer program or executable instructions, so that the electronic device executes the image rendering method described above in the embodiment of the present application.
- Embodiments of the present application provide a computer-readable storage medium storing computer programs or executable instructions.
- the computer program or executable instructions are stored therein.
- the processor executes the present application.
- the image rendering method provided by the embodiment is, for example, the image rendering method shown in Figures 3-5.
- the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; it may also include one or any combination of the above memories.
- Various equipment may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; it may also include one or any combination of the above memories.
- Various equipment may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; it may also include one or any combination of the above memories.
- executable instructions may take 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 their May be deployed in any form, including deployed as a stand-alone program or deployed as a module, component, subroutine, or other unit suitable for use in a computing environment.
- executable instructions may, but do not necessarily correspond to, files in a file system and may be stored as part of a file holding other programs or data, for example, in a Hyper Text Markup Language (HTML) document. in one or more scripts, in a single file that is specific to the program in question, or in multiple collaborative files (e.g., files that store one or more modules, subroutines, or portions of code).
- HTML Hyper Text Markup Language
- executable instructions may be deployed to execute on one electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected by a communications network. execute on.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computer Graphics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Geometry (AREA)
- Architecture (AREA)
- Computer Hardware Design (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Processing Or Creating Images (AREA)
Abstract
一种图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品;方法包括:获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标;对每个顶点的顶点坐标进行坐标转换处理,得到每个顶点的转换坐标;对每个顶点的转换坐标进行深度偏移处理,得到每个顶点的深度偏移坐标;基于每个顶点的深度偏移坐标对阴影投射对象进行裁剪处理,得到裁剪后的阴影投射对象;对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影。
Description
相关申请的交叉引用
本申请基于申请号为202210412423.9、申请日为2022年4月19日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。
本申请涉及计算机图形图像技术,尤其涉及一种图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品。
基于图形处理硬件的显示技术,扩展了感知环境以及获取信息的渠道,尤其是虚拟场景的显示技术,能够根据实际应用需求实现受控于用户或人工智能的虚拟对象之间的多样化的交互,具有各种典型的应用场景,例如在游戏等的虚拟场景中,能够模拟虚拟对象之间的真实的对战过程。
相关技术中,在进行阴影渲染时,在调用着色器进行着色的阶段使用片段丢弃功能以片段为粒度进行裁剪,使得渲染管线的片段输出不可预测,这种方案将浪费大量的存储空间以及计算资源,进而影响使用体验。
发明内容
本申请实施例提供一种图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品,能够节约相关的存储空间以及计算资源。
本申请实施例的技术方案是这样实现的:
本申请实施例提供一种图像渲染方法,包括:
获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标;
对每个所述顶点的顶点坐标进行坐标转换处理,得到每个所述顶点的转换坐标;
对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标;
基于每个所述顶点的深度偏移坐标对所述阴影投射对象进行裁剪处理,得到裁剪后的所述阴影投射对象;
对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影。
本申请实施例提供一种图像渲染装置,包括:
获取模块,配置为获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标;
转换模块,配置为对每个所述顶点的顶点坐标进行坐标转换处理,得到每个所述顶点的转换坐标;
偏移模块,配置为对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标;
裁剪模块,配置为基于每个所述顶点的深度偏移坐标对所述阴影投射对象进行裁剪处理,得到裁剪后的所述阴影投射对象;
渲染模块,配置为对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影。
本申请实施例提供一种用于图像渲染的电子设备,所述电子设备包括:
存储器,用于存储计算机程序或可执行指令;
处理器,用于执行所述存储器中存储的计算机程序或可执行指令时,实现本申请实施例提供的图像渲染方法。
本申请实施例提供一种计算机可读存储介质,存储有计算机程序或可执行指令,用于引起处理器执行时,实现本申请实施例提供的图像渲染方法。
本申请实施例提供一种计算机程序产品,包括计算机程序或可执行指令,所述计算机程序或可执行指令被处理器执行时实现本申请实施例提供的图像渲染方法。
本申请实施例具有以下有益效果:
通过对每个顶点的转换坐标进行深度偏移处理,并基于每个顶点的深度偏移坐标对阴影投射对象进行裁剪处理,以自动准确地裁剪掉需要丢弃的部分,并对裁剪后的阴影投射对象进行阴影渲染,相对于相关技术的调用片段丢弃功能,本申请实施例避免了丢弃的不确定性,准确地丢弃需要丢弃的部分,从而节约了需要丢弃的部分所占用的存储空间以及计算资源,进而提高阴影渲染效率。
图1A-图1B是本申请实施例提供的图像渲染方法的应用模式示意图;
图2是本申请实施例提供的用于图像渲染的电子设备的结构示意图;
图3-图5是本申请实施例提供的图像渲染方法的流程示意图;
图6-7是本申请实施例提供的投射阴影的场景示意图;
图8是相关技术提供的渲染管线的流程图;
图9是本申请实施例提供的投射阴影的场景示意图。
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,所描述的实施例不应视为对本申请的限制,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。
在以下的描述中,所涉及的术语“第一\第二”仅仅是是区别类似的对象,不代表针对对象的特定排序,可以理解地,“第一\第二”在允许的情况下可以互换特定的顺序或先后次序,以使这里描述的本申请实施例能够以除了在这里图示或描述的以外的顺序实施。
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中所使用的术语只是为了描述本申请实施例的目的,不是旨在限制本申请。
对本申请实施例进行进一步详细说明之前,对本申请实施例中涉及的名词和术语进行说明,本申请实施例中涉及的名词和术语适用于如下的解释。
1)响应于:用于表示所执行的操作所依赖的条件或者状态,当满足所依赖的条件或状态时,所执行的一个或多个操作可以是实时的,也可以具有设定的延迟;在没有特别说明的情况下,所执行的多个操作不存在执行先后顺序的限制。
2)客户端:终端中运行的用于提供各种服务的应用程序,例如视频播放客户端、游戏客户端等。
3)虚拟场景:游戏程序在终端上运行时显示(或提供)的虚拟游戏场景。该虚拟场景可以是对真实世界的仿真环境,也可以是半仿真半虚构的虚拟环境,还可以是纯虚构的虚拟环境。虚拟场景可以是二维虚拟场景、2.5维虚拟场景或者三维虚拟场景中的任意一种,本申请实施例对虚拟场景的维度不加以限定。例如,虚拟场景可以包括天空、陆地、海洋等,该陆地可以包括沙漠、城市等环境元素,用户可以控制虚拟对象在该虚拟场景中进行移动。
4)虚拟对象:虚拟场景中可以进行交互的各种人和物的形象,或在虚拟场景中的可活动对象。该可活动对象可以是虚拟人物、虚拟动物、动漫人物等,例如在虚拟场景中显示的人物、动物等。该虚拟对象可以是虚拟场景中的一个虚拟的用于代表用户的虚拟形象。虚拟场景中可以包括多个虚拟对象,每个虚拟对象在虚拟场景中具有自身的形状和体积,占据虚拟场景中的一部分空间。
其中,阴影投射对象为产生阴影投射的虚拟对象,阴影接收对象为接收阴影投射的虚拟对象,例如虚拟人物在地面上投射出阴影的场景下,虚拟人物为阴影投射对象,地面为阴影接收对象。
5)场景数据:表示虚拟场景的特征数据,例如可以是虚拟场景中建造区域的面积、虚拟场景当前所处的建筑风格等;也可以包括虚拟建筑在虚拟场景中所处的位置、以及虚拟建筑的占地面积等。
6)图形处理器(GPU,Graphics Processing Unit):一种用于现代个人计算机、服务器、移动设备、游戏主机等专门用于图形图像处理的专用芯片。
7)渲染管线:在GPU中运行的图形渲染流程,包括顶点着色器、光栅化、像素着色器等。通过在着色器中编写代码能够灵活控制GPU对渲染组件进行绘制渲染。
8)顶点着色器:GPU渲染管线的一个必选环节,顶点着色器程序会根据代码将模型的顶点进行逐个顶点计算,并将结果输出到下一个阶段。
9)坐标转换:将一个空间坐标系下的坐标变换到另一个空间坐标系的过程,坐标系之间的变换关系用矩阵表示,将矩阵左乘坐标向量,得到的值就是变换后的坐标。
10)片段着色器:GPU渲染管线的一个必选环节,片段着色器程序会根据代码将光栅化后的像素进行着色计算,通过测试之后输出到帧缓冲区,完成一次渲染管线流程。
11)视锥体剔除:GPU渲染管线中光栅化阶段的一个功能,用于剔除在视锥体以外的片段。视锥体(Frustum)是指虚拟场景中摄像机方向上的可见的一个锥体范围,包括上、下、左、右、近、远6个面,在视锥体内的对象可见,反之则不可见,为提高渲染性能,只对与视锥体有交集的对象进行绘制。
12)标准设备空间坐标系:与电子设备无关的一套三维坐标系,例如,即使电子设备使用不同的分辨率,同一个物体在标准设备空间坐标系中的坐标都是相同的。将四维的裁剪坐标系进行透视除法,得到标准设备空间坐标系,例如裁剪坐标系中的四维坐标除以第四维齐次坐标分量,即得到的标准设备空间坐标系。
13)片段丢弃:在片段着色器中,根据条件对片段进行丢弃的指令,能够使片段着色器丢弃的片段不输出到屏幕上,例如带透明边缘的模型渲染过程中,将采用片段丢弃功能。
14)提前深度测试(Early-Z):如果片段着色过程不会改变深度值,那么在片段着色之前先进行深度比较和写入操作,如果深度比较失败,则直接跳过片段着色,如果片段着色过程中存在片段丢弃会使得Early-Z失效。
15)图形应用程序接口(API,Application Programming Interface):在中央处理器(CPU,Central Processing Unit)向GPU进行通信的时候按照标准的图形API进行,图形API有OpenGL、OpenGL ES、Direct X、Metal、Vulkan等,在进行图形开发时,按
照接口所定义的方法来调用GPU即可。
16)本地坐标系:以物体自身位置作为原点的坐标系。本地坐标系用于表示物体间相对位置和方向,会根据物体自身旋转而旋转。
相关技术中,在图形渲染领域和行业应用中,阴影渲染包括阴影贴图、阴影离线烘焙和投射阴影几种渲染方式。其中,阴影贴图应用广泛,能够覆盖大部分复杂的场景渲染需求。但对于移动端平台来说,阴影渲染所需要的32位缓冲区会带来传输带宽压力。当虚拟场景的深度关系较为简单时,阴影投影者(即阴影投射对象)不作为接收者时,投射阴影技术可以用来取代阴影贴图技术,能够在8位的缓冲区中达到同样的动态阴影渲染目的,提升渲染性能。例如在一个棋盘场景中,棋子作为阴影投影者但不作为阴影接收者(即阴影接收对象),棋盘作为阴影接收者但不作为阴影投影者,符合投射阴影的使用要求。但由于投射阴影技术不具备深度比较功能,在阴影投影者的部分藏在阴影接收者下方的情况下,需要根据阴影接收者的几何模型对阴影投影者进行裁剪。
在GPU片段着色器中利用片段丢弃功能,以像素为粒度对模型(即阴影投影者)进行裁剪。这种裁剪方法能够用最精细的粒度裁剪,其裁剪面平整。但由于所有的片段都需要进行几何裁剪测试,带来额外的着色器计算开销,且开启片段丢弃会使得渲染管线的Early-Z功能失效,造成渲染流水线的效率降低。
为了解决上述问题,本申请实施例提供一种图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品,能够避免采用片段丢弃功能,以节约相关的存储空间以及计算资源。为便于更容易理解本申请实施例提供的图像渲染方法,首先说明本申请实施例提供的图像渲染方法的示例性实施场景,本申请实施例提供的图像渲染方法中的虚拟对象可以完全基于终端输出,或者基于终端和服务器协同输出。
在一些实施例中,虚拟场景可以是供游戏角色交互的环境,例如可以是供游戏角色在虚拟场景中进行对战,通过控制游戏角色的行动可以在虚拟场景中进行双方互动,从而使用户能够在游戏的过程中舒缓生活压力。
在一个实施场景中,参见图1A,图1A是本申请实施例提供的图像渲染方法的应用模式示意图,适用于一些完全依赖于终端400的图形处理硬件计算能力即可完成虚拟场景100的相关数据计算的应用模式,例如单机版或离线模式的游戏,通过智能手机、平板电脑和虚拟现实或增强现实设备等各种不同类型的终端400完成虚拟场景的输出。
作为示例,图形处理硬件的类型包括中央处理器(CPU,Central Processing Unit)和图形处理器(GPU,Graphics Processing Unit)。
当形成虚拟场景100的视觉感知时,终端400通过图形计算硬件计算显示所需要的数据,并完成显示数据的加载、解析和渲染,在图形输出硬件输出能够对虚拟场景形成视觉感知的视频帧,例如,在智能手机的显示屏幕呈现二维的视频帧,或者,在增强现实或虚拟现实眼镜的镜片上投射实现三维显示效果的视频帧;此外,为了丰富感知效果,终端400还可以借助不同的硬件来形成听觉感知、触觉感知、运动感知和味觉感知的一种或多种。
作为示例,终端400上运行有客户端410(例如单机版的游戏应用),在客户端410的运行过程中输出包括有角色扮演的虚拟场景,虚拟场景可以是供游戏角色交互的环境,例如可以是用于供游戏角色进行对战的平原、街道、山谷等等;以第一人称视角显示虚拟场景100为例,在虚拟场景100中显示带有投射阴影的阴影投射对象110,带有投射阴影的阴影投射对象110可以是受用户(或称玩家)控制的游戏角色,将响应于真实用户针对按钮(包括摇杆按钮、攻击按钮、防御按钮等)的操作而在虚拟场景中操作,例如当真实用户向左移动摇杆按钮时,带有投射阴影的阴影投射对象110将在虚拟场景中向左部移动,还可以保持原地静止、跳跃以及使用各种功能(如技能和道具);带有投
射阴影的阴影投射对象110也可以是通过训练设置在虚拟场景对战中的人工智能(AI,Artificial Intelligence);带有投射阴影的阴影投射对象110还可以是设置在虚拟场景互动中的非用户角色(NPC,Non-Player Character);带有投射阴影的阴影投射对象110还可以是虚拟场景100中不可活动对象或者可活动对象。
举例来说,以第一人称视角显示虚拟场景100为例,在虚拟场景100中显示待投射的阴影投射对象120,通过本申请实施例的图像渲染方法,获取待投射的阴影投射对象120的多个顶点,对每个顶点的顶点坐标进行坐标转换处理,得到每个顶点的转换坐标,对每个顶点的转换坐标进行深度偏移处理,得到每个顶点的深度偏移坐标,基于每个顶点的深度偏移坐标对待投射的阴影投射对象120进行裁剪处理,得到裁剪后的阴影投射对象,对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影130,以形成带有投射阴影的阴影投射对象110,并基于带有投射阴影的阴影投射对象110在虚拟场景中进行人机交互,例如游戏对抗。
在另一个实施场景中,参见图1B,图1B是本申请实施例提供的图像渲染方法的应用模式示意图,应用于终端400和服务器200,适用于依赖于服务器200的计算能力完成虚拟场景计算、并在终端400输出虚拟场景的应用模式。
以形成虚拟场景100的视觉感知为例,服务器200进行虚拟场景相关显示数据(例如场景数据)的计算并通过网络300发送到终端400,终端400依赖于图形计算硬件完成计算显示数据的加载、解析和渲染,依赖于图形输出硬件输出虚拟场景以形成视觉感知,例如可以在智能手机的显示屏幕呈现二维的视频帧,或者,在增强现实或虚拟现实眼镜的镜片上投射实现三维显示效果的视频帧;对于虚拟场景的形式的感知而言,可以理解,可以借助于终端400的相应硬件输出,例如使用麦克风形成听觉感知,使用振动器形成触觉感知等等。
作为示例,终端400上运行有客户端410(例如网络版的游戏应用),通过连接服务器200(例如游戏服务器)与其他用户进行游戏互动,终端400输出客户端410的虚拟场景100,以第一人称视角显示虚拟场景100为例,在虚拟场景100中显示带有投射阴影的阴影投射对象110,带有投射阴影的阴影投射对象110可以是受用户(或称玩家)控制的游戏角色,将响应于真实用户针对按钮(包括摇杆按钮、攻击按钮、防御按钮等)的操作而在虚拟场景中操作,例如当真实用户向左移动摇杆按钮时,带有投射阴影的阴影投射对象110将在虚拟场景中向左部移动,还可以保持原地静止、跳跃以及使用各种功能(如技能和道具);带有投射阴影的阴影投射对象110也可以是通过训练设置在虚拟场景对战中的人工智能(AI,Artificial Intelligence);带有投射阴影的阴影投射对象110还可以是设置在虚拟场景互动中的非用户角色(NPC,Non-Player Character);带有投射阴影的阴影投射对象110还可以是虚拟场景100中不可活动对象或者可活动对象。
举例来说,以第一人称视角显示虚拟场景100为例,在虚拟场景100中显示待投射的阴影投射对象120,通过本申请实施例的图像渲染方法,获取待投射的阴影投射对象120的多个顶点,对每个顶点的顶点坐标进行坐标转换处理,得到每个顶点的转换坐标,对每个顶点的转换坐标进行深度偏移处理,得到每个顶点的深度偏移坐标,基于每个顶点的深度偏移坐标对待投射的阴影投射对象120进行裁剪处理,得到裁剪后的阴影投射对象,对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影130,以形成带有投射阴影的阴影投射对象110,并基于带有投射阴影的阴影投射对象110在虚拟场景中进行人机交互,例如游戏对抗。
在一些实施例中,终端400可以通过运行计算机程序来实现本申请实施例提供的图像渲染方法,例如,计算机程序可以是操作系统中的原生程序或软件模块;可以是本地(Native)应用程序(APP,APPlication),即需要在操作系统中安装才能运行的程序,
例如换装游戏APP(即上述的客户端410);也可以是小程序,即只需要下载到浏览器环境中就可以运行的程序;还可以是能够嵌入至任意APP中的游戏小程序。总而言之,上述计算机程序可以是任意形式的应用程序、模块或插件。
以计算机程序为应用程序为例,在实际实施时,终端400安装和运行有支持虚拟场景的应用程序。该应用程序可以是第一人称射击游戏(FPS,First-Person Shooting game)、第三人称射击游戏、虚拟现实应用程序、三维地图程序或者多人枪战类生存游戏中的任意一种。用户使用终端400操作位于虚拟场景中的阴影投射对象进行活动,该活动包括但不限于:调整身体姿态、爬行、步行、奔跑、骑行、跳跃、驾驶、拾取、射击、攻击、投掷、建造虚拟建筑中的至少一种。示意性的,该阴影投射对象可以是虚拟人物,比如仿真人物角色或动漫人物角色等。
在一些实施例中,本申请实施例还可以借助于云技术(Cloud Technology)实现,云技术是指在广域网或局域网内将硬件、软件、网络等系列资源统一起来,实现数据的计算、储存、处理和共享的一种托管技术。
云技术是基于云计算商业模式应用的网络技术、信息技术、整合技术、管理平台技术、以及应用技术等的总称,可以组成资源池,按需所用,灵活便利。云计算技术将变成重要支撑。技术网络系统的后台服务需要大量的计算、存储资源。
示例的,图1B中的服务器200可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。终端400可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。终端400以及服务器200可以通过有线或无线通信方式进行直接或间接地连接,本申请实施例中不做限制。
参见图2,图2是本申请实施例提供的用于图像渲染的电子设备的结构示意图,以电子设备为终端400为例进行说明,图2所示的电子设备400包括:至少一个处理器420、存储器460、至少一个网络接口430和用户接口440。终端400中的各个组件通过总线系统450耦合在一起。可理解,总线系统450用于实现这些组件之间的连接通信。总线系统450除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图2中将各种总线都标为总线系统450。
处理器420可以是一种集成电路芯片,具有信号的处理能力,例如通用处理器、数字信号处理器(DSP,Digital Signal Processor),或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等,其中,通用处理器可以是微处理器或者任何常规的处理器等。
用户接口440包括使得能够呈现媒体内容的一个或多个输出装置441,包括一个或多个扬声器和/或一个或多个视觉显示屏。用户接口440还包括一个或多个输入装置442,包括有助于用户输入的用户接口部件,比如键盘、鼠标、麦克风、触屏显示屏、摄像头、其他输入按钮和控件。
存储器460可以是可移除的,不可移除的或其组合。示例性的硬件设备包括固态存储器,硬盘驱动器,光盘驱动器等。存储器460可选地包括在物理位置上远离处理器420的一个或多个存储设备。
存储器460包括易失性存储器或非易失性存储器,也可包括易失性和非易失性存储器两者。非易失性存储器可以是只读存储器(ROM,Read Only Memory),易失性存储器可以是随机存取存储器(RAM,Random Access Memory)。本申请实施例描述的存储器460旨在包括任意适合类型的存储器。
在一些实施例中,存储器460能够存储数据以支持各种操作,这些数据的示例包括程序、模块和数据结构或者其子集或超集,下面示例性说明。
操作系统461,包括用于处理各种基本系统服务和执行硬件相关任务的系统程序,例如框架层、核心库层、驱动层等,用于实现各种基础业务以及处理基于硬件的任务;
网络通信模块462,用于经由一个或多个(有线或无线)网络接口430到达其他电子设备,示例性的网络接口430包括:蓝牙、无线相容性认证(WiFi)、和通用串行总线(USB,Universal Serial Bus)等;
呈现模块463,用于经由一个或多个与用户接口440相关联的输出装置441(例如,显示屏、扬声器等)使得能够呈现信息(例如,用于操作外围设备和显示内容和信息的用户接口);
输入处理模块464,用于对一个或多个来自一个或多个输入装置442之一的一个或多个用户输入或互动进行检测以及翻译所检测的输入或互动。
在一些实施例中,本申请实施例提供的图像渲染装置可以采用软件方式实现,图2示出了存储在存储器460中的图像渲染装置465,其可以是程序和插件等形式的软件,包括以下软件模块:获取模块4651、转换模块4652、偏移模块4653、裁剪模块4654以及渲染模块4655,这些模块是逻辑上的,因此根据所实现的功能可以进行任意的组合或进一步拆分。
下面将结合附图对本申请实施例提供的图像渲染方法进行具体说明。本申请实施例提供的图像渲染方法可以由图1A中的终端400单独执行,也可以由图1B中的终端400和服务器200协同执行。
下面,以由图1A中的终端400单独执行本申请实施例提供的图像渲染方法为例进行说明。参见图3,图3是本申请实施例提供的图像渲染方法的流程示意图,将结合图3示出的步骤进行说明。
需要说明的是,图3示出的方法可以由终端400上运行的各种形式的计算机程序执行,并不局限于上述的客户端410,还可以是上文的操作系统461、软件模块和脚本,因此客户端不应视为对本申请实施例的限定。
在步骤101中,获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标。
例如,在三维渲染场景中,阴影投射对象包括多个顶点,阴影投射对象越精细,顶点的数量越多,基于顶点的图像渲染的计算也就越大。其中,每个顶点对应一个顶点坐标,该顶点坐标为三维坐标向量,包括顶点的x、y、z轴的坐标值。
在步骤102中,对每个顶点的顶点坐标进行坐标转换处理,得到每个顶点的转换坐标。在一些实施例中,坐标转换处理可以通过以下方式实现:对每个顶点的顶点坐标进行齐次化处理,得到每个顶点的齐次坐标;将每个顶点的齐次坐标转换至世界空间,得到每个顶点的世界空间坐标;将每个顶点的世界空间坐标转换至视投影空间,得到每个顶点在视投影空间的坐标,并作为转换坐标。
需要说明的是,每个顶点的顶点坐标为一个三维坐标向量,齐次坐标为一个四维坐标向量,将每个顶点的三维坐标向量与齐次值(齐次分量的值)进行拼接处理,得到每个顶点的四维坐标向量,以实现坐标齐次化,其中,齐次值为四维坐标向量的第四维数值。
作为一种示例,顶点的顶点坐标为v(vx,vy,vz),将顶点的三维坐标向量与齐次值进行拼接处理,得到顶点的四维坐标向量v1(vx,vy,vz,vw),其中,vw表示齐次值,例如,当顶点坐标为位置坐标向量时,vw为1,即顶点的四维坐标向量为v1(vx,vy,vz,1)。
在一些实施例中,对顶点坐标(本地坐标系的三维坐标向量)进行齐次化,得到四
维的齐次坐标v1(vx,vy,vz,1),再通过模型矩阵,将齐次坐标转换到世界空间,得到世界空间坐标v2=M×v1,再通过视投影矩阵,将世界空间坐标转换到视投影空间,得到转换坐标v3=VP×v2。其中,将每个顶点对应的旋转正交矩阵、平移矩阵以及缩放矩阵相乘,以得到每个顶点对应的模型矩阵,视投影矩阵是通过视空间矩阵以及投影矩阵相乘得到的。
例如,缩放矩阵其中,s1,s2,s3分别表示x、y、z三轴的缩放系数,平移矩阵其中Tx,Ty,Tz分别是x、y、z三轴的平移量,缩放矩阵其中α,β,γ分别是翻滚角(roll)、俯仰角(pitch)和偏航角(yaw)。将旋转正交矩阵、平移矩阵以及缩放矩阵相乘,得到每个顶点对应的模型矩阵
在步骤103中,对每个顶点的转换坐标进行深度偏移处理,得到每个顶点的深度偏移坐标。
例如,在顶点着色器中对阴影投影对象的顶点的深度进行偏移(即对顶点的转换坐标进行深度偏移),利用渲染管线的深度剔除功能,巧妙地自动丢弃阴影投影对象隐藏的片段,避免使用片段丢弃功能,实现在无额外开销的情况下支持投射阴影渲染过程的几何裁剪,以实现高效的渲染。
参见图4,图4是本申请实施例提供的图像渲染方法的一个可选的流程示意图,图4示出图3中的步骤103可以通过步骤1031-步骤1032实现:在步骤1031中,获取每个顶点的转换坐标中的深度分量,并获取每个顶点的世界空间坐标;在步骤1032中,基于每个顶点的世界空间坐标,对每个顶点的转换坐标中的深度分量进行更新处理,将更新后的深度分量作为每个顶点的深度偏移坐标。
需要说明的是,针对步骤1032进行以下说明:由于投射阴影所用的渲染对象(即阴影投射对象)不需要进行深度比较,阴影投射对象在渲染过程中输出固定的颜色值,没有前后之分,所以在投射阴影渲染过程中,转换坐标(即顶点在视投影空间的坐标,简称视投影空间坐标)中的z值(即深度分量)只用于裁剪。基于渲染管线的裁剪空间,可以对阴影投射对象的视投影空间坐标的z值(即深度分量)进行如下方式的更新:使得顶点的z值刚好处于裁剪分界点。即可利用管线裁剪对阴影投射对象进行裁剪。
设阴影投射对象的某个顶点的本地坐标为v(vx,vy,vz),本地坐标齐次化为v1(vx,vy,vz,1),经过模型矩阵M左乘之后,得到世界空间坐标v2=M×v1,再和视投影矩阵VP左乘之后,得到转换坐标v3=VP×v2,此时v3.x/v3.w、v3.y/v3.w分别表示标准设备空间坐标(即顶点在标准设备空间坐标系的坐标)的横坐标和纵坐标,而v3.z/v3.w表示深度值,v3.z表示转换坐标中的深度分量。
参见图5,图5是本申请实施例提供的图像渲染方法的一个可选的流程示意图,图5示出图4中的步骤1032可以通过步骤10321-步骤10323实现。
在步骤10321中,获取阴影投射对象的阴影接收对象。
在步骤10322中,基于每个顶点的世界空间坐标以及阴影投射对象的阴影接收对象,
确定每个顶点相对于阴影接收对象的相对高度。
在一些实施例中,当阴影接收对象为非水平面时,步骤10322可以通过以下方式实现:确定阴影接收对象的平面参数向量;将阴影接收对象的平面参数向量转换至世界空间,得到阴影接收对象在世界空间的平面参数向量;将阴影接收对象在世界空间的平面参数向量与每个顶点的世界空间坐标的乘积,作为每个顶点相对于阴影接收对象的相对高度。
例如,在特殊的虚拟场景中,当阴影接收对象为非水平面,具有倾斜度时,需要将阴影接收对象的平面参数向量也转换至世界空间中,并将阴影接收对象在世界空间的平面参数向量与每个顶点的世界空间坐标的乘积,作为每个顶点相对于阴影接收对象的相对高度,从而准确地计算每个顶点相对于阴影接收对象的相对高度,以便后续基于每个顶点相对于阴影接收对象的相对高度,对每个顶点的转换坐标中的深度分量进行更新。
在一些实施例中,上述的将阴影接收对象的平面参数向量转换至世界空间,得到阴影接收对象在世界空间的平面参数向量,可以通过以下方式实现:获取阴影接收对象的模型矩阵;将模型矩阵的转置矩阵的逆矩阵、与阴影接收对象的平面参数向量相乘,得到阴影接收对象在世界空间的平面参数向量。
需要说明的是,获取阴影接收对象的一般平面方程,例如Ax+By+Cz+D=0,记平面参数向量为P=(A,B,C,D)。例如,对于水平面的平面方程为y=0,本地空间的平面参数向量为P=(0,1,0,0)。模型矩阵为M’,那么世界空间的平面参数向量为P’=((M’)T)-1×P,其中,((M’)T)-1表示模型矩阵的转置矩阵的逆矩阵。
在一些实施例中,当阴影接收对象为水平面时,步骤10322可以通过以下方式实现:将每个顶点的世界空间坐标中的纵坐标作为每个顶点相对于阴影接收对象的相对高度。
承接上述示例,在大多数虚拟场景中,阴影接收对象为水平面,即平面参数向量为P=(0,1,0,0),当阴影接收对象为水平面时,直接将每个顶点的世界空间坐标中的纵坐标作为每个顶点相对于阴影接收对象的相对高度,则每个顶点将节约一次点乘计算(即P’·v2)。
在步骤10323中,基于每个顶点相对于阴影接收对象的相对高度,对每个顶点的转换坐标中的深度分量进行更新处理,将更新后的深度分量作为每个顶点的深度偏移坐标。
需要说明的是,考虑到阴影接收对象,计算每个顶点相对于阴影接收对象的相对高度,基于每个顶点相对于阴影接收对象的相对高度,对每个顶点的转换坐标中的深度分量进行更新处理,避免阴影投射对象投影到阴影接收对象时,出现投影错误。
在一些实施例中,当阴影渲染视角为透视投影时,即转换坐标中的齐次分量v3.w不等于1时,步骤10323可以通过以下方式实现:基于每个顶点相对于阴影接收对象的相对高度以及齐次分量,对每个顶点的转换坐标中的深度分量进行更新处理,将更新后的深度分量作为每个顶点的深度偏移坐标。
在一些实施例中,基于每个顶点相对于阴影接收对象的相对高度以及齐次分量,对每个顶点的转换坐标中的深度分量进行更新处理可以通过以下方式实现:获取虚拟场景的最大显示高度;将每个顶点相对于阴影接收对象的相对高度与最大显示高度的倒数相乘,得到第二乘积结果;将第二乘积结果与裁剪阈值的差值与齐次分量相乘,得到第三乘积结果,并将每个顶点的转换坐标中的深度分量更新为第三乘积结果。
例如,当阴影渲染视角为透视投影,即齐次分量v3.w不等于1时,更新过程为v3.z=v3.w*((P’·v2)*k-1),其中,P’·v2表示顶点相对于阴影接收对象的相对高度,k表示一个固定系数(用于将v3.z/v3.w控制在裁剪范围之间),设置为虚拟场景的最大显示高度的倒数,裁剪阈值为1,v3.w表示齐次分量。
在一些实施例中,当阴影渲染视角为正交投影时,步骤10323可以通过以下方式实
现:获取虚拟场景的最大显示高度;将每个顶点相对于阴影接收对象的相对高度与最大显示高度的倒数相乘,得到第一乘积结果;确定第一乘积结果与裁剪阈值的差值,并将每个顶点的转换坐标中的深度分量更新为差值。
例如,当阴影渲染视角为正交投影,即转换坐标中的齐次分量v3.w等于1时,更新过程为v3.z=(P’·v2)*k-1,其中,P’·v2表示顶点相对于阴影接收对象的相对高度,k表示一个固定系数(用于将v3.z/v3.w控制在裁剪范围之间),设置为虚拟场景的最大显示高度的倒数,裁剪阈值为1,从而节省一次乘法指令(即v3.w*(.))。
因此,深度分量进行更新之后,标准设备空间坐标的z值与世界空间坐标的y值存在以下关系:世界空间坐标中的y值大于0的顶点在标准设备空间坐标中的v3.z/v3.w会大于-1,而世界空间坐标中的y值小于0的顶点在标准设备空间坐标中的v3.z/v3.w会小于-1。由于在光栅化成片段的过程中,片段的标准设备空间坐标是随着顶点的标准设备空间坐标线性插值而来的,若标准设备空间坐标的z值与世界空间坐标的y值保持以上关系,在经过裁剪之后,世界空间坐标中y值小于0的片段会被完全剔除,不会发送到片段着色器,从而阴影投射对象被阴影接收对象遮挡的部分不会呈现出来。
在步骤104中,基于每个顶点的深度偏移坐标对阴影投射对象进行裁剪处理,得到裁剪后的阴影投射对象。
在一些实施例中,步骤104可以通过以下方式实现:对阴影投射对象的深度偏移坐标进行标准化处理,得到标准化后的深度偏移坐标;当标准化后的深度偏移坐标处于裁剪范围时,保留标准化后的深度偏移坐标对应的阴影投射对象;当标准化后的深度偏移坐标超出所述裁剪范围时,裁剪掉标准化后的深度偏移坐标对应的阴影投射对象,以得到裁剪后的阴影投射对象。
例如,对阴影投射对象的深度偏移坐标进行标准化处理可以通过以下方式实现:将阴影投射对象的深度偏移坐标除以视投影坐标的齐次分量(即转换坐标的齐次分量),得到标准化后的深度偏移坐标v3.z/v3.w,当v3.z/v3.w处于裁剪范围[-1,1]时,保留v3.z/v3.w对应的部分阴影投射对象,当v3.z/v3.w超出裁剪范围[-1,1]时,裁剪掉v3.z/v3.w对应的部分阴影投射对象,以得到裁剪后的阴影投射对象,后续对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影。
在步骤105中,对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影。
如图7所示,对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影,以正常显示阴影投射模型601(即阴影投射对象)的投影阴影。
在一些实施例中,对裁剪后的阴影投射对象进行阴影渲染处理,得到阴影投射对象的投射阴影,可以通过以下方式实现:对裁剪后的阴影投射对象进行阴影贴图渲染处理,得到裁剪后的阴影投射对象的阴影贴图;基于阴影贴图对裁剪后的阴影投射对象进行基础着色处理,得到阴影投射对象的投射阴影。
例如,裁剪后的阴影投射对象渲染到阴影贴图(即阴影贴图渲染)时,不会包含世界坐标y值小于0的部分,如图7所示,将阴影贴图投射到阴影接收对象的时候(即基础着色)就可以看到阴影接收对象以下的部分不会有影子出现在阴影接收对象上。
需要说明的是,场景渲染(即对包括阴影投射对象的虚拟场景进行渲染的过程)中的阴影渲染包含阴影阶段(即阴影贴图渲染过程)和基础着色阶段(即基础着色过程),在阴影阶段中,裁剪后的阴影投射对象会经过矩阵变换到光空间坐标系(以光源为原点的坐标系)中,将裁剪后的阴影投射对象在光空间坐标系的深度值渲染到一张阴影贴图,得到裁剪后的阴影投射对象的阴影贴图;在基础着色阶段中,裁剪后的阴影投射对象会经过矩阵变换到最终渲染的投影空间坐标系中,光栅化之后进行着色,在着色的时候根
据阴影贴图的深度值进行判断当前像素是否在阴影内,从而进行光照着色,得到阴影投射对象的投射阴影。其中,判断当前像素是否在阴影内的过程如下:遍历阴影贴图中的像素,当遍历到的当前像素的深度值处于阴影范围内时,确定当前像素在阴影内;当遍历到的当前像素的深度值超出阴影范围时,确定当前像素不在阴影内。
其中,两个阶段都会用到完整的GPU渲染管线,包括顶点着色、光栅化计算和像素着色计算,但是绘制的视角不同,绘制到的目标缓冲区不同,绘制所用的着色方法不同。
其中,GPU渲染管线包括以下处理:对每个顶点的转换坐标进行光栅化处理,得到每个顶点对应的像素,对每个顶点对应的像素进行着色处理,得到每个像素对应的颜色,对每个像素对应的颜色进行测试以及混合处理,得到渲染结果。其中,渲染结果可以是上述两个阶段的输出,例如阴影阶段的裁剪后的阴影投射对象的阴影贴图,基础着色阶段的投射阴影。
例如,在渲染初始化时,顶点信息(即顶点的顶点坐标)通过图形接口传入GPU,当渲染调用发生时,顶点通过GPU渲染管线的计算,最后输出到屏幕缓冲区中,进行画面呈现。GPU渲染管线会将顶点信息作为输入,然后基于顶点信息进行顶点着色器的计算,得到统一的转换坐标后,传入光栅化阶段进行光栅化计算,然后进行像素着色计算,最后进行测试、混合,得到渲染结果,将渲染结果输出到帧缓冲,进行画面呈现。其中,测试过程包括深度测试以及模板测试。
下面,将说明本申请实施例在一个实际的应用场景中的示例性应用。
本申请实施例可以应用于各种游戏的渲染场景,例如对抗游戏、赛车游戏、变装游戏等。下面以虚拟场景为游戏为例进行说明。
相关技术中,三维场景的模型(即阴影投影对象)需要在CPU端读取数据并传输给GPU,调用GPU进行渲染。在GPU中的渲染过程中,会经过GPU渲染管线的一连串计算,其中,顶点着色器用于确定顶点的投影空间坐标,光栅化器用于将转换到标准设备空间坐标系的图元光栅化成多个像素,并将多个像素提交给片段着色器进行最终颜色的确定。在需要进行裁剪的场景中,模型需要在渲染交互中进行实时的几何裁切。在GPU片段着色器中利用片段丢弃功能,但由于所有的片段都需要进行几何裁剪测试,带来额外的着色器计算开销,且开启片段丢弃会使得渲染管线的Early-Z功能失效,造成渲染流水线的效率降低。
为了解决上述问题,本申请实施例基于光栅化器的视锥体裁剪特性在顶点着色器中修改深度,从而达到几何裁剪的目的。在实现几何裁剪的同时能够不带来额外的性能消耗,可以被广泛应用于三维模型的投射阴影渲染中,提升总体渲染的性能。
下面结合图6所示的场景说明投射阴影方案。
图6的左侧部分是场景的大纲视图,场景包括渲染主视角相机(Main Camera)、方向性光源(Directional Light)、模型(Model)和阴影接收平面(Plane)。其中,方向性光源有两个子节点,分别是用来渲染投射阴影的阴影相机组件(Shadow Camera)和用来将阴影结果投射到阴影接收面的投射器组件(Projector)。模型包含6个阴影投射模型601(即阴影投射对象),分别拥有不同的位移和旋转。
图6的右侧部分可以看出投射阴影技术已经在运行之中了,但6个阴影投射模型601由于没有进行相交处理,会将阴影投射模型低于接收平面的部分602(即被接收平面遮挡的部分)也渲染出来,并投射到阴影接收平面上,造成错误的阴影渲染结果。
打开投射阴影所使用的着色器文件,如下所示:
其中,vert表示顶点着色器,用于对模型进行坐标变换并输出裁剪空间坐标;frag表示片段着色器,用于对所有片段输出0.04的阴影颜色值。
本申请实施例将着色器文件按照以下内容进行改写:
保存着色器文件的修改,并回到渲染场景中,如图7所示,阴影渲染结果恢复正常,正常显示6个阴影投射模型601的阴影,阴影投射模型601低于接收平面的部分(即被接收平面遮挡的部分)不会渲染出来。在无额外开销的情况下,使投射阴影兼容了阴影投影者与阴影接收者相交的情况,兼具高性能和适用性。
在应用了本申请实施例提供的修改后的着色器文件之后,相比于相关技术中的渲染方式,能够在保持阴影渲染结果精度不变的情况下,提升渲染的性能。使得在单位时间下,GPU能够绘制的顶点数量得到提升。
图像渲染发生过程中,在渲染初始化时,顶点信息通过图形接口传入GPU,当渲染调用发生时,顶点信息通过GPU渲染管线的计算,最后输出到屏幕缓冲区中,进行画
面呈现。
如图8所示,在渲染调用发生时的阶段为GPU渲染管线。GPU渲染管线会将顶点信息作为输入,然后基于顶点信息进行顶点着色器的计算,得到统一的转换坐标后,传入光栅化阶段进行光栅化计算,然后进行像素着色计算,最后进行测试、混合,得到渲染结果,将渲染结果输出到帧缓冲,进行画面呈现。
其中,在顶点着色计算中,顶点需要从本地坐标系的三维向量进行齐次化,得到四维齐次化坐标,之后采用模型矩阵左乘四维齐次化坐标,得到世界空间下的齐次坐标,再用视投影矩阵左乘世界空间下的齐次坐标,得到投影空间下的四维坐标,并将投影空间下的四维坐标(即投影空间坐标)输出,进行光栅化计算。
在光栅化计算中,投影空间坐标会进行透视除法,也就是除以w分量,得到标准设备空间坐标,之后将阴影投射模型中的三角形光栅化为片段(包括多个像素),并且截取坐标范围从(-1,-1,-1)到(1,1,1)的片段集合,将截取的片段发送至片段着色器进行着色。其中,x和y分量分别代表片段在缓冲区的横坐标和纵坐标,而z分量用于表示深度关系,在渲染管线中,这个z分量会与深度缓冲中对应的深度值进行比较,确定是否需要被渲染,例如当z分量大于深度缓冲区中对应的深度值时,确定片段不需要被渲染;当z分量小于或者等于深度缓冲区中对应的深度值时,确定片段需要被渲染。
由于投射阴影所用的渲染对象不需要进行深度比较,阴影投射模型在渲染过程中输出固定的颜色值,没有前后之分,所以在投射阴影渲染过程中,z分量只用于裁剪。基于渲染管线的裁剪空间和z分量,可以对阴影投射模型的投影空间坐标的z分量进行偏移,使得顶点的z分量刚好处于裁剪分界点-1或者1处,即可利用管线裁剪(即光栅化器的视锥体裁剪特性)对阴影投射模型进行裁剪。
设阴影投射模型的某个顶点的本地坐标为v(vx,vy,vz),本地坐标齐次化为v1(vx,vy,vz,1),经过模型矩阵M左乘之后,得到世界空间坐标v2=M×v1,再和视投影矩阵VP左乘之后,得到v3=VP×v2,此时v3.x/v3.w、v3.y/v3.w分别表示标准设备空间坐标的横坐标和纵坐标,而v3.z/v3.w表示深度值。这里在渲染视角为正交投影时,w分量为1,在渲染视角为透视投影时,w分量不为1,例如方向性光源的阴影渲染就可以看作是正交投影,此时如果需要对世界空间中低于地面(y值小于0)的部分进行剔除,则可以对v3.z进行偏移,如公式(1)所示:
v3.z=v3.w*(v2.y*k-1) (1)
v3.z=v3.w*(v2.y*k-1) (1)
其中,v2.y表示顶点的世界空间坐标的y值,k表示一个固定系数(用于将v3.z/v3.w控制在(-1,1)之间),设置为虚拟场景的最大高度的倒数,例如虚拟场景中模型的最大高度不超过20,k可以设置为0.05。
于是,阴影投射模型中,世界空间坐标中的y值大于0的顶点在标准设备空间坐标中的z值会大于-1,而世界空间坐标中的y值小于0的顶点在标准设备空间坐标中的z值会小于-1。在光栅化成片段时,片段的标准设备空间坐标随着顶点的标准设备空间坐标线性插值而来,标准设备空间坐标的z值与世界空间坐标的y值保持以上关系,在经过裁剪之后,世界空间坐标中y值小于0的片段被完全剔除,不会发送到片段着色器。
在经过这个变换之后,阴影投射模型渲染到阴影贴图时不会包含世界坐标y值小于0的部分,如图7所示,将阴影贴图投射到阴影接收者的时候就可以看到地平面以下的部分(即被阴影接收者遮挡的部分)不会有影子出现在地面(即阴影接收者)上。需要说明的是,在阴影渲染时,包含阴影阶段和基础着色阶段,在阴影阶段时,裁剪后的阴影投射模型会经过矩阵变换到光空间坐标系中,将裁剪后的阴影投射对象在光空间坐标系的深度值渲染到一张阴影贴图,得到裁剪后的阴影投射对象的阴影贴图;在基础着色阶段,裁剪后的阴影投射对象会经过矩阵变换到最终渲染的投影空间坐标系中,光栅化
之后进行着色,在着色的时候根据阴影贴图的深度值判断当前像素是否在阴影内,从而进行光照着色。其中,两个阶段都会用到完整的GPU渲染管线,包括顶点着色、光栅化计算和像素着色计算,但是绘制的视角不同,绘制到的目标缓冲区不同,绘制所用的着色方法不同。
需要说明的是,如果地面不在水平面上,或者带有倾斜,需要先获取平面的一般方程,例如Ax+By+Cz+D=0,记参数向量为(A,B,C,D)。例如,对于在本地空间中过0点且平行向上的平面,平面方程为y=0,本地空间的参数向量为P=(0,1,0,0),在经过变换之后,模型矩阵为M’,那么世界空间下的平面方程参数向量如公式(2)所示:
P’=((M’)T)-1×P (2)
P’=((M’)T)-1×P (2)
其中,((M’)T)-1表示模型矩阵的转置的逆。
将参数P’传入顶点着色器中,并将v3.z进行偏移,如公式(3)所示:
v3.z=v3.w*((P’·v2)*k-1) (3)
v3.z=v3.w*((P’·v2)*k-1) (3)
其中,P’·v2表示平面方程参数向量P’点乘顶点的世界空间坐标v2,即世界空间中顶点到平面的距离。
在经过这个变换之后,阴影投射模型渲染到阴影贴图时不会包含平面以下的部分,如图9所示,平面901不是水平面,具有倾斜度,将阴影贴图投射到平面901的时候就可以看到平面以下的部分不会有影子出现在地面上。
另外,在不同的图形API下,标准设备空间坐标系的裁剪范围不相同,一种是DirectX类,裁剪范围是0到1,另一种是OpenGL类,裁剪范围是-1到1。因此在考虑多平台时,需要进行如下改写:
本申请实施例所需要的额外计算量为每个顶点一次乘加指令(正交投影时),当需要接收平面(即阴影接收对象)需要一般性变换时,每个顶点还需要额外一次点乘计算(即P’·v2),这个计算量在GPU计算中可以忽略不计。
综上,在相关技术中,将世界空间坐标传输到片段着色器中并利用片段丢弃指令进行裁剪,然后顶点着色器向片段着色器传输一组插值向量,并对片段进行裁剪测试和片段丢弃,使得渲染管线的片段输出不可预测,影响Early-Z和其他GPU特性,带来较低的运行效率。对此,本申请实施例在顶点着色器中对阴影投影者的顶点深度进行偏移,利用渲染管线的深度剔除功能,巧妙地将相交于阴影接收者后方的片段(即被阴影接收者遮挡的片段)自动丢弃,避免使用片段丢弃,实现在无额外开销的情况下支持投射阴影渲染过程的几何裁剪,以实现高效的渲染,且同样兼具兼容性和可用性,能够进一步降低投射阴影的整体开销。
至此已经结合本申请实施例提供的终端或服务器的示例性应用和实施,说明本申请实施例提供的图像渲染方法,下面继续说明本申请实施例提供的图像渲染装置465中各个模块配合实现图像渲染方案。
获取模块4651,配置为获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标;转换模块4652,配置为对每个所述顶点的顶点坐标进行坐标转换处理,得到每个所述顶点的转换坐标;偏移模块4653,配置为对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标;裁剪模块4654,配置为基于每
个所述顶点的深度偏移坐标对所述阴影投射对象进行裁剪处理,得到裁剪后的所述阴影投射对象;渲染模块4655,用于对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影。
在一些实施例中,所述偏移模块4653还配置为获取每个所述顶点的转换坐标中的深度分量,并获取每个所述顶点的世界空间坐标;基于每个所述顶点的世界空间坐标,对每个所述顶点的转换坐标中的深度分量进行更新处理,将更新后的所述深度分量作为每个所述顶点的深度偏移坐标。
在一些实施例中,所述偏移模块4653还配置为获取所述阴影投射对象的阴影接收对象;基于每个所述顶点的世界空间坐标以及所述阴影投射对象的阴影接收对象,确定每个所述顶点相对于所述阴影接收对象的相对高度;基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理,得到每个所述顶点的深度偏移坐标。
在一些实施例中,所述偏移模块4653还配置为当所述阴影接收对象为水平面时,将每个所述顶点的世界空间坐标中的纵坐标作为每个所述顶点相对于所述阴影接收对象的相对高度。
在一些实施例中,所述偏移模块4653还配置为当所述阴影接收对象为非水平面时,确定所述阴影接收对象的平面参数向量;将所述阴影接收对象的平面参数向量转换至世界空间,得到所述阴影接收对象在所述世界空间的平面参数向量;将所述阴影接收对象在所述世界空间的平面参数向量与每个所述顶点的世界空间坐标的乘积,作为每个所述顶点相对于所述阴影接收对象的相对高度。
在一些实施例中,所述偏移模块4653还配置为获取所述阴影接收对象的模型矩阵;将所述模型矩阵的转置矩阵的逆矩阵、与所述阴影接收对象的平面参数向量相乘,得到所述阴影接收对象在所述世界空间的平面参数向量。
在一些实施例中,当阴影渲染视角为正交投影时,所述偏移模块4653还配置为获取所述虚拟场景的最大显示高度;将每个所述顶点相对于所述阴影接收对象的相对高度与所述最大显示高度的倒数相乘,得到第一乘积结果;将所述第一乘积结果与裁剪阈值的差值,并将每个所述顶点的转换坐标中的深度分量更新为所述差值。
在一些实施例中,当阴影渲染视角为透视投影时,所述基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理之前,所述偏移模块4653还配置为获取每个所述顶点的转换坐标中的齐次分量;基于每个所述顶点相对于所述阴影接收对象的相对高度以及齐次分量,对每个所述顶点的转换坐标中的深度分量进行更新处理。
在一些实施例中,所述偏移模块4653还配置为获取所述虚拟场景的最大显示高度;将每个所述顶点相对于所述阴影接收对象的相对高度与所述最大显示高度的倒数相乘,得到第二乘积结果;将所述第二乘积结果与裁剪阈值的差值与所述齐次分量相乘,得到第三乘积结果,并将每个所述顶点的转换坐标中的深度分量更新为所述第三乘积结果。
在一些实施例中,所述裁剪模块4654还配置为对所述阴影投射对象的深度偏移坐标进行标准化处理,得到标准化后的所述深度偏移坐标;当标准化后的所述深度偏移坐标处于裁剪范围时,保留标准化后的所述深度偏移坐标对应的所述阴影投射对象;当标准化后的所述深度偏移坐标超出所述裁剪范围时,裁剪掉标准化后的所述深度偏移坐标对应的所述阴影投射对象。
在一些实施例中,所述渲染模块4655还配置为对裁剪后的所述阴影投射对象进行阴影贴图渲染处理,得到裁剪后的所述阴影投射对象的阴影贴图;基于所述阴影贴图对裁剪后的所述阴影投射对象进行基础着色处理,得到所述阴影投射对象的投射阴影。
本申请实施例提供了一种计算机程序产品,该计算机程序产品包括计算机程序或可执行指令,该计算机程序或可执行指令存储在计算机可读存储介质中。电子设备的处理器从计算机可读存储介质读取该计算机程序或可执行指令,处理器执行该计算机程序或可执行指令,使得该电子设备执行本申请实施例上述的图像渲染方法。
本申请实施例提供一种存储有计算机程序或可执行指令的计算机可读存储介质,其中存储有计算机程序或可执行指令,当计算机程序或可执行指令被处理器执行时,处理器执行本申请实施例提供的图像渲染方法,例如,如图3-图5示出的图像渲染方法。
在一些实施例中,计算机可读存储介质可以是FRAM、ROM、PROM、EPROM、EEPROM、闪存、磁表面存储器、光盘、或CD-ROM等存储器;也可以是包括上述存储器之一或任意组合的各种设备。
在一些实施例中,可执行指令可以采用程序、软件、软件模块、脚本或代码的形式,按任意形式的编程语言(包括编译或解释语言,或者声明性或过程性语言)来编写,并且其可按任意形式部署,包括被部署为独立的程序或者被部署为模块、组件、子例程或者适合在计算环境中使用的其它单元。
作为示例,可执行指令可以但不一定对应于文件系统中的文件,可以可被存储在保存其它程序或数据的文件的一部分,例如,存储在超文本标记语言(HTML,Hyper Text Markup Language)文档中的一个或多个脚本中,存储在专用于所讨论的程序的单个文件中,或者,存储在多个协同文件(例如,存储一个或多个模块、子程序或代码部分的文件)中。
作为示例,可执行指令可被部署为在一个电子设备上执行,或者在位于一个地点的多个电子设备上执行,又或者,在分布在多个地点且通过通信网络互连的多个电子设备上执行。
以上所述,仅为本申请的实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和范围之内所作的任何修改、等同替换和改进等,均包含在本申请的保护范围之内。
Claims (15)
- 一种图像渲染方法,由电子设备执行,所述方法包括:获取虚拟场景中阴影投射对象的多个顶点,其中,每个所述顶点对应一个顶点坐标;对每个所述顶点的顶点坐标进行坐标转换处理,得到每个所述顶点的转换坐标;对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标;基于每个所述顶点的深度偏移坐标对所述阴影投射对象进行裁剪处理,得到裁剪后的所述阴影投射对象;对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影。
- 根据权利要求1所述的方法,其中,所述对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标,包括:获取每个所述顶点的转换坐标中的深度分量,并获取每个所述顶点的世界空间坐标;基于每个所述顶点的世界空间坐标,对每个所述顶点的转换坐标中的深度分量进行更新处理,将更新后的所述深度分量作为每个所述顶点的深度偏移坐标。
- 根据权利要求2所述的方法,其中,所述基于每个所述顶点的世界空间坐标,对每个所述顶点的转换坐标中的深度分量进行更新处理,包括:获取所述阴影投射对象的阴影接收对象;基于每个所述顶点的世界空间坐标以及所述阴影投射对象的阴影接收对象,确定每个所述顶点相对于所述阴影接收对象的相对高度;基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理。
- 根据权利要求3所述的方法,其中,所述基于每个所述顶点的世界空间坐标以及所述阴影投射对象的阴影接收对象,确定每个所述顶点相对于所述阴影接收对象的相对高度,包括:当所述阴影接收对象为水平面时,将每个所述顶点的世界空间坐标中的纵坐标作为每个所述顶点相对于所述阴影接收对象的相对高度。
- 根据权利要求3所述的方法,其中,所述基于每个所述顶点的世界空间坐标以及所述阴影投射对象的阴影接收对象,确定每个所述顶点相对于所述阴影接收对象的相对高度,包括:当所述阴影接收对象为非水平面时,确定所述阴影接收对象的平面参数向量;将所述阴影接收对象的平面参数向量转换至世界空间,得到所述阴影接收对象在所述世界空间的平面参数向量;将所述阴影接收对象在所述世界空间的平面参数向量与每个所述顶点的世界空间坐标的乘积,作为每个所述顶点相对于所述阴影接收对象的相对高度。
- 根据权利要求5所述的方法,其中,所述将所述阴影接收对象的平面参数向量转换至世界空间,得到所述阴影接收对象在所述世界空间的平面参数向量,包括:获取所述阴影接收对象的模型矩阵;将所述模型矩阵的转置矩阵的逆矩阵、与所述阴影接收对象的平面参数向量相乘,得到所述阴影接收对象在所述世界空间的平面参数向量。
- 根据权利要求3所述的方法,其中,当阴影渲染视角为正交投影时,所述基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理,包括:获取所述虚拟场景的最大显示高度;将每个所述顶点相对于所述阴影接收对象的相对高度与所述最大显示高度的倒数相乘,得到第一乘积结果;确定所述第一乘积结果与裁剪阈值的差值,并将每个所述顶点的转换坐标中的深度分量更新为所述差值。
- 根据权利要求3所述的方法,其中,当阴影渲染视角为透视投影时,所述基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理之前,所述方法还包括:获取每个所述顶点的转换坐标中的齐次分量;所述基于每个所述顶点相对于所述阴影接收对象的相对高度,对每个所述顶点的转换坐标中的深度分量进行更新处理,包括:基于每个所述顶点相对于所述阴影接收对象的相对高度以及齐次分量,对每个所述顶点的转换坐标中的深度分量进行更新处理。
- 根据权利要求8所述的方法,其中,所述基于每个所述顶点相对于所述阴影接收对象的相对高度以及齐次分量,对每个所述顶点的转换坐标中的深度分量进行更新处理,包括:获取所述虚拟场景的最大显示高度;将每个所述顶点相对于所述阴影接收对象的相对高度与所述最大显示高度的倒数相乘,得到第二乘积结果;将所述第二乘积结果与裁剪阈值的差值与所述齐次分量相乘,得到第三乘积结果,并将每个所述顶点的转换坐标中的深度分量更新为所述第三乘积结果。
- 根据权利要求1所述的方法,其中,所述基于所述阴影投射对象的深度偏移坐标对所述阴影投射对象进行裁剪处理,包括:对所述阴影投射对象的深度偏移坐标进行标准化处理,得到标准化后的所述深度偏移坐标;当标准化后的所述深度偏移坐标处于裁剪范围时,保留标准化后的所述深度偏移坐标对应的所述阴影投射对象;当标准化后的所述深度偏移坐标超出所述裁剪范围时,裁剪掉标准化后的所述深度偏移坐标对应的所述阴影投射对象。
- 根据权利要求1所述的方法,其中,所述对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影,包括:对裁剪后的所述阴影投射对象进行阴影贴图渲染处理,得到裁剪后的所述阴影投射对象的阴影贴图;基于所述阴影贴图对裁剪后的所述阴影投射对象进行基础着色处理,得到所述阴影投射对象的投射阴影。
- 一种图像渲染装置,所述装置包括:获取模块,配置为获取虚拟场景中阴影投射对象的多个顶点,其中,每个顶点对应一个顶点坐标;转换模块,配置为对每个所述顶点的顶点坐标进行坐标转换处理,得到每个所述顶点的转换坐标;偏移模块,配置为对每个所述顶点的转换坐标进行深度偏移处理,得到每个所述顶点的深度偏移坐标;裁剪模块,配置为基于每个所述顶点的深度偏移坐标对所述阴影投射对象进行裁剪处理,得到裁剪后的所述阴影投射对象;渲染模块,配置为对裁剪后的所述阴影投射对象进行阴影渲染处理,得到所述阴影投射对象的投射阴影。
- 一种电子设备,所述电子设备包括:存储器,用于存储计算机程序或可执行指令;处理器,用于执行所述存储器中存储的计算机程序或可执行指令时,实现权利要求1至11任一项所述的图像渲染方法。
- 一种计算机可读存储介质,存储有计算机程序或可执行指令,用于被处理器执行时实现权利要求1至11任一项所述的图像渲染方法。
- 一种计算机程序产品,包括计算机程序或可执行指令,所述计算机程序或可执行指令被处理器执行时实现权利要求1至11任一项所述的图像渲染方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210412423.9A CN116958390A (zh) | 2022-04-19 | 2022-04-19 | 一种图像渲染方法、装置、设备、存储介质及程序产品 |
CN202210412423.9 | 2022-04-19 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023202254A1 true WO2023202254A1 (zh) | 2023-10-26 |
Family
ID=88419063
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/080513 WO2023202254A1 (zh) | 2022-04-19 | 2023-03-09 | 图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN116958390A (zh) |
WO (1) | WO2023202254A1 (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117472592A (zh) * | 2023-12-27 | 2024-01-30 | 中建三局集团有限公司 | 基于顶点着色器与纹理映射的三维模型爆炸方法及系统 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6593923B1 (en) * | 2000-05-31 | 2003-07-15 | Nvidia Corporation | System, method and article of manufacture for shadow mapping |
CN102129677A (zh) * | 2010-01-15 | 2011-07-20 | 富士通株式会社 | 阴影形成方法和系统 |
CN103198516A (zh) * | 2011-11-29 | 2013-07-10 | 苹果公司 | 动态图形界面阴影 |
CN112419472A (zh) * | 2019-08-23 | 2021-02-26 | 南京理工大学 | 一种基于虚拟阴影图的增强现实实时阴影生成方法 |
CN114307139A (zh) * | 2021-12-29 | 2022-04-12 | 网易(杭州)网络有限公司 | 游戏场景中虚拟自然现象的生成方法和装置 |
-
2022
- 2022-04-19 CN CN202210412423.9A patent/CN116958390A/zh active Pending
-
2023
- 2023-03-09 WO PCT/CN2023/080513 patent/WO2023202254A1/zh unknown
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6593923B1 (en) * | 2000-05-31 | 2003-07-15 | Nvidia Corporation | System, method and article of manufacture for shadow mapping |
CN102129677A (zh) * | 2010-01-15 | 2011-07-20 | 富士通株式会社 | 阴影形成方法和系统 |
CN103198516A (zh) * | 2011-11-29 | 2013-07-10 | 苹果公司 | 动态图形界面阴影 |
CN112419472A (zh) * | 2019-08-23 | 2021-02-26 | 南京理工大学 | 一种基于虚拟阴影图的增强现实实时阴影生成方法 |
CN114307139A (zh) * | 2021-12-29 | 2022-04-12 | 网易(杭州)网络有限公司 | 游戏场景中虚拟自然现象的生成方法和装置 |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117472592A (zh) * | 2023-12-27 | 2024-01-30 | 中建三局集团有限公司 | 基于顶点着色器与纹理映射的三维模型爆炸方法及系统 |
CN117472592B (zh) * | 2023-12-27 | 2024-03-19 | 中建三局集团有限公司 | 基于顶点着色器与纹理映射的三维模型爆炸方法及系统 |
Also Published As
Publication number | Publication date |
---|---|
CN116958390A (zh) | 2023-10-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2023160054A1 (zh) | 一种图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 | |
CN110568923A (zh) | 基于Unity3D的虚拟现实交互方法、装置、设备及存储介质 | |
CN114067042A (zh) | 一种图像渲染方法、装置、设备、存储介质及程序产品 | |
CN114419099B (zh) | 捕捉待渲染虚拟对象的运动轨迹的方法 | |
WO2021253640A1 (zh) | 阴影数据确定方法、装置、设备和可读介质 | |
WO2023202254A1 (zh) | 图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 | |
CN112669194B (zh) | 虚拟场景中的动画处理方法、装置、设备及存储介质 | |
CN101477702A (zh) | 计算机显卡的植入式真三维立体驱动方法 | |
CN115082607B (zh) | 虚拟角色头发渲染方法、装置、电子设备和存储介质 | |
CN114359458A (zh) | 一种图像渲染方法、装置、设备、存储介质及程序产品 | |
CN113470153A (zh) | 虚拟场景的渲染方法、装置及电子设备 | |
CN115937389A (zh) | 阴影渲染方法、装置、存储介质和电子设备 | |
JP4073031B2 (ja) | プログラム、情報記憶媒体及び画像生成システム | |
CN114399580A (zh) | 一种图像渲染方法、装置、设备、存储介质及程序产品 | |
CN115970275A (zh) | 虚拟对象的投影处理方法、装置、存储介质与电子设备 | |
US7710419B2 (en) | Program, information storage medium, and image generation system | |
WO2023165198A1 (zh) | 图像渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品 | |
WO2021155688A1 (zh) | 图片处理方法、装置、存储介质及电子设备 | |
US8531453B2 (en) | Augmenting virtual worlds simulation with enhanced assets | |
US7724255B2 (en) | Program, information storage medium, and image generation system | |
US20240355035A1 (en) | Local space texture mapping based on reverse projection | |
Zhu et al. | Integrated Co-Designing Using Building Information Modeling and Mixed Reality with Erased Backgrounds for Stock Renovation | |
RU2810701C2 (ru) | Гибридный рендеринг | |
CN118537475A (zh) | 图像渲染方法、装置、电子设备、存储介质及程序产品 | |
JP2007272389A (ja) | プログラム、情報記録媒体および画像生成システム |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23790915 Country of ref document: EP Kind code of ref document: A1 |