Virtual scene rendering method, device and electronic equipment
By using a color buffer smaller than the screen buffer to render transparent objects and perform upsampling in virtual scene rendering, the problem of long rendering time and high computational pressure in virtual scene rendering is solved, achieving efficient rendering and good pictures. Effect.
Patent Information
- Application Number
- CN202110836252.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-23
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2041-07-23
AI Technical Summary
In the existing technology, in virtual scene rendering, the rendering size of the screen buffer is the same as the screen size, resulting in too many pixels and rendering taking too long. Especially when transparent objects are included, the calculation pressure is too high and rendering cannot be effectively reduced. pressure.
By creating a color buffer with a rendering size smaller than the screen buffer, render transparent objects in the virtual scene to the color buffer, perform upsampling during the rendering process, and finally render the result to the screen buffer for display, reducing the need for calculations The number of pixels reduces rendering pressure.
It effectively reduces the rendering time and calculation pressure while ensuring the picture effect, significantly improving the rendering efficiency and user experience.
Smart Images

Figure CN113470153B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer technology, and in particular to a virtual scene rendering method, device, electronic device and computer-readable storage medium. Background Art
[0002] With the rapid development of computer technology, virtual modeling technology has been widely used in game production, animation production and virtual reality (VR) and other fields. Through virtual modeling technology, virtual scenes that are different from the real world can be displayed on the screen, thus realizing a three-dimensional and realistic scene display.
[0003] In the solutions provided by related technologies, all objects in the virtual scene are usually rendered indiscriminately into the screen buffer, and then rendered to the screen through the screen buffer for display. However, the rendering size of the screen buffer is usually the same as the screen size, resulting in too many pixels to be calculated and too long rendering time; at the same time, when the virtual scene includes transparent objects, since the transparent objects cannot block or remove the objects behind them, there will be a situation where one pixel is drawn multiple times during rendering, resulting in excessive computing pressure. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and computer-readable storage medium for rendering a virtual scene, which can reduce rendering time and reduce computing pressure during rendering.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present application provides a method for rendering a virtual scene, including:
[0007] Create a color buffer with a rendering size smaller than the screen buffer;
[0008] Rendering the transparent objects in the virtual scene to the color buffer to obtain a first image;
[0009] Rendering the first image in the color buffer to the screen buffer, and performing upsampling processing during the rendering process to obtain a second image;
[0010] The second image in the screen buffer is rendered to a screen to display the second image on the screen.
[0011] The present application provides a virtual scene rendering device, including:
[0012] Create a module for creating a color buffer with a rendering size smaller than the screen buffer;
[0013] A first rendering module, used for rendering the transparent objects in the virtual scene into the color buffer to obtain a first image;
[0014] A second rendering module, used for rendering the first image in the color buffer to the screen buffer, and performing upsampling processing during the rendering process to obtain a second image;
[0015] The screen rendering module is used to render the second image in the screen buffer to the screen, so as to display the second image on the screen.
[0016] An embodiment of the present application provides an electronic device, including:
[0017] A memory for storing executable instructions;
[0018] The processor is used to implement the virtual scene rendering method provided in the embodiment of the present application when executing the executable instructions stored in the memory.
[0019] An embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute instructions to implement a virtual scene rendering method provided in an embodiment of the present application.
[0020] The embodiments of the present application have the following beneficial effects:
[0021] Render the transparent objects in the virtual scene to the color buffer, and then render them to the screen buffer by upsampling, and finally render from the screen buffer to the screen. Since the rendering size of the color buffer is smaller than the rendering size of the screen buffer, the number of pixels that need to be calculated (drawn) can be reduced, that is, the rendering pressure and rendering time can be reduced; at the same time, since transparent objects have little impact on the picture effect, the display effect of the virtual scene can also be guaranteed to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a schematic diagram of the architecture of a virtual scene rendering system provided in an embodiment of the present application;
[0023] Figure 2 It is a schematic diagram of the architecture of a terminal device provided in an embodiment of the present application;
[0024] Figure 3 It is a schematic diagram of the architecture of the virtual scene engine provided in the embodiment of the present application;
[0025] FIG. 4A to FIG. 4E It is a flowchart of a method for rendering a virtual scene provided in an embodiment of the present application;
[0026] Figure 5 is a schematic diagram of color mixing provided in an embodiment of the present application;
[0027] Figure 6 This is a schematic diagram of a process for dynamically turning on / off small-screen rendering provided in an embodiment of the present application;
[0028] Figure 7 is a rendering schematic diagram of a virtual scene provided in an embodiment of the present application;
[0029] Figure 8 is a schematic diagram of image comparison provided in an embodiment of the present application;
[0030] Fig.9A It is a schematic diagram of an image rendered according to a solution provided by the related art;
[0031] Fig. 9B is a schematic diagram of an image rendered according to the solution provided in an embodiment of the present application;
[0032] Fig. 10A It is a schematic diagram of rendering load in the solution provided by the related technology;
[0033] Fig. 10B This is a schematic diagram of the rendering load in the solution provided in the embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0035] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0036] In the following description, the terms "first\second\third" are only used to distinguish similar objects, and do not represent a specific order for the objects. It is understandable that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In the following description, the term "plurality" refers to at least two.
[0037] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0038] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0039] 1) Virtual scene: A scene that is different from the real world and output by an electronic device can form a visual perception of the virtual scene with the help of the naked eye or the equipment, such as a two-dimensional image output by a display screen, a three-dimensional image output by stereoscopic display technologies such as stereo projection, virtual reality and augmented reality technology; in addition, various possible hardware can be used to form various perceptions of the simulated real world, such as auditory perception, tactile perception, olfactory perception and motion perception. A virtual scene can be a simulation of the real world, a semi-simulated and semi-fictional virtual environment, or a purely fictional virtual environment. The embodiment of the present application does not limit the dimension of the virtual scene, for example, it can be a three-dimensional virtual scene.
[0040] 2) In response to: used to indicate the conditions or states on which the executed operations depend. When the dependent conditions or states are met, one or more operations executed may be in real time or have a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations executed are executed.
[0041] 3) Buffer: refers to the storage space located in the memory or video memory, which is used to store specific data. The embodiments of the present application involve a screen buffer, a color buffer and a depth buffer. Both the color buffer and the depth buffer may belong to a rendering target (RenderTarget), wherein the screen buffer refers to a buffer (such as Backbuffer) located in the video memory for screen image display, and the rendering size (or resolution) is consistent with the screen size; RenderTarget is a buffer located in the memory or video memory, and the rendering size may be inconsistent with the rendering size of the screen buffer. It is worth noting that for images (or image data) stored in the buffer, the size of the image is consistent with the rendering size of the buffer.
[0042] 4) Transparent objects: generally refer to objects in a virtual scene that cannot be blocked or removed. For example, transparent objects can refer to objects made of transparent materials.
[0043] 5) Upsampling: It is a method of enlarging an image in proportion to obtain a new image. In order to maintain the quality of the image during the enlargement process, interpolation can be used to fill in the missing pixels. Downsampling is similar to upsampling, except that downsampling refers to reducing the image in proportion.
[0044] 6) Pixel: refers to the element in the image that cannot be further divided.
[0045] 7) Virtual objects: images of various people and objects that can interact in a virtual scene, or movable objects in a virtual scene. The movable objects can be virtual characters, virtual animals, cartoon characters, etc., such as people, animals, plants, oil drums, walls, stones, etc. displayed in a virtual scene. The virtual object can be a virtual image in the virtual scene that represents the user. A virtual scene can include multiple virtual objects, each of which has its own shape and volume in the virtual scene and occupies a part of the space in the virtual scene.
[0046] The embodiments of the present application provide a method, device, electronic device and computer-readable storage medium for rendering a virtual scene, which can reduce rendering pressure and rendering time while ensuring the picture effect. The following describes an exemplary application of the electronic device provided by the embodiments of the present application. The electronic device provided by the embodiments of the present application can be implemented as various types of terminal devices or as a server.
[0047] See also Figure 1 , Figure 1 It is an architectural diagram of a virtual scene rendering system 100 provided in an embodiment of the present application, wherein a terminal device 400 is connected to a server 200 via a network 300, wherein the network 300 may be a wide area network or a local area network, or a combination of the two.
[0048] In some embodiments, taking the electronic device as a terminal device as an example, the rendering method of the virtual scene provided in the embodiment of the present application can be implemented by the terminal device. For example, the terminal device 400 can calculate the data required to display the virtual scene through the graphics computing hardware, and complete the loading, parsing and rendering of the display data, and output an image that can form a visual perception of the virtual scene with the help of graphics output hardware, for example, displaying an image of the virtual scene on the display screen of a smart phone, wherein the graphics computing hardware is such as a graphics processor (Graphics Processing Unit, GPU), and the graphics output hardware is such as a screen.
[0049] For example, the terminal device 400 can create a color buffer with a rendering size smaller than the screen buffer; render transparent objects in the virtual scene to the color buffer to obtain a first image; render the first image in the color buffer to the screen buffer, and perform upsampling during the rendering process to obtain a second image; render the second image in the screen buffer to the screen to display the second image on the screen.
[0050] In some embodiments, taking the electronic device as a server as an example, the virtual scene rendering method provided in the embodiment of the present application can also be implemented by the server and the terminal device in collaboration. For example, the server 200 calculates the display data related to the virtual scene and sends it to the terminal device 400, and the terminal device 400 relies on the graphics computing hardware to complete the loading, parsing and rendering of the display data, and relies on the graphics output hardware to output the image to form a visual perception.
[0051] In some embodiments, the terminal device 400 or the server 200 can implement the virtual scene rendering method provided in the embodiment of the present application by running a computer program, such as Figure 1 The client 410 shown. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, Application), that is, a program that needs to be installed in the operating system to run, such as a game application, etc.; it can also be a small program, that is, a program that can be run only after being downloaded to a browser environment; it can be a small program that can be embedded in any APP; it can also be a plug-in embedded in a virtual scene engine, wherein the plug-in can be controlled to run or closed by the user. In short, the above-mentioned computer program can be any form of application, module or plug-in. For game applications, it can be any type of first-person shooting (First-Person Shooting, FPS) games, third-person shooting (Third-Personal Shooting, TPS) games, multiplayer online tactical competitive (Multiplayer Online Battle Arena, MOBA) games, and multiplayer gun battle survival games, etc., without limitation.
[0052] In some embodiments, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, wherein the cloud service may be a data service for a virtual scene (for providing relevant data of a virtual scene) for the terminal device 400 to call. The terminal device 400 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart TV, a smart watch, etc., but is not limited thereto. The terminal device and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0053] Taking the electronic device provided in the embodiment of the present application as a terminal device as an example, it can be understood that in the case where the electronic device is a server, Figure 2 Some of the structures shown in FIG. 1 (such as the user interface, the presentation module, and the input processing module) may be omitted. Figure 2 , Figure 2 is a schematic diagram of the structure of a terminal device 400 provided in an embodiment of the present application, Figure 2 The terminal device 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the terminal device 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not shown in FIG. Figure 2 Various buses are labeled as bus system 440 .
[0054] Processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0055] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0056] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0057] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0058] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0059] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0060] A network communication module 452, used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0061] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., display screen, speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripherals and displaying content and information);
[0062] The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions.
[0063] In some embodiments, the virtual scene rendering device provided in the embodiments of the present application can be implemented in a software manner. Figure 2 A rendering device 455 of a virtual scene stored in a memory 450 is shown, which may be software in the form of a program or a plug-in, and includes the following software modules: a creation module 4551, a first rendering module 4552, a second rendering module 4553, and a screen rendering module 4554. These modules are logical, and thus may be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0064] See also Figure 3 , Figure 3 Schematic diagram of the principle of the virtual scene engine provided by the embodiment of the present application. In the case where the virtual scene is a game virtual scene, the virtual scene engine may be a game engine, such as Unreal Engine. Figure 3 As shown, the virtual scene engine includes but is not limited to a rendering component (such as a renderer), an editing component (such as an editor for editing / making a virtual scene), an underlying algorithm, a scene management (for managing multiple sub-scenes in a virtual scene), a sound effect (for managing the audio corresponding to the virtual scene), a script engine, and a camera component. The virtual scene rendering method provided in the embodiment of the present application can be Figure 2The various modules in the rendering device 455 of the virtual scene shown call Figure 3 The implementation of the related components of the virtual scene engine shown is illustrated below with examples.
[0065] For example, the creation module 4551 is used to call the rendering component in the virtual scene engine to create a color buffer whose rendering size is smaller than the screen buffer; the first rendering module 4552 is used to call the rendering component to render the transparent objects in the virtual scene to the color buffer to obtain a first image; the second rendering module 4553 is used to call the rendering component to render the first image in the color buffer to the screen buffer, and perform upsampling during the rendering process to obtain a second image; the screen rendering module 4554 is used to call the rendering component to render the second image in the screen buffer to the screen to display the second image on the screen.
[0066] Of course, the above examples do not constitute a limitation on the embodiments of the present application. The various components included in the virtual scene engine and the calling relationship between the various modules in the virtual scene rendering device 455 and the components in the virtual scene engine can all be adjusted according to the actual application scenario.
[0067] The method for rendering a virtual scene provided in the embodiment of the present application will be described in combination with the exemplary application and implementation of the electronic device provided in the embodiment of the present application.
[0068] See also Figure 4A , Figure 4A is a flowchart of a method for rendering a virtual scene provided in an embodiment of the present application, which will be combined with Figure 4A The steps shown are explained.
[0069] In step 101, a color buffer having a rendering size smaller than a screen buffer is created.
[0070] For example, a color buffer with a rendering size (or resolution) smaller than the screen buffer can be created for rendering transparent objects in a virtual scene, that is, small-screen rendering. The color buffer can be used to store information such as pixel color and transparency.
[0071] The embodiment of the present application does not limit the rendering size ratio between the screen buffer and the color buffer, and can be set according to the actual application scenario, for example, the rendering size of the screen buffer: the rendering size of the color buffer = 4:1.
[0072] It is worth noting that the color space used to represent colors in the embodiments of the present application is not limited, and may be, for example, RGB color space, CMYK color space, or Lab color space.
[0073] In some embodiments, the above-mentioned creation of a color buffer with a rendering size smaller than the screen buffer can be achieved in the following manner: a color buffer with a rendering size smaller than the screen buffer is created in the video memory. For example, the color buffer can be created in the tile storage space of the GPU, where the tile storage space is a high-speed storage space in the GPU. In this way, the problem of low data transmission efficiency and large power consumption caused by copying data back and forth between the GPU and the memory can be effectively solved, and the computing resource overhead in the rendering process can be reduced.
[0074] In step 102, transparent objects in the virtual scene are rendered into a color buffer to obtain a first image.
[0075] For example, a transparent object in a virtual scene is rendered to a color buffer in units of pixels to obtain a first image. It is worth noting that the first image here can also be referred to as first image data, which includes a plurality of pixels and colors corresponding to the plurality of pixels (and may also include transparency corresponding to the pixels), and the following intermediate images, second images, etc. are similar.
[0076] In some embodiments, the above-mentioned rendering of transparent objects in the virtual scene to the color buffer can be achieved in the following manner: when the optimized rendering conditions are met, the transparent objects in the virtual scene are rendered to the color buffer; wherein the optimized rendering conditions include at least one of the following: the sub-scene to be rendered of the virtual scene belongs to the optimized sub-scene; wherein the optimized sub-scene includes at least part of the sub-scenes in the virtual scene; the number of transparent objects with optimized rendering parameters in the virtual scene is greater than a quantity threshold; the scene parameters of the virtual scene are greater than a scene parameter threshold; wherein the scene parameters include at least one of the interaction parameters of the virtual objects, the number of virtual objects, and the device resource usage parameters.
[0077] In an embodiment of the present application, optimized rendering conditions can be set for small-screen rendering. When the optimized rendering conditions are met, it is determined to turn on the small-screen rendering, and the transparent objects in the virtual scene are rendered to the color buffer. When the optimized rendering conditions are not met, it is determined to turn off the small-screen rendering, and all objects in the virtual scene are rendered to the non-optimized buffer (i.e., large-screen rendering is performed). The non-optimized buffer will be explained in detail later.
[0078] Optimizing rendering conditions may include at least one of the following:
[0079] 1) The sub-scene currently to be rendered in the virtual scene belongs to the optimized sub-scene, wherein the virtual scene includes multiple sub-scenes, and the optimized sub-scene includes at least part of the sub-scenes in the virtual scene. For example, there are multiple copies in the game virtual scene, and each copy corresponds to a sub-scene; for another example, there are multiple areas in the game virtual scene, and each area corresponds to a sub-scene.
[0080] 2) The number of transparent objects with optimized rendering parameters in the virtual scene is greater than a quantity threshold, wherein the rendering parameters of the transparent objects may include optimized rendering parameters and non-optimized rendering parameters, the optimized rendering parameters are used to indicate that the transparent object needs to be rendered on a small screen, and the non-optimized rendering parameters are used to indicate that the transparent object does not need to be rendered on a small screen.
[0081] 3) The current scene parameter of the virtual scene is greater than the scene parameter threshold. The scene parameter includes at least one of the interaction parameter of the virtual object, the number of virtual objects, and the device resource usage parameter. The larger the scene parameter, the greater the rendering pressure. The scene parameter threshold can be set accordingly according to the type of scene parameter. Among them, the virtual object can refer to all virtual objects in general, or to a specific one or several virtual objects, such as a virtual character; the interaction parameter can include at least one of the number of interaction operations and the execution frequency, and the interaction operation can include at least one of the attack operation and the collaborative operation; the device resource usage parameter can include at least one of the central processing unit (CPU) usage rate and the GPU usage rate of the electronic device.
[0082] Through the above method, when the optimized rendering conditions are met, it is proved that the rendering pressure is large, so small-screen rendering is turned on, thereby reducing the overhead of computing resources and improving rendering efficiency; when the optimized rendering conditions are not met, it is proved that the rendering pressure is within an acceptable range, so small-screen rendering is turned off, thereby improving the accuracy of the final displayed image.
[0083] In some embodiments, the virtual scene includes multiple sub-scenes, and between any steps, it also includes: performing at least one of the following processing: in response to an optimized rendering configuration operation for at least part of the sub-scenes in the virtual scene, using at least part of the sub-scenes as optimized sub-scenes; screening and processing the multiple sub-scenes according to historical scene parameters corresponding to the multiple sub-scenes, to obtain optimized sub-scenes.
[0084] The present application embodiment provides the following two methods to determine the optimized sub-scenario:
[0085] 1) In response to the optimized rendering configuration operation for at least part of the sub-scenes in the virtual scene, the at least part of the sub-scenes is used as the optimized sub-scenes. For example, relevant personnel of the virtual scene (such as product personnel, planners, etc.) can configure each sub-scene in the virtual scene separately, that is, whether to use it as an optimized sub-scene. In this way, the degree of freedom in determining the optimized sub-scenes can be improved, and relevant personnel are supported to configure according to actual rendering needs.
[0086] 2) Filter multiple sub-scenes according to the historical scene parameters corresponding to the multiple sub-scenes to obtain optimized sub-scenes. For example, for each sub-scene, obtain the scene parameters in the historical time period as the historical scene parameters. Then, the sub-scene corresponding to the historical scene parameters greater than the scene parameter threshold can be used as the optimized sub-scene; or, the multiple sub-scenes can be sorted in descending order according to the historical scene parameters, and the sub-scenes in the TOP K after sorting are used as the optimized sub-scenes, where K is an integer greater than 0.
[0087] The above two methods can be used either one or in combination to improve flexibility.
[0088] In some embodiments, between any steps, it also includes: performing at least one of the following processing: in response to an optimized rendering configuration operation for at least a portion of the transparent objects in the virtual scene, updating the rendering parameters of at least a portion of the transparent objects to optimized rendering parameters; determining the types of multiple transparent objects in the virtual scene, and updating the rendering parameters of the transparent objects that meet the type conditions to optimized rendering parameters.
[0089] In the embodiment of the present application, the rendering parameters of the transparent objects in the virtual scene may be defaulted to non-optimized rendering parameters, and the rendering parameters may be updated by at least one of the following two methods:
[0090] 1) In response to an optimized rendering configuration operation for at least a portion of transparent objects in a virtual scene, the rendering parameters of the at least a portion of transparent objects are updated to optimized rendering parameters. In this way, it is possible to support personnel related to the virtual scene to manually configure transparent objects. For example, for some unimportant transparent objects, the corresponding rendering parameters can be configured to optimized rendering parameters. In addition, in response to a non-optimized rendering configuration operation for at least a portion of transparent objects in a virtual scene, the rendering parameters of the at least a portion of transparent objects can be updated to non-optimized rendering parameters.
[0091] 2) Determine the types of multiple transparent objects in the virtual scene, and update the rendering parameters of the transparent objects that meet the type conditions to the optimized rendering parameters. For example, the type conditions may include some types that have little impact on the picture effect, such as water (more natural transition), transparent particles (short duration), etc. For transparent objects belonging to these types, the corresponding rendering parameters are automatically updated to the optimized rendering parameters.
[0092] In step 103, the first image in the color buffer is rendered to the screen buffer, and up-sampling is performed during the rendering process to obtain a second image.
[0093] For example, the first image in the color buffer is rendered to the screen buffer. Since the screen buffer and the color buffer correspond to different rendering sizes, upsampling processing can be performed during the rendering process according to the rendering size ratio between the screen buffer and the color buffer to obtain the second image, wherein the size of the second image is consistent with the rendering size of the screen buffer.
[0094] In step 104 , the second image in the screen buffer is rendered to the screen to display the second image on the screen.
[0095] For example, the second image in the screen buffer is rendered to the screen (or user interface) to display the second image on the screen, that is, to realize the display of the transparent object in the virtual scene.
[0096] like Figure 4A As shown, the embodiment of the present application realizes the rendering of transparent objects through small-screen rendering, which can reduce the number of pixels that need to be calculated, thereby reducing the calculation pressure during rendering and improving rendering efficiency; at the same time, compared with non-transparent objects, transparent objects have less impact on the picture effect, and therefore, can also guarantee the quality of the final displayed image to a certain extent.
[0097] In some embodiments, see Figure 4B , Figure 4B is a flowchart of a method for rendering a virtual scene provided in an embodiment of the present application. Figure 4A The illustrated step 102 can be implemented through steps 201 to 203 , which will be described in conjunction with each step.
[0098] In step 201, a plurality of transparent objects corresponding to a first pixel in a first image are traversed and processed; wherein the first pixel represents any pixel in the first image.
[0099] For example, a blank first image is initialized in the color buffer, and an arbitrary pixel in the first image (hereinafter named the first pixel for ease of explanation) is taken as an example to illustrate the process of rendering a transparent object to the color buffer. First, multiple transparent objects that need to be rendered to the first pixel in the virtual scene are determined as the multiple transparent objects corresponding to the first pixel, and then the multiple transparent objects corresponding to the first pixel are traversed.
[0100] It is worth noting that a transparent object needs to be rendered to the first pixel, which means that at least a part of the transparent object needs to be rendered to the first pixel. In the rendered first image, a transparent object can be represented by at least one pixel.
[0101] In some embodiments, before step 201, it also includes: sorting multiple transparent objects in the virtual scene according to transparent object parameters to obtain a rendering order; wherein the transparent object parameters include at least one of depth, volume, and complexity; the above-mentioned traversal processing of multiple transparent objects corresponding to the first pixel in the first image can be achieved in this way: traversing the multiple transparent objects corresponding to the first pixel according to the rendering order.
[0102] For example, transparent object parameters corresponding to multiple transparent objects in the virtual scene may be determined, and the transparent object parameters may include at least one of depth, volume, and complexity. Then, the multiple transparent objects in the virtual scene are sorted according to the transparent object parameters to obtain a rendering order of the transparent objects, wherein the sorting process may be performed according to the order of transparent object parameters from large to small, but this does not constitute a limitation on the embodiments of the present application.
[0103] After the rendering order of the transparent objects is obtained, the multiple transparent objects corresponding to the first pixel can be traversed and processed according to the rendering order. In this way, orderly rendering can be achieved, and the effectiveness and accuracy of the rendering process can be improved.
[0104] In step 202, color mixing processing is performed according to the color of the traversed transparent object, the transparency of the traversed transparent object, the color of the first pixel, and the complementary transparency of the traversed transparent object to obtain a new color of the first pixel.
[0105] Here, for the traversed transparent objects, in the process of color mixing, the transparency of the traversed transparent objects can be used as the weight of the color of the traversed transparent objects, and the complementary transparency of the traversed transparent objects can be used as the weight of the color of the first pixel. The color of the traversed transparent objects and the color of the first pixel are weighted and summed to obtain a new color of the first pixel.
[0106] The sum of the transparency of the traversed transparent object and the complementary transparency of the traversed transparent object is 1, where 1 refers to the maximum transparency.
[0107] In step 203, transparency mixing processing is performed according to the transparency of the traversed transparent object and the transparency of the first pixel to obtain a new transparency of the first pixel.
[0108] For example, the complementary transparency of the traversed transparent object and the transparency of the first pixel may be multiplied to obtain a new transparency of the first pixel.
[0109] When the new color and new transparency of the first pixel are determined, the next transparent object is traversed until all transparent objects corresponding to the first pixel are traversed, and the rendering of the first pixel is completed. For other pixels in the first image, the above steps 201 to 203 can also be referred to for rendering transparent objects.
[0110] It is worth noting that in the embodiment of the present application, color and transparency can be represented by the RGBA color space, where RGB is used to represent color and A is used to represent transparency. In this case, the process of rendering the transparent object in the virtual scene to the color buffer to obtain the first image is essentially the process of updating the values of the four channels R, G, B, and A corresponding to the pixels in the first image. When initializing the first image, each pixel in the first image can be initialized to (0, 0, 0, 1), that is, the values corresponding to the three channels R, G, and B are all 0, and the value corresponding to the A channel is 1.
[0111] like Figure 4B As shown, the embodiment of the present application renders multiple transparent objects in sequence based on the mechanism of color mixing processing and transparency mixing processing, which can improve the effectiveness and accuracy of the rendering process.
[0112] In some embodiments, see Figure 4C , Figure 4C is a flowchart of a method for rendering a virtual scene provided in an embodiment of the present application. Figure 4A The illustrated step 103 can be implemented through steps 301 to 302 , which will be described in conjunction with each step.
[0113] In step 301, color mixing processing is performed according to the color of the first pixel in the first image, the transparency of the first pixel, and the color of the intermediate pixel in the intermediate image to obtain a new color of the intermediate pixel; wherein the first pixel represents any pixel in the first image, and the first pixel and the intermediate pixel correspond to the same pixel position; wherein the intermediate image is stored in the screen buffer and is used for upsampling processing to obtain the second image.
[0114] Here, for the convenience of explanation, the image stored in the screen buffer and to be up-sampled is named as an intermediate image, wherein the intermediate image has the same size as the first image.
[0115] In the process of rendering the first image in the color buffer to the screen buffer, taking the first pixel in the first image as an example, color mixing processing can be performed according to the color of the first pixel (referring to the color finally calculated), the transparency of the first pixel (referring to the transparency finally calculated), and the color of the middle pixel in the intermediate image (as the background color) to obtain a new color of the middle pixel, wherein the pixel position of the first pixel in the first image is the same as the pixel position of the middle pixel in the intermediate image.
[0116] For example, the transparency of the first pixel can be used as the weight of the color of the middle pixel, the weight of the color of the first pixel is set to 1 by default, and the color of the first pixel and the color of the middle pixel are weighted and summed to obtain a new color of the middle pixel.
[0117] For other pixels in the intermediate image, rendering can also be performed with reference to step 301 .
[0118] In step 302, pixel interpolation processing is performed on the intermediate image obtained by rendering based on the first image according to the rendering size ratio between the screen buffer and the color buffer to obtain a second image; wherein the size of the second image is the same as the rendering size of the screen buffer.
[0119] When rendering of each pixel in the intermediate image is completed (i.e., a new color is obtained), pixel interpolation processing is performed on the intermediate image according to the rendering size ratio between the screen buffer and the color buffer to obtain a second image, wherein the size of the second image is the same as the rendering size of the screen buffer, that is, the size ratio between the second image and the first image is consistent with the above-mentioned rendering size ratio.
[0120] The embodiment of the present application does not limit the algorithm used for pixel interpolation processing, for example, it can be a nearest neighbor interpolation algorithm, a linear interpolation algorithm, a bilinear interpolation algorithm or a bicubic interpolation algorithm.
[0121] like Figure 4C As shown, the embodiment of the present application combines the color mixing processing and the upsampling processing mechanism to achieve accurate rendering from a small screen to a large screen while saving the amount of calculation.
[0122] In some embodiments, see Figure 4D , Figure 4D is a flow chart of a method for rendering a virtual scene provided in an embodiment of the present application, based on Figure 4A , while executing step 102 or before executing step 102 , in step 401 , a plurality of transparent objects in the virtual scene may be traversed.
[0123] In an embodiment of the present application, the transparent object to be rendered for each pixel in the first image can be determined by a depth culling mechanism. First, multiple transparent objects in the virtual scene can be traversed, for example, multiple transparent objects in the virtual scene can be traversed according to the rendering order above.
[0124] In step 402, the traversed transparent object is rendered to a first depth buffer to obtain a first depth image; wherein the first depth buffer corresponds to the same rendering size as the screen buffer, and the first depth image includes a plurality of pixels and first depths corresponding to the plurality of pixels respectively.
[0125] Here, the traversed transparent object is rendered to the first depth buffer to obtain a first depth image, wherein the first depth buffer corresponds to the same rendering size as the screen buffer, and the first depth buffer is used to store depth information in the virtual scene. The obtained first depth image includes a plurality of pixels and depths corresponding to the plurality of pixels, respectively. For the sake of distinction, the depth in the first depth image is named the first depth.
[0126] In step 403, down-sampling processing is performed on the first depth image in the first depth buffer to obtain multiple down-sampling depths.
[0127] Since transparent objects in the virtual scene need to be rendered to the color buffer, and the color buffer and the first depth buffer correspond to different rendering sizes, in order to determine the transparent objects that need to be rendered for each pixel in the first image, the first depth image is downsampled here to obtain multiple downsampled depths, where one downsampled depth corresponds to multiple first depths in the first depth image.
[0128] In some embodiments, the above-mentioned downsampling processing of the first depth image in the first depth buffer to obtain multiple downsampling depths can be achieved in the following manner: determining the downsampling window according to the rendering size ratio between the screen buffer and the color buffer; performing sliding processing in the first depth image according to the downsampling window, and performing depth fusion processing on the first depth of the pixels covered by the downsampling window after each sliding processing to obtain the downsampling depth.
[0129] In an embodiment of the present application, the first depth image may be downsampled according to the ratio of the rendering size between the screen buffer and the color buffer. For example, first, the number of pixels covered by the downsampling window is determined according to the ratio of the rendering size between the screen buffer and the color buffer. For example, when the rendering size of the screen buffer: the rendering size of the color buffer = 4:1, it is determined that the downsampling window covers 4 pixels, wherein the shape of the downsampling window is not limited, for example, it may be a square.
[0130] Then, a sliding process is performed in the first depth image according to the determined downsampling window, and a depth fusion process is performed on the first depth of multiple pixels covered by the downsampling window after each sliding process to obtain the downsampling depth, until the downsampling window has covered all pixels in the first depth image. Among them, the downsampling window can be set not to cover the covered pixels, thereby improving the accuracy of downsampling; the depth fusion process can be an average process, taking the maximum value or taking the minimum value, etc. After experimental verification, taking the minimum value can obtain a better boundary effect.
[0131] In step 404, when any downsampled depth is less than the second depth corresponding to the same pixel position in the second depth image, the second depth is updated according to any downsampled depth, and the traversed transparent object is allowed to be rendered at the same pixel position in the first image.
[0132] For each downsampling depth obtained by the downsampling process (taking any downsampling depth as an example), when any downsampling depth is less than the second depth corresponding to the same pixel position in the second depth image, the second depth is updated according to the any downsampling depth (that is, the second depth is replaced with the any downsampling depth), and the traversed transparent object is allowed to be rendered at the same pixel position in the first image.
[0133] It is worth noting that the second depth image is located in the second depth buffer, wherein the rendering size ratio between the screen buffer and the color buffer is equal to the rendering size ratio between the first depth buffer and the second depth buffer. When initializing the second depth image, the depth (second depth) of each pixel included can be initialized to the maximum value within the depth value range to facilitate subsequent updates.
[0134] In step 405, when any downsampling depth is greater than or equal to the second depth, the second depth is kept unchanged, and rendering of the traversed transparent object at the same pixel position of the first image is prohibited; wherein the second depth image is stored in a second depth buffer, and the rendering size of the second depth buffer is smaller than the first depth buffer.
[0135] When any downsampling depth is greater than or equal to the second depth corresponding to the same pixel position in the second depth image, the second depth is kept unchanged, and rendering of the traversed transparent object at the same pixel position in the first image is prohibited.
[0136] like Figure 4D As shown, the embodiment of the present application can accurately determine the transparent objects that need to be rendered for each pixel in the first image through the depth culling processing mechanism, thereby ensuring the accuracy of the rendering process and saving computing resources in the rendering process.
[0137] In some embodiments, see Figure 4E , Figure 4E is a flowchart of a method for rendering a virtual scene provided in an embodiment of the present application. Figure 4A The illustrated step 102 may be updated to step 501, in which the optimized transparent objects in the virtual scene are rendered to the color buffer to obtain a first image; wherein the optimized transparent objects include any one of the following: all transparent objects in the virtual scene, and transparent objects in the virtual scene with optimized rendering parameters.
[0138] Here, the optimized transparent objects in the virtual scene can be rendered to the color buffer to obtain the first image. Specifically, it can refer to rendering all transparent objects in the virtual scene to the color buffer, or it can refer to rendering transparent objects with optimized rendering parameters in the virtual scene to the color buffer.
[0139] In some embodiments, before step 103, the method further includes: rendering non-optimized transparent objects and non-transparent objects in the virtual scene to a screen buffer.
[0140] For example, the non-optimized transparent objects and non-transparent objects in the virtual scene can be rendered to the screen buffer to obtain an intermediate image. Then, the first image in the color buffer is rendered to the screen buffer (i.e., rendered to the intermediate image obtained above), and upsampling is performed during the rendering process to obtain the second image. Finally, the second image in the screen buffer is rendered to the screen to display the second image on the screen.
[0141] like Figure 4E As shown, while, before or after executing step 501, in step 502, non-optimized transparent objects and non-transparent objects in the virtual scene can be rendered to a non-optimized buffer to obtain a third image; wherein the non-optimized buffer and the screen buffer have the same rendering size.
[0142] For objects in the virtual scene that are different from optimized transparent objects, large screen rendering can be enabled. For example, non-optimized transparent objects and non-transparent objects in the virtual scene can be rendered to the non-optimized buffer to obtain a third image, where non-optimized transparent objects refer to transparent objects that are different from optimized transparent objects, and non-transparent objects refer to objects that are different from transparent objects; the non-optimized buffer and the screen buffer have the same rendering size, and the non-optimized buffer can be a new screen buffer or a RenderTarget.
[0143] It is worth noting that the non-optimized transparent objects and non-transparent objects in the virtual scene can be rendered into the same non-optimized buffer, or the non-optimized transparent objects and non-transparent objects in the virtual scene can be rendered into different non-optimized buffers. The embodiments of the present application do not limit this.
[0144] exist Figure 4E middle, Figure 4A The illustrated step 104 may be updated to step 503 , in which the second image in the screen buffer and the third image in the non-optimized buffer are rendered to the screen together, so as to overlay and display the second image and the third image on the screen.
[0145] For example, the second image in the screen buffer and the third image in the non-optimized buffer are rendered to the screen together, so as to overlay the second image and the third image on the screen, that is, to display all objects in the virtual scene, thereby improving the rendering integrity of the virtual scene.
[0146] like Figure 4E As shown, the embodiment of the present application performs large-screen rendering on objects other than optimized transparent objects, which can improve the integrity of the rendering and ensure that all objects in the virtual scene (except objects prohibited from rendering) can be displayed on the screen.
[0147] Next, we will explain the exemplary application of the embodiment of the present application in actual application scenarios. First, we will introduce the rendering principle of the virtual scene. Figure 5 The schematic diagram shown is explained in step form.
[0148] 1) Set the render target (RenderTarget) or screen buffer as the canvas. RenderTarget refers to the intermediate buffer used to store image data during image rendering, corresponding to the color buffer mentioned above. Here, the rendering size of RenderTarget and the rendering size of the screen buffer are consistent with the screen size.
[0149] 2) Render the non-transparent objects in the virtual scene to the drawing board. When all non-transparent objects are rendered, set the color of a pixel (x, y) in the transparent object drawing area to Color 0 , used as the background color of transparent object 1 bg .
[0150] 3) Prepare to render the transparent object 1 in the virtual scene, such as Figure 5 As shown, set the blending formula of transparent object 1 to Color final =Color 1 *Alpha 1 +Color 0*(1-Alpha 1 ), where the color of transparent object 1 at pixel (x, y) is Color 1 (correspond Figure 5 Source Color), transparency is Alpha 1 (correspond Figure 5 Source transparency in Color, i.e. Source Alpha); 0 The background color bg (correspond Figure 5 The target color in (i.e. Dest Color), 1-Alpha 1 It can be regarded as the transparency of pixel (x, y); the color calculated by this mixing formula is Color final , Color final Used as the new color of the pixel (x, y). For transparent objects 2 that need to be rendered at pixel (x, y), Color final It becomes the new Color bg .
[0151] 4) Prepare to render transparent object 2 in the virtual scene. The blending formula is similar to that of transparent object 1. Then, after transparent object 2 is rendered at pixel (x, y), the color of pixel (x, y) is updated to Color final =(Color 1 *Alpha 1 +Color 0 *(1-Alpha 1 ))(1-Alpha 2 )+Color 2 *Alpha 2 .
[0152] 5) Similarly, after rendering multiple transparent objects, the final color of the pixel (x, y) is obtained. final , and output to the screen to complete the rendering.
[0153] However, when the virtual scene includes many transparent objects (such as a battle sub-scene in the game virtual scene includes many transparent particles), the transparent objects will be rendered in a RenderTarget or screen buffer with high precision (large rendering size). Since transparent objects cannot be blocked and removed, the transparent objects overlap seriously, and too many pixels need to be calculated for color and transparency (one pixel is drawn multiple times), which puts great pressure on the GPU. Therefore, in the embodiment of the present application, an off-screen rendering (small-screen rendering) method is adopted to render the transparent objects in the virtual scene that are more time-consuming to render into a RenderTarget whose rendering size is smaller than the screen buffer. Here, since the rendering area is small, the rendering can be completed at a faster speed. Then, the rendering results in the RenderTarget are upsampled back to the screen, which can significantly shorten the drawing process of transparent objects, improve the overall performance of the rendering process, and enhance the user experience.
[0154] For example, transparent objects that have little impact on resolution can be rendered into a RenderTarget whose rendering size is only 1 / 4 of the screen size. This greatly reduces the total number of pixels that need to be calculated, significantly improves the rendering performance of these transparent objects, and can also guarantee the picture effect to a certain extent. Among them, transparent objects that have little impact on resolution can include transparent objects with a relatively natural transition (such as water bodies) and transparent objects with a short duration (such as transparent particles). In addition, Figure 6 As shown, when the virtual scene includes a small number of transparent objects (such as the number of transparent objects is less than or equal to the number threshold), the small-screen rendering can be turned off through a dynamic switch to achieve better rendering effects. By using small-screen rendering through this dynamic strategy, a high and stable rendering speed can be obtained, while making the screen frame rate more stable and effectively reducing screen jitter.
[0155] The solution provided in the embodiment of the present application can be integrated into the rendering component of the virtual scene engine (such as Unreal Engine 4), and supports opening and closing through at least one of the following two strategies.
[0156] 1) Control the opening and closing through the console variables of the virtual scene engine. For example, relevant personnel of the virtual scene (such as product personnel, planners, etc.) can configure multiple sub-scenes in the virtual scene (such as copy sub-scenes, world area sub-scenes) one by one. For sub-scenes involving a large number of battles (or interactions) and / or high pressure on transparent object rendering, small-screen rendering can be set to be turned on; for single-player sub-scenes running pictures, small-screen rendering can be set to be turned off.
[0157] 2) Determine whether to turn on small screen rendering by automatically detecting the number of transparent objects. For example, the number of all transparent objects in the virtual scene that need to be rendered to the small screen can be determined, and the number can be compared with a preset number threshold. If the number is greater than the number threshold, small screen rendering is turned on to reduce rendering pressure; if the number is less than or equal to the number threshold, small screen rendering is turned off.
[0158] In an embodiment of the present application, the rendering parameters of transparent objects can default to Auto, which is used to indicate that transparent particles need to be rendered to a small screen, while other transparent objects do not need to be rendered to a small screen (i.e., large-screen rendering is required, where the large screen refers to the size of the screen). Of course, transparent objects can be forced to be rendered to a small screen, for example, by setting the rendering parameters to Force Down-sample Pass (corresponding to the optimized rendering parameters above); transparent objects can also be forced to be rendered to a large screen, for example, by setting the rendering parameters to Force Exclude Down-sample Pass.
[0159] As an example, the present application embodiment provides the following Figure 7 The rendering diagram of the virtual scene shown in Figure 7 In the process, the optimized transparent objects in the virtual scene (here refers to transparent objects with optimized rendering parameters) are rendered to RenderTarget, and then upsampled to the screen buffer. At the same time, the non-optimized transparent objects and non-transparent objects in the virtual scene are rendered to another screen buffer (corresponding to the non-optimized buffer above). Finally, multiple screen buffers are combined to perform superposition output of the picture to display on the screen. Among them, the screen size is 1366×752, and the rendering size of RenderTarget is 668×376, which is 1 / 4 of the screen size; Figure 7 The Load Action shown is a strategy for reading the color data required by the GPU from the memory to the GPU local storage. Load means completely copying the data from the memory to the GPU local storage (equivalent to memcpy on the CPU side), DontCare means discarding the data and not performing any operation (equivalent to keeping the GPU local storage in its original state), and Clear means discarding the data and setting the GPU local storage to the same default value (equivalent to memset on the CPU side). Figure 7The Store Action shown here refers to the strategy of writing the RenderTarget in the local Storage back to the memory after the GPU calculation is completed. Store means completely copying from the GPU local storage to the memory, and DontCare means not performing any operation. The data in the GPU local storage may be overwritten by other operations.
[0160] Next, we will combine Figure 7 The rendering process of the virtual scene in the embodiment of the present application is described in the form of steps for ease of understanding.
[0161] 1) Prepare an intermediate structure for storing small screen data. Here, a color buffer (i.e., color RenderTarget) with a rendering size smaller than the screen buffer can be created. The color buffer is used to store intermediate data such as color and transparency during the small screen rendering process.
[0162] 2) Prepare to perform depth culling on the small screen rendering process. For example, determine the first depth buffer (depth buffer, i.e., depth RenderTarget) corresponding to the virtual scene, which is used to store the depth information in the virtual scene, and the rendering size is consistent with the screen size. Then, downsample the data in the first depth buffer to obtain a second depth buffer, wherein one pixel in the second depth image of the second depth buffer corresponds to four pixels in the first depth image of the first depth buffer. During the downsampling process, a sliding process can be performed in the first depth image according to a downsampling window including four pixels, and a depth fusion process is performed on the depth of the four pixels covered by the downsampling window after each sliding process to obtain the depth of the corresponding pixel in the second depth image. Among them, the depth fusion process can be to take the maximum value or the minimum value.
[0163] As an example, the present application embodiment provides the following Figure 8 The comparison diagram shown in Figure 8 In FIG. 8 , an image 81 is shown which is finally displayed on the screen when the maximum value is taken during the downsampling process; and an image 82 is shown which is finally displayed on the screen when the minimum value is taken during the downsampling process. Figure 8 It can be determined that a better boundary effect can be obtained when the minimum value is taken. Therefore, during the downsampling process, the minimum depth among the four depths can be taken as the depth in the second depth image. The pseudo code is as follows:
[0164] Depth0=Texture2DSample(SourceTexture,SourceTextureSampler,LeftUpUV).r;
[0165] Depth1=Texture2DSample(SourceTexture,SourceTextureSampler,LeftDownUV).r;
[0166] Depth2=Texture2DSample(SourceTexture,SourceTextureSampler,RightUpUV).r;
[0167] Depth3=Texture2DSample(SourceTexture,SourceTextureSampler,RightDownUV).r;
[0168] OutDepth=min(min(Depth1,Depth0),min(Depth2,Depth3))
[0169] Among them, SourceTexture refers to the first depth buffer, which is a 2-dimensional depth data storage area. To retrieve one of the depths, you need to notify the specified vertical and horizontal coordinates, such as LeftUpUV; SourceTextureSampler is a sampler that takes data from the first depth buffer, and specifies the method of taking data. For example, you can get a single depth based on the LeftUpUV coordinate and return it, or you can get several depths around the coordinate and return them after averaging. The specific calculation is determined by the logic inside the sampler; LeftUpUV refers to the coordinate corresponding to the depth of the upper left corner of the four depths covered by the downsampling window, and the same applies to the other coordinates; Texture2Dsample refers to a function that takes data from the specified buffer to get the value of the corresponding coordinate.
[0170] 3) Determine whether to enable small screen rendering. For example, a comprehensive judgment can be made based on two conditions. When both conditions are met, small screen rendering will be enabled. When rendering the virtual scene in each frame, the pseudo code for determining whether to enable small screen rendering is as follows:
[0171] For all transparent objects in the virtual scene, perform the following processing:
[0172] When the rendering parameters of the transparent object are optimized rendering parameters (indicating that small-screen rendering is required), the small-screen count is +1;}
[0173] When the console variable of the virtual scene indicates that small screen rendering is performed and the small screen count is greater than the quantity threshold, the following processing is performed:
[0174] Enable small screen rendering;}
[0175] Among them, the small screen count can be initialized to zero during initialization.
[0176] 4) Set the mixing formula for small screen rendering and upsampling back to the large screen.
[0177] according to Figure 5 The transparent object rendering process shown can determine that the mixing formula for two transparent objects superimposed on the background color is:
[0178] Color final =(Color 1 *Alpha 1 +Color 0 *(1-Alpha 1 ))(1-Alpha 2 )+Color 2 *Alpha 2
[0179] Here, the background color 0 It has been involved in iteration since the first mix, but in the small screen rendering, the background color of the large screen is Color 0 It is mixed when the screen is restored to the large screen, so if you want to make the color of the small screen and the background color of the large screen 0 To get the same effect as normal transparent object rendering after mixing, you need to change the mixing formula. By transforming the above mixing formula, you can get:
[0180] =>Color final =Color 1 *Alpha 1 *(1-Alpha 2 )+Color 0 *(1-Alpha 1 )*(1-Alpha 2 )+Color 2 *Alpha 2
[0181] Here, if A = (1-Alpha 1 )*(1-Alpha 2 ) to the A channel of the RGBA four-channel, and the RGB channel saves RGB = Color 1 *Alpha 1 *(1-Alpha 2 )+Color 2 *Alpha 2, then when Upsampling back to the big screen, you can get the same calculation results as the normal big screen rendering process.
[0182] Therefore, the hybrid formula for small screen rendering can be determined as:
[0183] RGB=SourceColor*SourceAlpha+DestColor*ReverseSourceAlpha
[0184] A=DestAlpha*(1-SourceAlpha)+0
[0185] Among them, SourceColor indicates the color of the transparent object to be rendered this time, SourceAlpha indicates the transparency of the transparent object to be rendered this time, DestColor indicates the color of the pixel (background color), DestAlpha indicates the transparency of the pixel (background transparency), and ReverseSourceAlpha indicates the complementary transparency of the transparent object to be rendered this time, which is 1-SourceAlpha. The calculated A is the DestAlpha when rendering the next transparent object.
[0186] It is worth noting that in the formula for calculating the value of A, the value 0 is a format requirement in the engineering code, that is, in the engineering code, a mixed operation is generally the addition of two items.
[0187] In addition, the hybrid formula for rendering from the small screen back to the large screen can be determined as:
[0188] RGB=DestColor*SourceAlpha+SourceColor
[0189] Here, DestColor refers to the color (background color) of the large screen, SourceColor refers to the color finally calculated in the small screen, and SourceAlpha refers to the transparency finally calculated in the small screen.
[0190] For ease of understanding, the rendering is respectively (Color 1 , Alpha 1 ) and (Color 2 , Alpha 2 First, each pixel in the image of the small screen (corresponding to the first image above) is initialized to DestColor=0, DestAlpha=1.
[0191] In the first rendering, that is, rendering transparent objects (Color 1 , Alpha 1), the mixed formula is:
[0192] Colorfinal=Color 1 *Alpha 1 +0*(1-Alpha 1 )=Color 1 *Alpha 1
[0193] A=1*(1-Alpha 1 )=1-Alpha 1
[0194] In the second rendering, that is, rendering transparent objects (Color 2 , Alpha 2 ), the mixed formula is:
[0195] Colorfinal=Color 2 *Alpha 2 +Color 1 *Alpha 1 *(1-Alpha 2 )
[0196] A=1-Alpha 1 *(1-Alpha 2 )
[0197] When rendering back to the big screen, the blending formula is:
[0198] Colorfinal=Color 0 *(1-Alpha 1 *(1-Alpha 2 ))+Color 2 *Alpha 2 +Color 1 *Alpha 1 *(1-Alpha 2 )
[0199] This is consistent with the color obtained by normal large-screen rendering above.
[0200] It is worth mentioning that when rendering the small screen back to the large screen, it is first rendered to the screen buffer, and then rendered to the screen through the screen buffer. When rendering to the screen buffer, the length and width of the image need to be stretched twice, and the extra pixels can be calculated by interpolation RGB.
[0201] It is worth noting that when rendering the small screen back to the large screen, the obtained RGB can be used to display the screen, that is, the transparency effect can be reflected by RGB. The final calculated transparency can be ignored, and the transparency during display can be set to 0 by default, that is, the display window of the current virtual scene does not need to be transparent enough to see the desktop behind it. In this way, the data transmission process for transparency can be omitted, thereby reducing the transmission pressure.
[0202] 5) Bandwidth and memory-related optimization. In the above-mentioned small-screen rendering process, depth culling processing can be performed through the second depth buffer, thereby reducing the number of pixels that need to be calculated and optimizing memory and bandwidth usage. Here, the principle of depth culling processing is explained by taking the rendering of two transparent objects as an example. For example, the pixels in transparent objects A and transparent object B are far and near. A has two pixels Ap1 and Ap2, and B has two pixels Bp1 and Bp2. When displayed, it is possible that Ap1 blocks Bp1 and Bp2 blocks Ap2 at the same time, that is, both transparent objects can be seen partially and the other part is blocked. In view of this, if depth culling processing is not performed, A can only be drawn first and then B, resulting in the pixels of B completely covering A, or B can be drawn first and then A, resulting in the pixels of A completely covering B. Both methods will lead to incorrect drawing results. Therefore, the embodiment of the present application provides a mechanism for comparing the distance between pixels, that is, depth culling processing. For example, when drawing A first, the depths of Ap1 and Ap2 are written in the second depth buffer. Then, when drawing Bp1, it is found that Ap1 at the same position (i.e., the same pixel position) is closer to the observation point (smaller depth), then the color calculation result of Bp1 can be discarded, or there is no need to calculate the color of Bp1 at all, thereby ensuring that Ap1 can be located in the front. When drawing Bp2, it is found that the distance between Bp2 and the observation point is closer than Ap2, so the color of Bp2 is calculated and the color of Ap2 is overwritten (i.e., color mixing and transparency mixing are performed). In this way, it is ensured that Ap1 and Bp2 can be drawn correctly and then displayed accurately on the screen.
[0203] In addition, when creating a RenderTarget, you can set the flag Memoryless (for example, in iOS devices), so that the CPU does not need to allocate RT memory, and the GPU uses the Tile storage space to create the RenderTarget, where the Tile storage space is a high-speed storage space. In this way, the RenderTarget only occupies the graphics card space, not the memory space, which can effectively solve the problem of low data transmission efficiency and high power consumption caused by copying data back and forth between the GPU and the memory, and reduce the computing resource overhead during the rendering process.
[0204] The embodiments of the present application have at least the following technical effects: 1) The overall rendering speed of the GPU is accelerated, while the display effect is not greatly reduced. For the sake of convenience, the following is shown: Fig.9A The image rendered according to the solution provided by the related art is shown in FIG. 1 . The rendering time of the image is 7.6 milliseconds. Fig. 9B The image rendered according to the solution provided in the embodiment of the present application is shown, and the rendering time of the image is 4 milliseconds; 2) the computing load of the GPU is effectively reduced, Fig. 10A Shows Fig.9A The GPU usage (GUsage) during the rendering process of the corresponding image, the example value is 65%, Fig. 10B Shows Fig. 9B The example value of the GPU usage rate during the rendering process of the corresponding image is 32%. Therefore, the GPU load is significantly reduced by about 33% through the embodiment of the present application.
[0205] In addition to the above solutions, in the embodiments of the present application, the rendering pressure can be reduced and the rendering efficiency can be improved by reducing the complexity of transparent objects, reducing material nodes, and reducing shader complex functions.
[0206] The following is an exemplary structure of the virtual scene rendering device 455 provided in the embodiment of the present application being implemented as a software module. In some embodiments, for example Figure 2 As shown, the software modules in the rendering device 455 of the virtual scene stored in the memory 450 may include: a creation module 4551, used to create a color buffer with a rendering size smaller than the screen buffer; a first rendering module 4552, used to render transparent objects in the virtual scene to the color buffer to obtain a first image; a second rendering module 4553, used to render the first image in the color buffer to the screen buffer, and perform upsampling processing during the rendering process to obtain a second image; a screen rendering module 4554, used to render the second image in the screen buffer to the screen to display the second image on the screen.
[0207] In some embodiments, the first rendering module 4552 is also used to: traverse multiple transparent objects corresponding to the first pixel in the first image, and perform the following processing based on the traversed transparent objects: perform color mixing processing based on the color of the traversed transparent object, the transparency of the traversed transparent object, the color of the first pixel, and the complementary transparency of the traversed transparent object to obtain a new color for the first pixel; perform transparency mixing processing based on the transparency of the traversed transparent object and the transparency of the first pixel to obtain a new transparency for the first pixel; wherein the first pixel represents any pixel in the first image.
[0208] In some embodiments, the rendering device 455 of the virtual scene also includes a sorting module, which is used to sort multiple transparent objects in the virtual scene according to transparent object parameters to obtain a rendering order; wherein the transparent object parameters include at least one of depth, volume, and complexity; the first rendering module 4552 is also used to traverse multiple transparent objects corresponding to the first pixel according to the rendering order.
[0209] In some embodiments, the second rendering module 4553 is also used to: perform color mixing processing according to the color of the first pixel in the first image, the transparency of the first pixel, and the color of the intermediate pixel in the intermediate image to obtain a new color of the intermediate pixel; wherein the first pixel represents any pixel in the first image, and the first pixel and the intermediate pixel correspond to the same pixel position; wherein the intermediate image is stored in the screen buffer and is used to perform upsampling processing to obtain the second image.
[0210] In some embodiments, the first rendering module 4552 is also used to render transparent objects in the virtual scene to the color buffer when the optimized rendering conditions are met; wherein the optimized rendering conditions include at least one of the following: the sub-scene to be rendered of the virtual scene belongs to the optimized sub-scene; wherein the optimized sub-scene includes at least part of the sub-scenes in the virtual scene; the number of transparent objects with optimized rendering parameters in the virtual scene is greater than a quantity threshold; the scene parameters of the virtual scene are greater than a scene parameter threshold; wherein the scene parameters include at least one of the interaction parameters of the virtual objects, the number of virtual objects, and device resource usage parameters.
[0211] In some embodiments, the virtual scene includes multiple sub-scenes; the rendering device 455 of the virtual scene also includes a scene optimization module, which is used to perform at least one of the following processing: in response to an optimized rendering configuration operation for at least part of the sub-scenes in the virtual scene, at least part of the sub-scenes are used as optimized sub-scenes; and multiple sub-scenes are screened and processed according to historical scene parameters corresponding to the multiple sub-scenes to obtain optimized sub-scenes.
[0212] In some embodiments, the rendering device 455 of the virtual scene also includes a transparent object optimization module for performing at least one of the following processing: in response to an optimized rendering configuration operation for at least a portion of the transparent objects in the virtual scene, updating the rendering parameters of at least a portion of the transparent objects to optimized rendering parameters; determining the types of multiple transparent objects in the virtual scene, and updating the rendering parameters of the transparent objects that meet the type conditions to optimized rendering parameters.
[0213] In some embodiments, the rendering device 455 of the virtual scene also includes a depth culling module, which is used to: traverse multiple transparent objects in the virtual scene, and perform the following processing according to the traversed transparent objects: render the traversed transparent objects to a first depth buffer to obtain a first depth image; wherein the first depth buffer corresponds to the same rendering size as the screen buffer, and the first depth image includes multiple pixels and first depths corresponding to the multiple pixels respectively; downsample the first depth image in the first depth buffer to obtain multiple downsampled depths; when any downsampled depth is less than the second depth corresponding to the same pixel position in the second depth image, update the second depth according to any downsampled depth, and allow the traversed transparent object to be rendered at the same pixel position in the first image; when any downsampled depth is greater than or equal to the second depth, keep the second depth unchanged, and prohibit the traversed transparent object from being rendered at the same pixel position in the first image; wherein the second depth image is stored in the second depth buffer, and the rendering size of the second depth buffer is smaller than the first depth buffer.
[0214] In some embodiments, the depth culling module is also used to: determine the downsampling window based on the rendering size ratio between the screen buffer and the color buffer; perform sliding processing in the first depth image according to the downsampling window, and perform depth fusion processing on the first depth of the pixels covered by the downsampling window after each sliding processing to obtain the downsampling depth.
[0215] In some embodiments, the first rendering module 4552 is also used to: render the optimized transparent objects in the virtual scene to the color buffer; wherein the optimized transparent objects include any one of the following: all transparent objects in the virtual scene, transparent objects with optimized rendering parameters in the virtual scene; the second rendering module 4553 is also used to: render the non-optimized transparent objects and non-transparent objects in the virtual scene to the screen buffer.
[0216] In some embodiments, the first rendering module 4552 is also used to: render the optimized transparent objects in the virtual scene to the color buffer; wherein the optimized transparent objects include any one of the following: all transparent objects in the virtual scene, transparent objects with optimized rendering parameters in the virtual scene; the virtual scene rendering device 455 also includes a large screen rendering module, which is used to: render the non-optimized transparent objects and non-transparent objects in the virtual scene to the non-optimized buffer to obtain a third image; wherein the non-optimized buffer and the screen buffer correspond to the same rendering size; the screen rendering module 4554 is also used to render the second image in the screen buffer and the third image in the non-optimized buffer to the screen together, so as to superimpose the second image and the third image on the screen.
[0217] In some embodiments, the second rendering module 4553 is also used to: perform pixel interpolation processing on the intermediate image obtained by rendering based on the first image according to the rendering size ratio between the screen buffer and the color buffer, so as to obtain a second image; wherein the size of the second image is the same as the rendering size of the screen buffer.
[0218] The embodiment of the present application provides a computer program product or a computer program, which includes computer instructions (i.e., executable instructions), which are stored in a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the virtual scene rendering method described in the embodiment of the present application.
[0219] The present application embodiment provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the virtual scene rendering method provided by the present application embodiment, for example, Figure 4A , Figure 4B , Figure 4C , Figure 4D and Figure 4E A method for rendering a virtual scene is shown.
[0220] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.
[0221] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0222] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0223] As an example, the executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0224] The above are only embodiments of the present application and are not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A method for rendering a virtual scene, characterized in that: The method comprises: Create a color buffer with a rendering size smaller than the screen buffer; Rendering the transparent objects in the virtual scene to the color buffer to obtain a first image; Rendering non-transparent objects in the virtual scene to the screen buffer to obtain an intermediate image, wherein the screen buffer serves as a drawing board; When the non-transparent object is rendered, the first image is rendered to an intermediate image in the screen buffer according to the color of the first pixel in the first image, the transparency of the first pixel, and the color of the intermediate pixel in the intermediate image, and the intermediate image is upsampled during the rendering process to obtain a second image, wherein the size of the second image is the same as the size of the screen buffer; The second image in the screen buffer is rendered to a screen to display the second image on the screen.
2. The method according to claim 1, characterized in that The step of rendering the transparent object in the virtual scene to the color buffer to obtain a first image includes: Perform traversal processing on multiple transparent objects corresponding to the first pixel in the first image, and perform the following processing according to the traversed transparent objects: Performing color mixing processing according to the color of the traversed transparent object, the transparency of the traversed transparent object, the color of the first pixel, and the complementary transparency of the traversed transparent object to obtain a new color of the first pixel; Performing transparency mixing processing according to the transparency of the traversed transparent object and the transparency of the first pixel to obtain a new transparency of the first pixel; The first pixel represents any pixel in the first image.
3. The method according to claim 2, characterized in that Before traversing the plurality of transparent objects corresponding to the first pixel in the first image, the method further includes: Sorting multiple transparent objects in the virtual scene according to transparent object parameters to obtain a rendering order; Wherein, the transparent object parameter includes at least one of depth, volume, and complexity; The traversing process of the plurality of transparent objects corresponding to the first pixel in the first image includes: A plurality of transparent objects corresponding to the first pixel are traversed and processed according to the rendering order.
4. The method according to claim 1, characterized in that: The rendering of the first image to the intermediate image in the screen buffer according to the color of the first pixel in the first image, the transparency of the first pixel, and the color of the intermediate pixel in the intermediate image comprises: Performing a color mixing process according to the color of the first pixel in the first image, the transparency of the first pixel, and the color of the intermediate pixel in the intermediate image to obtain a new color of the intermediate pixel; The first pixel represents any pixel in the first image, and the first pixel and the intermediate pixel correspond to the same pixel position; The intermediate image is stored in the screen buffer and is used to perform the upsampling process to obtain the second image.
5. The method according to any one of claims 1 to 4, characterized in that: The step of rendering the transparent object in the virtual scene to the color buffer comprises: When the optimized rendering condition is met, rendering the transparent objects in the virtual scene to the color buffer; The optimized rendering condition includes at least one of the following: The sub-scene to be rendered of the virtual scene belongs to an optimized sub-scene; wherein the optimized sub-scene includes at least part of the sub-scenes in the virtual scene; The number of transparent objects with optimized rendering parameters in the virtual scene is greater than a number threshold; The scene parameter of the virtual scene is greater than a scene parameter threshold; wherein the scene parameter includes at least one of an interaction parameter of a virtual object, the number of virtual objects, and a device resource usage parameter.
6. The method according to claim 5, characterized in that The virtual scene includes a plurality of sub-scenes; and the method further includes: Perform at least one of the following actions: In response to an optimized rendering configuration operation for at least part of the sub-scenes in the virtual scene, taking the at least part of the sub-scenes as optimized sub-scenes; The multiple sub-scenes are screened and processed according to the historical scene parameters respectively corresponding to the multiple sub-scenes to obtain optimized sub-scenes.
7. The method according to claim 5, characterized in that The method further comprises: Perform at least one of the following actions: In response to an optimized rendering configuration operation for at least a portion of the transparent objects in the virtual scene, updating rendering parameters of the at least a portion of the transparent objects to the optimized rendering parameters; The types of multiple transparent objects in the virtual scene are determined, and the rendering parameters of the transparent objects that meet the type conditions are updated to the optimized rendering parameters.
8. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Traverse multiple transparent objects in the virtual scene, and perform the following processing according to the traversed transparent objects: Rendering the traversed transparent object to a first depth buffer to obtain a first depth image; wherein the first depth buffer corresponds to the same rendering size as the screen buffer, and the first depth image includes a plurality of pixels and first depths respectively corresponding to the plurality of pixels; Downsampling the first depth image in the first depth buffer to obtain multiple downsampling depths; When any down-sampling depth is less than a second depth corresponding to the same pixel position in the second depth image, updating the second depth according to the any down-sampling depth, and allowing the traversed transparent object to be rendered at the same pixel position in the first image; When any one of the downsampling depths is greater than or equal to the second depth, the second depth is kept unchanged, and rendering the traversed transparent object at the same pixel position of the first image is prohibited; The second depth image is stored in a second depth buffer, and a rendering size of the second depth buffer is smaller than that of the first depth buffer.
9. The method according to claim 8, characterized in that The downsampling the first depth image in the first depth buffer to obtain a plurality of downsampling depths includes: Determining a downsampling window according to a rendering size ratio between the screen buffer and the color buffer; A sliding process is performed in the first depth image according to the downsampling window, and a depth fusion process is performed on the first depth of the pixels covered by the downsampling window after each sliding process to obtain a downsampling depth.
10. The method according to any one of claims 1 to 4, characterized in that: The step of rendering the transparent object in the virtual scene to the color buffer comprises: Rendering the optimized transparent objects in the virtual scene to the color buffer; Wherein, the optimized transparent objects include any one of the following: all transparent objects in the virtual scene, transparent objects with optimized rendering parameters in the virtual scene; Before rendering the first image in the color buffer to the screen buffer, the method further includes: The non-optimized transparent objects and non-transparent objects in the virtual scene are rendered to the screen buffer.
11. The method according to any one of claims 1 to 4, characterized in that: The up-sampling process of the intermediate image during the rendering process includes: According to the rendering size ratio between the screen buffer and the color buffer, pixel interpolation processing is performed on the intermediate image obtained by rendering based on the first image.
12. A virtual scene rendering device, characterized in that: The device comprises: Create a module for creating a color buffer with a rendering size smaller than the screen buffer; A first rendering module, used for rendering transparent objects in the virtual scene to the color buffer to obtain a first image; rendering non-transparent objects in the virtual scene to the screen buffer to obtain an intermediate image, wherein the screen buffer serves as a drawing board; A second rendering module is used for rendering the first image to an intermediate image in the screen buffer according to the color of the first pixel in the first image, the transparency of the first pixel and the color of the intermediate pixel in the intermediate image when the rendering of the non-transparent object is completed, and upsampling the intermediate image during the rendering process to obtain a second image, wherein the size of the second image is the same as the size of the screen buffer; The screen rendering module is used to render the second image in the screen buffer to the screen, so as to display the second image on the screen.
13. An electronic device, characterized in that: include: A memory for storing executable instructions; The processor is used to implement the virtual scene rendering method described in any one of claims 1 to 11 when executing the executable instructions stored in the memory.
14. A computer-readable storage medium, characterized in that: Executable instructions are stored, and when executed by a processor, the method for rendering a virtual scene according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Low-resolution particle drawing method for improving resolution based on double buffering
CN104008525A
Image rendering method in panoramic application and terminal equipment
CN113129417A
Temporary Low Resolution Rendering of 3D Objects
US20080122835A1
Method for rendering images from a three-dimensional virtual scene
WO2012076778A1
