A game rendering method, device, electronic device and medium

By using depth images to perform real-time shadow calculations in the graphics processor, the problem of excessive CPU computing pressure is solved, and the game operation efficiency and shadow display accuracy are improved.

CN114904272BActive Publication Date: 2025-07-25NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210599547.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-30
Publication Date
2025-07-25
Estimated Expiration
2042-05-30

AI Technical Summary

Technical Problem

The existing two-dimensional scene dynamic shadow generation method performs collision calculations of complex blocking objects on the CPU, resulting in excessive calculation pressure and affecting the game running efficiency.

Method used

By using the depth image in the graphics processor to perform real-time shadow calculation, compare the distance information of the pixel point to be rendered with the depth information of the blocking object, determine whether to perform shadow rendering, and transfer the computing burden of the CPU to the GPU.

Benefits of technology

It improves the overall running efficiency of the game, and the shadow display accuracy reaches the pixel level, significantly improving the shadow display effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114904272B_ABST
    Figure CN114904272B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a game rendering method, apparatus, electronic device, and medium. The method includes: determining a target pixel point of a game character in an image frame of a game screen, and determining distance information between a pixel point to be rendered and the target pixel point; determining a depth image corresponding to the image frame, and determining depth information of an occlusion object corresponding to the pixel point to be rendered in the image frame in the depth image; if a distance value corresponding to the distance information is greater than a distance value corresponding to the depth information, performing shadow rendering on the pixel point to be rendered. According to the embodiment of the present invention, a game rendering method using a depth image is provided. By comparing each pixel point to be rendered to determine whether to perform shadow rendering, the display accuracy of the final shadow area can reach the pixel level, greatly improving the shadow display effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technologies, and particularly to a game rendering method, a game rendering device, an electronic device, and a computer-readable storage medium. Background Art

[0002] The two-dimensional scenes in games are formed by superimposing multiple planar pictures. Adding dynamic shadows to the two-dimensional scenes can not only enhance the realism of the scenes, but also provide more interesting mechanisms for game play.

[0003] The existing methods for generating dynamic shadows in two-dimensional scenes are mainly based on ray detection of a physical engine. The collision calculation with blocking objects is completed by a central processing unit (CPU), and a mesh of the shadow area is generated in real time according to the collision points, and finally handed over to the engine for rendering.

[0004] The above solution has an obvious drawback. When there are more blocking objects, the shapes are more complex, and the accuracy requirements of the shadow mesh are higher, the computational pressure on the CPU will increase geometrically, resulting in a decrease in the running efficiency of the game and ultimately affecting the overall experience of the game. Summary of the Invention

[0005] In view of the above problems, embodiments of the present invention are proposed to provide a game rendering method, a corresponding game rendering device, an electronic device, and a computer-readable storage medium that overcome the above problems or at least partially solve the above problems.

[0006] Embodiments of the present invention disclose a game rendering method, and the method includes:

[0007] Determine a target pixel point of a game character in an image frame of a game screen, and determine distance information between a pixel point to be rendered and the target pixel point;

[0008] Determine a depth image corresponding to the image frame, and determine depth information of a blocking object corresponding to the pixel point to be rendered in the image frame in the depth image;

[0009] If a distance value corresponding to the distance information is greater than a distance value corresponding to the depth information, perform shadow rendering on the pixel point to be rendered.

[0010] Optionally, the determining the depth image corresponding to the image frame includes:

[0011] Obtain contour information of the blocking object pre-edited; the contour information includes contour line segments sequentially connected by contour points;

[0012] Determine the viewing range of the game character;

[0013] In a coordinate system with the target pixel point as the coordinate origin, determine the distance between the points on the contour line segment that fall within the visual field range and the coordinate origin, and determine the angle between the line segment connecting the points on the contour line segment that fall within the visual field range and the coordinate origin and the X-axis of the coordinate system;

[0014] Establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

[0015] Optionally, the determining the visual field range of the game character includes:

[0016] Use a circle with the target pixel point as the center and a preset distance as the radius as the visual field range of the game character.

[0017] Optionally, the establishing the mapping relationship between the distance and the angle and drawing the depth image based on the mapping relationship includes:

[0018] Map the angle to the abscissa of the depth image, and map the distance to the pixel value of the pixel point corresponding to the abscissa.

[0019] Optionally, the determining the depth information of the blocking object corresponding to the pixel point to be rendered in the depth image includes:

[0020] In a coordinate system with the target pixel point as the coordinate origin, determine the target angle between the line segment connecting the pixel point to be rendered and the coordinate origin and the X-axis of the coordinate system;

[0021] Based on the mapping relationship, determine the target distance corresponding to the target angle from the depth image, and use the target distance as the depth information of the blocking object in the depth image.

[0022] Optionally, the mapping the distance to the pixel value of the pixel point corresponding to the abscissa includes:

[0023] Determine the distance value currently stored in the pixel value of the pixel point corresponding to the abscissa;

[0024] Judge whether the distance value corresponding to the distance is less than the currently stored distance value;

[0025] If the distance value corresponding to the distance is less than the currently stored distance value, map the distance value corresponding to the distance to the pixel value of the pixel point corresponding to the abscissa; otherwise, keep the pixel value of the pixel point corresponding to the abscissa unchanged.

