Shadow production method, device, equipment and storage medium

By recording the shadow state of the model vertices in the game in the color attribute, the problem of excessive data volume and high calculation volume caused by static shadows is solved, and efficient shadow drawing is achieved, reducing the data volume of the game installation package and reducing the calculation requirements.

CN115054916BActive Publication Date: 2025-07-11SIKELI CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210613313.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2025-07-11
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

In the prior art, the static shadow production method causes the game installation package data to be too large and the calculation amount is high, which cannot effectively reduce the amount of shadow effect calculation during game operation.

Method used

Record the shadow state by determining the distance and depth values between the model vertex and the light source in the scene. In the Vertex Color property, the game runs and reads the shadow state from the Vertex Color property to draw the shadow, avoiding baked shadow maps.

Benefits of technology

It reduces the amount of data in the game installation package, reduces the amount of shadow effects calculation, and improves the game running efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115054916B_ABST
    Figure CN115054916B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a method, apparatus, device, and storage medium for shadow production. The method includes: determining the distances between the vertices of each model in a scene and a preset light source respectively; obtaining the depth values corresponding to the vertices of each model respectively; determining the shadow states corresponding to the vertices of each model respectively based on the distances and the depth values, where the shadow state is used to indicate whether the corresponding vertex is in the shadow; and recording the shadow states corresponding to the vertices of each model in the color attributes of each vertex. By adopting the present invention, after the game is produced, the installation package of the game carries the color attributes of the vertices of the model, and the shadow states corresponding to the vertices of the model are recorded in the color attributes. Further, during the running of the game, the shadow states corresponding to the corresponding vertices can be read from the color attributes of the vertices of the model. Since no dedicated baked shadow map is added to the installation package of the game, the data volume of the installation package will be greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image rendering, and in particular, to a method, apparatus, device, and storage medium for shadow production. Background Art

[0002] In order to improve the realism of game scenes, shadow effects are added to models in the scene during the operation of the game. Generally speaking, dynamic shadows or static shadows can be selected to add shadow effects to the models.

[0003] For dynamic shadows, it is necessary to calculate the shadow effects corresponding to each model in real time during the operation of the game. Therefore, the amount of computation required for dynamic shadows is relatively high. For static shadows, it is no longer necessary to calculate the shadow effects corresponding to each model in real time. Instead, each scene is pre-baked in advance when writing the game to obtain a baked shadow map, and then during the operation of the game, only the baked shadow map needs to be sampled to obtain the shadow effects of each model.

[0004] Since the method of static shadows requires the use of baked shadow maps to obtain shadow effects, this leads to a large number of shadow maps being added to the game installation package. A large number of shadow maps will cause a sharp increase in the data volume of the installation package. Summary of the Invention

[0005] Embodiments of the present invention provide a method, apparatus, device, and storage medium for shadow production, so as to reduce the amount of computation for shadow effects during the operation of the game while reducing the data volume of the game installation package.

[0006] In a first aspect, an embodiment of the present invention provides a method for shadow production, the method comprising:

[0007] Determine the distances between the vertices of each model in the scene and a preset light source;

[0008] Obtain the depth value corresponding to each vertex of each model;

[0009] Based on the distance and the depth value, determine the shadow state corresponding to each vertex of each model, where the shadow state is used to indicate whether the corresponding vertex is in the shadow;

[0010] Record the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

[0011] Optionally, after recording the shadow state corresponding to each vertex of each model in the color attribute of each vertex, the method further comprises:

[0012] Obtain the shadow state corresponding to each vertex of each model through the color attribute of the vertex of each model in the shader;

[0013] Based on the shadow state, perform rendering processing on each model in the scene to draw the shadows corresponding to each model respectively.

[0014] Optionally, recording the shadow state corresponding to each vertex of each model in the color attribute of each vertex includes:

[0015] If the shadow state corresponding to any vertex indicates that the any vertex is in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the first value;

[0016] If the shadow state corresponding to any vertex indicates that the any vertex is not in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the second value, and the second value is different from the first value.

[0017] Optionally, determining the shadow state corresponding to each vertex of each model based on the distance and the depth value includes:

