Determination Method and Device for Visible Elements, Storage Medium, and Electronic Device
By numbering and color value analysis of three-dimensional scene elements, a collection of visible elements is generated, which solves the problem of low computing efficiency of visible sets in the prior art, and improves rendering speed and CPU resource utilization.
Patent Information
- Application Number
- CN202210037758.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-13
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-01-13
AI Technical Summary
In the prior art, the rasterized rendering method is inefficient when calculating visible sets in a three-dimensional scene, resulting in excessive CPU resource usage and long frame buffer readback time.
By numbering and rendering three-dimensional scene elements, the target rendering image is generated, and the color value is used to determine the scene elements to which each pixel belongs, thereby obtaining a collection of visible elements to reduce dependence on the CPU.
Improves the efficiency of visible set computing, reduces CPU resource usage, and improves rendering speed.
Smart Images

Figure CN114429513B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular, to a method and apparatus for determining visible elements, a storage medium, and an electronic device. Background Art
[0002] In the field of graphics rendering research and industrial applications, visibility determination is applied in processes such as scene rendering performance optimization and ray casting. However, it is difficult to obtain the visible set of scene elements at a certain viewpoint in a three-dimensional scene.
[0003] The rasterization rendering method is a commonly used method for calculating the visible set. Its main principle is to take the viewpoint as the center, call the Graphics Processing Unit (GPU) to render the scene elements in the three-dimensional scene, and read the rendered frame buffer back to the Central Processing Unit (CPU) for determination. However, a large number of data copying operations require CPU resources, resulting in a long read-back time for the frame buffer and low efficiency.
[0004] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention
[0005] Embodiments of this application provide a method and apparatus for determining visible elements, a storage medium, and an electronic device, so as to at least solve the technical problem of low calculation efficiency of the visible set.
[0006] According to one aspect of the embodiments of this application, a method for determining visible elements is provided, including: rendering each scene element in a first set of scene elements at a target viewpoint to obtain a target rendered image, where the first set of scene elements includes scene elements to be rendered at the target viewpoint in a target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first set of scene elements at the target viewpoint, the target rendered image includes pixels of the scene elements in the first set of scene elements except the occluded scene elements; determining the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image to obtain a target number set; determining a second set of scene elements in the first set of scene elements, and determining the scene elements in the second set of scene elements as visible elements at the target viewpoint, where the numbers of the scene elements in the second set of scene elements are the numbers in the target number set.
[0007] Optionally, before rendering each scene element in the first set of scene elements from the target perspective to obtain a target rendered image, the method further includes: finding the scene elements located within the range of the target perspective in the target three-dimensional scene to obtain the first set of scene elements.
[0008] Optionally, the rendering each scene element in the first set of scene elements from the target perspective to obtain a target rendered image includes: respectively determining the color values corresponding to the respective scene elements according to the numbers of the respective scene elements in the first set of scene elements, where the color values corresponding to different numbered scene elements are different; determining the color values of the pixels in each of the scene elements as the color values corresponding to the respective scene elements, where the color values of the pixels in the same scene element are all the color values corresponding to the same scene element; storing the color values of the pixels in each of the scene elements at the corresponding storage positions in the target storage space according to the positions of the respective scene elements in the target perspective, where when there are a first scene element and a second scene element among the respective scene elements and the position of the first scene element in the target perspective is blocked by the position of the second scene element in the target perspective, the color values of the pixels in the first scene element stored in the target storage space are overwritten by the color values of the pixels in the second scene element, and the color values of the pixels stored in the target storage space are the color values of the pixels in the target rendered image.
[0009] Optionally, the storing the color values of the pixels in each of the scene elements at the corresponding storage positions in the target storage space according to the positions of the respective scene elements in the target perspective includes: performing the following operations on each scene element in the first set of scene elements. When performing the following operations, each scene element is the current scene element, and the position of the current scene element in the target perspective is the current position: finding the current storage position corresponding to the current position in the target storage space; when the color values of the pixels in a scene element have been stored at the current storage position, overwriting the color values of the pixels in the stored scene element with the color values of the pixels in the current scene element at the current storage position, where the position of the stored scene element is blocked by the position of the current scene element in the target perspective; when no color values of the pixels in any scene element have been stored at the current storage position, storing the color values of the pixels in the current scene element at the current storage position.
[0010] Optionally, determining the color value corresponding to each scene element according to the numbers of the respective scene elements in the first scene element set includes: performing the following operations on each scene element in the first scene element set. When performing the following operations, each scene element is the current scene element: obtaining the number of the current scene element; performing a logical operation on the number of the current scene element to obtain the color value corresponding to the current scene element.
[0011] Optionally, determining the number of the scene element where each pixel in the target rendered image is located according to the color value of each pixel in the target rendered image to obtain a target number set includes: performing the following operations on the color values of the respective pixels stored in the target storage space. When performing the following operations, each pixel is the current pixel: performing an inverse logical operation corresponding to the logical operation on the color value of the current pixel to obtain the number of the scene element where the current pixel is located.
[0012] Optionally, determining the number of the scene element where each pixel in the target rendered image is located according to the color value of each pixel in the target rendered image to obtain a target number set includes: obtaining the color values of the pixels in the target rendered image in parallel through a target thread set, and determining the number of the scene element where the obtained color value of the pixel is located according to the obtained color value of the pixel. Wherein, the target rendered image includes a plurality of image blocks, and each thread in the target thread set is used to read the color values of the pixels in an image block of a target size in the target rendered image each time.
[0013] Optionally, determining the scene elements in the second scene element set as visible elements in the target view includes: when the second scene element set is a second model set and each scene element in the second scene element set is each model in the second model set, determining each model in the second model set as a visible model in the target view; or when the second scene element set is a second primitive set and each scene element in the second scene element set is each primitive in the second primitive set, determining each primitive in the second primitive set as a visible primitive in the target view.
[0014] Optionally, rendering each scene element in the first set of scene elements from the target perspective to obtain a target rendered image includes: when the first set of scene elements is a first set of models and each scene element in the first set of scene elements is a model in the first set of models, determining color values corresponding to the models in the first set of models according to the numbers of the models, where models with different numbers correspond to different color values, and the color values of the pixels in the same model are all the color values corresponding to the same model; determining the target rendered image according to the color values corresponding to the models in the first set of models and the positions of the models from the target perspective; or when the first set of scene elements is a first set of primitive elements and each scene element in the first set of scene elements is a primitive element in the first set of primitive elements, determining color values corresponding to the primitive elements in the first set of primitive elements according to the numbers of the primitive elements, where primitive elements with different numbers correspond to different color values, and the color values of the pixels in the same primitive element are all the color values corresponding to the same primitive element; determining the target rendered image according to the color values corresponding to the primitive elements in the first set of primitive elements and the positions of the primitive elements from the target perspective.
[0015] Optionally, in the case where the scene elements in the second set of scene elements are determined to be visible elements in the target perspective, the method further includes: setting the values of the first set of units corresponding to the second set of scene elements in the first array to a first value, and setting the values of the units in the first array other than the first set of units to a second value, where the number of units in the first array is the number of scene elements in the first set of scene elements, the units in the first array have a one-to-one correspondence with the scene elements in the first set of scene elements, the units with the value of the first value indicate that the corresponding scene elements are visible elements in the target perspective, and the units with the value of the second value indicate that the corresponding scene elements are invisible elements in the target perspective; sending the first array to a target processing device; or setting the values of the second set of units corresponding to the second set of scene elements in the second array to a first value, setting the values of the units in the third set of units in the second array other than the second set of units to a second value, and setting the values of the units in the second array other than the third set of units to a third value, where the third set of units is the set of units corresponding to the first set of scene elements in the second array, the number of units in the second array is the number of scene elements in the target three-dimensional scene, the units in the second array have a one-to-one correspondence with the scene elements in the target three-dimensional scene, the units with the value of the first value indicate that the corresponding scene elements are visible elements in the target perspective, the units with the value of the second value indicate that the corresponding scene elements are invisible elements in the target perspective, and the units with the value of the third value indicate that the corresponding scene elements are not within the range of the target perspective; sending the second array to a target processing device.
[0016] According to another aspect of the embodiments of the present application, there is also provided a device for determining visible elements, including: a rendering module, configured to render each scene element in the first set of scene elements from a target perspective to obtain a target rendered image, where the first set of scene elements includes the scene elements to be rendered from the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first set of scene elements from the target perspective, the target rendered image includes the pixels in the scene elements in the first set of scene elements except the occluded scene elements; a first determination module, configured to determine the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image to obtain a target set of numbers; a second determination module, configured to determine a second set of scene elements in the first set of scene elements and determine the scene elements in the second set of scene elements as visible elements from the target perspective, where the numbers of the scene elements in the second set of scene elements are the numbers in the target set of numbers.
[0017] According to still another aspect of the embodiments of the present application, there is also provided a computer-readable storage medium, in which a computer program is stored, where the computer program is configured to execute the above-mentioned method for determining visible elements when running.
[0018] According to yet another aspect of the embodiments of the present application, there is provided a computer program product or a computer program, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for determining visible elements as above.
[0019] According to still another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory and a processor, a computer program is stored in the memory, and the processor is configured to execute the above-mentioned method for determining visible elements through the computer program.
[0020] In the embodiments of the present application, each scene element in the three-dimensional scene is numbered. When rendering the scene elements from the target perspective, the color value of each scene element is the color obtained according to the number of the scene element. From the color value of each pixel in the target rendered image obtained by rendering, the number of the scene element where each pixel in the target rendered image is located can be obtained, and then the set of visible scene elements from the target perspective can be determined according to the number. In this way, it is not necessary to read the rendered frame buffer back to the CPU side, saving CPU resources and improving the calculation efficiency of the visible set, thereby solving the technical problem of low calculation efficiency of the visible set. Description of the Drawings
[0021] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0022] Figure 1 is a schematic diagram of the application environment of an optional method for determining visible elements according to an embodiment of the present application;
[0023] Figure 2 is a flowchart of an optional method for determining visible elements according to an embodiment of the present application;
[0024] Figure 3 is a schematic diagram of an optional target three-dimensional scene according to an embodiment of the present application;
[0025] Figure 4 is a schematic diagram of an optional target perspective according to an embodiment of the present application;
[0026] Figure 5 is a schematic diagram of an optional target storage space according to an embodiment of the present application;
[0027] Figure 6 is a schematic diagram of an optional image block according to an embodiment of the present application;
[0028] Figure 7 is a schematic diagram of an optional array according to an embodiment of the present application;
[0029] Figure 8 is another schematic diagram of an optional array according to an embodiment of the present application;
[0030] Figure 9 is a schematic diagram of an optional development interface according to an embodiment of the present application;
[0031] Figure 10 is another schematic diagram of an optional development interface according to an embodiment of the present application;
[0032] Figure 11 It is a schematic structural diagram of a determining device for an optional visible element according to an embodiment of the present application;
[0033] Figure 12 It is a block diagram of a computer system structure of an optional electronic device according to an embodiment of the present application;
[0034] Figure 13 It is a schematic structural diagram of an optional electronic device according to an embodiment of the present application. Detailed implementation manners
[0035] In order to enable those skilled in the art of the present technology to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0036] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application described here can be implemented in an order different from those illustrated or described here. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily need to be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these process, method, product, or device.
[0037] According to one aspect of the embodiments of the present application, a method for determining a visible element is provided. Optionally, as an optional implementation manner, the above method for determining a visible element can be but is not limited to being applied to an application environment such as Figure 1 shown in the figure. The above application environment includes a terminal device 101, a server 102, and a database 103.
[0038] Optionally, in this embodiment, the above terminal device may be a terminal device configured with a target client, and may include but are not limited to at least one of the following: mobile phone (such as Android mobile phone, iOS mobile phone, etc.), laptop computer, tablet computer, handheld computer, MID (Mobile Internet Devices), PAD, desktop computer, smart TV, etc. The target client may be a video client, instant messaging client, browser client, game client, etc. The above network may include but is not limited to: wired network, wireless network, where the wired network includes: local area network, metropolitan area network and wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that implement wireless communication. The above server 102 may be a single server, or a server cluster composed of multiple servers, or a cloud server. The above database 103 is used to store data, including but not limited to scene elements in a three-dimensional scene, rendered images, etc. The above is only an example, and this embodiment does not make any limitation thereto.
[0039] Optionally, as an alternative implementation, as Figure 2 shown, the method for determining the above visible elements includes:
[0040] Step S202, rendering each scene element in the first scene element set from a target perspective to obtain a target rendered image, where the first scene element set includes scene elements to be rendered from the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first scene element set from the target perspective, the target rendered image includes pixels of the scene elements in the first scene element set except the occluded scene elements;
[0041] Among them, the above-mentioned target scene includes but is not limited to a three-dimensional scene, such as a three-dimensional game scene in a virtual game scene. The above-mentioned scene elements include but are not limited to spatial regions, scene models, model triangles, primitives, etc. in a three-dimensional scene. For example, they can be virtual elements in a virtual game scene, virtual props, virtual characters, virtual objects, etc. Assume that there are N scene elements in the three-dimensional scene under the target view (the value of N can be determined according to the actual situation, such as 200, 300, 1000, etc.). These N scene elements have corresponding numbers, assumed to be numbered from 0 to N-1. The color value (primary colors, abbreviated as RGB) of each scene element is encoded according to the number of the scene element. For the specific encoding method, refer to the following embodiments. Render the scene elements in the three-dimensional scene under the target view according to the color value corresponding to each scene element to obtain a target rendered image. During the process of rendering the scene elements in the three-dimensional scene under the target view, the pixel colors of the scene elements that are invisible under the target view will not appear on the target rendered image. For example, the scene elements under the target view include A, B, and C. Assume that A is blocked by B under the target view, then the color value of A will not appear in the target rendered image.
[0042] Step S204, determine the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image, and obtain a target number set;
[0043] Among them, by decoding the color value of each pixel in the target rendered image, the encoding of the scene element where the pixel is located can be obtained. Furthermore, the scene element corresponding to this encoding is the visible element under the target view. Furthermore, by the color value of each pixel in the target rendered image, the set of visible scene elements under this target view can be determined.
[0044] Step S206, determine a second scene element set in the first scene element set, and determine the scene elements in the second scene element set as the visible elements under the target view, where the numbers of the scene elements in the second scene element set are the numbers in the target number set.
[0045] Among them, the color value of the scene element is encoded according to the number during rendering. According to the color value of each pixel in the rendered target rendered image, the number of the scene element where the pixel is located can be decoded. The scene element corresponding to the number is the visible element under this target view. Furthermore, by the color value of each pixel in the target rendered image, the set of visible scene elements under this target view can be determined, which can also be called the visible set (the second scene element set).
[0046] Optionally, the execution subject of the above method for determining visible elements can be a compute shader.
[0047] Optionally, the method further includes: before rendering each scene element in the first scene element set from a target perspective to obtain a target rendered image, the method further includes: searching for scene elements located within the range of the target perspective in the target three-dimensional scene to obtain the first scene element set.
[0048] As an optional way, Figure 3 Taking the shown target three-dimensional scene as an example, as shown in the figure, the target three-dimensional scene includes scene elements A, B, C, D, and E. Among them, scene elements A, B, and C are located within the range of the target perspective, and the above first scene element set includes scene elements A, B, and C.
[0049] Optionally, the rendering of each scene element in the first scene element set from a target perspective to obtain a target rendered image includes: respectively determining color values corresponding to the respective scene elements according to the numbers of the respective scene elements in the first scene element set, where different numbered scene elements correspond to different color values; determining the color values of the pixels in each scene element as the color values corresponding to the respective scene elements, where the color values of the pixels in the same scene element are all the color values corresponding to the same scene element; storing the color values of the pixels in each scene element at corresponding storage positions in a target storage space according to the positions of the respective scene elements from the target perspective, where when there are a first scene element and a second scene element among the respective scene elements and the position of the first scene element from the target perspective is blocked by the position of the second scene element from the target perspective, the color values of the pixels in the first scene element stored in the target storage space are overwritten by the color values of the pixels in the second scene element, and the color values of the pixels stored in the target storage space are the color values of the pixels in the target rendered image.
[0050] As an optional implementation manner, assuming that the above first scene element set includes N scene elements, numbering the above N scene elements from 0 to n - 1, taking each number as the index of the scene element, and encoding the color values of each scene element according to each scene element index to obtain the color value corresponding to the scene element, encoding formula:
[0051]
[0052] where color red (index), color green (index) and color blue (index) are the color values of the three primary colors RGB of the scene element corresponding to the index, that is, the color value includes colorred (index), color green (index) and color blue (index), where "mod" is the modulo operation. h is a preset parameter that can be set according to actual situations. For example, it can be 128, 256, 512, etc. It can be seen from the above encoding formula that the color values obtained by encoding scene elements with different numbers are different. One scene element corresponds to one number, one number corresponds to one color value, and thus one scene element corresponds to one color value, that is, one scene element is one color.
[0053] As an optional implementation, taking Figure 3 the target scene shown as an example, the first set of scene elements includes scene elements A, B, and C. Number the scene elements A, B, and C. Assume the number of A is 0, the number of B is 1, and the label of C is 2. The color value of scene element A obtained by the above encoding formula is (color red (0), color green (0), color blue (0)), the color value of scene element B is (color red (1), color green (1), color blue (1)), and the color value of scene element C is (color red (2), color green (2), color blue (2)).
[0054] As an optional implementation, if the above scene elements are models, set the material for model rendering to a non-illuminated solid color material, and set the color used for the material to the corresponding color value. If the above scene elements are primitives, set up a proxy model according to the original model, and set the vertex color of each primitive to the corresponding color value. And set the material used for the proxy model to non-illuminated vertex color. For the occluder model that is not occluded (this model is not occluded and this model occludes other models), a non-illuminated pure black material can be used. When setting the above materials, the back-face culling switch can be set to the back-face culling switch of the original model's material.
[0055] As an optional implementation, clear the frame buffer during the rendering stage, turn off anti-aliasing, high dynamic range, and post-processing functions to avoid affecting the rendering result. As an optional implementation, the above target storage space can be the frame buffer. Render the scene elements in the first set of scene elements in the frame buffer, and store the color values of the pixels of each scene element at the corresponding storage positions according to the positions of each scene element in the first set of scene elements in the target view.
[0056] As an alternative implementation, when rendering each scene element in the frame buffer, the scene elements are rendered according to the target rendering order, where the target rendering order is related to the distance between the scene element and the target view point, and the scene element with a greater distance from the target view point is sorted earlier. Taking Figure 4 the scene elements A, B, and C shown as an example, where the distances between the scene elements A, B, and C and the target view point from far to near are C, A, and B respectively, and the rendering order in the rendering stage is C, A, B.
[0057] In Figure 4 the target view shown, the first scene element A is blocked by the second scene element B because the distance between A and the target view point is greater than the distance between B and the target view point. When rendering, A is rendered first and then B. That is, the color values of the pixels of the scene element A are first stored in the corresponding storage positions in the target storage space, and then the color values of the scene element B are stored in the corresponding positions in the target storage space. Since the storage positions overlap. After rendering the scene element B, the color values of the scene element A are overwritten by the color values of the scene element B, and there are no color values of the scene element A in the target storage space. As Figure 5 shown in the rendering process, color(2) is the color value of the element scene element C, including (color red (2), color green (2), color blue (2)), color(0) is the color value of the scene element A, including (color red (0), color green (0), color blue (0)), color(1) is the color value of the scene element B, including (color red (1), color green (1), color blue (1)). As shown in the figure, during the rendering of the scene elements, the color values of the scene element C are first stored in the corresponding storage position 500 in the target storage space, then the color values of the scene element A are stored in the corresponding storage position 501 in the target storage space, and finally the color values of the scene element B are stored in the corresponding position 501 in the target storage space. Since the scene element B and the scene element A overlap in the target view and their storage positions in the target storage space overlap, with the overlapping storage position being 501, the color values of the scene element B in the target storage space overwrite the color values of the scene element A. There is no scene element A in the rendered target rendering image, and there are no color values of the scene element A in the target storage space.
[0058] Optionally, storing the color values of the pixels in each scene element at corresponding storage positions in the target storage space according to the positions of the respective scene elements in the target perspective includes: performing the following operations on each scene element in the first set of scene elements. When performing the following operations, each scene element is the current scene element, and the position of the current scene element in the target perspective is the current position: searching for the current storage position corresponding to the current position in the target storage space; when a color value of a pixel in a scene element has been stored at the current storage position, overwriting the stored color value of the pixel in the one scene element with the color value of the pixel in the current scene element, where the position of the one scene element in the target perspective is occluded by the position of the current scene element in the target perspective; when no color value of a pixel in any scene element has been stored at the current storage position, storing the color value of the pixel in the current scene element at the current storage position.
[0059] As an optional implementation manner, as Figure 5 shown, during the process of rendering model elements, the model elements C, A, and B are rendered in this rendering order. When rendering scene element A, the color value of scene element A is stored at storage position 501 in the target storage space. If no value is stored at storage position 501, the color value color(0) is stored at storage position 501 (the current storage position) in the target storage space.
[0060] When rendering scene element B, the storage position of scene element B in the target storage space is 501, and this storage position 501 has stored the color value color(0) of scene element A. Then, the color value color(1) of scene element B overwrites the color value color(0) of scene element A, and the color value color(1) of scene element B is stored at storage position 501, and the color value color(0) of scene element A is no longer stored at storage position 501.
[0061] First, the color value of model element C is stored at the corresponding storage position in the target storage space, then the color value of scene element A is stored at the corresponding storage position in the target storage space, and finally the color value of scene element B is stored at the corresponding position in the target storage space. Since scene element B overlaps with scene element A in the target perspective and overlaps in the storage position in the target storage space, the color value of scene element B in the target storage space overwrites the color value of scene element A. There is no scene element A in the target rendered image, and there is no color value of scene element A in the target storage space.
[0062] Optionally, determining the color value corresponding to each scene element according to the numbers of the respective scene elements in the first scene element set includes: performing the following operations on each scene element in the first scene element set. When performing the following operations, each scene element is the current scene element: obtaining the number of the current scene element; performing a logical operation on the number of the current scene element to obtain the color value corresponding to the current scene element.
[0063] As an optional implementation manner, the above logical operation is the above encoding formula:
[0064]
[0065] where index is the number of the current scene element, and the corresponding color value includes the above color red (index), color green (index) and color blue (index). The above h is a preset parameter and can be set according to actual situations. For example, it can be 128, 256, 512, etc.
[0066] Optionally, determining the number of the scene element where each pixel is located according to the color value of each pixel in the target rendering image to obtain a target number set includes: performing the following operations on the color values of the respective pixels stored in the target storage space. When performing the following operations, each pixel is the current pixel: performing an inverse logical operation corresponding to the above logical operation on the color value of the current pixel to obtain the number of the scene element where the current pixel is located.
[0067] As an optional implementation manner, the above inverse logical operation is a decoding operation, and the decoding equation is:
[0068] index = color blue ×h 2 +color green ×h + color red -1
[0069] where color blue , color green , color red are the color values of the pixel, and index is the number of the scene element where the pixel is located. Among them, h is the same as h in the above encoding formula and can be determined according to actual situations. For example: 128, 256, 512, etc.
[0070] Optionally, determining the numbers of the scene elements where each pixel in the target rendered image is located based on the color values of each pixel in the target rendered image to obtain a target number set includes: obtaining the color values of the pixels in the target rendered image in parallel through a target thread set, and determining the numbers of the scene elements where the obtained color values of the pixels are located according to the obtained color values of the pixels. The target rendered image includes a plurality of image blocks, and each thread in the target thread set is used to read the color values of the pixels in an image block with a target size in the target rendered image each time.
[0071] As an optional implementation manner, the target thread set is Ts, the width and height of Ts can be (64, 16), and the total number of parallel threads is 64×16×1 = 1024. Assume that the width W of the frame buffer size is 4096 pixels and the height H is 2048 pixels, that is, the width of the target rendered image is 4096 pixels and the height is 2048 pixels, which are integer multiples of 64 and 16 respectively. The target rendered image is allocated into respective picture blocks according to the width and height (64, 16) of Ts. The size of each image block is: (W, H) / (64, 16). The size of each image block is (64, 128). As Figure 6 shown, for the thread (0, 0, 0) in the target thread set, the image block 1 to be processed is from (0, 0) to (63, 127). Each thread in the target thread set needs to traverse the elements in its corresponding image block, load the color values of each pixel, and decode the number index of the scene element where each pixel is located using the above decoding equation. Until all the pixels in the target rendered image are traversed.
[0072] Optionally, determining the scene elements in the second scene element set as visible elements in the target view includes: when the second scene element set is a second model set and each scene element in the second scene element set is a model in the second model set, determining each model in the second model set as a visible model in the target view; or when the second scene element set is a second primitive set and each scene element in the second scene element set is a primitive in the second primitive set, determining each primitive in the second primitive set as a visible primitive in the target view.
[0073] Optionally, rendering each scene element in the first set of scene elements from the target perspective to obtain a target rendered image includes: when the first set of scene elements is a first set of models and each scene element in the first set of scene elements is a model in the first set of models, determining color values corresponding to the models in the first set of models according to the numbers of the models, where different models have different corresponding color values, and the color values of the pixels in the same model are all the color values corresponding to the same model; determining the target rendered image according to the color values corresponding to the models in the first set of models and the positions of the models from the target perspective; or when the first set of scene elements is a first set of primitive elements and each scene element in the first set of scene elements is a primitive element in the first set of primitive elements, determining color values corresponding to the primitive elements in the first set of primitive elements according to the numbers of the primitive elements, where different primitive elements have different corresponding color values, and the color values of the pixels in the same primitive element are all the color values corresponding to the same primitive element; determining the target rendered image according to the color values corresponding to the primitive elements in the first set of primitive elements and the positions of the primitive elements from the target perspective.
[0074] Optionally, in the case where the scene elements in the second set of scene elements are determined to be visible elements in the target perspective, the method further includes: setting the values of the first set of units corresponding to the second set of scene elements in the first array to a first value, and setting the values of the units in the first array other than the first set of units to a second value, where the number of units in the first array is the number of scene elements in the first set of scene elements, the units in the first array have a one-to-one correspondence with the scene elements in the first set of scene elements, the units with the value of the first value indicate that the corresponding scene elements are visible elements in the target perspective, and the units with the value of the second value indicate that the corresponding scene elements are invisible elements in the target perspective; sending the first array to a target processing device; or setting the values of the second set of units corresponding to the second set of scene elements in the second array to a first value, setting the values of the units in the third set of units in the second array other than the second set of units to a second value, and setting the values of the units in the second array other than the third set of units to a third value, where the third set of units is the set of units corresponding to the first set of scene elements in the second array, the number of units in the second array is the number of scene elements in the target three-dimensional scene, the units in the second array have a one-to-one correspondence with the scene elements in the target three-dimensional scene, the units with the value of the first value indicate that the corresponding scene elements are visible elements in the target perspective, the units with the value of the second value indicate that the corresponding scene elements are invisible elements in the target perspective, and the units with the value of the third value indicate that the corresponding scene elements are not within the range of the target perspective; sending the second array to a target processing device.
[0075] As an optional implementation manner, the above-mentioned first array is array S, the units in the first set of units are the array units in the first array, such as S[i]. The above-mentioned first value is 1 and the second value is 0. The number of units included in the first array is the number of scene elements in the first set of scene elements, that is, the number of scene elements within the target perspective range. Assuming that the first set of scene elements includes 1024 scene elements, then the first array includes 1024 array units, and each array unit corresponds to a scene element. As Figure 7 shown, for the visible scene element (number i), the value in the corresponding array unit S[i] is the first value 1, and for the invisible scene element (number j), the value in the corresponding array unit S[j] is the second value 0.
[0076] As an optional implementation, for the above-mentioned second array S, the first value is 1, the second value is 0, and the third value can be -1. The number of units included in the second array is the number of scene elements in the target three-dimensional scene (greater than or equal to the number of scene elements within the target viewing range (the number in the first set of scene elements)). Assuming that the number of scene elements in the three-dimensional scene is 2028, the first array includes 2028 array units, and each array unit corresponds to a scene element in the target three-dimensional scene. Assuming that the first set of scene elements includes 1024 scene elements, then the 1024 array units included in the third unit set in the second array S respectively correspond to the 1024 scene elements in the first set of scene elements. The first set of scene elements includes visible and invisible scene elements. For the visible scene elements in the first set of scene elements, they correspond to the second unit set in the second array, and the value of each unit in the second unit set is 1, as Figure 8 shown, the value of the array unit corresponding to the visible scene element is 1. For the invisible scene elements in the first set of scene elements, they correspond to the other array units in the third unit set except the second unit set, and the value is 0. As Figure 8 shown, the value of the array unit corresponding to the invisible scene element is 0. For the array units in the array except the third unit set corresponding to the first set of scene elements, as Figure 8 described, the value setting is -1.
[0077] As an optional implementation, the above-mentioned target processing device is a CPU, and the computing shader sends the above-mentioned first array and second array to the CPU.
[0078] Optionally, in the initialization stage of the computing shader, first define the thread width of the computing shader as Ts=(64, 16, 1), and the total number of parallel threads is 64×16×1 = 1024. The number of work tasks n can be aligned to a width of 1024 and set as n', and there is:
[0079]
[0080] Create a new array S with the data type of unsigned integer and the length of n' to store visibility. The above-mentioned mod is the remainder operation. Transmit the primitive / model number n, the aligned number n' and the array S to the computing shader. Call the clear data kernel function of the computing shader to initialize the array S.
[0081] In the data clearing kernel function, the width of the working thread is the same as Ts, and the input of the kernel function is a three-dimensional unsigned integer variable Coord. The total number of working threads is 1024, and the workload is n'. Then the workload of each thread is Stripe = n' / 1024. That is, thread (0, 0, 0) needs to clear the 0th to the (Stripe - 1)th elements of array S, thread (1, 0, 0) needs to clear the Stripe to the (2×Stripe - 1)th elements of array S, and so on... That is, for the working thread numbered Coord, it is necessary to assign: S[i] = 0. After the kernel function execution is completed, all n' elements in array S are set to 0. Among them:
[0082]
[0083] In the parallel visible set acquisition stage, in the compute shader, another kernel function is defined to calculate the visible set. The workload with width W and height H is divided into individual image blocks according to the width and height of Ts (64, 16). The size of each block is: (W, H) / (64, 16). Each thread needs to traverse the corresponding image block, load the color value of each pixel, and use the decoding equation index = color blue ×256 2 +color green ×256+color red -1 for decoding. If index < n, then set S[index] = 1. Until all pixels are traversed.
[0084] The compute shader reads the visible set S back into memory, and the CPU determines the elements. 0 represents that the element is invisible, and 1 represents that the element is visible.
[0085] As an optional implementation, support can be provided for the graphics rendering development process in the form of a Unity tool plugin. As Figure 9 shown in the development interface, the first button is used to initialize the visibility data system of the scene, the second button is used to unload the system, and the third button can expand the settings window. The interface of the expanded settings window is as Figure 10 shown. In Figure 10 the shown interface, developers can set the positions, regions, and calculation densities where the visible set needs to be calculated. Click the build button at the bottom to start generating the visible set. Developers can also flexibly perform rendering and obtain the visible set by writing scripts and calling the plugin, and then perform subsequent processing according to requirements. The plugin provides methods for debugging intermediate results, and developers can still choose to read back the frame buffer in the form of a texture to view the color of the frame buffer at this time.
[0086] As an optional implementation, taking the rendering of scene elements in a virtual ranger scene as an example, the following steps may be included:
[0087] S1. Render the virtual scene elements in the virtual game scene from the target perspective to obtain a virtual game scene map from the target perspective. The above virtual scene elements include but are not limited to virtual elements in the virtual game scene, such as virtual characters, virtual props, virtual objects, etc.;
[0088] During the above rendering process, number the virtual scene elements from the target perspective. The numbering method can be set according to the actual situation. For example, it can be 1, 2, 3... etc. During rendering, the color value corresponding to each virtual scene element is obtained through the following formula:
[0089]
[0090] where index is the number of the virtual scene element, color red (index), color green (index) and color blue (index) are the color values of the three primary colors RGB of the virtual scene element corresponding to the number, that is, the color value includes color red (index), color green (index) and color blue (index), and mod is the modulo operation. h is a preset parameter, which can be set according to the actual situation. For example, it can be 128, 256, 512, etc. It can be seen from the above encoding formula that the color values encoded for virtual scene elements with different numbers are different. One virtual scene element corresponds to one number, one number corresponds to one color value, and thus one virtual scene element corresponds to one color value, that is, one virtual scene element is a kind of color.
[0091] During rendering, store the color values of the pixels in each virtual scene element at the corresponding storage positions in the frame buffer according to the positions of the virtual scene elements in the virtual game scene from the target perspective.
[0092] When storing the virtual scene elements in the above frame buffer, if the position of the virtual scene element A from the target perspective is blocked by the position of the virtual scene element B from the target perspective, the color value of the pixels in the virtual scene element A stored in the above frame buffer is overwritten by the color value of the virtual scene element B.
[0093] As Figure 5 shown in the rendering process, color(0) is the color value of the virtual scene element A, and color(1) is the color value of the virtual scene element B, including (colorred (1), color green (1), color blue (1)), as shown in the figure, during the rendering of virtual scene elements, first store the color value of virtual scene element A in the corresponding storage location 501 of the target storage space, and then store the color value of virtual scene element B in the corresponding location 501 of the target storage space. Since virtual scene element B overlaps with virtual scene element A in the target view and overlaps in the storage location in the frame buffer, and the overlapping storage location is 501, the color value of virtual scene element B in the frame buffer will overwrite the color value of virtual scene element A. There is no virtual scene element A in the rendered virtual game scene, and there is no color value of scene element A in the frame buffer.
[0094] S2. Obtain the color value of each pixel in the virtual game scene graph obtained by the above rendering, and determine the number of the virtual scene element corresponding to each pixel according to the color value.
[0095] Specifically, the number of the scene element corresponding to each pixel in the virtual game scene graph can be obtained by decoding, and the decoding equation is:
[0096] index = color blue ×h 2 + color green ×h + color red - 1
[0097] where color blue , color green , color red are the color values of the pixel, and index is the number of the scene element where the pixel is located. Among them, h is the same as h in the above encoding formula and can be determined according to the actual situation, for example: 128, 256, 512, etc.
[0098] S3. Obtain the visible virtual scene elements in the virtual game scene from the number of the scene elements obtained by the above decoding in the target view.
[0099] Through the above embodiments, the visible virtual scene elements in each view can be quickly determined in the virtual game scene, the rendering efficiency of the virtual game scene in each view is improved, and when the player quickly switches the game view, the game screen corresponding to the corresponding view can be quickly switched, the rendering speed of the game screen is accelerated, and the game experience is improved.
[0100] In this application, during the process of obtaining the visible set, the read-back visibility array is used to replace the read-back buffer, which greatly improves the calculation efficiency. It is compatible with most existing graphics production processes and is scalable for different operating platforms, and can be applied to different graphics rendering products in the industry. Replacing the read-back frame buffer with the read-back visible set data can greatly improve the efficiency, so that higher resolution can be used for rendering during application. Taking a frame buffer with a resolution of 4096×2048 as an example, the buffer size of the RGBA32 format is 4096×2048×4 Byte = 32 MB. Assuming that it contains 100,000 primitives, the data volume only accounts for 0.38 MB. And in actual projects, several or even dozens of frame buffers generated by multiple view planes of a viewpoint can repeatedly write to the visible set by calling the compute shader kernel function multiple times, and finally the data volume read back to the CPU can remain unchanged. This greatly improves the flexibility, efficiency and accuracy of obtaining the visible set in applications. This application can be flexibly applied in commercial engines such as the Unity 3D engine and the Unreal engine, and can be modified according to the actual needs of the project and applied in real-time rendering and offline calculation processes.
[0101] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that this application is not limited by the described action sequence, because according to this application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0102] According to another aspect of the embodiments of this application, a visible element determination device for implementing the above visible element determination method is also provided. As Figure 11As shown in the figure, the device includes: a rendering module 1102, configured to render each scene element in the first set of scene elements from the target perspective to obtain a target rendered image, where the first set of scene elements includes the scene elements to be rendered from the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first set of scene elements from the target perspective, the target rendered image includes the pixels in the scene elements in the first set of scene elements except the occluded scene elements; a first determination module 1104, configured to determine the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image to obtain a target set of numbers; a second determination module 1106, configured to determine a second set of scene elements in the first set of scene elements and determine the scene elements in the second set of scene elements as visible elements from the target perspective, where the numbers of the scene elements in the second set of scene elements are the numbers in the target set of numbers.
[0103] Optionally, the above device is further configured to, before rendering each scene element in the first set of scene elements from the target perspective to obtain a target rendered image, search for the scene elements within the range of the target perspective in the target three-dimensional scene to obtain the first set of scene elements.
[0104] Optionally, the above device is further configured to respectively determine the color values corresponding to the respective scene elements according to the numbers of the respective scene elements in the first set of scene elements, where the color values corresponding to different numbered scene elements are different; determine the color values of the pixels in the respective scene elements as the color values corresponding to the respective scene elements, where the color values of the pixels in the same scene element are all the color values corresponding to the same scene element; store the color values of the pixels in the respective scene elements at the corresponding storage positions in the target storage space according to the positions of the respective scene elements from the target perspective, where when there are a first scene element and a second scene element among the respective scene elements and the position of the first scene element from the target perspective is occluded by the position of the second scene element from the target perspective, the color values of the pixels in the first scene element stored in the target storage space are overwritten by the color values of the pixels in the second scene element, and the color values of the pixels stored in the target storage space are the color values of the pixels in the target rendered image.
[0105] Optionally, the above device is further configured to perform the following operations on each scene element in the first scene element set. When performing the following operations, each of the scene elements is the current scene element, and the position of the current scene element in the target perspective is the current position: Search for the current storage position corresponding to the current position in the target storage space; when the color value of a pixel in a scene element has been stored at the current storage position, overwrite the stored color value of the pixel in the one scene element with the color value of the pixel in the current scene element, where the position of the one scene element in the target perspective is blocked by the position of the current scene element in the target perspective; when no color value of a pixel in any scene element is stored at the current storage position, store the color value of the pixel in the current scene element at the current storage position.
[0106] Optionally, the above device is further configured to perform the following operations on each scene element in the first scene element set. When performing the following operations, each of the scene elements is the current scene element: Obtain the number of the current scene element; perform a logical operation on the number of the current scene element to obtain the color value corresponding to the current scene element.
[0107] Optionally, the above device is further configured to perform the following operations on the color values of each pixel stored in the target storage space. When performing the following operations, each of the pixels is the current pixel: Perform an inverse logical operation corresponding to the logical operation on the color value of the current pixel to obtain the number of the scene element where the current pixel is located.
[0108] Optionally, the above device is further configured to obtain the color values of the pixels in the target rendered image in parallel through a target thread set, and determine the number of the scene element where the obtained color value of the pixel is located according to the obtained color value of the pixel, where the target rendered image includes a plurality of image blocks, and each thread in the target thread set is used to read the color values of the pixels in an image block of a target size in the target rendered image each time.
[0109] Optionally, when the second scene element set is a second model set and each scene element in the second scene element set is each model in the second model set, the above device is further configured to determine each model in the second model set as a visible model in the target perspective; when the second scene element set is a second primitive set and each scene element in the second scene element set is each primitive in the second primitive set, the above device is further configured to determine each primitive in the second primitive set as a visible primitive in the target perspective.
[0110] Optionally, the above-mentioned device is further configured to, when the first scene element set is a first model set and each scene element in the first scene element set is a model in the first model set, determine color values corresponding to the models in the first model set according to the numbers of the models, where models with different numbers correspond to different color values, and the color values of the pixels in the same model are all the color values corresponding to the same model; determine the target rendering image according to the color values corresponding to the models in the first model set and the positions of the models in the target perspective; when the first scene element set is a first primitive set and each scene element in the first scene element set is a primitive in the first primitive set, determine color values corresponding to the primitives in the first primitive set according to the numbers of the primitives, where primitives with different numbers correspond to different color values, and the color values of the pixels in the same primitive are all the color values corresponding to the same primitive; determine the target rendering image according to the color values corresponding to the primitives in the first primitive set and the positions of the primitives in the target perspective.
[0111] Optionally, the above device is further configured to, in the case of determining that the scene elements in the second set of scene elements are visible elements in the target perspective, set the values of the first set of units corresponding to the second set of scene elements in the first array to a first value, and set the values of the units in the first array other than the first set of units to a second value, where the number of units in the first array is equal to the number of scene elements in the first set of scene elements, and there is a one-to-one correspondence between the units in the first array and the scene elements in the first set of scene elements, and a unit with a value of the first value indicates that the corresponding scene element is a visible element in the target perspective, and a unit with a value of the second value indicates that the corresponding scene element is an invisible element in the target perspective; send the first array to a target processing device; set the values of the second set of units corresponding to the second set of scene elements in the second array to a first value, set the values of the units in the third set of units in the second array other than the second set of units to a second value, and set the values of the units in the second array other than the third set of units to a third value, where the third set of units is the set of units in the second array corresponding to the first set of scene elements, the number of units in the second array is equal to the number of scene elements in the target three-dimensional scene, and there is a one-to-one correspondence between the units in the second array and the scene elements in the target three-dimensional scene, a unit with a value of the first value indicates that the corresponding scene element is a visible element in the target perspective, a unit with a value of the second value indicates that the corresponding scene element is an invisible element in the target perspective, and a unit with a value of the third value indicates that the corresponding scene element is not within the range of the target perspective; send the second array to the target processing device.
[0112] According to one aspect of the present application, there is provided a computer program product, which includes computer programs / instructions, and the computer programs / instructions include program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 1209 and / or installed from the removable medium 1211. When the computer program is executed by the central processing unit 1201, various functions provided by the embodiments of the present application are executed.
[0113] The serial numbers of the above embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0114] Figure 12 Schematically shown is a block diagram of a computer system of an electronic device for implementing the embodiments of the present application.
[0115] It should be noted that Figure 12The computer system 1200 of the illustrated electronic device is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application.
[0116] As Figure 12 shown, the computer system 1200 includes a central processing unit 1201 (CPU), which can perform various appropriate actions and processes according to the program stored in the read-only memory 1202 (ROM) or the program loaded from the storage section 1208 into the random access memory 1203 (RAM). In the random access memory 1203, various programs and data required for system operation are also stored. The central processing unit 1201, the read-only memory 1202, and the random access memory 1203 are connected to each other via a bus 1204. The input / output interface 1205 (Input / Output interface, i.e., I / O interface) is also connected to the bus 1204.
[0117] The following components are connected to the input / output interface 1205: an input section 1206 including a keyboard, a mouse, etc.; an output section 1207 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1208 including a hard disk, etc.; and a communication section 1209 including a network interface card such as a local area network card, a modem, etc. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the input / output interface 1205 as required. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1210 as required so that the computer program read from it can be installed into the storage section 1208 as required.
[0118] Specifically, according to the embodiments of the present application, the processes described in each method flowchart can be implemented as computer software programs. For example, the embodiments of the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 1209, and / or installed from the removable medium 1211. When the computer program is executed by the central processing unit 1201, various functions defined in the system of the present application are executed.
[0119] According to another aspect of the embodiments of the present application, there is also provided an electronic device for implementing the above-described method for determining visible elements. The electronic device may be Figure 1 the terminal device or server shown in the figure. In this embodiment, the server is taken as an example of the electronic device for illustration. As Figure 13 shown, the electronic device includes a memory 1302 and a processor 1304. A computer program is stored in the memory 1302, and the processor 1304 is configured to execute the steps in any of the above method embodiments through the computer program.
[0120] Optionally, in this embodiment, the above electronic device may be at least one of multiple network devices in a computer network.
[0121] Optionally, in this embodiment, the above processor may be configured to execute the following steps through a computer program:
[0122] S1. Render each scene element in the first set of scene elements from the target perspective to obtain a target rendered image, where the first set of scene elements includes the scene elements to be rendered from the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first set of scene elements from the target perspective, the target rendered image includes the pixels in the scene elements in the first set of scene elements except the occluded scene elements;
[0123] S2. Determine the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image to obtain a target number set;
[0124] S3. Determine a second set of scene elements in the first set of scene elements, and determine the scene elements in the second set of scene elements as the visible elements from the target perspective, where the numbers of the scene elements in the second set of scene elements are the numbers in the target number set.
[0125] Optionally, those of ordinary skill in the art can understand that Figure 13 the structure shown in the figure is only schematic. The electronic device may also be a terminal device such as a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a handheld computer, and a Mobile Internet Device (MID), a PAD, etc. Figure 13 It does not limit the structure of the above electronic device. For example, the electronic device may further include more Figure 13more or fewer components (such as network interfaces, etc.) shown in the figure, or having a configuration different from that shown in Figure 13 the figure.
[0126] Among them, the memory 1302 can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and device for determining visible elements in the embodiments of the present application. The processor 1304 executes various functional applications and data processing by running the software programs and modules stored in the memory 1302, that is, implements the above-mentioned method for determining visible elements. The memory 1302 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 1302 may further include a memory remotely disposed relative to the processor 1304, and these remote memories can be connected to the terminal through a network. Examples of the above network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and their combinations. Among them, the memory 1302 can specifically but not limitedly be used to store information such as scene elements. As an example, as Figure 13 shown in the figure, the above-mentioned memory 1302 may include but are not limited to the rendering module 1102, the first determination module 1104, and the second determination module 1106 in the above-mentioned device for determining visible elements. In addition, it may also include but are not limited to other module units in the above-mentioned device for determining visible elements, which will not be elaborated in this example.
[0127] Optionally, the above-mentioned transmission device 1306 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one instance, the transmission device 1306 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers through a network cable, so as to communicate with the Internet or a local area network. In one instance, the transmission device 1306 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0128] In addition, the above-mentioned electronic device further includes: a display 1308, which is used to display the above-mentioned visible scene elements; and a connection bus 1310, which is used to connect each module component in the above-mentioned electronic device.
[0129] In other embodiments, the above-mentioned terminal device or server may be a node in a distributed system. The distributed system may be a blockchain system, which may be a distributed system formed by connecting the multiple nodes in a network communication manner. Among them, the nodes may form a peer-to-peer (P2P) network, and any form of computing device, such as electronic devices like servers and terminals, can become a node in the blockchain system by joining the peer-to-peer network.
[0130] According to one aspect of the present application, there is provided a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above various optional implementation manners.
[0131] Optionally, in this embodiment, the above-mentioned computer-readable storage medium may be set to store a computer program for executing the following steps:
[0132] S1, rendering each scene element in the first scene element set from a target perspective to obtain a target rendered image, where the first scene element set includes the scene elements to be rendered from the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first scene element set from the target perspective, the target rendered image includes the pixels of the scene elements in the first scene element set except the occluded scene elements;
[0133] S2, determining the number of the scene element where each pixel is located according to the color value of each pixel in the target rendered image to obtain a target number set;
[0134] S3, determining a second scene element set in the first scene element set and determining the scene elements in the second scene element set as the visible elements from the target perspective, where the numbers of the scene elements in the second scene element set are the numbers in the target number set.
[0135] Optionally, in this embodiment, those of ordinary skill in the art can understand that all or part of the steps in the above various methods can be completed by instructing the relevant hardware of the terminal device through a program. The program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.
[0136] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage media. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing one or more computer devices (which can be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in various embodiments of this application.
[0137] In the above embodiments of this application, the descriptions of each embodiment have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0138] In the several embodiments provided by this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of units or modules can be in electrical or other forms.
[0139] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0140] In addition, the functional units in each embodiment of this application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0141] The above are only the preferred embodiments of this application. It should be noted that for those of ordinary skill in the art, without departing from the principle of this application, several improvements and refinements can still be made, and these improvements and refinements should also be regarded as the protection scope of this application.
Claims
1. A method for determining visible elements, characterized in that, Including: Render each scene element in the first set of scene elements in the target perspective in the frame buffer to obtain a target rendered image, and store the color values of the pixels in each of the scene elements in the frame buffer, where the first set of scene elements includes the scene elements to be rendered in the target perspective in the target scene, each of the scene elements has a corresponding number, and the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs. When there are occluded scene elements in the first set of scene elements in the target perspective, the target rendered image includes the pixels in the scene elements in the first set of scene elements other than the occluded scene elements; Parallelly calculate and determine the numbers of the scene elements where each pixel is located according to the color values of each pixel stored in the frame buffer in the compute shader to obtain a target set of numbers; Determine a second set of scene elements from the first set of scene elements according to the compute shader, where the scene elements in the second set of scene elements are visible elements in the target perspective; Determine the array units that match the target set of numbers, where the values of the array units that match the visible elements in the array units are the first value, and the values of the array units that match the invisible elements are the second value; Send the array units to the CPU, where the CPU is used to determine the target game screen that matches the target rendered image according to the array units.
2. The method according to claim 1, characterized in that, Before rendering each scene element in the first set of scene elements in the target perspective to obtain a target rendered image, the method further includes: Search for the scene elements within the range of the target perspective in the target scene to obtain the first set of scene elements.
3. The method according to claim 1, characterized in that, The rendering each scene element in the first set of scene elements in the target perspective in the frame buffer to obtain a target rendered image includes: Respectively determine the color values corresponding to the respective scene elements according to the numbers of the respective scene elements in the first set of scene elements, where the color values corresponding to different numbered scene elements are different; Determine the color values of the pixels in each of the scene elements as the color values corresponding to the respective scene elements, where the color values of the pixels in the same scene element are all the color values corresponding to the same scene element; According to the positions of the respective scene elements in the target perspective, store the color values of the pixels in each of the scene elements at the corresponding storage positions in the target storage space. When there are a first scene element and a second scene element in the respective scene elements and the position of the first scene element in the target perspective is occluded by the position of the second scene element in the target perspective, the color values of the pixels in the first scene element stored in the target storage space are overwritten by the color values of the pixels in the second scene element, and the color values of the pixels stored in the target storage space are the color values of the pixels in the target rendered image.
4. The method according to claim 3, wherein Storing the color values of the pixels in each of the scene elements at corresponding storage positions in the target storage space according to the positions of the respective scene elements in the target view includes: Performing the following operations on each of the scene elements in the first set of scene elements. When performing the following operations, each of the scene elements is the current scene element, and the position of the current scene element in the target view is the current position: Searching for the current storage position corresponding to the current position in the target storage space; When the color value of the pixels in a scene element has been stored at the current storage position, overwriting the stored color value of the pixels in the one scene element with the color value of the pixels in the current scene element, where the position of the one scene element in the target view is occluded by the position of the current scene element in the target view; When no color value of the pixels in any scene element is stored at the current storage position, storing the color value of the pixels in the current scene element at the current storage position.
5. The method according to claim 3, characterized in that Determining the color values corresponding to the respective scene elements according to the numbers of the respective scene elements in the first set of scene elements includes: Performing the following operations on each of the scene elements in the first set of scene elements. When performing the following operations, each of the scene elements is the current scene element: Obtaining the number of the current scene element; Performing a logical operation on the number of the current scene element to obtain the color value corresponding to the current scene element.
6. The method according to claim 5, wherein Parallelly calculating and determining the numbers of the scene elements to which each of the pixels stored in the frame buffer belongs in the compute shader to obtain a set of target numbers, including: Performing the following operations on the color values of the respective pixels stored in the target storage space. When performing the following operations, each of the pixels is the current pixel: Performing an inverse logical operation corresponding to the logical operation on the color value of the current pixel to obtain the number of the scene element to which the current pixel belongs.
7. The method according to claim 1, wherein Parallelly calculating and determining the numbers of the scene elements to which each of the pixels stored in the frame buffer belongs in the compute shader to obtain a set of target numbers, including: Parallelly obtaining the color values of the pixels in the target rendered image through a set of target threads, and determining the numbers of the scene elements to which the obtained color values of the pixels belong according to the obtained color values of the pixels, where the target rendered image includes a plurality of image blocks, and each thread in the set of target threads is used to read the color values of the pixels in an image block of a target size in the target rendered image each time.
8. The method according to claim 1, characterized in that Determining the scene elements in the second set of scene elements as visible elements in the target view includes: When the second set of scene elements is a second set of models and each of the scene elements in the second set of scene elements is a model in the second set of models, determining each of the models in the second set of models as a visible model in the target view; or When the second set of scene elements is the second set of graphic elements and each scene element in the second set of scene elements is a graphic element in the second set of graphic elements, each graphic element in the second set of graphic elements is determined as a visible graphic element in the target perspective.
9. The method according to claim 1, characterized in that Rendering each scene element in the first set of scene elements in the target perspective in a frame buffer to obtain a target rendered image includes: When the first set of scene elements is the first set of models and each scene element in the first set of scene elements is a model in the first set of models, determining color values corresponding to the models in the first set of models according to the numbers of the models, where different models have different corresponding color values, and the color values of pixels in the same model are all the color values corresponding to the same model; determining the target rendered image according to the color values corresponding to the models in the first set of models and the positions of the models in the target perspective; or When the first set of scene elements is the first set of graphic elements and each scene element in the first set of scene elements is a graphic element in the first set of graphic elements, determining color values corresponding to the graphic elements in the first set of graphic elements according to the numbers of the graphic elements, where different graphic elements have different corresponding color values, and the color values of pixels in the same graphic element are all the color values corresponding to the same graphic element; determining the target rendered image according to the color values corresponding to the graphic elements in the first set of graphic elements and the positions of the graphic elements in the target perspective.
10. The method according to any one of claims 1 to 9, characterized in that, In the case where the scene elements in the second set of scene elements are determined as visible elements in the target perspective, the method further includes: Setting the values of the first set of units in the first array corresponding to the second set of scene elements to a first value, and setting the values of the units in the first array other than the first set of units to a second value, where the number of units in the first array is the number of scene elements in the first set of scene elements, the units in the first array have a one-to-one correspondence with the scene elements in the first set of scene elements, the units with the value of the first value indicate that the corresponding scene elements are visible elements in the target perspective, and the units with the value of the second value indicate that the corresponding scene elements are invisible elements in the target perspective; sending the first array to a target processing device; or Set the values of the second unit set corresponding to the second scene element set in the second array to the first value, set the values of the units in the third unit set in the second array other than the second unit set to the second value, and set the values of the units in the second array other than the third unit set to the third value, where the third unit set is the unit set in the second array corresponding to the first scene element set, the number of units in the second array is the number of scene elements in the target scene, the units in the second array have a one-to-one correspondence with the scene elements in the target scene, the units with the first value indicate that the corresponding scene elements are visible elements in the target perspective, the units with the second value indicate that the corresponding scene elements are invisible elements in the target perspective, and the units with the third value indicate that the corresponding scene elements are not within the range of the target perspective; send the second array to the target processing device.
11. A determining device for visible elements, characterized in that, Including: A rendering module, configured to render each scene element in the first scene element set in the target perspective in a frame buffer to obtain a target rendered image, and store the color values of the pixels in each of the scene elements in the frame buffer, where the first scene element set includes the scene elements to be rendered in the target perspective in the target scene, each of the scene elements has a corresponding number, the color value of each pixel in the target rendered image is rendered according to the number of the scene element to which each pixel belongs, and when there are occluded scene elements in the first scene element set in the target perspective, the target rendered image includes the pixels in the scene elements in the first scene element set other than the occluded scene elements; A first determination module, configured to parallelly calculate and determine the number of the scene element where each pixel is located according to the color value of each pixel stored in the frame buffer in a compute shader to obtain a target number set; A second determination module, configured to determine a second scene element set from the first scene element set according to the compute shader, where the scene elements in the second scene element set are visible elements in the target perspective; Determine the array units that match the target number set, where the values of the array units that match the visible elements in the array units are the first value, and the values of the array units that match the invisible elements are the second value; Send the array units to the CPU, where the CPU is configured to determine a target game screen that matches the target rendered image according to the array units.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, where the program, when running, executes the method described in any one of claims 1 to 10.
13. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by a processor, it implements the steps of the method described in any one of claims 1 to 10.
14. An electronic device, comprising a memory and a processor, characterized in that, A computer program is stored in the memory, and the processor is configured to execute the method described in any one of claims 1 to 10 through the computer program.
Citation Information
Patent Citations
Picture rendering method and device, storage medium, and electronic device
CN109461199A
Back component removing method and system based on off-screen rendering and storage medium
CN111951342A
Picture display method and device, information generation method and device, equipment and storage medium
CN113457161A