[0026] Optionally, the method is applied to a graphics processing unit, and the size of the depth image is 1024*1.

[0027] An embodiment of the present invention also discloses a game rendering device, and the device includes:

[0028] A first determination module, configured to determine a target pixel point of a game character in an image frame of a game screen, and determine distance information between a pixel point to be rendered and the target pixel point;

[0029] A second determination module, configured to determine a depth image corresponding to the image frame, and determine depth information of an occlusion object corresponding to the pixel point to be rendered in the depth image;

[0030] A rendering module, configured to perform shadow rendering on the pixel point to be rendered if a distance value corresponding to the distance information is greater than a distance value corresponding to the depth information.

[0031] Optionally, the second determination module includes:

[0032] An acquisition sub-module, configured to acquire contour information of the occlusion object pre-edited; the contour information includes contour line segments sequentially connected by contour points;

[0033] A first determination sub-module, configured to determine a field of view range of the game character;

[0034] A second determination sub-module, configured to determine, in a coordinate system with the target pixel point as the coordinate origin, a distance between a point on the contour line segment falling within the field of view range and the coordinate origin, and determine an angle between a line segment connecting the point on the contour line segment falling within the field of view range and the coordinate origin and the X-axis of the coordinate system;

[0035] A drawing sub-module, configured to establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

[0036] Optionally, the first determination sub-module includes:

[0037] A determination unit, configured to use a circle with the target pixel point as the center and a preset distance as the radius as the field of view range of the game character.

[0038] Optionally, the drawing sub-module includes:

[0039] A mapping unit, configured to map the angle to the abscissa of the depth image, and map the distance to the pixel value of the pixel point corresponding to the abscissa.

[0040] Optionally, the second determination module includes:

[0041] A third determination sub-module, configured to determine a target angle between a line segment connecting the pixel point to be rendered and the coordinate origin and the X-axis of the coordinate system in a coordinate system with the target pixel point as the coordinate origin;

[0042] A fourth determination sub-module, configured to determine a target distance corresponding to the target angle from the depth image based on the mapping relationship, and use the target distance as the depth information of the blocking object in the depth image.

[0043] Optionally, the mapping unit includes:

[0044] A determination sub-unit, configured to determine a distance value currently stored in the pixel value of the pixel point corresponding to the abscissa;

[0045] A judgment sub-unit, configured to judge whether the distance value corresponding to the distance is less than the currently stored distance value;

[0046] A mapping sub-unit, configured to, if the distance value corresponding to the distance is less than the currently stored distance value, map the distance value corresponding to the distance to the pixel value of the pixel point corresponding to the abscissa; otherwise, keep the pixel value of the pixel point corresponding to the abscissa unchanged.

[0047] Optionally, the device is applied to a graphics processor, and the size of the depth image is 1024*1.

[0048] An embodiment of the present invention also discloses an electronic device, including: a processor, a memory, and a computer program stored on the memory and capable of running on the processor, where when the computer program is executed by the processor, the steps of a game rendering method as described above are implemented.

[0049] An embodiment of the present invention also discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of a game rendering method as described above are implemented.

[0050] The embodiments of the present invention include the following advantages:

[0051] In the embodiments of the present invention, by comparing the distance information between the pixel to be rendered and the target pixel with the depth information of the blocking object corresponding to the pixel to be rendered in the depth image, it can be determined whether shadow rendering needs to be performed on the pixel to be rendered. By adopting the above method, a rendering method is provided for determining which pixels are within the shadow rendering area range and which pixels are within the non-shadow rendering area range using the depth image. Moreover, this method can be executed in a graphics processing unit, and during runtime, real-time shadow calculation is based on the GPU. Utilizing the powerful parallel computing ability of the GPU, a large amount of computing burden of the CPU is transferred to the GPU, improving the overall operation efficiency of the game. And by comparing each pixel to determine whether shadow rendering is performed, the display accuracy of the final shadow area can reach the pixel level accuracy, greatly improving the shadow display effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 is a schematic diagram of the shadow effect in a game;

[0053] Figure 2 is another schematic diagram of the shadow effect in a game;

[0054] Figure 3 is a flowchart of the steps of a game rendering method provided by an embodiment of the present invention;

[0055] Figure 4 is a flowchart of the steps of another game rendering method provided by an embodiment of the present invention;

[0056] Figure 5 is a schematic diagram of a depth image;

[0057] Figure 6 is a schematic diagram of a depth image according to an embodiment of the present invention;

[0058] Figure 7 is a model diagram of the positional relationship between a game character and a blocking object;

[0059] Figure 8 is according to Figure 7 the depth image mapped from the positional relationship in;

[0060] Figure 9 is a flowchart of a game rendering method according to an embodiment of the present invention;

[0061] Figure 10 is a structural block diagram of a game rendering device provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0062] To make the above objects, features, and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention belong to the scope of protection of the present invention.

[0063] A two-dimensional scene is composed of multiple superimposed planar pictures. Adding dynamic shadows to a two-dimensional scene can not only enhance the realism of the scene but also provide more interesting mechanisms for gameplay.