[0018] If the distance between any vertex and the preset light source is greater than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is in the shadow;

[0019] If the distance between any vertex and the preset light source is less than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is not in the shadow.

[0020] Optionally, determining the distances between the vertices of each model in the scene and the preset light source respectively includes:

[0021] Obtain the light source matrix corresponding to the preset light source;

[0022] Obtain the world coordinates corresponding to each vertex of each model, where the world coordinates are the coordinates of the corresponding vertex in the pre-established world coordinate system;

[0023] Based on the light source matrix and the world coordinates, determine the distances between the vertices of each model and the preset light source respectively.

[0024] Optionally, obtaining the light source matrix corresponding to the preset light source includes:

[0025] Determine the minimum bounding box corresponding to each model;

[0026] Obtain the orientation information of the preset light source;

[0027] Based on the minimum bounding box and the orientation information, determine the light source matrix corresponding to the preset light source.

[0028] Optionally, the determining the distances between the vertices of each model and the preset light source based on the light source matrix and the world coordinates further includes:

[0029] Based on the light source matrix and the world coordinates, determine the sampling coordinates corresponding to each vertex, where the sampling coordinates are used to perform a sampling operation on the depth map;

[0030] The obtaining the depth values corresponding to the vertices of each model includes:

[0031] Obtain the depth map;

[0032] Based on the sampling coordinates, perform a sampling operation on the depth map to obtain the depth values corresponding to each vertex.

[0033] Optionally, the specification size of the depth map is determined by the precision parameters of the rendered image captured by the camera.

[0034] In a second aspect, an embodiment of the present invention provides a shadow making device, including:

[0035] A determining module, configured to determine the distances between the vertices of each model in the scene and a preset light source;

[0036] An obtaining module, configured to obtain the depth values corresponding to the vertices of each model;

[0037] The determining module is configured to determine the shadow states corresponding to the vertices of each model based on the distances and the depth values, where the shadow states are used to indicate whether the corresponding vertices are in the shadow;

[0038] A storage module, configured to record the shadow states corresponding to the vertices of each model in the color attributes of each vertex.

[0039] Optionally, the device further includes a rendering module, and the rendering module is configured to:

[0040] In the shader, obtain the shadow states corresponding to the vertices of each model through the color attributes of the vertices of each model;

[0041] Based on the shadow states, perform a rendering process on each model in the scene to draw the shadows corresponding to each model.

[0042] Optionally, the storage module is configured to:

[0043] If the shadow state corresponding to any vertex indicates that the any vertex is in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the first value;

[0044] If the shadow state corresponding to any vertex indicates that the any vertex is not in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the second value, and the second value is different from the first value.

[0045] Optionally, the determining module is configured to:

[0046] If the distance between any vertex and the preset light source is greater than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is being in the shadow;

[0047] If the distance between any vertex and the preset light source is less than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is not being in the shadow.

[0048] Optionally, the determining module is configured to:

[0049] Obtain the light source matrix corresponding to the preset light source;

[0050] Obtain the world coordinates respectively corresponding to the vertices of each model, where the world coordinates are the coordinates of the corresponding vertices in the pre-established world coordinate system;

[0051] Based on the light source matrix and the world coordinates, determine the distances between the vertices of each model and the preset light source respectively.

[0052] Optionally, the obtaining module is configured to:

[0053] Determine the minimum bounding box corresponding to each model;

[0054] Obtain the orientation information of the preset light source;

[0055] Based on the minimum bounding box and the orientation information, determine the light source matrix corresponding to the preset light source.

[0056] Optionally, the determining module is further configured to:

[0057] Based on the light source matrix and the world coordinates, determine the sampling coordinates respectively corresponding to the vertices, where the sampling coordinates are used for sampling the depth map;

[0058] Obtain the depth map;

[0059] Perform a sampling operation on the depth map based on the sampling coordinates to obtain the depth values respectively corresponding to the vertices.

[0060] Optionally, the specification size of the depth map is determined by the accuracy parameter of the rendered image captured by the camera.

