Projection decal method and device, electronic equipment and storage medium
By projecting the decal method, decal information is obtained and processed, the decal effect is rendered without pre-baking, and the problems of high memory footprint and low decal freedom in the prior art are solved, saving resources and improving the flexibility of decals.
Patent Information
- Application Number
- CN202411972657.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-25
AI Technical Summary
The prior art requires pre-baking processing when realizing the decal effect, resulting in high memory usage, large resource consumption, and limited decal position, direction and angle.
Through the projection decal method, the decal information of the target model, including the coordinates and setting order of the decals, and the projection mapping is performed for each decal, and the texture coordinate group covered with decals is obtained, and the coloring is performed according to the texture coordinate group and setting order to achieve the decal effect.
No pre-baked textures are required, which saves the size and memory space of the game package, reduces resource consumption, and increases the freedom of decals. Users can freely choose the position, direction and angle of the decals.
Smart Images

Figure CN119888056A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a projection decal method, device, electronic equipment and storage medium. Background Art
[0002] In games, decals are often used to enhance the aesthetics and fun of the game. Decals are a technique used to add details to the surface of a 3D model, which can generate effects such as bullet holes, bloodstains, and graffiti.
[0003] Currently, there are three main technical solutions for implementing decals: 1) Use artistic means to create a translucent patch that completely overlaps with the decal location model and overlay it on the model surface; 2) For decals fixed on the model, the decal texture can be overlaid on the model's map in advance by unfolding UVs, so that the model with the decal can be drawn at once during rendering.
[0004] However, these methods all require pre-baking of decals, resulting in high memory usage and large resource consumption. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a projection decal method, device, electronic device and storage medium, so that users can freely select the position, direction and angle of the decal without re-baking the texture, saving the game package size, reducing the occupied memory space, and not occupying the precious template buffer.
[0006] In order to achieve the above object, the technical solution adopted by the present invention is as follows:
[0007] In a first aspect, the present invention provides a projection decal method, the method comprising:
[0008] Acquire decal information of the target model; wherein the decal information includes coordinates of at least one decal and a setting order of the decals;
[0009] For each of the decals, projection mapping the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal;
[0010] According to each of the texture coordinate groups and the setting order, a shading process is performed to display a target model with decals on a target scene.
[0011] Optionally, the step of projection mapping the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal comprises:
[0012] Obtaining a transformation matrix of the decal according to the size information of the decal and the coordinates of the center point of the decal on the target scene; wherein the transformation matrix represents coverage information of the projection mapping of the decal onto the target model;
[0013] A texture coordinate group of the target model covered with the decal is obtained according to the transformation matrix and the vertex information of the target model.
[0014] Optionally, the step of obtaining a transformation matrix of the decal according to size information of the decal and coordinates of a center point of the decal on a target scene comprises:
[0015] According to the coordinates of the center point of the decal on the target scene, a translation matrix with the center point of the decal as the origin is obtained;
[0016] Directing the projection direction of the decal toward the Z axis of the target scene to obtain a rotation matrix of the decal;
[0017] Orthogonally projecting the decal in the direction of the target model to obtain a projection matrix;
[0018] The transformation matrix of the decal is obtained according to the preset coordinate mapping matrix, the translation matrix, the rotation matrix and the projection matrix; wherein the coordinate mapping matrix is a matrix for adjusting the coordinate range of the decal to be within the texture coordinate range of the graphics processor.
[0019] Optionally, the vertex information includes coordinate values of each vertex;
[0020] The step of obtaining a texture coordinate group of the target model covered with the decal according to the transformation matrix and the vertex information of the target model comprises:
[0021] For each vertex of the target model, multiply the transformation matrix by the coordinate value of the vertex to obtain texture data of the vertex;
[0022] The texture data of each of the vertices are integrated to obtain a texture coordinate group of the target model covered with the decal.
[0023] Optionally, the texture coordinate group includes texture coordinates and coverage values of each vertex of the target model, and the coverage value represents the coverage of the decal on the vertex;
[0024] The step of performing shading processing according to each of the texture coordinate groups and the setting order comprises:
[0025] According to the coverage value of the vertex in each of the texture coordinate groups, a candidate decal for each vertex is obtained from each of the decals; wherein the candidate decal is a decal that covers the vertex;
[0026] When the candidate decal is zero, coloring the vertex using the original material of the target model;
[0027] When there are one or more candidate decals, the vertex is colored using a texture of one of the candidate decals according to the setting order.
[0028] Optionally, the step of coloring the vertices using a texture of the candidate decal according to the setting order comprises:
[0029] From the candidate decals, selecting the candidate decal that is last in the setting order as the hit decal;
[0030] The vertex is shaded using the texture of the hit decal.
[0031] Optionally, the step of obtaining a candidate decal for each vertex from each decal according to the coverage value of the vertex in each texture coordinate group comprises:
[0032] For each vertex of the target model, selecting a valid texture coordinate group represented by a coverage value of the vertex as a hit group;
[0033] The decals corresponding to the hit group are used as candidate decals.
[0034] In a second aspect, the present invention provides a projection decal device, including a decal projection module and a coloring module;
[0035] The decal projection module is used to obtain decal information of the target model; wherein the decal information includes the coordinates of at least one decal and the order in which the decals are set;
[0036] The decal projection module is further used to project each decal onto the target model to obtain a texture coordinate group of the target model covered with the decal;
[0037] The shading module is used to perform shading processing according to each of the texture coordinate groups and the setting sequence, so as to display the target model with the decal on the target scene.
[0038] In a third aspect, the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the projection decal method as described in any of the aforementioned embodiments.
[0039] In a fourth aspect, the present invention provides a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the projection decal method as described in any one of the aforementioned embodiments.
[0040] The projection decal method, device, electronic device and storage medium provided by the embodiment of the present invention include: obtaining decal information of a target model; wherein the decal information includes the coordinates of at least one decal and the setting order of the decals; for each decal, projecting the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal; performing shading processing according to each texture coordinate group and the setting order to display the target model with the decal on the target scene. In this way, the texture coordinate group of the target model covered with the decal is first obtained by projection mapping, and then the decal is completed by shading processing according to the texture coordinate group, without the need to bake the texture map, saving the size of the game package, reducing the occupied memory space, and not occupying the template buffer, reducing resource consumption.
[0041] In addition, since there is no need for pre-baking, users can freely choose the position, direction and angle of the decals, greatly improving the freedom of decals.
[0042] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 A schematic diagram of the system architecture of a projection decal system provided by an embodiment of the present invention is shown.
[0045] Figure 2 A schematic diagram of a module architecture of an electronic device provided by an embodiment of the present invention is shown.
[0046] Figure 3 A schematic flow chart of a projection decal method provided by an embodiment of the present invention is shown.
[0047] Figure 4 Shows Figure 3 Schematic diagram of the process flow of some sub-steps of step 13.
[0048] Figure 5 Shows Figure 4A flowchart of some sub-steps of step 131 in FIG.
[0049] Figure 6 Shows Figure 4 A flowchart of some sub-steps of step 133 in FIG.
[0050] Figure 7 Shows Figure 3 Schematic diagram of the process flow of some sub-steps of step 15.
[0051] Figure 8 A schematic diagram of the module architecture of the projection decal device provided in an embodiment of the present invention is shown.
[0052] Explanation of the reference numerals: 10 - projection decal system; 110 - client; 120 - server; 20 - electronic device; 210 - memory; 220 - processor; 230 - communication module; 30 - projection decal device; 310 - decal projection module; 320 - coloring module. DETAILED DESCRIPTION
[0053] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0054] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0055] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0056] The projection decal method provided by the embodiment of the present invention can be applied to Figure 1In the projection decal system 10 shown, the projection decal system 10 includes a client 110 and a server 120, and the server 120 can be connected to the client 110 through a network.
[0057] The server 120 is used to provide game data processing and exchange, resource package distribution, login verification, and social interaction functions. For example, it receives data requests from the client 110 (player device), such as character movement, skill release and other operation instructions, and feeds back to the corresponding client 110 after processing, transfers messages between clients 110 (i.e. players) and maintains the session status.
[0058] The client 110 is used to render and display game images and sound effects, process player input, such as movement and attack instructions, and send requests to the server 120, as well as the projection decal method provided by the embodiment of the present invention.
[0059] The client 110 may be, but is not limited to, a personal computer, a laptop computer, a tablet computer, a game console, a mobile phone, etc. The server 120 may be an independent server 120 or a server 120 cluster.
[0060] Please refer to Figure 2 , is a block diagram of an electronic device 20, which may be Figure 1 The client 110 in the projection decal system 10 is shown. The electronic device 20 includes a memory 210, a processor 220, and a communication module 230. The memory 210, the processor 220, and the communication module 230 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0061] The memory 210 is used to store programs or data. The memory 210 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0062] The processor 220 is used to read / write data or programs stored in the memory 210 and execute corresponding functions. For example, Figure 1In the projection decal system 10 shown, the processor 220 of the client 110 executes a computer program stored in the storage to implement the projection decal method provided by the embodiment of the present invention.
[0063] The communication module 230 is used to establish a communication connection between the electronic device 20 and other communication terminals through the network, and to send and receive data through the network. Figure 1 In the projection decal system 10 shown, the client 110 transmits and receives data with the server 120 via a network through a module.
[0064] It should be understood that Figure 2 The structure shown is only a schematic diagram of the structure of the electronic device 20. The electronic device 20 may also include Figure 2 More or fewer components as shown, or with Figure 2 Different configurations shown. Figure 2 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0065] In order to improve the problem that the current game decal method requires pre-baking of decals, resulting in high memory usage and large resource consumption, the embodiment of the present invention provides a projection decal method, referring to Figure 3 , including steps 11 to 15. Thus,: Figure 1 In the projection decal system 10 shown, the client 110 is Figure 2 The structure shown implements steps 11 to 15 when the processor 220 executes the computer program stored in the storage.
[0066] Step 11, obtain the decal information of the target model.
[0067] The decal information includes the coordinates of at least one decal and the order in which the decals are set.
[0068] Step 13: For each decal, projection-map the decal to the target model to obtain a texture coordinate group of the target model covered with the decal.
[0069] Step 15, performing shading processing according to each texture coordinate group and setting order to display the target model with the decal on the target scene.
[0070] The target scene may be any three-dimensional game scene.
[0071] For example, in combination Figure 1The projection decal system 10 shown, for a game equipped with a decal function, when the client 110 downloads the game or the game updates the decal content, the server 120 downloads all the current decals' texture, size and other attribute information to the client 110. After the player enters the game through the client 110 and opens the decal function interface, and selects and configures decals for game characters, game mounts, pets and other models, the client 110 obtains the decal information of each target model (including the coordinates of the decal in the three-dimensional scene of the game and the order in which the decals are set).
[0072] Then, for each decal of the target model, the client 110 projects the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal, wherein the texture coordinate group includes each texture coordinate of the target model covered with the decal. Then, the client 110 performs shading processing in a pixel shader according to the setting order of each texture coordinate group and each decal of the target model, so as to display the target model with the decal on the target scene.
[0073] One decal method used in game development is to use screen space decal technology. After normal rendering is completed, a box is drawn separately, and a certain face of the box is designated as the projection face, and then projected backwards. If an object intersects with the box, the screen space depth is sampled to obtain the world coordinates of the point closest to the projection face, and the decal is projected onto the surface of the object. However, decals drawn in this way will be blocked by other objects, and template values need to be written for copy judgment, resulting in poor decal effects and high resource consumption.
[0074] Other decal methods include: (1) using artistic means to create a semi-transparent patch that completely overlaps with the decal position model, and superimpose it on the surface of the object model; (2) for decals fixed on the model, the decal texture can be overlaid on the model's map in advance by unfolding the UV, so that the model with the decal can be drawn at once during rendering. The former method cannot switch the position of the decal on the model, and the decal and the object are modeled separately, which takes up a lot of memory. The latter method, when there are a large number of identical models in the game with different decals, needs to generate many sets of maps, which takes up a lot of memory.
[0075] Compared with the related decal method, in the above steps 11 to 15, only the attribute information of the decal needs to be stored in the client, and there is no need to pre-bake the decal (i.e., calculate the decal effect in advance and store it in the map), so that the texture coordinate group of the target model covered with the decal is obtained through projection mapping, and then the decal is rendered at the same time as the object model is drawn according to the texture coordinate group. This saves the size of the game package, reduces the memory space occupied, and does not occupy the template buffer, reducing resource consumption. In addition, since there is no need for pre-bake, users can freely choose the position, direction and angle of the decal, which greatly improves the freedom of decals.
[0076] The method of projecting the decal onto the target model in step 13 can be flexibly set, for example, projection can be performed according to a preset projection matrix or according to a preset rule. The above methods are only examples, and the implementation methods are not limited.
[0077] When rendering, the camera position, camera orientation, object position, and camera projection parameters can determine which pixels will eventually be drawn to the canvas in the range [-1,1]. Similarly, by determining multiple additional camera positions and orientations in the scene, multiple planes in the range [-1,1] can be projected, which can be transformed into planes in the range [0,1] after a simple mapping transformation, which coincides with the UV coordinates. If the decal covers the entire plane of these additional cameras, it can be determined which parts of the object will be drawn with the UV coordinates that the decal has already corresponded to.
[0078] Therefore, in order to render the decals together with the object model, the decal projection mapping in step 13 first projects the decals onto the target scene where the target model is located (i.e., the decals are covered onto the projection plane corresponding to the camera position in the target scene where the target model is located), and then obtains the texture coordinate group of the target model covered with the decals. Figure 4 The implementation process of step 13 includes the following steps 131 to 133.
[0079] Step 131 , obtaining a transformation matrix of the decal according to the size information of the decal and the coordinates of the center point of the decal on the target scene.
[0080] The target scene is the 3D game scene where the target model is located, and the transformation matrix represents the coverage information of the decal projection mapped onto the target model. The center point coordinates of the decal on the target scene are the coordinates of the center point of the decal on the target scene when the user chooses to set the decal.
[0081] Step 133, obtaining a texture coordinate group of the target model covered with the decal according to the transformation matrix and the vertex information of the target model.
[0082] The texture coordinate group of the target model can also be understood as the UV coordinate set of the target model covered with decals.
[0083] Through the above steps 131 to 133, projection transformation is performed based on the size information of the decal and the center point coordinates, and the decal is covered on the projection plane corresponding to the camera position in the scene where the target model is located, so that the decal and the target model have the same measurement scale. Based on this, combined with the vertex information of the target model, the coverage relationship between the decal and the target model (i.e., the texture coordinate group of the target model covered with the decal) is obtained, avoiding the error caused by different measurement scales, thereby making the coverage relationship more accurate.
[0084] In order to accurately cover the decal on the projection plane corresponding to the camera position in the target scene where the target model is located, the concept of obtaining the transformation matrix of the decal through translation, rotation, projection and coordinate mapping is introduced in step 131. Figure 5 , the implementation process of step 131 includes steps 1311 to 1357.
[0085] Step 1311, based on the coordinates of the center point of the decal on the target scene, obtain a translation matrix with the center point of the decal as the origin.
[0086] Step 1313, align the projection direction of the decal toward the Z axis of the target scene to obtain the rotation matrix of the decal.
[0087] Step 1315, orthogonally project the decal toward the target model to obtain a projection matrix.
[0088] Step 1317, obtaining the transformation matrix of the decal according to the preset coordinate mapping matrix, translation matrix, rotation matrix and projection matrix.
[0089] The coordinate mapping matrix is a matrix that adjusts the coordinate range of the decal to be within the texture coordinate range of the graphics processor.
[0090] The process from step 1311 to step 1317 is calculated in the CPU of the client.
[0091] The translation matrix can be expressed as The coordinates of the center point of the decal on the target scene are (x, y, z).
[0092] Through the translation matrix M, the center of the decal is projected in a certain direction to translate all object models in the target scene in the opposite direction (x, y, z), so that the center point of the decal is located at the origin in the new coordinate system to facilitate subsequent calculations.
[0093] The rotation matrix can be expressed as: Where (dir x ,dir y,dir z ) represents the projection direction vector of the decal, that is, it specifies the projection direction, (up x , up y , up z ) is the up vector, which represents the vector perpendicular to the camera's visual axis and usually points upward. (right x , right y , right z ) represents the vector that is perpendicular to the camera's viewing axis and up vector (i.e., a virtual observation point that simulates the function of a camera in the real world and is used to capture and render 3D scenes).
[0094] Through the rotation matrix, it is known that the projection direction of the decal is dir. The right vector can be calculated by the vector product of the y axis of the world coordinate system (i.e. the world coordinate system of the game scene) where the target scene is located and dir. The up vector can be calculated by the vector product of dir and right. These three sets of vectors are perpendicular to each other and form a new coordinate system, and in this coordinate system, the dir vector faces the z axis of the coordinate system. Therefore, the projection direction of the decal faces the z axis (0, 0, 1) of the world coordinate system where the target scene is located.
[0095] The projection matrix can be expressed as: Among them, width, height, and nearToFar represent the width, height, and depth that the decal will cover (i.e., the size of the decal). Through the projection matrix, the decal is orthogonally projected toward the target model. After projection, the pixels with coordinates in the range of [-1,1] are the pixels covered by the decal.
[0096] The coordinate mapping matrix can be expressed as: Since the coordinate range of the projected object is [-1,1], but the UV coordinate range of the graphics processing unit (GPU) to access the texture is [0,1], the origin is located in the upper left corner of the image and the y-axis is downward. Therefore, the coordinates are remapped through the coordinate mapping matrix so that the converted coordinate range is consistent with the UV coordinates of the graphics processor. At the same time, the x-axis is also reversed through the coordinate mapping matrix to prevent the decal from being mirrored after being affixed to the model.
[0097] The transformation matrix of the decal can be expressed as: A=R·P·V·M.
[0098] Through the above step 131 and its sub-steps 1311 to 1317, the decal is quickly and accurately covered on the projection plane corresponding to the camera position in the target scene where the target model is located, and a transformation matrix, that is, coverage information of the decal, is obtained.
[0099] The transformation matrix of the decal obtained above is then passed to the GPU to execute step 133 to obtain a texture coordinate group of the target model covered with the decal, so as to render the target model and the decal at the same time.
[0100] The method of obtaining the texture coordinate group in step 133 can be flexibly selected. For example, a pre-trained texture sampling model can be used to generate a texture coordinate group according to the transformation matrix and the vertex information of the target model, or a texture coordinate group can be obtained by processing according to a preset rule. The above methods are only examples, and their implementation methods are not limited.
[0101] In order to obtain the coverage of the decal and the target model more accurately, i.e., the texture coordinate group is more accurate, the idea of sampling and calculating each vertex of the target model one by one according to the transformation matrix is introduced in step 133. At this time, the vertex information of the target model includes the coordinate value of each vertex (i.e., the coordinate in the world coordinate system of the target scene (game scene)), and refers to Figure 6 , the implementation of step 133 includes steps 1331 to 1333.
[0102] Step 1331, for each vertex of the target model, multiply the transformation matrix by the coordinate value of the vertex to obtain the texture data of the vertex.
[0103] The texture data includes texture coordinates and coverage values, and the coverage value represents the coverage of the decal on the vertex. A vertex is a point on the surface of the target model and is one of the basic geometric elements that constitute the 3D target model. It defines the shape and structure of the model.
[0104] Step 1333 , the texture data of each vertex is integrated to obtain a texture coordinate set of the target model covered with the decal.
[0105] For example, in Figure 1 In the vertex shader of the client 110 of the projection decal system 10 shown, the change matrix of the decal is multiplied by the coordinates of each vertex of the target model to obtain the texture coordinates of the decal corresponding to each vertex. If the texture coordinate is within [0,1], it means that the vertex is covered by the decal, and the texture coordinate (i.e., UV coordinate) is recorded. The coverage value can be set to the texture coordinate itself or a valid value (such as 1). If the texture coordinate is not within the range of [0,1], it means that the vertex is not covered by the decal. At this time, the coverage value is set to an invalid value (such as 2), indicating that it is out of range.
[0106] For each decal, the texture data of the corresponding vertices are integrated to obtain a texture coordinate group of the target model covered with the decal. That is, the texture coordinate group includes the texture coordinates and coverage values of each vertex of the target model, and the coverage value represents the coverage of the decal on the vertex.
[0107] Through the above steps, the coverage of the target model by the decal is obtained vertex by vertex, and more accurate coverage texture information (i.e., texture coordinate group) is obtained. Then, the obtained texture coordinate group is passed to the pixel shader for shading, and step 15 is executed to render the target model and the decal at one time, so as to achieve the decal effect on the target model.
[0108] In step 15, the method of coloring can be flexibly selected. For example, each texture coordinate group can be colored one by one according to the setting order of the decal, or it can be colored according to preset rules. The implementation method is not limited.
[0109] In order to avoid the confusion of decals displayed after shading in the case of multiple decals and reduce the consumption of shading resources, the texture coordinates of the overlapping decals are determined in step 15, and one of the overlapping decals is selected for shading. Figure 7 The coloring process of step 15 includes steps 151 to 155.
[0110] Step 151 , obtaining a candidate decal for each vertex from each decal according to the coverage value of the vertex in each texture coordinate group.
[0111] The candidate decals are decals that cover the vertices.
[0112] Step 153, when the candidate decal is zero, the original material of the target model is used to color the vertices.
[0113] Step 155 , when there are one or more candidate decals, use the texture of one candidate decal to color the vertices according to the setting order.
[0114] Through the above steps 151 to 155, when there is one or more vertices that fit and cover the same vertex of the target model, only the texture of one decal is selected to color the vertex to cover the original material of the target model, and the vertices not covered by the decal are colored according to the original texture material of the target model. Thus, each vertex is colored only once, and the target model and the decal are rendered at the same time, so that the decal effect is rendered and displayed together with the target model, which greatly reduces the consumption of coloring resources.
[0115] In step 151 , all candidate decals for each vertex may be obtained by traversal query or concurrent query, and the implementation method is not limited.
[0116] Regardless of traversal query or concurrent query, all texture coordinate groups must be queried to avoid missing and causing shading errors. For example, for each vertex of the target model, a valid texture coordinate group represented by the coverage value of the vertex is selected as the hit group, and then the decal corresponding to the hit group is selected as the candidate decal.
[0117] Through the above method, it is ensured that the coverage between each decal and each vertex is queried, avoiding the situation where the decal is missed and causing shading errors, which greatly improves the accuracy of shading.
[0118] In step 153, for a vertex with only one candidate decal, the vertex is colored with the texture of the candidate decal. For a vertex with more than one candidate decal, the texture of one candidate decal can be arbitrarily selected to color the vertex, or the texture of a candidate decal can be selected according to a preset rule to color the vertex, and the implementation method is not limited.
[0119] In order to meet the user's decal design requirements and improve the user experience, in step 153, when there is more than one candidate decal for a vertex, the candidate decal with the last setting order is selected from the candidate decals as the hit decal, and the vertex is colored using the texture of the hit decal through the pixel shader.
[0120] For example, if there are three candidate decals for a vertex, and the order of setting is decal A, decal B, and decal C, then the texture of decal C is used to color the vertex.
[0121] Through the above method, when there are multiple overlapping decals, the last decal texture set by the user is used for coloring to meet the user's final decal setting design and improve the user experience.
[0122] Based on the same concept as the above-mentioned projection decal method, refer to Figure 8 The embodiment of the present invention further provides a projection decal device 30, which includes a decal projection module 310 and a coloring module 320. The projection decal device 30 can be applied to Figure 1 The client 110 of the projection decal system 10 is shown.
[0123] The decal projection module 310 is used to obtain decal information of the target model, wherein the decal information includes the coordinates of at least one decal and the order in which the decals are set.
[0124] The decal projection module 310 is further used to project each decal onto the target model to obtain a texture coordinate group of the target model covered with the decal.
[0125] The shading module 320 is used to perform shading processing according to each texture coordinate group and setting order to display the target model with decals on the target scene.
[0126] Under the synergistic effect of the decal projection module 310 and the coloring module 320, the above-mentioned projection decal device 30 only needs to store the attribute information of the decal in the client 110, and does not need to pre-bake the decal (i.e., calculate the decal effect in advance and store it in the map), so as to obtain the texture coordinate group of the target model covered with the decal through projection mapping, and then perform coloring processing according to the texture coordinate group, so that the decal can be rendered at the same time as the object model is drawn, saving the size of the game package, reducing the occupied memory space, and not occupying the template buffer, reducing resource consumption. In addition, since there is no need for pre-baking, the user can freely choose the position, direction and angle of the decal, which greatly improves the degree of freedom of the decal.
[0127] For the specific implementation and effect of the projection decal device 30, please refer to the description of the implementation of the projection decal method above. For example, for the specific implementation and effect of the decal projection module 310, please refer to the description of the relevant contents of step 11 and step 13 above. For the specific implementation and effect of the coloring module 320, please refer to the description of the relevant contents of step 15 above. No further details will be given here.
[0128] In addition, each module of the projection decal device 30 can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of the processor 220 in the electronic device 20 in the form of hardware, or can be stored in the memory 210 of the electronic device 20 in the form of software, so that the processor 220 can call and execute the operations corresponding to each module to implement the projection decal method provided above.
[0129] The embodiment of the present invention also provides an electronic device 20, including a processor 220 and a memory 210, wherein the memory 210 stores a computer program that can be executed by the processor 220, and the processor 220 can execute the computer program to implement the projection decal method provided above.
[0130] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 220, the projection decal method proposed in the embodiment of the present invention is implemented.
[0131] In summary, the projection decal method, device, electronic device and storage medium provided by the embodiments of the present invention have at least the following beneficial effects:
[0132] (1) Decals are rendered at the same time as the object model is drawn, reducing resource consumption;
[0133] (2) There is no need to pre-bake decal effects, which saves the size of the game package and reduces the memory space occupied. It does not occupy the template buffer, further reducing resource consumption;
[0134] (iii) The position, direction and angle of the decals are not restricted. Users can freely choose the position, direction and angle of the decals, which greatly improves the freedom of decals.
[0135] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes 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 box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0136] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0137] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.
[0138] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A projection decal method, characterized in that: The method comprises: Acquire decal information of the target model; wherein the decal information includes coordinates of at least one decal and a setting order of the decals; For each of the decals, projection mapping the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal; According to each of the texture coordinate groups and the setting order, a shading process is performed to display a target model with decals on a target scene.
2. The projection decal method according to claim 1, characterized in that: The step of projecting the decal onto the target model to obtain a texture coordinate group of the target model covered with the decal comprises: Obtaining a transformation matrix of the decal according to the size information of the decal and the coordinates of the center point of the decal on the target scene; wherein the transformation matrix represents coverage information of the projection mapping of the decal onto the target model; A texture coordinate group of the target model covered with the decal is obtained according to the transformation matrix and the vertex information of the target model.
3. The projection decal method according to claim 2, characterized in that: The step of obtaining the transformation matrix of the decal according to the size information of the decal and the coordinates of the center point of the decal on the target scene comprises: According to the coordinates of the center point of the decal on the target scene, a translation matrix with the center point of the decal as the origin is obtained; Directing the projection direction of the decal toward the Z axis of the target scene to obtain a rotation matrix of the decal; Orthogonally projecting the decal in the direction of the target model to obtain a projection matrix; The transformation matrix of the decal is obtained according to the preset coordinate mapping matrix, the translation matrix, the rotation matrix and the projection matrix; wherein the coordinate mapping matrix is a matrix for adjusting the coordinate range of the decal to be within the texture coordinate range of the graphics processor.
4. The projection decal method according to claim 2, characterized in that: The vertex information includes the coordinate value of each vertex; The step of obtaining a texture coordinate group of the target model covered with the decal according to the transformation matrix and the vertex information of the target model comprises: For each vertex of the target model, multiply the transformation matrix by the coordinate value of the vertex to obtain texture data of the vertex; The texture data of each of the vertices are integrated to obtain a texture coordinate group of the target model covered with the decal.
5. The projection decal method according to any one of claims 1 to 4, characterized in that: The texture coordinate group includes texture coordinates and coverage values of each vertex of the target model, and the coverage value represents the coverage of the decal on the vertex; The step of performing shading processing according to each of the texture coordinate groups and the setting order comprises: According to the coverage value of the vertex in each of the texture coordinate groups, a candidate decal for each vertex is obtained from each of the decals; wherein the candidate decal is a decal that covers the vertex; When the candidate decal is zero, coloring the vertex using the original material of the target model; When there are one or more candidate decals, the vertex is colored using a texture of one of the candidate decals according to the setting order.
6. The projection decal method according to claim 5, characterized in that: The step of coloring the vertices using a texture of the candidate decal according to the setting order comprises: From the candidate decals, selecting the candidate decal that is last in the setting order as the hit decal; The vertex is shaded using the texture of the hit decal.
7. The projection decal method according to claim 5, characterized in that: The step of obtaining a candidate decal for each vertex from each decal according to the coverage value of the vertex in each texture coordinate group comprises: For each vertex of the target model, selecting a valid texture coordinate group represented by a coverage value of the vertex as a hit group; The decals corresponding to the hit group are used as candidate decals.
8. A projection decal device, characterized in that: Includes decal projection module and shading module; The decal projection module is used to obtain decal information of the target model; wherein the decal information includes the coordinates of at least one decal and the order in which the decals are set; The decal projection module is further used to project each decal onto the target model to obtain a texture coordinate group of the target model covered with the decal; The shading module is used to perform shading processing according to each of the texture coordinate groups and the setting sequence, so as to display the target model with the decal on the target scene.
9. An electronic device, characterized in that: The invention comprises a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the projection decal method according to any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the projection decal method according to any one of claims 1 to 7 is implemented.