[0064] Refer to Figure 1 As shown, it is a schematic diagram of the shadow effect in a game. Under the vision of Player 1 (Player 1 in the figure), Player 3 and Player 5 (Player 3 and Player 5 in the figure) blocked by the wall / scene objects can only be seen partially, and the rest are not displayed in the shadow area; due to the opening of the door between Player 1 and Player 2 (Player 2 in the figure), Player 2 is in the visible area of Player 1.

[0065] Refer to Figure 2 As shown, it is another schematic diagram of the shadow effect in a game. After the door between Player 1 and Player 2 is closed, Player 2 changes from Figure 1 being in the visible area of Player 1 to being in the shadow area blocked by the door and is not displayed in the game.

[0066] The method for generating dynamic shadows in a two-dimensional scene is mainly based on ray detection of a physics engine. The collision calculation with the blocking object is completed by the central processing unit (CPU), and the mesh of the shadow area is generated in real time according to the collision point, and finally handed over to the engine for rendering.

[0067] The above solution has an obvious drawback. When there are more blocking objects, the shape is more complex, and the accuracy requirement of the shadow mesh is higher, the computational pressure on the CPU will increase geometrically, resulting in a decrease in the running efficiency of the game and ultimately affecting the overall gaming experience.

[0068] One of the core concepts of the embodiments of the present invention is that by comparing the distance information between the pixel point to be rendered and the target pixel point with the depth information of the blocking object corresponding to the pixel point to be rendered in the depth image, it can be determined whether shadow rendering needs to be performed on the pixel point to be rendered. By adopting the above method, a rendering method is provided for determining which pixels are within the shadow rendering area range and which pixels are within the non-shadow rendering area range using the depth image, and this method can be executed in a graphics processing unit. During runtime, real-time shadow calculation is based on the GPU. By utilizing the powerful parallel computing ability of the GPU, a large amount of computing burden of the CPU is transferred to the GPU, improving the overall operating efficiency of the game. And by comparing each pixel point to determine whether shadow rendering is performed, the display accuracy of the final shadow area can reach the pixel level accuracy, greatly improving the shadow display effect.

[0069] Referring Figure 3 , a step flowchart of a game rendering method provided by an embodiment of the present invention is shown, which may specifically include the following steps:

[0070] Step 301, determine the target pixel point of the game character in the image frame of the game screen, and determine the distance information between the pixel point to be rendered and the target pixel point.

[0071] A Graphical User Interface (GUI, also known as a graphical user interface) refers to a computer operation user interface displayed in a graphical manner. Most games interact with game players through the graphical user interface.

[0072] In the embodiments of the present invention, after the game is started, the game screen can be displayed in the graphical user interface. The game screen can display the character model of the game character controlled by the player.

[0073] The target pixel point where the game character is located in the image frame of the game screen can be determined, and the distance information between the pixel point to be rendered in the image frame and the target pixel point can be determined. Among them, the pixel point to be rendered refers to the pixel point that has not been shadow-rendered.

[0074] Step 302, determine the depth image corresponding to the image frame, and determine the depth information of the blocking object corresponding to the pixel point to be rendered in the image frame in the depth image.

[0075] Determine the depth image corresponding to the current image frame. Among them, the depth image can be a depth texture map. A depth texture map is a technology used in 3D computer graphics and computer vision, and is an image or image channel that contains information related to the distance from the surface of the scene object to the viewpoint, and is used to simulate or reconstruct 3D shapes.

[0076] In an embodiment of the present invention, a depth image can be pre-configured for an image frame that needs to be shaded. The depth image can be determined according to the positional relationship between the game character and the blocking object in the image frame. After configuring the depth image for the image frame, a mapping relationship can be established between the image frame and the depth image. In one example, the image frame and the depth image are in one-to-one correspondence. For a current image frame that needs to be shaded, a corresponding depth image can be determined.

[0077] After determining the depth image corresponding to the current image frame, the blocking object corresponding to the pixel to be rendered can be determined. For example, taking the target pixel as the viewpoint, observing in the direction of the pixel to be rendered, determining the blocking object in this line-of-sight direction, and the depth information of the blocking object in the depth image can be determined.

[0078] Step 303, if the distance value corresponding to the distance information is greater than the distance value corresponding to the depth information, then shade the pixel to be rendered.

[0079] In an embodiment of the present invention, by comparing the distance information between the pixel to be rendered and the target pixel with the depth information of the blocking object corresponding to the pixel to be rendered in the depth image, it can be determined whether the pixel to be rendered needs to be shaded.

[0080] If the distance value corresponding to the distance information is greater than the distance value corresponding to the depth information, then shade the pixel to be rendered; if the distance value corresponding to the distance information is not greater than the distance value corresponding to the depth information, then do not shade the pixel to be rendered.

[0081] After rendering all the pixels in the image frame that are determined to need to be shaded, the image frame can be displayed, thereby displaying the shaded effect after rendering.