[0061] In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory. The memory stores executable code. When the executable code is executed by the processor, the processor can at least implement the shadow production method in the first aspect.

[0062] In a fourth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium. The non-transitory machine-readable storage medium stores executable code. When the executable code is executed by the processor of an electronic device, the processor can at least implement the shadow production method in the first aspect.

[0063] By using the present invention, based on the distances between the vertices of each model in the scene and a preset light source, and the depth values corresponding to the vertices of each model respectively, the shadow states corresponding to the vertices of each model can be determined, and then the shadow states corresponding to the vertices of each model are recorded in the color attributes of each vertex. In this way, after the game is produced, the installation package of the game carries the color attributes of the vertices of the model, and the shadow states corresponding to the vertices of the model are recorded in the color attributes. Furthermore, during the running of the game, the shadow states corresponding to the corresponding vertices can be read from the color attributes of the vertices of the model, and the shadows of the model are drawn based on the read shadow states. Since no dedicated baked shadow map is added to the installation package of the game, the data volume of the installation package will be greatly reduced.

[0064] On the other hand, since the shadows of the model are drawn by reading the shadow states corresponding to the corresponding vertices from the color attributes of the vertices of the model, this can avoid the process of sampling the baked shadow map, so the running consumption of sampling the baked shadow map can be reduced. Description of the Drawings

[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0066] Figure 1 It is a schematic flowchart of a shadow production method provided by an embodiment of the present invention;

[0067] Figure 2 It is a schematic flowchart of a method for determining the distances between the vertices of a model and a preset light source respectively provided by an embodiment of the present invention.

[0068] Figure 3 A schematic flowchart of another method for making a shadow provided by an embodiment of the present invention;

[0069] Figure 4 A schematic flowchart of another method for making a shadow provided by an embodiment of the present invention;

[0070] Figure 5 A schematic structural diagram of a shadow making device provided by an embodiment of the present invention;

[0071] Figure 6 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners

[0072] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0073] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. "Plural" generally includes at least two.

[0074] Depending on the context, the words "if", "when" as used herein can be interpreted as "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detecting (stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)".

[0075] In addition, the step timings in the following method embodiments are only examples, and are not strictly limited.

[0076] Figure 1 A flowchart of a method for making a shadow provided by an embodiment of the present invention. This method can be applied to an electronic device. As Figure 1 shown, the method includes the following steps:

[0077] 101. Determine the distances between the vertices of each model in the scene and a preset light source respectively.

[0078] 102. Obtain the depth value corresponding to each vertex of each model.

[0079] 103. Based on the distance and the depth value, determine the shadow state corresponding to each vertex of each model, where the shadow state is used to indicate whether the corresponding vertex is in the shadow.

[0080] 104. Record the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

[0081] In practical applications, since the shadow is drawn for each vertex in the model during the shadow drawing process, the shadow state corresponding to each vertex in the model can be determined in advance, and then the shadow state corresponding to each vertex is recorded in the color attribute of the corresponding vertex. In this way, during the shadow drawing process, the corresponding shadow state can be read from the color attribute of each vertex of the model, and then the shadow of the model is drawn based on the shadow state corresponding to each vertex.

[0082] Optionally, the shadow state can be expressed in the following way: if the shadow state corresponding to any vertex n indicates that the vertex n is in the shadow, then determine that the parameter corresponding to the shadow state in the color attribute of the vertex n is the first value; if the shadow state corresponding to the vertex n indicates that the vertex n is not in the shadow, then determine that the parameter corresponding to the shadow state in the color attribute of the vertex n is the second value, and the second value is different from the first value.

[0083] In some alternative embodiments, for example, the first value can be set to 0, and the second value can be set to 1. Of course, in practical applications, the values used to represent whether the vertex n is in the shadow can be freely selected, and even characters such as letters can be used to represent whether the vertex n is in the shadow. The embodiments of the present invention do not limit this.

[0084] Assume that setting 0 indicates that the vertex n is in the shadow, and setting 1 indicates that the vertex n is not in the shadow. Then, when the shadow state read from the color attribute of the vertex n is 0, it can be known that the vertex n is in the shadow, and then corresponding means can be taken to draw the shadow effect of the vertex n. When the shadow state read from the color attribute of the vertex n is 1, it can be known that the vertex n is not in the shadow.

