Image rendering method, device, readable medium and electronic device
By obtaining and using the target shadow height of each pixel in the target scene to determine the shadow value for rendering, the problem of low rendering efficiency caused by many distant objects in the existing technology is solved, and the efficiency and effect of image rendering are improved.
Patent Information
- Application Number
- CN202210363937.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-04-07
AI Technical Summary
When the existing technology handles many distant objects, the real-time shadow rendering efficiency is low, resulting in high CPU and GPU overhead and affecting the image rendering effect.
By obtaining the target shadow height of each pixel in the target scene, determining the shadow value based on the height, and rendering the pixel, the amount of data processed during the rendering process is reduced.
It improves the efficiency of image rendering, reduces the cost of CPU and GPU, and improves the rendering effect.
Smart Images

Figure CN114742934B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular, to an image rendering method, device, readable medium and electronic device. Background Art
[0002] With the continuous development of the gaming industry, users have higher and higher requirements for picture performance. In order to enhance the display effect of the game, relevant real-time shadow technology is usually used to render shadows for game objects moving in the scene.
[0003] In the related art, a depth map of the scene is first rendered at the light source position, and then the entire scene is rendered at the camera position and compared with the previously rendered depth map to obtain the shadow effect of the scene. However, when there are many distant objects, the amount of data required to process the two scene renderings is relatively large, resulting in low rendering efficiency. Summary of the invention
[0004] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0005] In a first aspect, the present disclosure provides an image rendering method, the method comprising:
[0006] Obtain the scene image to be rendered in the target scene;
[0007] For each pixel in the scene image, determine a target shadow height corresponding to the pixel, determine a shadow value corresponding to the pixel according to the target shadow height, and render the pixel according to the shadow value to render the scene image;
[0008] Among them, the target shadow height is the height of a specified pixel point in the shadow of the scene image, and the specified pixel point is a pixel point that has the same position as the pixel point in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space.
[0009] In a second aspect, the present disclosure provides an image rendering device, the device comprising:
[0010] An image acquisition module is used to acquire a scene image to be rendered in a target scene;
[0011] An image rendering module, for determining, for each pixel in the scene image, a target shadow height corresponding to the pixel, and determining a shadow value corresponding to the pixel according to the target shadow height, and rendering the pixel according to the shadow value to render the scene image;
[0012] Among them, the target shadow height is the height of a specified pixel point in the shadow of the scene image, and the specified pixel point is a pixel point that has the same position as the pixel point in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space.
[0013] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect of the present disclosure.
[0014] In a fourth aspect, the present disclosure provides an electronic device, including:
[0015] a storage device having a computer program stored thereon;
[0016] A processing device is used to execute the computer program in the storage device to implement the steps of the method described in the first aspect of the present disclosure.
[0017] Through the above technical solution, by obtaining the scene image to be rendered in the target scene; for each pixel in the scene image, determining the target shadow height corresponding to the pixel, and according to the target shadow height, determining the shadow value corresponding to the pixel, and rendering the pixel according to the shadow value, to render the scene image; wherein the target shadow height is the height of a specified pixel in the shadow of the scene image, and the specified pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene, and whose height in the height direction of the world space is greater than or equal to a preset height threshold. In other words, the present disclosure can determine the shadow value of the pixel according to the target shadow height corresponding to the pixel, and render the pixel according to the shadow value, so that the amount of data that needs to be processed during the rendering process is relatively small, thereby improving the efficiency of image rendering.
[0018] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale. In the drawings:
[0020] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment of the present disclosure;
[0021] Figure 2 is a schematic diagram showing a target shadow height according to an exemplary embodiment of the present disclosure;
[0022] Figure 3 is a flowchart of another image rendering method according to an exemplary embodiment of the present disclosure;
[0023] Figure 4 is a shadow height schematic diagram according to an exemplary embodiment of the present disclosure;
[0024] Figure 5 is a block diagram of an image rendering device according to an exemplary embodiment of the present disclosure;
[0025] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0027] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0028] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0029] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0030] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0031] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0032] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0033] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0034] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0035] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0036] At the same time, it is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.
[0037] First, the application scenarios of the present disclosure are explained. The current mobile long-range shadow solutions include Cascade Shadow Map algorithm, baked shadows, contact shadows, etc. Among them, the Cascade Shadow Map algorithm is equivalent to rendering the scene twice during the processing process, and the corresponding Drawcall (drawing initiation) data volume will be relatively large, resulting in a relatively large CPU (Central Processing Unit) and GPU (Graphics Processing Unit) overhead, affecting the rendering efficiency, the baking speed of baked shadows is relatively slow, and the rendering effect of contact shadows is relatively poor.
[0038] In order to solve the above-mentioned problems, the present disclosure provides an image rendering method, device, readable medium and electronic device, which can determine the shadow value of a pixel point according to the target shadow height corresponding to the pixel point, and render the pixel point according to the shadow value. In this way, the amount of data that needs to be processed during the rendering process is relatively small, thereby improving the efficiency of image rendering.
[0039] The present disclosure is described below in conjunction with specific embodiments.
[0040] Figure 1 is a flowchart of an image rendering method according to an exemplary embodiment of the present disclosure. Figure 1 As shown, the method may include:
[0041] S101: Obtain a scene image to be rendered in a target scene.
[0042] The target scene may be a game scene, and the scene image may be an image in the game scene that needs to be rendered.
[0043] S102. For each pixel in the scene image, determine a target shadow height corresponding to the pixel, and determine a shadow value corresponding to the pixel according to the target shadow height, and render the pixel according to the shadow value to render the scene image.
[0044] The target shadow height is the height of a designated pixel in the shadow of the scene image, and the designated pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene, and has a height greater than or equal to a preset height threshold in the height direction of the world space. The preset height threshold may be the height corresponding to the pixel that has the same position as the pixel in the height direction of the world space, and has the highest position in the horizontal direction of the world space. Figure 2 is a schematic diagram showing a target shadow height according to an exemplary embodiment of the present disclosure, such as Figure 2As shown, the terrain in the scene image is rendered from a top-down perspective, and the target shadow height may be the intersection of a straight line in the height direction of the world space and a straight line in the light source direction.
[0045] In this step, for each pixel in the scene image, the designated pixel corresponding to the pixel can be determined first, the height of the designated pixel can be determined, and the height of the designated pixel can be used as the target shadow height corresponding to the pixel.
[0046] Furthermore, after obtaining the target shadow height corresponding to the pixel point, the coordinates of the pixel point in the world space can be obtained, and the shadow value corresponding to the pixel point can be calculated by the following formula:
[0047] Shadow=saturate(exp (MaxOcclusionHeight–C*positionWS.y)) (1)
[0048] Among them, Shadow is the shadow value, MaxOcclusionHeight is the target shadow height, positionWS.y is the y-axis of the coordinate of the pixel point in the world space, and C is a preset constant. C can be obtained in advance according to the experiment. For example, C can be 20. The function of the Saturate(x) function is to return 0 when the value of x is less than or equal to 0, return 1 when the value of x is greater than or equal to 1, and return x when the value of x is a value between 0 and 1. When the shadow value corresponding to the pixel point is 0, it means that the pixel point is not in the shadow. When the shadow value corresponding to the pixel point is 1, it means that the pixel point is in the shadow and the shadow color is the darkest. When the shadow value corresponding to the pixel point is a value between 0 and 1, the corresponding shadow color can be rendered according to the size of the shadow value. For example, the larger the shadow value, the darker the color can be, and the smaller the shadow value, the lighter the color can be.
[0049] After obtaining the shadow value corresponding to the pixel point, the pixel point may be rendered with reference to the rendering method of the prior art, which will not be described in detail here.
[0050] By adopting the above method, the shadow value of the pixel can be determined according to the target shadow height corresponding to the pixel, and the pixel can be rendered according to the shadow value. In this way, the amount of data to be processed during the rendering process is relatively small, thereby improving the efficiency of image rendering.
[0051] Figure 3 is a flowchart of another image rendering method according to an exemplary embodiment of the present disclosure. Figure 3 As shown, the method may include:
[0052] S301: Obtain a scene image to be rendered in a target scene.
[0053] The target scene may be a game scene, and the scene image may be an image in the game scene that needs to be rendered.
[0054] S302: For each pixel point in the scene image, determine the texture coordinates corresponding to the pixel point.
[0055] In a possible implementation, for each pixel in the scene image, the coordinates of the world space corresponding to the pixel, the pixel size corresponding to the height texture, and the ratio of the world space can be obtained, and the offset value between the center point of the terrain corresponding to the scene image and the origin of the coordinates of the world space corresponding to the pixel is determined, and the texture coordinates corresponding to the pixel are determined according to the coordinates of the world space corresponding to the pixel, the offset value, the ratio, and the pixel size. Among them, the coordinates of the world space corresponding to the pixel and the pixel size corresponding to the height texture can be obtained by the existing technology, which will not be repeated here. The world space ratio corresponding to the height texture can be pre-set according to the scene image. For example, if the pixel occupies a world space of 1m*1m, the ratio can be 1. The smaller the ratio, the greater the density of the pixels in the scene image, and the better the rendering effect.
[0056] For example, the texture coordinates corresponding to the pixel point can be calculated by the following formula:
[0057] cellU=(positionWS.x-HeightOcclusionStartPoint)*
[0058] TexelsPerMeter*HeightOcclusionTex_TexelSize(2)
[0059] cellV=(positionWS.z-HeightOcclusionStartPoint)*
[0060] TexelsPerMeter*HeightOcclusionTex_TexelSize(3)
[0061] Among them, (cellU, cellV) is the texture coordinate corresponding to the pixel, positionWS.x is the x-axis of the coordinate of the pixel corresponding to the world space, positionWS.z is the z-axis of the coordinate of the pixel corresponding to the world space, HeightOcclusionStartPoint is the offset value, TexelsPerMeter is the proportion of the world space corresponding to the pixel, HeightOcclusionTex_TexelSize is the pixel size corresponding to the height texture, and the pixel size can be a quaternion, which can be represented by a four-dimensional vector. For example, the four-dimensional vector can be Vector4(1 / width, 1 / height, width, height).
[0062] S303 . For each pixel in the scene image, determine a designated pixel according to the texture coordinates of the pixel and a pre-acquired height texture corresponding to the scene image.
[0063] The height texture may include the shadow height corresponding to each pixel point of the scene image.
[0064] In this step, for each pixel point in the scene image, after obtaining the texture coordinates of the pixel point, the height texture can be obtained, and based on the texture coordinates of the pixel point, a specified pixel point in the height texture is determined that has the same position as the pixel point in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space.
[0065] The height texture can be pre-acquired in the following manner: for each pixel in the scene image, determine the scene depth of the pixel in the direction of the light source in the scene image, and based on the scene depth, determine the shadow height corresponding to the pixel, and use the set of shadow heights corresponding to multiple pixels as the height texture.
[0066] For each pixel in the scene image, the scene depth of the pixel in the direction of the light source in the scene image can be determined by referring to the implementation method of the ShadowMap algorithm. Furthermore, for each pixel in the scene image, after determining the scene depth of the pixel in the direction of the light source in the scene image, the terrain height corresponding to the pixel can be determined. When it is determined that the position corresponding to the terrain height is in the shadow of the scene image, a preset height interval is obtained, and the shadow height corresponding to the pixel is determined based on the terrain height and the preset height interval. The terrain height can be the height of a reference surface directly below the pixel in the height direction of the world space coordinates in the scene image, such as Figure 3As shown, the reference plane can be the ground or the plane where the highest point of the tree is located, and the terrain height can be pre-acquired based on the terrain in the scene image. Among them, the preset height interval can be obtained by pre-testing the scene image. The smaller the preset height interval, the higher the accuracy of the determined shadow height. However, due to the large amount of calculation, the performance will be relatively poor. For scenes with higher accuracy requirements and lower performance requirements, a smaller preset height interval can be set. For example, the preset height interval can be 5m. For scenes with lower accuracy requirements and higher performance requirements, a larger preset height interval can be set. For example, the preset height interval can be 7m. The present disclosure does not limit the setting method of the preset height interval.
[0067] In a possible implementation, when it is determined that the position corresponding to the terrain height is in the shadow of the scene image, the terrain height can be used as the pending height, and the shadow height determination step is performed repeatedly until it is determined that the position corresponding to the new pending height is not in the shadow of the scene image, and the difference between the new pending height and the preset height interval is used as the shadow height corresponding to the pixel point. The shadow height determination step includes: determining whether the position corresponding to the pending height is in the shadow according to the scene depth, and when the position corresponding to the pending height is in the shadow, the sum of the pending height and the preset height interval is used as the new pending height.
[0068] For example, it is possible to determine whether the position corresponding to the undetermined height is in the shadow of the scene image according to the scene depth corresponding to the pixel point, and then continue to Figure 2 Take an example to illustrate, Figure 2 It can be seen that the terrain height h is in the shadow. In this case, we can first determine whether the position corresponding to h+5 (the preset height interval is 5m) is in the shadow. If the position corresponding to h+5 is in the shadow, then continue to determine whether the position corresponding to h+10 is in the shadow, and so on. If it is finally determined that the position corresponding to h+30 is not in the shadow, then determine h+25 as the shadow height.
[0069] Table 1 lists the shadow heights corresponding to multiple pixel points in the scene image. As shown in Table 1, the shadow heights corresponding to the pixel points in the scene image include 0, 25, 30, and 35. It should be noted that the shadow heights shown in Table 1 are only the shadow heights corresponding to some pixel points in the scene image.
[0070]
[0071] Table 1
[0072] It should be noted that the present disclosure can obtain the shadow height corresponding to each pixel in the scene image in advance, or can obtain the shadow height corresponding to each pixel in the scene image in real time, and the present disclosure is not limited to this. Compared with the method of obtaining the shadow height in real time, obtaining the shadow height in advance can reduce the performance overhead in the image rendering process and further improve the rendering efficiency.
[0073] After obtaining the shadow height corresponding to each pixel in the scene image, the shadow height corresponding to each pixel in the scene image can be filtered, and the set of shadow heights after filtering is used as the height texture. In this way, the shadow height can be blurred once, so that the overall edge of the shadow rendering is softer, achieving a soft shadow effect.
[0074] For example, the shadow height corresponding to each pixel may be filtered by the ESM algorithm in Logarithmic Space Filtering. For example, taking the shadow height corresponding to any pixel in the scene image as an example, the filtering formula may be:
[0075]
[0076] Among them, d is the filtered shadow height corresponding to the current pixel in the scene image, d0 is the shadow height corresponding to the current pixel, and d i is the shadow height corresponding to the i-th pixel around the current pixel, N is 8, w0 is the weight value corresponding to the current pixel, w i is the weight value corresponding to the i-th pixel, c is a preset constant, which can be obtained by pre-testing, for example, c is 20. The weight value corresponding to each pixel can be predetermined according to the filtering method. For example, if the filtering method is 3*3 BOX filtering, the weight value corresponding to each pixel is the same, which is 1 / 9. If the filtering method is Gaussian filtering, the weight value corresponding to each pixel is different.
[0077] For the shadow height of the pixel points corresponding to the scene image shown in Table 1, if the current pixel point in the scene image is the pixel point in the 2nd row and 6th column (the pixel point with a black background in Table 1), the shadow height corresponding to the current pixel point is 30, and the shadow heights (d1~d8) corresponding to the 8 pixels around the current pixel point are 30, 30, 30, 30, 0, 0, 0, 30 respectively.
[0078] Figure 4 is a schematic diagram of shadow height according to an exemplary embodiment of the present disclosure. Figure 4As shown, the shadow height corresponding to each pixel in the scene image is displayed in an image with a resolution of 4096*4096 and a format of R16.
[0079] S304: For each pixel in the scene image, the shadow height corresponding to the designated pixel is used as the target shadow height.
[0080] S305 . For each pixel in the scene image, determine a shadow value corresponding to the pixel according to the coordinates of the pixel in the world space and the target shadow height.
[0081] S306: Render each pixel in the scene image according to the shadow value to render the scene image.
[0082] By adopting the above method, the target shadow height corresponding to the pixel point in the scene image can be determined from the pre-acquired height texture corresponding to the scene image according to the texture coordinates corresponding to the pixel point in the scene image, the shadow value of the pixel point can be determined according to the target shadow height, and the pixel point can be rendered according to the shadow value. In this way, the amount of data to be processed during the rendering process is relatively small, so that the operating performance is relatively high, thereby improving the efficiency of image rendering, and the overhead of the video memory during the rendering process is also relatively small, which can save disk and memory space. Furthermore, the present disclosure can also filter the pre-acquired shadow height to achieve the effect of soft shadow.
[0083] Figure 5 is a block diagram of an image rendering device according to an exemplary embodiment of the present disclosure. Figure 5 As shown, the device may include:
[0084] An image acquisition module 501 is used to acquire a scene image to be rendered in a target scene;
[0085] An image rendering module 502 is used to determine, for each pixel in the scene image, a target shadow height corresponding to the pixel, determine a shadow value corresponding to the pixel according to the target shadow height, and render the pixel according to the shadow value to render the scene image;
[0086] Among them, the target shadow height is the height of a specified pixel point in the shadow of the scene image, and the specified pixel point is a pixel point that has the same position as the pixel point in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space.
[0087] Optionally, the image rendering module 502 is further used for:
[0088] Determine the texture coordinates corresponding to the pixel point;
[0089] Determine the designated pixel point according to the texture coordinates and a pre-acquired height texture corresponding to the scene image, wherein the height texture includes a shadow height corresponding to each pixel point of the scene image;
[0090] The shadow height corresponding to the designated pixel point is used as the target shadow height.
[0091] Optionally, the image rendering module 502 is further used for:
[0092] Get the coordinates of the pixel point corresponding to the world space, the pixel size corresponding to the height texture, and the scale of the world space;
[0093] Determine the offset value between the center point of the terrain corresponding to the scene image and the origin of the coordinates of the pixel point corresponding to the world space;
[0094] The texture coordinate corresponding to the pixel point is determined according to the coordinate of the pixel point corresponding to the world space, the ratio, the pixel size, and the offset value.
[0095] Optionally, the image rendering module 502 is further used for:
[0096] For each pixel in the scene image, determine the scene depth of the pixel in the direction of the light source in the scene image, and determine the shadow height corresponding to the pixel according to the scene depth;
[0097] A set consisting of the shadow heights corresponding to a plurality of the pixel points is used as the height texture.
[0098] Optionally, the image rendering module 502 is further used for:
[0099] Determine the terrain height corresponding to the pixel point, where the terrain height is the height of a reference surface directly below the pixel point in the scene image in the height direction of the world space coordinates;
[0100] When it is determined that the position corresponding to the terrain height is in the shadow of the scene image, a preset height interval is obtained, and the shadow height corresponding to the pixel point is determined according to the terrain height and the preset height interval.
[0101] Optionally, the image rendering module 502 is further used for:
[0102] The terrain height is used as the pending height, and the shadow height determination step is executed repeatedly until it is determined that the position corresponding to the new pending height is not in the shadow of the scene image, and the difference between the new pending height and the preset height is used as the shadow height corresponding to the pixel point;
[0103] The shadow height determination step includes:
[0104] According to the scene depth, determining whether the position corresponding to the to-be-determined height is in the shadow;
[0105] When the position corresponding to the undetermined height is in the shadow, the sum of the interval between the undetermined height and the preset height is used as the new undetermined height.
[0106] Optionally, the image rendering module 502 is further used for:
[0107] Perform filtering on the shadow height;
[0108] The set of shadow heights corresponding to the plurality of pixel points as the height texture includes:
[0109] The set of shadow heights after filtering is used as the height texture.
[0110] Optionally, the image rendering module 502 is further used for:
[0111] The shadow value corresponding to the pixel point is determined according to the coordinates of the pixel point in the world space and the shadow height.
[0112] Optionally, the scene image is a game scene image.
[0113] Through the above device, the shadow value of the pixel can be determined according to the target shadow height corresponding to the pixel, and the pixel is rendered according to the shadow value. In this way, the amount of data to be processed during the rendering process is relatively small, thereby improving the efficiency of image rendering.
[0114] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0115] Reference below Figure 6 , which shows a schematic diagram of the structure of an electronic device (such as a terminal device or a server) 600 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0116] like Figure 6As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0117] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0118] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0119] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0120] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0121] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0122] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a scene image to be rendered in a target scene; determines a target shadow height corresponding to each pixel in the scene image, and determines a shadow value corresponding to the pixel based on the target shadow height, and renders the pixel based on the shadow value to render the scene image; wherein the target shadow height is the height of a specified pixel in the shadow of the scene image, and the specified pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene, and whose height in the height direction of the world space is greater than or equal to a preset height threshold.
[0123] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0125] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, an image acquisition module may also be described as a "module for acquiring a scene image to be rendered in a target scene".
[0126] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0127] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0128] According to one or more embodiments of the present disclosure, Example 1 provides an image rendering method, the method comprising: obtaining a scene image to be rendered in a target scene; for each pixel in the scene image, determining a target shadow height corresponding to the pixel, and determining a shadow value corresponding to the pixel based on the target shadow height, and rendering the pixel based on the shadow value to render the scene image; wherein the target shadow height is the height of a specified pixel in the shadow of the scene image, and the specified pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene, and whose height in the height direction of the world space is greater than or equal to a preset height threshold.
[0129] According to one or more embodiments of the present disclosure, Example 2 provides the method of Example 1, wherein determining the target shadow height corresponding to the pixel point includes: determining the texture coordinates corresponding to the pixel point; determining the designated pixel point based on the texture coordinates and a height texture corresponding to the scene image acquired in advance, the height texture including the shadow height corresponding to each pixel point of the scene image; and using the shadow height corresponding to the designated pixel point as the target shadow height.
[0130] According to one or more embodiments of the present disclosure, Example 3 provides the method of Example 2, wherein determining the texture coordinates corresponding to the pixel point includes: obtaining the coordinates of the pixel point corresponding to the world space, the pixel size corresponding to the height texture, and the scale of the world space; determining the offset value between the center point of the terrain corresponding to the scene image and the origin of the coordinates of the pixel point corresponding to the world space; determining the texture coordinates corresponding to the pixel point based on the coordinates of the pixel point corresponding to the world space, the scale, the pixel size, and the offset value.
[0131] According to one or more embodiments of the present disclosure, Example 4 provides the method of Example 2, and the height texture is pre-acquired in the following manner: for each pixel point in the scene image, determining the scene depth of the pixel point in the direction of the light source in the scene image, and determining the shadow height corresponding to the pixel point based on the scene depth; and taking a set consisting of the shadow heights corresponding to multiple pixel points as the height texture.
[0132] According to one or more embodiments of the present disclosure, Example 5 provides the method of Example 4, wherein determining the shadow height corresponding to the pixel point based on the scene depth includes: determining the terrain height corresponding to the pixel point, the terrain height being the height of a reference surface in the scene image that is directly below the pixel point in the height direction of the coordinates of the pixel point corresponding to the world space; when it is determined that the position corresponding to the terrain height is in the shadow of the scene image, obtaining a preset height interval, and determining the shadow height corresponding to the pixel point based on the terrain height and the preset height interval.
[0133] According to one or more embodiments of the present disclosure, Example 6 provides the method of Example 5, wherein determining the shadow height corresponding to the pixel point based on the terrain height and the preset height interval includes: taking the terrain height as the pending height, and repeatedly executing the shadow height determination step until it is determined that the position corresponding to the new pending height is not in the shadow of the scene image, and taking the difference between the new pending height and the preset height interval as the shadow height corresponding to the pixel point; the shadow height determination step includes: determining whether the position corresponding to the pending height is in the shadow based on the scene depth; and when the position corresponding to the pending height is in the shadow, taking the sum of the pending height and the preset height interval as the new pending height.
[0134] According to one or more embodiments of the present disclosure, Example 7 provides the method of Example 4, and before using the set composed of the shadow heights corresponding to the multiple pixel points as the height texture, the method also includes: filtering the shadow heights; using the set composed of the shadow heights corresponding to the multiple pixel points as the height texture includes: using the set composed of the filtered shadow heights as the height texture.
[0135] According to one or more embodiments of the present disclosure, Example 8 provides the method of Example 1, wherein determining the shadow value corresponding to the pixel point based on the target shadow height includes: determining the shadow value corresponding to the pixel point based on the coordinates of the pixel point corresponding to the world space and the shadow height.
[0136] According to one or more embodiments of the present disclosure, Example 9 provides the method of any one of Examples 1-8, wherein the scene image is a game scene image.
[0137] According to one or more embodiments of the present disclosure, Example 10 provides an image rendering device, comprising: an image acquisition module, used to acquire a scene image to be rendered in a target scene; an image rendering module, used to determine, for each pixel in the scene image, a target shadow height corresponding to the pixel, and determine a shadow value corresponding to the pixel based on the target shadow height, and render the pixel based on the shadow value to render the scene image; wherein the target shadow height is the height of a specified pixel in the shadow of the scene image, and the specified pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene, and has a height greater than or equal to a preset height threshold in the height direction of the world space.
[0138] According to one or more embodiments of the present disclosure, Example 11 provides a computer-readable medium having a computer program stored thereon, which implements the steps of the method described in any one of Examples 1-9 when executed by a processing device.
[0139] According to one or more embodiments of the present disclosure, Example 12 provides an electronic device, comprising: a storage device on which a computer program is stored; and a processing device for executing the computer program in the storage device to implement the steps of the method described in any one of Examples 1-9.
[0140] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0141] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0142] Although the subject matter has been described in language specific to structural features and / or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Claims
1. An image rendering method, characterized in that: The method comprises: Obtain the scene image to be rendered in the target scene; For each pixel in the scene image, determine a target shadow height corresponding to the pixel, determine a shadow value corresponding to the pixel according to the target shadow height, and render the pixel according to the shadow value to render the scene image; The target shadow height is the height of a designated pixel in the shadow of the scene image, and the designated pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space; the preset height threshold is the height corresponding to the pixel that has the same position as the pixel in the height direction of the world space and has the highest position in the horizontal direction of the world space; Determining the target shadow height corresponding to the pixel point includes: Determine the texture coordinates corresponding to the pixel point; Determine the designated pixel point according to the texture coordinates and a pre-acquired height texture corresponding to the scene image, wherein the height texture includes a shadow height corresponding to each pixel point of the scene image; The shadow height corresponding to the designated pixel point is used as the target shadow height.
2. The method according to claim 1, characterized in that Determining the texture coordinates corresponding to the pixel point includes: Obtaining the coordinates of the pixel point corresponding to the world space, the pixel size corresponding to the height texture, and the scale of the world space; Determine an offset value between a center point of the terrain corresponding to the scene image and an origin of coordinates of the pixel point corresponding to the world space; The texture coordinates corresponding to the pixel point are determined according to the coordinates of the pixel point corresponding to the world space, the ratio, the pixel size, and the offset value.
3. The method according to claim 1, characterized in that: The height texture is pre-fetched in the following way: For each pixel in the scene image, determine the scene depth of the pixel in the direction of the light source in the scene image, and determine the shadow height corresponding to the pixel according to the scene depth; A set consisting of the shadow heights corresponding to the plurality of pixel points is used as the height texture.
4. The method according to claim 3, characterized in that The determining, according to the scene depth, the shadow height corresponding to the pixel point comprises: Determine a terrain height corresponding to the pixel point, where the terrain height is a height of a reference surface located directly below the pixel point in the scene image in a height direction of a coordinate of the pixel point corresponding to the world space; When it is determined that the position corresponding to the terrain height is in the shadow of the scene image, a preset height interval is obtained, and the shadow height corresponding to the pixel point is determined according to the terrain height and the preset height interval.
5. The method according to claim 4, characterized in that The determining the shadow height corresponding to the pixel point according to the terrain height and the preset height interval comprises: The terrain height is used as the pending height, and the shadow height determination step is executed repeatedly until it is determined that the position corresponding to the new pending height is not in the shadow of the scene image, and the difference between the new pending height and the preset height interval is used as the shadow height corresponding to the pixel point; The shadow height determination step comprises: Determining, according to the scene depth, whether the position corresponding to the to-be-determined height is in a shadow; When the position corresponding to the undetermined height is in the shadow, the sum of the interval between the undetermined height and the preset height is taken as the new undetermined height.
6. The method according to claim 3, characterized in that Before using a set of the shadow heights corresponding to the plurality of pixel points as the height texture, the method further includes: Performing filtering on the shadow height; The step of using a set of shadow heights corresponding to a plurality of pixel points as the height texture comprises: The set of shadow heights after filtering is used as the height texture.
7. The method according to claim 1, characterized in that Determining the shadow value corresponding to the pixel point according to the target shadow height includes: The shadow value corresponding to the pixel point is determined according to the coordinates of the pixel point corresponding to the world space and the target shadow height.
8. The method according to any one of claims 1 to 7, characterized in that: The scene image is a game scene image.
9. An image rendering device, characterized in that: The device comprises: An image acquisition module is used to acquire a scene image to be rendered in a target scene; An image rendering module, for determining, for each pixel in the scene image, a target shadow height corresponding to the pixel, and determining a shadow value corresponding to the pixel according to the target shadow height, and rendering the pixel according to the shadow value to render the scene image; The target shadow height is the height of a designated pixel in the shadow of the scene image, and the designated pixel is a pixel that has the same position as the pixel in the horizontal direction of the world space corresponding to the target scene and has a height greater than or equal to a preset height threshold in the height direction of the world space; the preset height threshold is the height corresponding to the pixel that has the same position as the pixel in the height direction of the world space and has the highest position in the horizontal direction of the world space; The image rendering module is used to determine the texture coordinates corresponding to the pixel point; determine the designated pixel point according to the texture coordinates and the height texture corresponding to the scene image acquired in advance, the height texture including the shadow height corresponding to each pixel point of the scene image; and use the shadow height corresponding to the designated pixel point as the target shadow height.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processing device, the steps of the method described in any one of claims 1 to 8 are implemented.
11. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1 to 8.