[0082] In summary, in an embodiment of the present invention, by comparing the distance information between the pixel to be rendered and the target pixel with the depth information of the blocking object corresponding to the pixel to be rendered in the depth image, it can be determined whether the pixel to be rendered needs to be shaded. By adopting the above method, a rendering method is provided for determining which pixels are within the shaded area range and which pixels are within the non-shaded area range using the depth image. And this method can be executed in a graphics processing unit. During operation, it is based on real-time shadow calculation of the GPU. By utilizing the powerful parallel computing ability of the GPU, a large amount of computing burden of the CPU is transferred to the GPU, improving the overall operation efficiency of the game. And by comparing each pixel point to determine whether to perform shadow rendering, the display accuracy of the final shadow area can reach the pixel level accuracy, greatly improving the shadow display effect.

[0083] Reference Figure 4 , a step flowchart of another game rendering method provided by an embodiment of the present invention is shown, which may specifically include the following steps:

[0084] Step 401, determine the target pixel points of the game character in the image frame of the game screen, and determine the distance information between the pixel points to be rendered and the target pixel points.

[0085] In an embodiment of the present invention, after the game is started, the game screen can be displayed in the graphical user interface. The character model of the game character controlled by the player can be displayed in the game screen.

[0086] The target pixel points where the game character is located in the image frame of the game screen can be determined, and the distance information between the pixel points to be rendered in this image frame and the target pixel points can be determined. Among them, the pixel points to be rendered refer to the pixel points that have not been shaded.

[0087] In an alternative embodiment, a game rendering method of an embodiment of the present invention can be executed in a graphics processing unit. Based on the GPU (graphics processing unit) for real-time shadow calculation, using the powerful parallel computing ability of the GPU to transfer a large amount of computing burden of the CPU to the GPU can improve the overall operation efficiency of the game.

[0088] Step 402, determine the depth image corresponding to the image frame.

[0089] Determine the depth image corresponding to the current image frame, where the depth image can be a depth texture map.

[0090] For step 402, the following steps can be executed:

[0091] Sub-step S11, obtain the contour information of the blocking object pre-edited.

[0092] Among them, the contour information includes contour line segments connected in sequence by contour points.

[0093] In an embodiment of the present invention, it can be in the game screen production stage, in the engine editor, such as the Unity engine or the Cocos Creator engine, to edit the contour information of the blocking object. Through the polygon editing function provided by the game engine, the contour of the blocking object can be edited. In the two-dimensional plane, the contour of the blocking object is formed by connecting N points in a certain order. When the game object in the game is blocked by the blocking object, the corresponding shadow effect needs to be rendered, thereby improving the realism of the game.

[0094] In the initialization stage of game operation, a depth image can be created to record depth values, which can be composed of (r, g, b, a). A depth image with a size of M*N can sample the depth value (r, g, b, a) stored in the specified pixel in the figure through the two-dimensional plane coordinates (m, n).

[0095] Refer to Figure 5 As shown, it is a schematic diagram of a depth image. The larger the size of the depth image, the higher the memory occupancy, the higher the corresponding accuracy, and the better the final shadow display quality. For example, a depth image with a size of 1920*1080 stores 1920*1080 pixel data. Each pixel point in the rendering result of the screen display samples from these pixel data according to the mapping relationship. If the display pixels of the screen are also 1920*1080, the mapping relationship between the display pixels and the depth image is a one-to-one relationship (that is, one display pixel corresponds to one pixel data in the depth image); if the display pixels of the screen are 3840*2160, then there will be a situation where multiple display pixels correspond to the same pixel data in the depth image. Therefore, the larger the size of the depth image, the more pixel data can be stored, the higher the sampling accuracy, and the higher the final display quality. And the larger the size of the depth image, the more hardware resources (memory / video memory and bandwidth) are required.

[0096] In an alternative embodiment of the present invention, the size of the depth image can be set to 1024*1. Refer to Figure 6 As shown, it is a schematic diagram of a depth image according to an embodiment of the present invention, and this depth image stores 1024*1 pixel data.

[0097] In the frame loop stage of game operation, at the beginning of each frame loop, the depth image can be reset first, that is, the depth value recorded in the depth image is set to the default value, for example, set to (1, 0, 0, 0).

[0098] When the game is running, there is a timing loop mechanism, also known as the frame rate, which represents the number of times of running per second. If the game frame rate is 30 frames, it means that the main logic method of the game is run 30 times within one second. When the frame loop starts, which means when the above main logic method starts, a method for clearing the depth image will be executed, and this method is used to change all the data recorded in the depth image to the default value. Since the shadow in the game rendering method provided by the embodiment of the present invention needs to be calculated in real time, that is, the current shadow range needs to be calculated once for each frame, it is necessary to reset the result of the previous calculation in the depth image at the beginning of each frame, and then perform a complete calculation of the shadow range again.

[0099] After resetting the depth value data recorded in the depth image, the contour points of the blocking object output during the game screen production stage can be uploaded to the GPU in the form of line segments. Therefore, the contour information of the pre-edited blocking object can be obtained in the GPU.

[0100] Sub-step S12, determining the field of view range of the game character.

[0101] In the embodiment of the present invention, the game player can set different field of view ranges for the game character. The field of view range can be set to a circle, or it can be set to other shapes, such as a rectangle, a square, a rhombus, etc., that is, it can also be set to a figure containing a center point. By customizing the field of view range of the game character, the gameplay can be enriched.

[0102] For sub-step S12, the following steps can be executed:

[0103] Taking the circle with the target pixel point as the center and the preset distance as the radius as the field of view range of the game character.