[0085] In the embodiments of the present invention, the shadow state corresponding to each vertex of the model can be determined by the distance between each vertex of the model and a preset light source and the depth value corresponding to each vertex of the model.

[0086] The process of determining the distance between each vertex of the model and the preset light source is introduced below. As Figure 2As shown, the process of determining the distances between the respective vertices of the model and the preset light source may include the following steps:

[0087] 201. Obtain the light source matrix corresponding to the preset light source.

[0088] Optionally, the process of obtaining the light source matrix corresponding to the preset light source may be implemented as follows: Determine the minimum bounding box (Render Bounds) corresponding to each model; Obtain the orientation information of the preset light source; Based on the minimum bounding box and the orientation information, determine the light source matrix corresponding to the preset light source.

[0089] It should be noted that the above minimum bounding box may be a cuboid, and the boundaries of the corresponding model can be enclosed within it by this cuboid. In this way, after determining the shooting angle of the camera, if all the vertices of the minimum bounding box corresponding to any model are within the shooting range of the camera, then this model needs to be drawn into the scene, thereby determining which models among multiple models need to appear in the scene and be shown to the user.

[0090] 202. Obtain the world coordinates corresponding to the respective vertices of the model, where the world coordinates are the coordinates of the corresponding vertices in the pre-established world coordinate system.

[0091] 203. Based on the light source matrix and the world coordinates corresponding to the respective vertices of the model, determine the distances between the respective vertices of the model and the preset light source.

[0092] The following introduces the process of determining the depth values corresponding to the respective vertices of the model.

[0093] In practical applications, based on the light source matrix and the world coordinates, in addition to being able to determine the distances between the respective vertices of the model and the preset light source, the sampling coordinates (UV) corresponding to the respective vertices of the model can also be determined. Among them, the sampling coordinates are used for sampling operations on the depth map. Correspondingly, the process of determining the depth values corresponding to the respective vertices of the model can be implemented as follows: Obtain the depth map; Perform sampling operations on the depth map based on the sampling coordinates to obtain the depth values corresponding to the respective vertices of the model.

[0094] Optionally, the specification size of the depth map may be determined based on the accuracy parameters of the rendered image captured by the camera.

[0095] Among them, the units of the accuracy parameters may include pixels, meters, etc.

[0096] Among them, the specification size of the depth map may be, for example, 1024×1024, 256×256, etc.

[0097] In some alternative embodiments, the accuracy parameters of the rendered images captured by the camera can be preset in advance, and then based on these accuracy parameters, the specification dimensions of the depth map are initialized, and it is set to output the depth map to a render texture (which can be represented by RenderTexture). In this way, after the rendering process by the Graphics Processing Unit (GPU for short), the depth map with the specified specification dimensions can be directly output to the RenderTexture, and then the rendered depth map can be read from the RenderTexture. Then, sampling operations can be performed on the depth map based on the sampling coordinates to obtain the depth values corresponding to the respective vertices of the model.

[0098] After determining the distances between the respective vertices of the model and the preset light source, and the depth values corresponding to the respective vertices of the model, based on the distances between the respective vertices of the model and the preset light source, and the depth values corresponding to the respective vertices of the model, the shadow states corresponding to the respective vertices of the model can be determined.

[0099] Optionally, the process of determining the shadow states corresponding to the respective vertices of the model based on the distance and the depth value can be implemented as follows: If the distance between any vertex m and the preset light source is greater than the depth value of the vertex m, it is determined that the shadow state corresponding to the vertex m is in the shadow; if the distance between the vertex m and the preset light source is less than the depth value of the vertex m, it is determined that the shadow state corresponding to the vertex m is not in the shadow.

[0100] It can be understood that if the distance between vertex m and the preset light source is greater than the depth value of the vertex m, it means that the vertex m cannot be illuminated by the preset light source, so the shadow state corresponding to the vertex m is in the shadow. If the distance between vertex m and the preset light source is less than the depth value of the vertex m, it means that the vertex m can be illuminated by the preset light source, so the shadow state corresponding to the vertex m is not in the shadow.

