A method, device, medium and product for generating a war fog
By generating fog of war using the GPU, distinguishing between static and dynamic objects based on their update frequency, and using rendering textures to generate fog of war, the problems of high CPU load and poor compatibility with low-end devices are solved, achieving fast and stable fog of war display.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, generating fog of war using the CPU involves high computational load, causing frame drops or stuttering on mobile devices; while generating fog of war using the GPU results in poor compatibility with low-end devices.
The system uses GPUs to generate fog of war, distinguishes between static and dynamic objects based on their update frequency, uses Render Texture to create rendering textures, generates fog of war, avoids reliance on Compute Shader, and is compatible with multiple platforms and rendering interfaces.
Reduce CPU load, improve compatibility with low-end devices, process faster, be compatible with both high-end and low-end devices, and avoid frame drops or stuttering.
Smart Images

Figure CN120860587B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information technology, and in particular to a method, device, medium and product for generating fog of war. Background Technology
[0002] Fog of War is a game mechanic used to hide areas that players have not yet explored or cannot currently observe. It is commonly used in simulation games, such as strategy war games, as well as role-playing games.
[0003] There are two common methods for creating fog of war: one is to calculate the visibility range of each unit in the CPU and synthesize a fog map; the other is to generate the fog map using the GPU's computing cores.
[0004] However, the inventors have discovered at least the following technical problems in the related technology: 1. When generating fog of war based on CPU, the CPU's computing load is high in complex scenes, which can cause frame drops or frame drops when displayed on mobile devices; 2. In the process of generating fog of war mask through the computing core of GPU, many low-end devices do not support or only support this feature, resulting in poor compatibility. Summary of the Invention
[0005] One objective of this application is to provide a solution that addresses the problems of high computational load when generating fog of war using CPUs and the fact that many low-end devices do not support or have limited support for the fog of war masking generated via GPU computing cores.
[0006] To achieve the above objectives, some embodiments of this application provide the following aspects:
[0007] In a first aspect, some embodiments of this application provide a method for generating fog of war, the method being applied to a graphics processor, the method comprising: determining static objects and dynamic objects based on the update frequency of objects during game operation; determining a first rendering texture and / or a second rendering texture based on the static objects and the dynamic objects; the first rendering texture being used to characterize the state of an area covered by the view of a static object, and the second rendering texture being used to characterize the state of an area covered by the view of a static object and / or a dynamic object; and generating fog of war based on the first rendering texture and / or the second rendering texture.
[0008] Secondly, some embodiments of this application also provide an electronic device, the electronic device comprising: one or more processors; and a memory storing computer program instructions, which, when executed, cause the processor to perform the steps of the method described above.
[0009] In a third aspect, some embodiments of the present application further provide a computer readable medium having stored thereon computer program instructions, which can be executed by a processor to implement the method as described above.
[0010] In a fourth aspect, some embodiments of the present application further provide a computer program product comprising computer program / instructions, which, when executed by a processor, implement the steps of the method as described above.
[0011] Compared with the related art, in the scheme provided by the embodiments of the present application, the generation of war fog based on GPU can reduce the burden of CPU and take advantage of parallel computing of GPU to perform accelerated operation. According to the update frequency of objects in the game running process, static objects and dynamic objects are determined. In this way, after different objects are determined, the CPU pressure can be further reduced without frame-by-frame updating. Then, according to the classification idea, the first rendering texture and / or the second rendering texture are determined according to the static objects and the dynamic objects. The first rendering texture is used to represent the state of the area covered by the static objects. The second rendering texture is used to represent the state of the area covered by the static objects and / or the dynamic objects. This process does not depend on Compute Shader. Only Render Texture needs to be created and managed in GPU. This can improve the adaptability to low-end devices to a certain extent, and can adapt to multiple platforms such as mobile terminals, PCs and hosts, and different rendering interfaces (APIs), and has better expansibility and wide device compatibility. Finally, the war fog is generated according to the first rendering texture and / or the second rendering texture, which can flexibly take into account the static objects and the dynamic objects. In this way, by providing a war fog generation method based on GPU, the overloading work of CPU and the dependence on interface applets can be avoided. In the face of complex game graphics processing scenarios, the processing speed is faster, and it is not easy to drop or frame in the display. It can be compatible with high-end and low-end devices. BRIEF DESCRIPTION OF DRAWINGS
[0012] One or more embodiments are illustrated by way of example in the figures that are part of this document, and which illustrate key / representative principles of the embodiments. Such embodiments do not constitute an exhaustive list of embodiments that can be made therewithin. The drawings in the figures are not to scale and are provided merely to clarify key principles of the embodiments.
[0013] Figure 1 An exemplary flowchart of a war fog generation method provided by some embodiments of the present application;
[0014] Figure 2 An exemplary flowchart of generating war fog according to the first rendering texture and / or the second rendering texture provided by some embodiments of the present application;
[0015] Figure 3 An exemplary structural schematic diagram of an electronic device is provided for some embodiments of the present application. DETAILED DESCRIPTION
[0016] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0017] The following terms are used herein.
[0018] CPU, Central Processing Unit, the running core and control core of a computer manufactured by using a super large scale integrated circuit.
[0019] GPU, Graphics Processing Unit, a graphics processor, used for processing graphics rendering related tasks, with high parallel computing capability.
[0020] Fog of War, a game mechanism used for hiding areas that have not been explored or are currently unable to be observed by players.
[0021] SLG, Simulation Game, a simulation game such as a strategy war game.
[0022] RPG, Role-Palying Game, a role-playing game.
[0023] OpenGL / OpenGL ES, Open Graphics Library, an open graphics library, is a cross-language and cross-platform application program interface used for rendering 2D and 3D vector graphics, composed of nearly 350 different function calls, used to draw simple graphics bits to complex three-dimensional scenes.
[0024] Compute Shader, a compute shader, is a shader program type in OpenGL (and OpenGL ES), used for performing general computing tasks on a GPU.
[0025] Render Texture, a render texture, is used for rendering a drawn picture, allows the rendering result to be saved as a reusable map, and is essentially a temporary memory area for storing images, created and managed by a GPU.
[0026] Fragment shaders perform color calculations on pixels during the rendering process.
[0027] Vulkan is a low-overhead, cross-platform 2D and 3D graphics and computing application interface. Unlike OpenGL, Vulkan is a low-level API that can perform parallel tasks and better allocate the use of multiple CPU cores.
[0028] Metal, developed by Apple, is an application programming interface that combines graphics and computing functions, targeting low-level, low-overhead hardware acceleration.
[0029] API stands for Application Programming Interface.
[0030] First Embodiment
[0031] The first embodiment of this application relates to a method for generating fog of war. For example... Figure 1 As shown, the method is applied to a graphics processor, and the method may include the following steps:
[0032] Step S10: Determine static and dynamic objects based on their update frequency during the game.
[0033] Step S20: Determine a first rendering texture and / or a second rendering texture based on the static object and the dynamic object; the first rendering texture is used to characterize the state of the area covered by the view of the static object, and the second rendering texture is used to characterize the state of the area covered by the view of the static object and / or the dynamic object.
[0034] Step S30: Generate fog of war based on the first rendering texture and / or the second rendering texture.
[0035] First, it should be noted that the method is applied to a graphics processing unit (GPU), and the technical solution of this embodiment uses the GPU as the execution entity. In some embodiments, the method can be adapted to multiple platforms such as mobile devices, PCs, and consoles, and can be adapted to various application programming interfaces such as OpenGL, Vulkan, and Metal.
[0036] The following sections will provide a detailed explanation of each of the above steps.
[0037] For step S10, specifically, the update frequency can generally refer to the time interval of twice state refresh of objects in the game, that is, after the last update is completed, the state of the object is refreshed and modified again after a certain time interval. Static objects can include objects whose position and state usually do not change during game running, and dynamic objects can include objects whose position and state can change during game running. The update frequency of static objects is lower than that of dynamic objects. For example, in an open-world RPG game, static objects can be scenes in the game, including terrain, buildings, fixed trees, and immovable decorations such as street lamps and benches, etc. Dynamic objects can be player characters, NPCs, props, etc.
[0038] For step S20, specifically, at the beginning of the rendering process, two render textures are created, and the initial default value of the pixels is black, which represents invisible areas, and white, which represents visible areas. The static objects are rendered to the first render texture, and the dynamic objects and the first render texture are jointly rendered to the second render texture.
[0039] For example, when the static objects are updated, the static objects are rendered to the first render texture, and the dynamic objects and the first render texture are jointly rendered to the second render texture. When the static objects are not updated, only the dynamic objects are rendered to the second render texture. At this time, the first render texture is directly reused instead of being rendered. Therefore, when the static objects do not change, significant performance optimization and simplified process are brought. For example, in an SLG game, the first render texture can show the explored war fog area in the game, and the second render texture can show the character movement. The first render texture is only updated when the player opens a new area for exploration, and can be directly reused in the current area.
[0040] For step S30, specifically, the first render texture and the second render texture are superimposed, and the final war fog picture is mixed by performing logical operation on each pixel in the two render textures. For example, the logical operation can be a Boolean operation.
[0041] For steps S10-S30, for example, in a real-time strategy game, static objects such as fixed buildings and mountains are included, and dynamic objects such as moving soldiers and heroes are also included. First, the static objects and the dynamic objects are distinguished, and the objects with an update frequency greater than 2 minutes / time are distinguished as static objects, and the objects with an update frequency less than or equal to 2 minutes / time are distinguished as dynamic objects. Then, the first render texture is generated for recording the constant light area covered by the building view, and the second render texture is generated for superimposing the temporary view of the soldiers and heroes moving on the basis of the first render texture. Finally, the area not covered by the texture generates the war fog.
[0042] It can be understood that in the related art, the technical solution of generating a war fog mask is generally calculated by a CPU, and the CPU operation load is high in a complex scene. In the process of generating a war fog mask by a computing core of a GPU, although the operation can be accelerated and the burden of the CPU can be reduced, it depends on the support of Compute Shader, and Compute Shader is a Shader program type in OpenGL ES and OpenGL, which can only support high versions of OpenGLES and OpenGL (OpenGLES 3.1 or above, OpenGL 4.3 or above).
[0043] It can be found that, compared with the related art, in the scheme provided by the embodiments of the application, the generation of war fog based on GPU can take advantage of the parallel computing of GPU to accelerate operation, and according to the update frequency of objects in the game running process, static objects and dynamic objects are determined. In this way, after different objects are determined, the CPU pressure can be further reduced without updating frame by frame. Then, according to the classification idea, the first rendering texture and / or the second rendering texture are determined according to the static objects and the dynamic objects, wherein the first rendering texture is used to represent the state of the area covered by the static objects, and the second rendering texture is used to represent the state of the area covered by the static objects and / or the dynamic objects. This process does not depend on Compute Shader, and only needs to create and manage Render Texture in GPU, which can improve the adaptability to low-end devices to a certain extent, and can adapt to multiple platforms such as mobile terminals, PCs and hosts, and different rendering interfaces, and has better expansibility and wide device compatibility. Finally, according to the first rendering texture and / or the second rendering texture, the war fog is generated, and the static objects and the dynamic objects can be flexibly considered. In this way, by providing a war fog generation method based on GPU, the overloading work of CPU and the dependence on interface applets can be avoided. In the face of complex game graphics processing scene, the processing speed is faster, and it is not easy to drop frame or frame in the display, and it can be compatible with high-end and low-end devices.
[0044] Second embodiment
[0045] The second embodiment of the application relates to a war fog generation method. The second embodiment is an improvement based on the first embodiment, and the specific improvement is that in the embodiment, a method for determining static objects and dynamic objects according to the update frequency is provided, and a method for determining the first rendering texture is provided.
[0046] Optionally, in some embodiments, the determination of static objects and dynamic objects according to the update frequency of objects in the game running process, i.e., step S10, can include:
[0047] Step S101, determining the object with an update frequency greater than a preset threshold as a static object;
[0048] Step S102, determining the object with an update frequency less than or equal to the preset threshold as a dynamic object; wherein the number of the dynamic objects is less than the number of the static objects.
[0049] The following is described with the GPU as the execution subject.
[0050] For steps S101 and S102, specifically, by determining the relationship between the update frequency of the object and the preset threshold, the object with an update frequency greater than the preset threshold is determined as a static object, and the object with an update frequency less than or equal to the preset threshold is determined as a dynamic object. Exemplarily, the preset threshold can be 1 minute / time. Since the number of dynamic objects is less than the number of static objects in game design, although the update frequency of dynamic objects is less than that of static objects, static objects can be processed by merging to reduce the communication pressure from CPU to GPU, and the less the number of dynamic objects, the less the GPU calculation amount. This way of distinguishing can greatly reduce the calculation burden.
[0051] For steps S101-S102, for example, in an open-world survival game, it is necessary to distinguish static and dynamic objects to optimize the calculation of war fog. Assuming that the preset threshold is 2 minutes / time, according to step S101, it can be determined that the position and state of the tree almost do not change and can be marked as a static object; according to step S102, it can be determined that the player character moves multiple times per second and the monster performs random walk, which can be marked as a dynamic object. Moreover, there can be thousands of static trees on the map, but the player, monsters, etc. usually only have a few tens, which meets the setting that the number of dynamic objects is less than that of static objects. Since static objects do not need to be recalculated every frame, the real-time view of dynamic objects is maintained.
[0052] Optionally, in some embodiments, in step S20, the determination method of the first rendering texture can include:
[0053] Step S2010, when detecting the state update of the static object, setting a first initialization rendering texture as a rendering target; the first initialization rendering texture is used to represent a single-channel texture that is pre-created and initialized as all black;
[0054] Step S2011, obtaining a first parameter set; the first parameter set at least includes: a map size parameter in a world scene, a map-to-world scale parameter, and a position coordinate and a view range parameter of all static objects;
[0055] Step S2012, determining a first rendering texture according to the first initialization rendering texture and the first parameter set.
[0056] For step S2010, specifically, at the beginning of the rendering process, two RenderTextures have been created, and the initial default value of the pixels is black. When the static object state update is detected, one of the pre-created RenderTextures is set as the first initialization RenderTexture and is set as the rendering target.
[0057] For step S2011, specifically, the relevant parameters of the world scene and the static objects need to be obtained, and the first parameter set composed of the relevant parameters at least includes: the map size parameter in the world scene, the scale parameter of the map to the world, the position coordinates of all static objects, and the field of view range parameter. The map size parameter of the world scene can be used to determine the coverage range of the rendering texture. If the map of the world scene is large, the rendering texture needs to be divided into blocks. The scale parameter of the map to the world can be used to avoid stretching of the map or misalignment of the pixels. Since the size of the rendering texture is different from the size of the game world, the scale of the rendering texture as a map needs to be adjusted to be consistent with the world, otherwise the content of the rendering texture will be distorted or blurred. The position coordinates of the static objects can be used to determine the coverage range of the pixels; the field of view range parameter can be used to determine the field of view range of the static objects, control the rendering area of the rendering texture, and the field of view range area is the area visible to the player in the game.
[0058] For step S2012, specifically, the position coordinates of each static object are traversed in the Fragment Shader, and the pixels covered by the static object are drawn in white according to the field of view range parameter. The initial default value of the pixels not covered can be kept, i.e., black. When the state of the static object changes, the check flag can be reset and the checking process can be re-executed to update the visible area of the static object.
[0059] For steps S2010-S2012, for example, in a strategy war game, the following static objects exist on the game map: a watchtower, a circular field of view with a radius of 5 meters; a city wall, used to block the field of view. According to step S2010, the pre-created rendering texture is taken as the first initialization rendering texture, with an initial value of RGB (0, 0, 0), indicating that the initial war fog coverage. According to step S2011, the map size parameters in the world scene are obtained, and since the map size is 100m x 100m, the resolution of the first initialization rendering texture can be 1024 pixels x 1024 pixels; the scale parameters of the map and the world scene are obtained, 1 pixel = 0.1 meters; the position coordinates and field of view range parameters of the static objects are obtained, wherein the position coordinates of the watchtower 1 are (20m, 30m), and the field of view radius is 5m, the position coordinates of the watchtower 2 are (70m, 50m), and the field of view radius is 5m, and the position coordinates of the city wall are (40m-60m, 40m), and the width is 20m and completely blocks the rear field of view. According to step S2012, a white circle with a radius of 50 pixels is drawn with the position coordinates of the watchtower 1 as the center, indicating the visible area; a white circle with a radius of 50 pixels is drawn with the position coordinates of the watchtower 2 as the center, indicating the visible area; for the city wall area, it is marked as black, indicating that it is blocked, and when the watchtower field of view covers the city wall, the rear is not visible. Finally, the output result is output to the first rendering texture, so that the field of view range of the static object can be reflected in the first rendering texture.
[0060] Optionally, in some embodiments, the determining the first rendering texture according to the first initialization rendering texture and the first parameter set, i.e., step S2012, comprises:
[0061] Step S20121, generating a first geometric primitive according to the size of the first initialization rendering texture, and establishing a first mapping relationship between the geometric vertex and the texture coordinate;
[0062] Step S20122, for each pixel covered by the first geometric primitive, performing the following operations: obtaining the current texture coordinate according to the first mapping relationship, converting the texture coordinate into a world coordinate according to the map size parameters and the scale parameters; determining the coverage state of the world coordinate according to the position coordinates and the field of view range parameters of the static object; determining the static visibility value according to the coverage state; the static visibility value is used to represent whether the current pixel position is covered by the field of view of the static object;
[0063] Step S20123, writing the static visibility value into the corresponding position of the first initialization rendering texture to determine the first rendering texture.
[0064] For step S20121, specifically, the texture cannot be directly rendered, and it must be mapped to the geometric primitive for rendering, and after mapping, the first geometric primitive covering the first initialization rendering texture can be generated; and since the world scene coordinates in the game are 3D coordinates, and the rendering texture coordinates are 2D coordinates, a mapping relationship from three dimensions to two dimensions can be established, specifically, a first mapping relationship from the vertex of the 3D model in the world scene to the texture coordinate is established, so that the information corresponding to the 3D model that needs to be rendered can be found according to the texture coordinate.
[0065] Generally, the texture coordinate is represented by S, T, and can also be represented by U, V, also known as UV coordinate, and the specific calculation method can be referred to as follows:
[0066] Suppose the map length is h, the width is w, and the origin of the map is , the input point is , and the current UV coordinate is .
[0067] For step S20122, specifically, for each pixel on which the rendering texture is mapped to the first geometric primitive, its actual position in the game, i.e. the world coordinate, is back calculated through the above UV coordinate calculation method, and then static field of view detection is performed to determine whether the world coordinate corresponding to the current pixel is covered by at least one static object, specifically by using the position coordinate and the field of view range parameter of the static object, the following determination is performed:
[0068] If the field of view range is circular, the distance between the world coordinate and the position coordinate is calculated, and if it is less than or equal to the radius of the circle, it is determined to be in the covered state;
[0069] If the field of view range is rectangular, it is determined whether the world coordinate is within the rectangular boundary centered on the position coordinate, and if it falls within the rectangular boundary, it is determined to be in the covered state.
[0070] The calculation method can be specifically referred to as follows:
[0071] 1. Determine whether the current input is within the radius range.
[0072]
[0073] If the condition is met, set the color to white, and if not, set it to black.
[0074] 2. When the current input is rectangular, the input width is , and the input length is
[0075] The maximum and minimum values corresponding to the UV coordinates are calculated.
[0076]
[0077]
[0078] determine whether the current input (u, v) is in the rectangle.
[0079]
[0080] If the condition is met, set to white, otherwise set to black.
[0081] For example, the static visibility value can be a binary, when the static visibility value is 1, it indicates that there is an overlay state; when the static visibility value is 0, it indicates that there is no overlay state.
[0082] For step S20123, specifically, the static visibility value is stored in the corresponding pixel position in the first initialized rendering texture, thereby determining the first rendering texture for the generation of the war fog.
[0083] For steps S20121-S20123, for example, assuming that the map size is a 1000m×1000m terrain grid, the watchtower field of view is a circle with a radius of 20m, the coordinates in the world scene are (200m, 50m, 10m), the rendering texture resolution is 1024×1024 pixels, and 1 pixel ≈ 0.98m. According to step S20121, the XZ plane of the 3D world is projected onto the UV coordinates to create a 2D rectangle covering the entire map, with the vertex UV range being (0, 0) to (1, 1), for carrying the rendering texture, establishing a first mapping relationship; according to step S20122, assuming that for a certain pixel in the texture, the coordinates are (205, 51), the world coordinates (200m, 50m) are obtained by back calculation, by calculating the distance between this pixel and the watchtower, it is determined that the pixel is within the field of view of the watchtower, then the pixel can be white, and the static visibility value can be 1; according to step S20123, the static visibility value is written to the corresponding position of the first initialized rendering texture, and the first rendering texture is determined.
[0084] It can be found that in the embodiments of the present application, by providing classification of static objects and dynamic objects according to the update frequency, the work burden of the GPU can be reduced. The provided first rendering texture determination method initializes the rendering texture, then maps the texture to the primitive, and establishes the mapping relationship between the world scene and the texture coordinates, uses the first parameter set to assist in determining whether the world coordinates corresponding to the current pixel are covered by the static object, and then determines the visible range of the static object war fog to generate the first rendering texture. In this way, it is beneficial to mark the invisible area, without the need for recalculation, accurate to the pixel level to ensure that there is no omission, only the visible area is rendered, and the GPU workflow is simplified.
[0085] Third embodiment
[0086] The third embodiment of the present application relates to a method for determining a second rendering texture. The third embodiment is an improvement on the basis of the first embodiment, and the specific improvement is that in the embodiment, a method for determining the second rendering texture is provided.
[0087] Optionally, in some embodiments, the method for determining the second rendering texture in step S20 can include:
[0088] In step S2020, when the state update of the dynamic object is detected, a second initialization rendering texture is set as a rendering target; the second initialization rendering texture is used to represent a single-channel texture that is pre-created and initialized as all black;
[0089] In step S2021, a second parameter set is obtained; the second parameter set at least includes: a map size parameter and the scale parameter in the first parameter set, position coordinates and a field of view range parameter of all dynamic objects, and pixel data of the first rendering texture;
[0090] In step S2022, the second rendering texture is determined according to the second initialization rendering texture and the second parameter set.
[0091] For step S2020, specifically, when the rendering process starts, two black and white textures have been created, and the initial default value of the pixels is black. When the dynamic object state update message is received, one of the pre-created black and white textures is set as the second initialization rendering texture and is set as the rendering target.
[0092] For step S2021, specifically, the related parameters of the dynamic object need to be obtained, and the second parameter set related to the dynamic object at least includes: the map size parameter and the scale parameter in the first parameter set, the position coordinates and the field of view range parameter of the dynamic object, and the pixel data of the first rendering texture. Among them, the map size parameter and the scale parameter in the first parameter set are introduced to ensure that the dynamic object is aligned with the map scale of the world scene, and to ensure that the coordinate conversion is consistent. The pixel data of the first rendering texture is used to provide visible information of the static object, so that the dynamic object is rendered on this basis. The position coordinates of the dynamic object are used to determine the pixel coverage range, and the field of view range parameter is used to determine the field of view range of the dynamic object, to control the rendering area of the rendering texture. The field of view range area is the area that can be seen by the player's perspective in the game.
[0093] For step S2022, specifically, the position coordinates of each dynamic object are traversed in the Fragment Shader, and the pixels covered by the static object are drawn white according to the field of view range parameters, and the pixels not covered can remain the initial default value, i.e., black. When the state of the dynamic object changes, the check flag can be reset and the check process can be re-executed to update the visible area of the dynamic object.
[0094] For steps S2020-S2022, for example, it is assumed that a first rendering texture has been generated according to the static object, the circular field of view area of the watchtower in the first rendering texture is white, and the rest is black, and the player character as a dynamic object has coordinates (150m, 200m) in the world scene and a field of view range radius of 15m, and the map size is 500m x 500m. First, an all-black rendering texture is selected as the second rendering texture, and the data of the above-mentioned second parameter set is input, wherein the scale parameter is 1 pixel ≈ 0.49m, and then the Fragment Shader performs coordinate conversion and dynamic field of view detection on the pixels. Taking pixel (300, 400) as an example, the world scene coordinates obtained by coordinate conversion are (147m, 196m), and the distance between the pixel and the player is calculated to be 5.85m. Therefore, the pixel is within the dynamic field of view range and can be marked as white, and the dynamic visibility value can be 1. According to step S2022, the dynamic visibility value is written to the corresponding position of the second initialization rendering texture to determine the second rendering texture.
[0095] Optionally, in some embodiments, the second rendering texture is determined according to the second initialization rendering texture and the second parameter set, i.e., step S2022 includes:
[0096] Step S20221, generating a second geometric primitive according to the size of the second initialization rendering texture, and establishing a second mapping relationship between the geometric vertex and the texture coordinate:
[0097] Step S20222, for each pixel covered by the second geometric primitive, the following operations are performed: obtaining the current texture coordinate according to the second mapping relationship; converting the texture coordinate into a world coordinate according to the map size parameter and the scale parameter; determining the coverage state of the world coordinate according to the position coordinates and the field of view range parameter of the dynamic object; determining the dynamic visibility value according to the coverage state; sampling the first rendering texture data to obtain the static visibility value; determining the mixed visibility value according to the static visibility value and the dynamic visibility value;
[0098] Step S20223, writing the mixed visibility value to the corresponding position of the second initialization rendering texture to determine the second rendering texture.
[0099] For step S20221, specifically, the texture needs to be mapped onto the geometric primitive for rendering, generating a second geometric primitive covering the second initialization rendering texture, and in addition, a coordinate mapping from the world scene in the game to the rendering texture needs to be established to cooperate with the second geometric primitive for later rendering. Among them, the second mapping relationship from the vertex of the 3D model in the world scene to the texture coordinate is established, so that according to the texture coordinate, the information corresponding to the 3D model that needs to be rendered can be found, and the conversion from the 3D model of the world scene to the texture coordinate can use the UV coordinate calculation method in the second embodiment.
[0100] For step S20222, specifically, for each pixel on which the rendering texture is mapped onto the second geometric primitive, its corresponding actual position in the game, i.e. the world coordinate, is back calculated through the UV coordinate calculation method, and then dynamic field of view detection is performed to determine whether the world coordinate corresponding to the current pixel is covered by at least one dynamic object, which is specifically determined by the position coordinate and the field of view range parameter of the dynamic object as follows:
[0101] If the field of view range is circular, the distance between the world coordinate and the position coordinate is calculated, and if it is less than or equal to the radius of the circle, it is determined to be in the covered state;
[0102] If the field of view range is rectangular, it is determined whether the world coordinate is within the rectangular boundary centered on the position coordinate, and if it falls within the rectangular boundary, it is determined to be in the covered state.
[0103] Exemplarily, the dynamic visibility value can be a binary, when the dynamic visibility value is 1, it indicates that there is a covered state; when the dynamic visibility value is 0, it indicates that there is no covered state. Then the first rendering texture data is sampled to obtain the static visibility value; according to the static visibility value and the dynamic visibility value, the mixed visibility value is determined, and in this process, the static visibility value and the dynamic visibility value can be logically operated, for example, when OR operation is performed, any visibility is 1, then the final visibility is visible; when AND operation is performed, both are 1, then the visibility is visible.
[0104] For step S20223, specifically, the mixed visibility value after logical operation is stored in the corresponding pixel position in the second initialization rendering texture, thereby determining the second rendering texture for the generation of war fog.
[0105] For steps S20121-S20123, for example, assuming a terrain grid with a map size of 1000m x 1000m, a sentry field of view of a circle with a radius of 20m, a coordinate in the world scene of (200m, 50m, 10m), a rendering texture resolution of 1024 x 1024 pixels, 1 pixel ≈ 0.98m, a current position of the player (150m, 200m, 0m), and a field of view radius of 15m. First, project the XZ plane of the 3D world onto the UV coordinate to create a 2D rectangle covering the entire map, with the vertex UV range being (0, 0) to (1, 1), for carrying the rendering texture, to establish a second mapping relationship; second, assuming that for a certain pixel in the texture, the coordinate (300, 400) is converted into the coordinate (293m, 391m) in the world scene, then dynamic field of view detection is performed, and after calculation, the distance between the pixel and the player is 238.5m, which is beyond the player's field of view range, then the pixel can be black, the dynamic visibility value is 0, and assuming that after sampling the first rendering texture, the static visibility value of the pixel is 1, after OR operation of the Boolean operation, the final mixed value is 1, the mixed value is written into the corresponding position of the first initialization rendering texture, and the second rendering texture is determined.
[0106] It should be noted that the present embodiment can also be an improvement based on the second embodiment.
[0107] It can be found that in the embodiments of the present application, a method for determining a second rendering texture is provided, an initialization rendering texture is provided, and then the texture is mapped to a primitive, and a mapping relationship between a world scene and a texture coordinate is established. In order to ensure that a dynamic object is aligned with a map scale of a world scene and consistent with a coordinate conversion of a static object, a first parameter set is introduced, then whether the world coordinate corresponding to the current pixel is covered by the dynamic object is judged according to the position coordinate and the field of view range parameter of the dynamic object, then the visible range of the war fog of the dynamic object is determined, and the second rendering texture is generated. In this way, the second rendering texture is mixed on the basis of the first rendering texture of the static object, and the consistency of the static object and the dynamic object is ensured.
[0108] Fourth Embodiment
[0109] The fourth embodiment of the present application relates to a method for generating war fog, and the fourth embodiment is an improvement based on any one or more of the first to third embodiments, and the specific improvement is that in the present embodiment, a method for generating war fog according to the first rendering texture and / or the second rendering texture is provided.
[0110] Optionally, in some embodiments, the generating war fog according to the first rendering texture and / or the second rendering texture, i.e., step S30, comprises:
[0111] Step S301, rendering a semi-transparent geometric patch covering the game map region;
[0112] Step S302, obtaining the texture coordinates corresponding to the current pixel in the semi-transparent geometric patch;
[0113] Step S303, determining the visibility value according to the first rendering texture and / or the second rendering texture: if the visibility value represents the covering state, output the pixel color with a transparency of 0; if the visibility value represents the uncovered state, output the war fog color with a preset transparency;
[0114] Step S304, writing the pixel color into the screen buffer to generate the war fog.
[0115] For example, referring to Figure 2 This embodiment demonstrates the formal rendering stage of the war fog:
[0116] I. Rendering the semi-transparent geometric patch: covering a semi-transparent patch on the game map as the canvas of the war fog, with a default RGB (0.2, 0.2, 0.2) dark gray color and a transparency of 0.5.
[0117] II. Obtaining the texture coordinates of the current pixel, and obtaining the texture coordinates (UV coordinates) corresponding to the pixel through the established coordinate mapping relationship.
[0118] III. Determining the visibility value: determining the visibility value according to the first rendering texture and / or the second rendering texture. Specifically, according to whether the pixel is covered by the field of view, the content displayed on the screen is determined. For example, when the visibility value is 1, it indicates that the position in the game world scene corresponding to the current pixel is covered by the field of view, and the output color is completely transparent, without displaying the fog; when the visibility value is 0, it indicates that the position is not within the coverage range of the field of view, and the output color is the war fog color with a preset transparency, such as black.
[0119] IV. Writing the pixel color into the screen buffer to generate the war fog. Specifically, white is displayed as completely transparent in the visible region, revealing the underlying game world scene, and black is displayed as semi-transparent gray in the invisible region.
[0120] The step division of the above methods is only for clear description, and in implementation, one step can be combined or some steps can be split and decomposed into multiple steps, as long as the same logical relationship is included, all of which are within the protection scope of the present application; adding insignificant modifications or introducing insignificant designs in the algorithm or flow, but not changing the core design of the algorithm and flow, are within the protection scope of the present application.
[0121] Fifth embodiment
[0122] Some embodiments of the application also provide an electronic device. The electronic device can be a digital computer of various forms, such as a laptop computer, a desktop computer, a workstation, a personal digital assistant, a server, a blade server, a mainframe computer, and so on. The electronic device can also be a mobile device of various forms, such as a personal digital assistant, a cellular phone, a smart phone, a wearable device, and other similar computing devices.
[0123] The electronic device includes one or more processors, and a memory storing computer program instructions that, when executed, cause the processor to perform the steps of the method provided by any one or more embodiments described above. FIG. XX discloses an exemplary structural diagram of the electronic device. The electronic device includes one or more processors 1101, a memory 1102, and interfaces for connecting components, including high-speed interfaces and low-speed interfaces. The components are connected to each other by different buses, and can be installed on a common motherboard or in other manners as needed. The processor can process instructions executed within the electronic device, including instructions stored in the memory or graphics information stored in the memory to display a GUI on an external input / output device, such as a display device coupled to the interface. In some other embodiments, multiple processors and / or buses can be used with multiple memories and multiple storage as needed. Also, multiple electronic devices can be connected, each device providing part of the necessary operations. Among them, the components shown herein, their connections and relationships, and their functions are only examples, and are not intended to limit the implementation of the application described and / or claimed herein.
[0124] The electronic device can also include an input device 1103 and an output device 1104. The processor 1101, the memory 1102, the input device 1103, and the output device 1104 can be connected by a bus or other means, and are connected by a bus in the figure as an example.
[0125] The input device 1103 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device, such as touch screen, keypad, mouse, trackpad, touchpad, pointing stick, one or more mouse buttons, trackball, joystick, and other input devices. The output device 1104 can include a display device, an auxiliary lighting device (e.g., LED), and a tactile feedback device (e.g., a vibration motor), and so on. The display device can include but is not limited to a liquid crystal display, a light-emitting diode display, and a plasma display. In some embodiments, the display device can be a touch screen.
[0126] To provide for interaction with a user, the electronic device can be a computer. The computer has a display device (e.g., a cathode ray tube or LCD monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, etc.); and input from the user can be received in any form (e.g., acoustic input, speech input, tactile input, etc.).
[0127] In the embodiments of the present application, the computer program / instruction stored on the computer readable medium is executed by the processor to implement the steps of the method provided by any one or more of the above embodiments. The computer readable medium can be included in the electronic device described in the above embodiments; or can exist separately and not be assembled into the device. The computer readable medium carries one or more computer readable instructions.
[0128] The memory 1102 can be used as a non-transitory computer readable storage medium to store non-transitory software programs, non-transitory computer executable programs and modules. The processor 1101 executes various functions and data processing of the server by running the non-transitory software programs, instructions and modules stored in the memory 1102, so as to implement the program instructions / modules corresponding to the method provided by any one or more of the above embodiments in the embodiments of the present application.
[0129] The memory 1102 can include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required by a function; and the data storage area can store data created according to the use of the electronic device, etc. In addition, the memory 1102 can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory 1102 can optionally include a memory disposed remotely with respect to the processor 1101, and these remote memories can be connected to the electronic device through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0130] Note that the computer-readable medium described herein can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable medium can be, for example but not limited to, a system, a device, or a computer program product embodied in one or more computer readable media embodying computer readable instructions, data structures, program modules, or other data. Computer-readable storage media include, at least, volatile memory, non-volatile memory, removable or non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase-change memory, static random access memory, dynamic random access memory, other types of random access memory, read-only memory, electrically erasable programmable read-only memory, flash memory or other memory technology, compact disc read-only memory, digital versatile discs or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information for access by a computing device. In addition, computer-readable storage media can include any appropriate media, which can be used for storing data accessible by a computing device, including a hard disk drive, solid state drive, RAM, ROM, EEPROM, CD-ROM or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information for access by a computing device.
[0131] Computer-readable media includes permanent and non-permanent, removable and non-removable media, which can be implemented by any method or technology for information storage. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase-change memory, static random access memory, dynamic random access memory, other types of random access memory, read-only memory, electrically erasable programmable read-only memory, flash memory or other memory technology, read-only optical disc, digital versatile disc or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage device or any other non-transmission medium that can be used to store information for access by a computing device.
[0132] Computer program code for carrying out operations of the present application can be written in one or more programming languages or combinations of languages including object-oriented, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as the C programming language or similar programming languages. Program code can be executed entirely on a user computer, partially on a user computer, as a standalone software package, partially on a user computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user computer through any kind of network, including a local area network or a wide area network, or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0133] In the above-described embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. For example, application specific integrated circuits, general purpose computers or any other similar hardware devices can be used. In some embodiments, the software programs of the present application can be executed by a processor to implement the above steps or functions. Similarly, the software programs of the present application (including related data structures) can be stored in a computer-readable recording medium, such as a RAM memory, a magnetic or optical drive or a soft disk and the like. In addition, some steps or functions of the present application can be implemented by hardware, such as a circuit cooperating with a processor to perform the respective steps or functions.
[0134] The computer program product provided by the embodiments of the present application includes one or more computer programs / instructions, which, when executed by a processor, generate all or part of the processes or functions described in the embodiments of the present application. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another, for example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be magnetic media (such as floppy disk, hard disk, magnetic tape), optical media (such as DVD), or semiconductor media (such as solid state disk) and the like.
[0135] The flowchart or block diagram in the drawings illustrates the architecture, functionality, and operation of possible implementations of devices, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram can represent a module, a segment, or a portion of code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks noted in succession can in fact be executed substantially concurrently, or the blocks can sometimes be executed in reverse order, depending on the functionality involved. It will also be noted that each block of the block diagrams and / or flowchart illustrations, or combinations of blocks in the block diagrams and / or flowchart illustrations, can be implemented by special-purpose hardware-based systems that perform the specified functions or operations, or combinations of special-purpose hardware and computer instructions.
[0136] The scope of the application is defined by the appended claims rather than by the description set forth herein, and therefore the specification is not intended to limit the claimed application, except as it may be limited by the claims. No admission is made that any of the related art references are prior art, either alone or in combination, or that such references are part of the common general knowledge of those working in the field, unless specified to be prior art by the claims. Any reference to or identification of a document in this specification is not an admission that such document is prior art to the claimed application, or part of the common general knowledge of the field, or that it is specifically identified as prior art by the claims. Any reference to background art in this specification is not to be construed as an admission that the claimed application is not entitled to antedate such art, or that the claimed application is required to solve the problems or meet the needs of the prior art identified in the background art section. It is further noted that the claims can be drafted to exclude any or all elements of any prior art disclosed in this specification, including those which are stated above. The claims can be drafted to exclude any or all of the features disclosed in the specification, including those which are stated above. The claims can be drafted to exclude any or all of the features disclosed in the specification, including those which are stated above. The claims can be drafted to exclude any or all of the features disclosed in the specification, including those which are stated above. The claims can be drafted to exclude any or all of the features disclosed in the specification, including those which are stated above.
[0137] The above description is only specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be defined by the protection scope of the claims, and the above embodiments should be regarded as exemplary and non-limiting.
Claims
1. A method for generating fog of war, characterized in that, The method is applied to a graphics processor, and the method includes: Based on the update frequency of objects during game operation, static and dynamic objects are determined, including: defining objects with an update frequency greater than a preset threshold as static objects, and defining objects with an update frequency less than or equal to the preset threshold as dynamic objects, wherein the number of dynamic objects is less than the number of static objects. Based on the static object and the dynamic object, a first rendering texture and / or a second rendering texture are determined; the first rendering texture is used to characterize the state of the area covered by the view of the static object, and the second rendering texture is used to characterize the state of the area covered by the view of the static object and / or the dynamic object. The method for determining the first rendering texture includes: when a state update of the static object is detected, setting the first initial rendering texture as the rendering target; the first initial rendering texture is used to represent a pre-created and initialized all-black single-channel texture; obtaining a first parameter set; the first parameter set includes at least: map size parameters in the world scene, texture-to-world ratio parameters, and position coordinates and field of view parameters of all static objects; determining the first rendering texture based on the first initial rendering texture and the first parameter set; The method for determining the second rendering texture includes: when a state update of the dynamic object is detected, setting the second initial rendering texture as the rendering target; the second initial rendering texture is used to represent a pre-created and initialized all-black single-channel texture; obtaining a second parameter set; the second parameter set includes at least: map size parameters and scale parameters in the first parameter set, position coordinates and field of view parameters of all dynamic objects, and pixel data of the first rendering texture; determining the second rendering texture based on the second initial rendering texture and the second parameter set; Generate fog of war based on the first and second rendering textures, including: superimposing the first and second rendering textures, and mixing them into the final fog of war image by performing logical operations on each pixel of the two rendering textures.
2. The method according to claim 1, characterized in that, The step of determining the first rendering texture based on the first initialized rendering texture and the first parameter set includes: Generate a first geometric primitive based on the size of the first initialized rendering texture, and establish a first mapping relationship from geometric vertices to texture coordinates: For each pixel covered by the first geometric primitive, perform the following operations: obtain the current texture coordinates according to the first mapping relationship; convert the texture coordinates into world coordinates according to the map size parameters and scale parameters; determine the coverage state of the world coordinates according to the position coordinates and field of view parameters of the static object; determine the static visibility value according to the coverage state; the static visibility value is used to characterize whether the current pixel position is covered by the field of view of the static object. Write the static visibility value to the corresponding position of the first initialized rendering texture to determine the first rendering texture.
3. The method according to claim 1, characterized in that, The step of determining the second rendering texture based on the second initialized rendering texture and the second parameter set includes: Generate a second geometric primitive based on the size of the second initialized rendering texture, and establish a second mapping relationship from geometric vertices to texture coordinates: For each pixel covered by the second geometric primitive, perform the following operations: obtain the current texture coordinates according to the second mapping relationship; convert the texture coordinates into world coordinates according to the map size parameters and scale parameters; determine the coverage state of the world coordinates according to the position coordinates and field of view parameters of the dynamic object; determine the dynamic visibility value according to the coverage state; sample the first rendered texture data to obtain the static visibility value; determine the mixed visibility value according to the static visibility value and the dynamic visibility value. The mixed visibility value is written to the corresponding position of the second initial rendering texture to determine the second rendering texture.
4. The method according to any one of claims 1 to 3, characterized in that, The step of generating the fog of war based on the first rendering texture and / or the second rendering texture includes: Render semi-transparent geometric patches covering the game map area; Obtain the texture coordinates corresponding to the current pixel in the semi-transparent geometric patch; Based on the first rendering texture and / or the second rendering texture, a visibility value is determined: if the visibility value indicates an overlay state, a pixel color with an opacity of 0 is output; if the visibility value indicates an uncovered state, a fog of war color with a preset opacity is output. The pixel colors are written to the screen buffer to generate fog of war.
5. An electronic device, characterized in that, The electronic device includes: One or more processors; and A memory storing computer program instructions, which, when executed, cause the processor to perform the steps of the method as described in any one of claims 1 to 3.
6. A computer-readable medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 3.
7. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Dynamic generation method and device for large-scale static shadow
CN115147534A
Rendering display method, rendering display device, electronic equipment and storage medium
CN119672197A