[0104] In an embodiment of the present invention, a circular area formed by taking the target pixel point where the game character is located as the center and the preset distance as the radius can be used as the field of view range of the game character.

[0105] It should be noted that it is also possible to construct other shapes (rectangles, squares, rhombuses, etc.) of areas with the target pixel point where the game character is located as the center point as the field of view area of the game character. The present application does not specifically limit the shape of the area corresponding to the field of view range of the game character.

[0106] Sub-step S13, in the coordinate system with the target pixel point as the coordinate origin, determining the distance between the points on the contour line segment falling within the field of view range and the coordinate origin, and determining the angle between the line segment connecting the points on the contour line segment falling within the field of view range and the coordinate origin and the X-axis of the coordinate system.

[0107] In the embodiment of the present invention, a coordinate system of a two-dimensional plane can be established with the target pixel point as the coordinate origin, the points on the contour line segment falling within the field of view range can be determined, and the distance between each point on the contour line segment falling within the field of view range and the coordinate origin can be determined. The points on the contour line segment falling within the field of view range and the coordinate origin can be connected as endpoints to obtain corresponding line segments, and the angle between each line segment and the X-axis of the coordinate system can be determined.

[0108] The above process can be understood as determining the line-of-sight direction of the game character and determining the distance between the blocking object and the game character in each line-of-sight direction.

[0109] Sub-step S14: Establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

[0110] For each line segment, establish a mapping relationship between its length (i.e., the distance between the two endpoints) and the angle between it and the X-axis of the coordinate system, and draw the depth image based on this mapping relationship.

[0111] For sub-step S14, the following steps can be executed:

[0112] Map the angle to the abscissa of the depth image, and map the distance to the pixel value of the pixel point corresponding to the abscissa.

[0113] In the embodiment of the present invention, the angle can be mapped to the abscissa of the depth image, and the distance can be mapped to the pixel value / depth value of the pixel point corresponding to the abscissa.

[0114] Refer to Figure 7 As shown, it is a model diagram of the positional relationship between the game character and the blocking object. The position where the game character is located can be used as the coordinate origin O. The contour line segment of the blocking object is assumed to be AB, the visual field range of the game character is assumed to be a circle, and the radius of the visual field range is assumed to be OR. It can be seen from the figure that the length of the line segment formed by the coordinate origin O and any point on AB is less than OR, that is, it can be determined that the points on AB all fall within the visual field range of the game character. Any point on AB can be represented by D. The distance between point D and the coordinate origin O can be calculated, and the angle between OD and the X-axis can be calculated. The angle θ between OD and the X-axis and the distance L from point D to the coordinate origin O can be correspondingly mapped into the depth image.

[0115] In an embodiment of the present invention, the size of the depth image is 1024*1. The abscissa range [0, 1024] of the depth image can be mapped to the angle range [0, 2π]. Then, the angle θ between the calculated line segment and the X-axis of the coordinate system can be found corresponding to the abscissa in the depth image, and the distance L between the two endpoints of the calculated line segment can be written into the pixel value of the pixel point corresponding to the abscissa, for example, it can be written into the r value of the pixel point, that is, (L, 0, 0, 1).

[0116] Refer to Figure 8 As shown, it is according to Figure 7The depth image obtained by mapping the positional relationship in []. Each pixel point in the depth image records the depth value corresponding to the angle, and the depth values corresponding to the angles in [0, 2π] are recorded in total. For the line segment AB, assuming that the angle between the X-axis and OA is α, the distance between the endpoints of OA corresponding to the angle α is a, the angle between the X-axis and OB is β, and the distance between the endpoints of OB corresponding to the angle β is b, the angle between the angle α and the angle β can be mapped to the abscissa of the depth image, and the distance corresponding to the angle is mapped to the pixel value / depth value of the pixel point corresponding to the abscissa.

[0117] In an optional embodiment of the present invention, for the step of mapping the distance to the pixel value of the pixel point corresponding to the abscissa, the following steps can be performed:

[0118] Determine the currently stored distance value in the pixel value of the pixel point corresponding to the abscissa; judge whether the distance value corresponding to the distance is less than the currently stored distance value; if the distance value corresponding to the distance is less than the currently stored distance value, then map the distance value corresponding to the distance to the pixel value of the pixel point corresponding to the abscissa; otherwise, keep the pixel value of the pixel point corresponding to the abscissa unchanged.

[0119] In the process of generating the depth image corresponding to the image frame, within the field of view of the game character, the intersection between the line of sight of the game character and the blocking object can be calculated, and the intersection point with the shortest distance from the game character among the intersection points in the line of sight direction is used as the target intersection point, and the distance between the target intersection point and the game character is recorded in the depth image. The above steps ensure that the distance recorded in the depth image is the shortest distance in this direction.

[0120] Step 403, in the coordinate system with the target pixel point as the coordinate origin, determine the target angle between the line segment connecting the pixel point to be rendered and the coordinate origin and the X-axis of the coordinate system.

[0121] Establish a coordinate system of a two-dimensional plane with the target pixel point as the coordinate origin, connect a line segment with the pixel point to be rendered and the coordinate origin as endpoints, and determine the target angle between this line segment and the X-axis of the coordinate system.