[0101] As Figure 3 shown, it is a flowchart of another method for making shadows provided by an embodiment of the present invention. As Figure 3 shown, the method includes the following steps:

[0102] 301. Determine the distances between the respective vertices of each model in the scene and the preset light source.

[0103] 302. Obtain the depth values corresponding to the respective vertices of each model.

[0104] 303. Based on the distance and the depth value, determine the shadow states corresponding to the respective vertices of each model, where the shadow state is used to indicate whether the corresponding vertex is in the shadow.

[0105] 304. Record the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

[0106] For the specific implementation manners of the above steps 301 - 304, reference can be made to the descriptions in the foregoing embodiments, and details are not described herein again.

[0107] 305. In the shader, obtain the shadow state corresponding to each vertex of each model through the color attribute of the vertices of each model.

[0108] 306. Based on the shadow state, perform rendering processing on each model in the scene to draw the shadows corresponding to each model.

[0109] Steps 305 - 306 correspond to the process of game running. Before the game runs, technicians can pre - produce the shadow state corresponding to each vertex of the model and record it in the corresponding vertex color attribute. In this way, after the game is made, the game installation package carries the color attributes of each vertex of the model, and the shadow state corresponding to each vertex of the model is recorded in the color attribute.

[0110] Based on this, after the user obtains the game installation package and installs the game, the game can be run, and during the game running process, the shadow state corresponding to the corresponding vertex can be read from the color attributes of each vertex of the model. Furthermore, based on the read shadow state corresponding to each vertex of the model, rendering processing can be performed on each model in the scene to draw the shadows corresponding to each model, and finally the shadow effect of each model is realized.

[0111] As Figure 4 shown, it is a flowchart of another shadow production method provided by an embodiment of the present invention. As Figure 4 shown, this method includes the following steps:

[0112] 401. Determine the minimum bounding box corresponding to each model.

[0113] 402. Based on the minimum bounding box and the orientation information of the preset light source, determine the light source matrix corresponding to the preset light source.

[0114] 403. Initialize the specification size of the depth map based on the precision parameter, and set to output the depth map to the RenderTexture.

[0115] 404. Output the depth map with the specified depth map specification size to the RenderTexture.

[0116] 405. Based on the light source matrix and the world coordinates, determine the distance between each vertex of the model and the preset light source respectively, and the sampling coordinates corresponding to each vertex of the model respectively.

[0117] 406. Sample the depth map based on the sampling coordinates to obtain the depth values corresponding to the vertices of the model respectively.

[0118] 407. Determine the shadow state corresponding to each vertex of each model based on the distance and the depth value, and record the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

[0119] 408. Read the shadow state corresponding to the corresponding vertex from the color attribute of each vertex of the model during the running of the game.

[0120] 409. Render each model in the scene based on the shadow state to draw the shadows corresponding to each model respectively.

[0121] By adopting the present invention, the shadow state corresponding to each vertex of each model can be determined based on the distance between each vertex of each model in the scene and the preset light source and the depth value corresponding to each vertex of each model, and then the shadow state corresponding to each vertex of each model is recorded in the color attribute of each vertex. In this way, after the game is produced, the installation package of the game carries the color attributes of each vertex of the model, and the shadow state corresponding to each vertex of the model is recorded in the color attribute. Furthermore, during the running of the game, the shadow state corresponding to the corresponding vertex can be read from the color attribute of each vertex of the model, and the shadow of the model is drawn based on the read shadow state. Since no dedicated baked shadow map is added to the installation package of the game, the data volume of the installation package will be greatly reduced.

[0122] On the other hand, since the shadow of the model is drawn by reading the shadow state corresponding to the corresponding vertex from the color attribute of each vertex of the model during the process of drawing the shadow of the model, this can avoid the process of sampling the baked shadow map, so the running consumption of sampling the baked shadow map can be reduced.

[0123] The shadow production device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art can understand that these shadow production devices can all be configured by using commercially available hardware components through the steps taught by this solution.