[0122] The above process can be understood as determining the target line of sight direction where the pixel point to be rendered is located.

[0123] Step 404, based on the mapping relationship, determine the target distance corresponding to the target angle from the depth image, and use the target distance as the depth information of the blocking object in the depth image.

[0124] The abscissa of each pixel point in the depth image corresponds to a preset angle, and the pixel value of the pixel point stores a distance value. Therefore, the target angle corresponding to the target included angle can be determined from the preset angles, and the corresponding target pixel point can be found based on the target angle, so that the target distance value corresponding to the target distance stored in the target pixel point can be found.

[0125] In the pixel shader for shadow Mesh rendering, determine the included angle α1 between the line connecting any pixel point N to be rendered in the game screen and the origin O of the coordinates and the X-axis. Sample the depth image generated in real time according to α1 to obtain the depth value H recorded corresponding to this angle in the depth image. Compare the depth value H with the length of ON. If the length of ON is greater than H, it means that this pixel point to be rendered is in the shadow area, and corresponding shadow blending is performed. Repeat this step for all pixel points to be rendered to obtain the final shadow effect of this image frame.

[0126] Step 405, if the distance value corresponding to the distance information is greater than the distance value corresponding to the depth information, perform shadow rendering on the pixel point to be rendered.

[0127] If the distance value corresponding to the distance information is greater than the distance value corresponding to the depth information, perform shadow rendering on the pixel point to be rendered; if the distance value corresponding to the distance information is not greater than the distance value corresponding to the depth information, do not perform shadow rendering on the pixel point to be rendered.

[0128] After rendering all the pixel points determined to need shadow rendering in this image frame, this image frame can be displayed, thereby displaying the rendered shadow effect.

[0129] To enable those skilled in the art to better understand steps 401 to 405 of the embodiments of the present invention, the following is illustrated by an example:

[0130] Refer to Figure 9 The flowchart of a game rendering method according to an embodiment of the present invention is shown. Among them, the depth image can be a depth texture map, and the specific process is as follows:

[0131] 1. In the editing stage of making the game screen, the outline of the blocking object or the blocking area can be edited.

[0132] 2. In the initialization stage of the game running, a depth texture map can be created to record the depth values (r, g, b, a).

[0133] 3. In the frame loop stage of the game running, at the beginning of each frame loop, the depth texture map can be reset, that is, the depth values recorded in the depth texture map are set to the default values (1, 0, 0, 0).

[0134] 4. Upload the contour points of the blocking object output in the editing stage to the GPU in the form of line segments.

[0135] 5. In the vertex shader, use the position of the player character as the coordinate origin O. Assume the two endpoints of the contour line segment of the blocking object are A and B, and calculate the angle α between the X-axis and OA, and the angle β between the X-axis and OB respectively.

[0136] 6. In the pixel shader, use the position of the player character as the coordinate origin O, and the radius R of the player character's field of view as the length. Interpolate from the angle α to the angle β to obtain the line segment OR, calculate the intersection point D of OR and the line segment AB, and calculate the distance between the intersection point D and the origin O.

[0137] 7. Write the angle θ between OD and the X-axis and the distance L (depth value) from the intersection point D to the origin O into the depth texture map. The abscissa range [0, 1024] of the depth texture map is mapped to [0, 2π]. That is, the angle θ corresponds to a unique value on the abscissa of the depth texture map, and the distance L is used as the r value in the depth value corresponding to this abscissa in the depth texture map, that is, (L, 0, 0, 1).

[0138] 8. Repeat the above steps 5-7, traverse all contour line segments in the image frame, calculate the depth values corresponding to the corresponding angles and write them into the depth texture map to obtain the final real-time depth texture map. Each grid in the depth texture map represents the depth value corresponding to the corresponding angle, and the depth values corresponding to the angles [0, 2π] are recorded in total.

[0139] 9. In the pixel shader of the shadow Mesh rendering, determine the angle α1 between the line connecting the pixel point N to be rendered and the coordinate origin O and the X-axis, sample the above real-time generated depth texture map according to α1, obtain the depth value H recorded corresponding to this angle in the depth texture map, compare the depth value H and the length of ON. If the length of ON is greater than H, it means that this pixel point to be rendered is in the shadow area, and perform the corresponding shadow blending. Repeat this step for all pixel points to be rendered to obtain the final shadow area effect.

[0140] 10. During the game operation, repeat the above steps 3-9 in each frame loop to obtain the shadow area of each frame, that is, the real-time dynamic shadow.

[0141] In summary, in the embodiment of the present invention, by comparing the distance information between the pixel point to be rendered and the target pixel point with the depth information of the blocking object corresponding to the pixel point to be rendered in the depth image, it can be determined whether shadow rendering needs to be performed on the pixel point to be rendered. By adopting the above method, a rendering method for determining which pixels are within the shadow rendering area range and which pixels are within the non-shadow rendering area range by using the depth image is provided, and this method can be executed in a graphics processing unit. During operation, real-time shadow calculation based on the GPU is performed, and the powerful parallel computing ability of the GPU is used to transfer a large amount of computing burdens of the CPU to the GPU, improving the overall operation efficiency of the game. Moreover, by comparing each pixel point to determine whether shadow rendering is performed, the display accuracy of the final shadow area can reach the pixel level, greatly improving the shadow display effect.