[0124] Figure 5 The structural schematic diagram of a shadow production device provided by an embodiment of the present invention is as Figure 5 shown, and the device includes:

[0125] A determination module 51, configured to determine the distance between each vertex of each model in the scene and the preset light source;

[0126] An acquisition module 52, configured to acquire the depth value corresponding to each vertex of each model;

[0127] The determining module 51 is configured to determine the shadow state corresponding to each vertex of the models based on the distance and the depth value, where the shadow state is used to indicate whether the corresponding vertex is in the shadow;

[0128] The storage module 53 is configured to record the shadow state corresponding to each vertex of the models in the color attribute of each vertex.

[0129] Optionally, the device further includes a rendering module, and the rendering module is configured to:

[0130] Obtain the shadow state corresponding to each vertex of the models through the color attributes of the vertices of the models in the shader;

[0131] Render each model in the scene based on the shadow state to draw the shadows corresponding to the models respectively.

[0132] Optionally, the storage module 53 is configured to:

[0133] If the shadow state corresponding to any vertex indicates that the any vertex is in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the first value;

[0134] If the shadow state corresponding to any vertex indicates that the any vertex is not in the shadow, determine that the parameter corresponding to the shadow state in the color attribute of the any vertex is the second value, where the second value is different from the first value.

[0135] Optionally, the determining module 51 is configured to:

[0136] If the distance between any vertex and the preset light source is greater than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is in the shadow;

[0137] If the distance between any vertex and the preset light source is less than the depth value of the any vertex, determine that the shadow state corresponding to the any vertex is not in the shadow.

[0138] Optionally, the determining module 51 is configured to:

[0139] Obtain the light source matrix corresponding to the preset light source;

[0140] Obtain the world coordinates corresponding to each vertex of the models, where the world coordinates are the coordinates of the corresponding vertex in the pre-established world coordinate system;

[0141] Determine the distances between the vertices of the models and the preset light source respectively based on the light source matrix and the world coordinates.

[0142] Optionally, the obtaining module 52 is configured to:

[0143] Determine the minimum bounding box corresponding to each model;

[0144] Obtain the orientation information of the preset light source;

[0145] Based on the minimum bounding box and the orientation information, determine the light source matrix corresponding to the preset light source.

[0146] Optionally, the determining module 51 is further configured to:

[0147] Based on the light source matrix and the world coordinates, determine the sampling coordinates corresponding to each vertex, and the sampling coordinates are used for sampling the depth map;

[0148] Obtain the depth map;

[0149] Perform a sampling operation on the depth map based on the sampling coordinates to obtain the depth values corresponding to each vertex.

[0150] Optionally, the specification size of the depth map is determined by the accuracy parameter of the rendered image captured by the camera.

[0151] Figure 5 The device shown can execute the shadow production method provided in the foregoing Figures 1 to 4 For the detailed execution process and technical effects, refer to the description in the foregoing embodiments, which will not be repeated here.

[0152] In a possible design, the structure of the foregoing Figure 5 shown shadow production device can be implemented as an electronic device. As Figure 6 shown, the electronic device may include: a processor 91 and a memory 92. Wherein, an executable code is stored on the memory 92, and when the executable code is executed by the processor 91, the processor 91 can at least implement the shadow production method provided in the foregoing Figures 1 to 4 shown embodiments.

[0153] Optionally, the electronic device may further include a communication interface 93 for communicating with other devices.

[0154] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which an executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the shadow production method provided in the foregoing Figures 1 to 4 shown embodiments.

[0155] The device embodiments described above are merely illustrative, where the units described as separate components may or may not be physically separated. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0156] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of adding a necessary general hardware platform, and of course, it can also be implemented by a combination of hardware and software. Based on such an understanding, the above technical solution, in essence, or the part that contributes to the prior art can be embodied in the form of a computer product. The present invention can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) that contain computer-usable program code.