[0142] This method is based on the engine editor to pre-edit the light blocking objects for the 2D scene in advance. During the game operation, the graphics processing unit is used to calculate the collision detection between the game character's line of sight and the blocking objects within the field of view of the game character, generating a real-time shadow area. Through preprocessing, the light blocking objects of the 2D scene are saved in the form of point coordinate data. During operation, real-time shadow calculation based on the GPU is performed, and the powerful parallel computing ability of the GPU is used to transfer a large amount of computing burdens of the CPU to the GPU, improving the overall operation efficiency of the game. Moreover, the display accuracy of the final shadow area reaches the pixel level, greatly improving the final display effect. The additional consumption is only a depth texture map with a size of 1024*1. All renderings based on modern graphics APIs can adopt the above method to generate real-time shadows.

[0143] It should be noted that for the 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 the embodiments of the present invention are not limited by the described action sequences, because according to the embodiments of the present invention, 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 involved are not necessarily essential for the embodiments of the present invention.

[0144] Refer to Figure 10 , which shows a structural block diagram of a game rendering device provided by an embodiment of the present invention, and specifically may include the following modules:

[0145] The first determination module 1001 is configured to determine the target pixel point of the game character in the image frame of the game screen, and determine the distance information between the pixel point to be rendered and the target pixel point;

[0146] The second determination module 1002 is configured to determine a depth image corresponding to the image frame, and determine depth information of an occlusion object corresponding to the pixel point to be rendered in the depth image;

[0147] The rendering module 1003 is configured to perform shadow rendering on the pixel point to be rendered if the distance value corresponding to the distance information is greater than the distance value corresponding to the depth information.

[0148] In an embodiment of the present invention, the second determination module includes:

[0149] An acquisition sub-module, configured to acquire contour information of the occlusion object pre-edited; the contour information includes contour line segments connected in sequence by contour points;

[0150] A first determination sub-module, configured to determine a field of view range of the game character;

[0151] A second determination sub-module, configured to determine, in a coordinate system with the target pixel point as the coordinate origin, a distance between a point on the contour line segment falling within the field of view range and the coordinate origin, and determine an angle between a line segment connected by the point on the contour line segment falling within the field of view range and the coordinate origin and the X-axis of the coordinate system;

[0152] A drawing sub-module, configured to establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

[0153] In an embodiment of the present invention, the first determination sub-module includes:

[0154] A determination unit, configured to use a circle with the target pixel point as the center and a preset distance as the radius as the field of view range of the game character.

[0155] In an embodiment of the present invention, the drawing sub-module includes:

[0156] A mapping unit, configured to map the angle to the abscissa of the depth image, and map the distance to the pixel value of the pixel point corresponding to the abscissa.

[0157] In an embodiment of the present invention, the second determination module includes:

[0158] A third determination sub-module, configured to determine, in a coordinate system with the target pixel point as the coordinate origin, a target angle between a line segment connected by the pixel point to be rendered and the coordinate origin and the X-axis of the coordinate system;

[0159] A fourth determination sub-module, configured to determine a target distance corresponding to the target angle from the depth image based on the mapping relationship, and use the target distance as the depth information of the blocking object in the depth image.

[0160] In an embodiment of the present invention, the mapping unit includes:

[0161] A determination sub-unit, configured to determine the currently stored distance value in the pixel value of the pixel point corresponding to the abscissa;

[0162] A judgment sub-unit, configured to judge whether the distance value corresponding to the distance is less than the currently stored distance value;

[0163] A mapping sub-unit, configured to, if the distance value corresponding to the distance is less than the currently stored distance value, map the distance value corresponding to the distance to the pixel value of the pixel point corresponding to the abscissa; otherwise, keep the pixel value of the pixel point corresponding to the abscissa unchanged.

[0164] In an embodiment of the present invention, the device is applied to a graphics processor, and the size of the depth image is 1024*1.

[0165] In summary, in an embodiment of the present invention, by comparing the distance information between the pixel point to be rendered and the target pixel point with the depth information of the blocking object corresponding to the pixel point to be rendered in the depth image, it can be determined whether shadow rendering needs to be performed on the pixel point to be rendered. By adopting the above method, a rendering method for determining which pixels are within the shadow rendering area range and which pixels are within the non-shadow rendering area range using a depth image is provided, and this method can be executed in a graphics processor. During operation, real-time shadow calculation based on the GPU is performed, and the powerful parallel computing ability of the GPU is used to transfer a large amount of computing burdens of the CPU to the GPU, improving the overall operation efficiency of the game. Moreover, by comparing each pixel point to determine whether shadow rendering is performed, the display accuracy of the final shadow area can reach the pixel level, greatly improving the shadow display effect.

[0166] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For related parts, refer to the partial description of the method embodiment.

[0167] An embodiment of the present invention further provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, it implements each process of the above-mentioned embodiment of a game rendering method and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0168] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements each process of the above embodiment of a game rendering method and can achieve the same technical effect. To avoid repetition, it will not be described here again.

[0169] Each embodiment in this specification is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other.

[0170] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a device, or a computer program product. Therefore, the embodiments of the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0171] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the processes and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal devices generate a device for implementing the specified functions in one process Figure 1 one process or multiple processes and / or blocks Figure 1 or multiple blocks.

[0172] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured product including an instruction device, and the instruction device implements the specified functions in one process Figure 1 one process or multiple processes and / or blocks Figure 1 or multiple blocks.

[0173] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device, so that a series of operation steps are executed on the computer or other programmable terminal device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable terminal device provide for implementing the specified functions in one process Figure 1One or more processes and / or blocks Figure 1 Steps of functions specified in one or more blocks.

[0174] Although the preferred embodiments of the embodiments of the present invention have been described, those skilled in the art can make additional changes and modifications to these embodiments once they know the basic creative concept. Therefore, the appended claims are intended to be construed to include the preferred embodiments and all changes and modifications falling within the scope of the embodiments of the present invention.

[0175] Finally, it should also be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or terminal device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or terminal device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or terminal device comprising the element.

[0176] The above has introduced in detail a game rendering method, a game rendering device, an electronic device and a computer-readable storage medium provided by the present invention. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.

Claims

1. A game rendering method, characterized in that, The method includes: Determine a target pixel point of a game character in an image frame of a game screen, and determine distance information between a pixel point to be rendered and the target pixel point; Determine a depth image corresponding to the image frame, and determine depth information of an occlusion object corresponding to the pixel point to be rendered in the image frame in the depth image; If a distance value corresponding to the distance information is greater than a distance value corresponding to the depth information, it is confirmed that within the field of view of the game character, the pixel point to be rendered is occluded by the occlusion object, and shadow rendering is performed on the pixel point to be rendered; Wherein, the determining the depth image corresponding to the image frame includes: Obtain contour information of the occlusion object pre-edited; the contour information includes contour line segments connected in sequence by contour points; Determine the field of view of the game character; In a coordinate system with the target pixel point as the coordinate origin, determine the distance between a point on the contour line segment falling within the field of view and the coordinate origin, and determine an angle between a line segment connected by the point on the contour line segment falling within the field of view and the coordinate origin and the X-axis of the coordinate system; Establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

2. The method according to claim 1, wherein The determining the field of view of the game character includes: Taking a circle with the target pixel point as the center and a preset distance as the radius as the field of view of the game character.

3. The method according to claim 1, characterized in that, The establishing the mapping relationship between the distance and the angle, and drawing the depth image based on the mapping relationship includes: Map the angle to the abscissa of the depth image, and map the distance to the pixel value of the pixel point corresponding to the abscissa.

4. The method according to claim 1, wherein The determining the depth information of the occlusion object corresponding to the pixel point to be rendered in the image frame in the depth image includes: In a coordinate system with the target pixel point as the coordinate origin, determine a target angle between a line segment connected by the pixel point to be rendered and the coordinate origin and the X-axis of the coordinate system; Based on the mapping relationship, determine a target distance corresponding to the target angle from the depth image, and use the target distance as the depth information of the occlusion object in the depth image.

5. The method according to claim 3, characterized in that, The mapping the distance to the pixel value of the pixel point corresponding to the abscissa includes: Determine a currently stored distance value in the pixel value of the pixel point corresponding to the abscissa; Judge whether the distance value corresponding to the distance is less than the currently stored distance value; If the distance value corresponding to the distance is less than the currently stored distance value, map the distance value corresponding to the distance to the pixel value of the pixel point corresponding to the abscissa; otherwise, keep the pixel value of the pixel point corresponding to the abscissa unchanged.

6. The method according to claim 1, wherein The method is applied to a graphics processing unit, and the size of the depth image is 1024*1.

7. A game rendering device, characterized in that, The device includes: A first determination module, configured to determine a target pixel point of a game character in an image frame of a game screen, and determine distance information between a pixel point to be rendered and the target pixel point; A second determination module, configured to determine a depth image corresponding to the image frame, and determine depth information of an occlusion object corresponding to the pixel point to be rendered in the depth image within the image frame; A rendering module, configured to, if a distance value corresponding to the distance information is greater than a distance value corresponding to the depth information, confirm that the pixel point to be rendered is occluded by the occlusion object within the field of view of the game character, and perform shadow rendering on the pixel point to be rendered; Wherein, the second determination module includes: An acquisition sub-module, configured to acquire contour information of the occlusion object edited in advance; the contour information includes contour line segments sequentially connected by contour points; A first determination sub-module, configured to determine the field of view of the game character; A second determination sub-module, configured to, in a coordinate system with the target pixel point as the coordinate origin, determine a distance between a point on the contour line segment falling within the field of view and the coordinate origin, and determine an angle between a line segment connecting the point on the contour line segment falling within the field of view and the coordinate origin as endpoints and the X-axis of the coordinate system; A drawing sub-module, configured to establish a mapping relationship between the distance and the angle, and draw the depth image based on the mapping relationship.

8. An electronic device, characterized in that, including: A processor, a memory, and a computer program stored on the memory and capable of running on the processor, where when the computer program is executed by the processor, the steps of a game rendering method according to any one of claims 1-6 are implemented.

9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of a game rendering method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Shadow rendering method and device, terminal and storage medium

    CN109993823A

  • Image processing method and device, electronic equipment and storage medium

    CN110400372A