[0157] The shadow production method provided by the embodiments of the present invention can be executed by a certain program / software, which can be provided by the network side. The electronic device mentioned in the foregoing embodiments can download the program / software to the local non-volatile storage medium, and when it needs to execute the foregoing shadow production method, the program / software is read into the memory by the CPU, and then the CPU executes the program / software to implement the shadow production method provided in the foregoing embodiments. The execution process can refer to the illustration in the foregoing Figures 1 to 4 above.

[0158] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for making a shadow, characterized in that Including: Obtaining the depth value corresponding to each vertex of each model and the light source matrix corresponding to a preset light source; Obtaining the world coordinates corresponding to each vertex of each model, where the world coordinates are the coordinates of the corresponding vertex in a pre-established world coordinate system; Based on the light source matrix and the world coordinates, determining the distances between the vertices of each model and the preset light source respectively; Based on the distances and the depth values, determining the shadow state corresponding to each vertex of each model, where the shadow state is used to indicate whether the corresponding vertex is in the shadow; Recording the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

2. The method according to claim 1, characterized in that, After recording the shadow state corresponding to each vertex of each model in the color attribute of each vertex, the method further includes: In the shader, obtaining the shadow state corresponding to each vertex of each model through the color attribute of each vertex; Based on the shadow state, performing a rendering process on each model in the scene to draw the shadows corresponding to each model respectively.

3. The method according to claim 1, characterized in that The recording the shadow state corresponding to each vertex of each model in the color attribute of each vertex includes: If the shadow state corresponding to any vertex indicates that the any vertex is in the shadow, determining that the parameter corresponding to the shadow state in the color attribute of the any vertex is a first value; If the shadow state corresponding to any vertex indicates that the any vertex is not in the shadow, determining that the parameter corresponding to the shadow state in the color attribute of the any vertex is a second value, where the second value is different from the first value.

4. The method according to claim 1, wherein The determining the shadow state corresponding to each vertex of each model based on the distances and the depth values includes: If the distance between any vertex and the preset light source is greater than the depth value of the any vertex, determining that the shadow state corresponding to the any vertex is being in the shadow; If the distance between any vertex and the preset light source is less than the depth value of the any vertex, determining that the shadow state corresponding to the any vertex is not being in the shadow.

5. The method according to claim 1, characterized in that, The obtaining the light source matrix corresponding to the preset light source includes: Determining the minimum bounding box corresponding to each model; Obtaining the orientation information of the preset light source; Based on the minimum bounding box and the orientation information, determining the light source matrix corresponding to the preset light source.

6. The method according to claim 1, characterized in that, The determining the distances between the vertices of each model and the preset light source respectively based on the light source matrix and the world coordinates further includes: Based on the light source matrix and the world coordinates, determining the sampling coordinates corresponding to each vertex respectively, where the sampling coordinates are used to perform a sampling operation on a depth map; The obtaining the depth value corresponding to each vertex of each model includes: Obtaining the depth map; Based on the sampling coordinates, performing a sampling operation on the depth map to obtain the depth value corresponding to each vertex respectively.

7. A shadow production device, characterized in that, Including: A determining module, configured to obtain the light source matrix corresponding to the preset light source; Obtain the world coordinates corresponding to each vertex of each model, where the world coordinates are the coordinates of the corresponding vertex in a pre-established world coordinate system; based on the light source matrix and the world coordinates, determine the distances between the vertices of each model and the preset light source respectively; An obtaining module, configured to obtain the depth value corresponding to each vertex of each model; The determining module is configured to determine the shadow state corresponding to each vertex of each model based on the distance and the depth value, and the shadow state is used to indicate whether the corresponding vertex is in the shadow; A storage module, configured to record the shadow state corresponding to each vertex of each model in the color attribute of each vertex.

8. An electronic device, characterized in that, Comprising: A memory and a processor; wherein, an executable code is stored on the memory, and when the executable code is executed by the processor, the processor executes the shadow making method according to any one of claims 1-6.

9. A non-transitory machine-readable storage medium, characterized in that, An executable code is stored on the non-transitory machine-readable storage medium, and when the executable code is executed by the processor of the electronic device, the processor executes the shadow making method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Method for real-time and realistic rendering of complex scenes on internet

    US20150035830A1