Decorative effect rendering method and device and electronic equipment
By creating an initial patch in a virtual scene and using the virtual camera view vector to determine the offset information, generating the target patch and rendering the decal effect, the problem of over-rendering in deep decal technology is solved, and performance consumption is reduced and rendering efficiency is improved.
Patent Information
- Application Number
- CN202510543653.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-09-26
AI Technical Summary
In the existing technology, deep decal technology needs to construct a three-dimensional cube during the rendering process, resulting in a large number of invisible pixels being included in the rendering pipeline, causing problems of excessive rendering and high performance consumption.
By creating an initial patch in the virtual scene, using the virtual camera's viewing angle vector to determine the offset information of each position point, controlling the position point offset to generate the target patch, and rendering the decal effect based on the UV sampling coordinates, the construction of a three-dimensional cube is avoided.
While ensuring visual effects, performance consumption is reduced, rendering efficiency is improved, and unnecessary waste of resources is avoided.
Smart Images

Figure CN120707718A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of model rendering, and in particular to a rendering method, device, and electronic device for decal effects. Background Art
[0002] In the field of real-time rendering, deep decal technology is widely used to dynamically project detailed textures on scene surfaces. In related technologies, a bounding box or projection cube is usually used to define the decal's area of influence, and the world space is reconstructed through depth information to determine the final visible pixels. However, although the decal's visual effect is a planar projection, its bounding box needs to be constructed as a three-dimensional cube to ensure the integrity of the projection. This results in a large number of invisible pixels that exceed the actual surface range being included in the rendering pipeline. In particular, a higher cube volume is required in higher geometric surfaces to avoid visual truncation. This method will lead to over-rendering problems, seriously waste shader resources, and have high performance consumption. Summary of the Invention
[0003] In view of this, the purpose of the present disclosure is to provide a rendering method, device and electronic device for decal effects, construct a patch above the horizontal plane, determine the offset information of each position point in the patch through the perspective vector of the virtual camera, offset the patch, and the offset patch always covers the range required for parallax mapping. After rendering the patch, the decal effect is always in the target area of the horizontal plane. There is no need to construct a three-dimensional cube, and performance consumption is reduced while ensuring visual effects.
[0004] In a first aspect, an embodiment of the present disclosure provides a method for rendering a decal effect, the method comprising: creating an initial patch in a virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene; obtaining the camera position of a virtual camera in the virtual scene; for each position point on the initial patch, determining the offset information of the position point according to the projection position of the position point on the horizontal plane and the camera position; controlling the position point to offset based on the offset information of the position point to obtain a target patch after offset; wherein the target patch is reduced relative to the initial patch; according to the target patch, generating UV sampling coordinates of a preset decal, and rendering the preset decal onto the target patch based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, and the target area is the projection area of the initial patch on the horizontal plane.
[0005] In a second aspect, an embodiment of the present disclosure provides a rendering device for a decal effect, the device comprising: an initial face creation module, for creating an initial face in a virtual scene; wherein the initial face is parallel to the horizontal plane of the virtual scene; a camera position acquisition module, for acquiring the camera position of a virtual camera in the virtual scene; an offset information determination module, for determining, for each position point on the initial face, the offset information of the position point according to the projection position of the position point on the horizontal plane and the camera position; a target face determination module, for controlling the offset of the position point based on the offset information of the position point to obtain a target face after offset; wherein the target face is reduced relative to the initial face; a decal effect rendering module, for generating UV sampling coordinates of a preset decal based on the target face, and rendering the preset decal onto the target face based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, and the target area is the projection area of the initial face on the horizontal plane.
[0006] In a third aspect, an embodiment of the present disclosure provides an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the rendering method of the decal effect of any one of the first aspects.
[0007] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the rendering method of the decal effect of any one of the first aspects.
[0008] The embodiments of the present disclosure bring the following beneficial effects:
[0009] The present disclosure provides a method, device, and electronic device for rendering a decal effect, comprising: creating an initial patch in a virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene; obtaining the camera position of a virtual camera in the virtual scene; determining offset information for each position point on the initial patch based on the projection position of the position point on the horizontal plane and the camera position; controlling the position point to be offset based on the offset information to obtain a target patch after the offset; wherein the target patch is reduced relative to the initial patch; generating UV sampling coordinates for a preset decal based on the target patch; rendering the preset decal onto the target patch based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, the target area being the projection area of the initial patch on the horizontal plane. In this method, a patch is constructed above the horizontal plane, and the offset information of each position point in the patch is determined using the view vector of the virtual camera. The patch is offset, and the offset patch always covers the range required for parallax mapping. After rendering the patch, the decal effect always remains in the target area on the horizontal plane, eliminating the need to construct a three-dimensional cube, thereby reducing performance consumption while ensuring visual effects.
[0010] Other features and advantages of the present disclosure will be described in the following description, and in part will become apparent from the description, or understood by practicing the present disclosure. The objectives and other advantages of the present disclosure are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0011] In order to make the above-mentioned objectives, features and advantages of the present disclosure 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
[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 A flowchart of a method for rendering a decal effect provided by an embodiment of the present disclosure;
[0014] Figure 2 A geometric diagram for determining offset information provided by an embodiment of the present disclosure;
[0015] Figure 3 A schematic diagram of a decal effect provided by an embodiment of the present disclosure;
[0016] Figure 4A top view of an initial facet provided in an embodiment of the present disclosure;
[0017] Figure 5 Another geometric diagram for determining offset information provided by an embodiment of the present disclosure;
[0018] Figure 6 Another geometric diagram for determining offset information provided by an embodiment of the present disclosure;
[0019] Figure 7 A schematic structural diagram of a decal effect rendering device provided by an embodiment of the present disclosure;
[0020] Figure 8 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] To make the purpose, technical solutions, and advantages of the embodiments of the present disclosure more clear, the technical solutions of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of the present disclosure, not all of them. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present disclosure.
[0022] Currently in the field of real-time rendering, deep decal technology is widely used to dynamically project detailed textures on scene surfaces. In related technologies, a bounding box or a projection cube is usually used to define the decal's impact area, and the world space is reconstructed through depth information to determine the final visible pixels. However, although the decal's visual effect appears as a planar projection, its bounding box needs to be constructed as a three-dimensional cube to ensure the integrity of the projection, which results in a large number of invisible pixels that exceed the actual surface range being included in the rendering pipeline, especially in higher geometric surfaces where a higher cube volume is required to avoid visual truncation. This approach can lead to over-rendering problems, serious waste of shader resources, and high performance consumption. Based on this, the embodiments of the present disclosure provide a rendering method, device, and electronic device for decal effects, which can be applied to mobile phones, notebooks, computers, tablets, and other devices.
[0023] To facilitate understanding of this embodiment, a rendering method for a decal effect disclosed in an embodiment of the present disclosure is first described in detail. Figure 1 As shown, the method includes the following steps:
[0024] Step S102, creating an initial patch in the virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene;
[0025] The initial patch is a planar mesh, and the size and shape of the initial patch are usually set according to the size of the object to be rendered. Usually, the size of the initial patch is greater than or equal to the size of the object.
[0026] Optionally, the vertical distance between the initial patch and the horizontal plane is set according to the height of the target to be rendered. Usually, the vertical distance between the initial patch and the horizontal plane is higher than the height of the target to be rendered.
[0027] Optionally, an initial patch is created in a designated area of the virtual scene, and a projection area of the designated area on the horizontal plane completely covers the surface of the object to be rendered.
[0028] Step S104, obtaining the camera position of the virtual camera in the virtual scene;
[0029] Optionally, the vertical distance between the virtual camera and the horizontal plane is greater than the vertical distance between the initial mesh and the horizontal plane. This ensures that the decal effect is visually present after rendering is complete, ensuring that the decal effect appears on the target surface being rendered. If the vertical distance between the virtual camera and the horizontal plane is less than or equal to the vertical distance between the initial mesh and the horizontal plane, the decal effect will not appear on the target surface after rendering is complete.
[0030] Step S106: for each position point on the initial patch, determine the offset information of the position point according to the projection position of the position point on the horizontal plane and the camera position;
[0031] The above-mentioned position point usually refers to a model vertex in a plane mesh. The above-mentioned offset information includes an offset distance and an offset direction.
[0032] Optionally, based on the projection position of the position point on the horizontal plane, determine the first vector from the projection position to the camera position, determine the first intersection of the first vector and the initial facet, determine the target vector of the position point and the first intersection, and determine the vector value and vector direction of the target vector as offset information.
[0033] Optionally, based on the projection position of the location point on the horizontal plane, determine the first vector from the projection position to the camera position, and determine the first intersection point of the first vector with the initial facet; calculate the unit vector of the first vector; determine the first projection vector of the unit vector in the target direction, calculate the difference between the unit vector and the first projection vector, and obtain the difference vector; based on the similarity between the triangle formed by the unit vector, the first projection vector and the difference vector and the triangle formed by the location point, the projection position and the first intersection point, determine the target distance between the location point and the first intersection point based on the vertical distance between the initial facet and the horizontal plane, the vector value of the first projection vector and the vector value of the difference vector; determine the vector direction of the projection vector of the vector from the location point to the camera position on the initial facet; determine the offset information of the location point based on the target distance and the vector direction.
[0034] Step S108, controlling the position point to shift based on the shift information of the position point to obtain a shifted target patch; wherein the target patch is reduced relative to the initial patch;
[0035] Specifically, the position point is controlled to shift in the shift direction by a corresponding shift distance, and each position point on the initial patch is shifted to obtain a target patch, where the target patch is the viewing area of the virtual camera.
[0036] For example, Figure 2 The side view of the initial patch is shown, where AB is the initial patch and A'B' is the target patch.
[0037] Step S110, generating UV sampling coordinates of a preset decal according to the target surface, and rendering the preset decal onto the target surface based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, and the target area is a projection area of the initial surface on the horizontal plane.
[0038] The above preset decals are usually set according to rendering needs. For example, Figure 3 The decal effect shown, where the preset decal is gray, is obtained by rendering the preset decal on the target patch. The visual effect of the decal is that the preset decal is rendered on the surface of the target area instead of on the target patch.
[0039] The present disclosure provides a method for rendering a decal effect, comprising: creating an initial patch in a virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene; obtaining the camera position of a virtual camera in the virtual scene; determining offset information for each position point on the initial patch based on the projection position of the position point on the horizontal plane and the camera position; controlling the position point to be offset based on the offset information to obtain a target patch after the offset; wherein the target patch is reduced relative to the initial patch; generating UV sampling coordinates for a preset decal based on the target patch; rendering the preset decal onto the target patch based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, the target area being the projection area of the initial patch on the horizontal plane. In this method, a patch is constructed above the horizontal plane, and the offset information of each position point in the patch is determined using the view vector of the virtual camera. The patch is offset, and the offset patch always covers the range required for parallax mapping. After rendering the patch, the decal effect always remains in the target area on the horizontal plane, eliminating the need to construct a three-dimensional cube. This reduces performance consumption while ensuring visual effects.
[0040] A possible implementation of the above step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position is as follows:
[0041] Determine a first vector from the projection position of the position point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determine a second vector from the position point to the first intersection point, and determine offset information of the position point based on the second vector.
[0042] like Figure 2 As shown, point A is the above-mentioned position point, point a is the projection position of the position point on the horizontal plane, point E is the camera position of the virtual camera, from point a to point E is the above-mentioned first vector n1, point A' is the above-mentioned first intersection point, and from point A to point A' is the above-mentioned second vector n2.
[0043] Optionally, the offset information is determined based on the vector value and vector direction of the second vector.
[0044] Specifically, the vector value of the second vector is determined as the offset distance, the vector direction of the second vector is determined as the offset direction; and the offset distance and the offset direction are determined as the offset information.
[0045] For example, Figure 4 In the top view of the initial patch shown, the distance from point A to point A' is the offset distance, and the direction from point A to point A' is the offset direction.
[0046] Another possible implementation of the above step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position is as follows:
[0047] (1) determining a first vector from the projection position of the position point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane;
[0048] like Figure 5 As shown, point A is the above-mentioned position point, point a is the projection position of the position point on the horizontal plane, point E is the camera position of the virtual camera, from point a to point E is the above-mentioned first vector n1, and point A' is the above-mentioned first intersection point.
[0049] (2) determining an offset distance of the position point based on the first vector and the first intersection point;
[0050] Optionally, a vector from the projection position of the location point on the horizontal plane to the first intersection point is determined, and a vector value of the vector is determined as the offset distance of the location point.
[0051] Optionally, calculate a first projection vector of the first vector in the target direction; wherein the target direction is perpendicular to the horizontal plane; calculate the first projection vector minus the target first vector to obtain a fourth vector; determine the target distance between the position point and the first intersection point based on the vector value of the fourth vector through the principle of similar triangles, and determine the target distance as the offset distance of the position point.
[0052] Specifically, the first triangle is determined according to the first projection vector, the first vector and the fourth vector; the second triangle is determined according to the position point, the first intersection point and the projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; through the similarity between the first triangle and the second triangle, the target distance between the position point and the first intersection point is determined according to the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane, and the target distance is determined as the offset distance of the position point.
[0053] For example, Figure 5 As shown, aE is the first vector, aE' is the first projection vector, and E'E is the fourth vector; through the similarity of triangle E'Ea and triangle AaA', AA' / EE'=Aa / aE' is calculated, and Aa is calculated through the known AA', EE', and aE', that is, the offset distance of the above-mentioned position point.
[0054] Optionally, before the step of calculating the first projection vector of the first vector in the target direction, the method further includes: normalizing the first vector.
[0055] The above-mentioned step of determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector through the principle of similar triangles includes: determining the first triangle according to the first projection vector, the target first vector and the fourth vector; determining the second triangle according to the position point, the first intersection point and the projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane through the similarity between the first triangle and the second triangle, and determining the target distance as the offset distance of the position point.
[0056] For example, Figure 6 As shown, ac is the first vector, ac' is the first projection vector, and c'c is the fourth vector; through the similarity between triangle c'ca and triangle AaA', AA' / cc'=Aa / ac' is calculated, and Aa is calculated through the known AA', cc', and ac', that is, the offset distance of the above-mentioned position point.
[0057] (3) Determine a third vector from the position point to the camera position, and determine an offset direction of the position point based on the third vector; determine the offset direction and offset distance as offset information.
[0058] For example, Figure 5 and Figure 6 As shown, the third vector n3 from position point A to camera position E.
[0059] Optionally, the vector direction of the third vector is determined as the offset direction of the position point.
[0060] In this approach, geometric reconstruction transforms the traditional cubic bounding box into a flat mesh above the ground. To address the issue of decal edge clipping near the camera when viewed from the side, a world position offset based on the view vector is introduced. The angle between the camera ray direction and the decal plane is calculated in real time. The vertex shader dynamically adjusts the displacement of mesh vertices along the normal direction, expanding the mesh boundaries so that the visible area always covers the required range for parallax mapping. This significantly reduces performance overhead while ensuring the visual effect is functional.
[0061] Corresponding to the above method embodiment, the present disclosure provides a rendering device for decal effect, such as Figure 7 As shown, the device includes:
[0062] The initial patch creation module 701 is used to create an initial patch in the virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene;
[0063] A camera position acquisition module 702 is used to acquire the camera position of a virtual camera in a virtual scene;
[0064] An offset information determination module 703 is configured to determine, for each position point on the initial patch, offset information of the position point based on the projection position of the position point on the horizontal plane and the camera position;
[0065] A target patch determining module 704 is configured to control the position point to shift based on the shift information of the position point to obtain a shifted target patch; wherein the target patch is reduced relative to the initial patch;
[0066] The decal effect rendering module 705 is used to generate UV sampling coordinates of a preset decal based on the target surface, and render the preset decal onto the target surface based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, and the target area is the projection area of the initial surface on the horizontal plane.
[0067] The present disclosure provides a rendering device for a decal effect, which creates an initial patch in a virtual scene; wherein the initial patch is parallel to the horizontal plane of the virtual scene; obtains the camera position of a virtual camera in the virtual scene; for each position point on the initial patch, determines the offset information of the position point based on the projection position of the position point on the horizontal plane and the camera position; controls the position point to be offset based on the offset information to obtain a target patch after the offset; wherein the target patch is reduced relative to the initial patch; generates UV sampling coordinates of a preset decal based on the target patch; renders the preset decal onto the target patch based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, where the target area is the projection area of the initial patch on the horizontal plane. In this method, a patch is constructed above the horizontal plane, and the offset information of each position point in the patch is determined by the view vector of the virtual camera. The patch is offset, and the offset patch always covers the range required for parallax mapping. After rendering the patch, the decal effect always stays in the target area on the horizontal plane. There is no need to construct a three-dimensional cube, which reduces performance consumption while ensuring visual effects.
[0068] The vertical distance between the virtual camera and the horizontal plane is greater than the vertical distance between the initial surface and the horizontal plane.
[0069] The above-mentioned offset information determination module is also used to: determine the first vector from the projection position of the position point on the horizontal plane to the camera position, and the first intersection of the first vector and the initial horizontal plane; determine the second vector from the position point to the first intersection, and determine the offset information of the position point based on the second vector.
[0070] The offset information determination module is further configured to: determine the vector value of the second vector as the offset distance, determine the vector direction of the second vector as the offset direction; and determine the offset distance and the offset direction as the offset information.
[0071] The above-mentioned offset information determination module is also used to: determine the first vector from the projection position of the location point on the horizontal plane to the camera position, and the first intersection point of the first vector and the initial horizontal plane; determine the offset distance of the location point based on the first vector and the first intersection point; determine the third vector from the location point to the camera position, and determine the offset direction of the location point based on the third vector; and determine the offset direction and offset distance as offset information.
[0072] The above-mentioned offset information determination module is also used to: calculate the first projection vector of the first vector in the target direction; wherein the target direction is perpendicular to the horizontal plane; calculate the first projection vector minus the target first vector to obtain a fourth vector; through the principle of similar triangles, according to the vector value of the fourth vector, determine the target distance between the position point and the first intersection point, and determine the target distance as the offset distance of the position point.
[0073] The above-mentioned offset information determination module is further used to: perform normalization processing on the first vector.
[0074] The above-mentioned offset information determination module is also used to: determine the first triangle based on the first projection vector, the target first vector and the fourth vector; determine the second triangle based on the position point, the first intersection point and the projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; through the similarity between the first triangle and the second triangle, determine the target distance between the position point and the first intersection point based on the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane, and determine the target distance as the offset distance of the position point.
[0075] The above-mentioned offset information determination module is further used to: determine the vector direction of the third vector as the offset direction of the position point.
[0076] The decal effect rendering device provided in the embodiment of the present disclosure has the same technical features as the decal effect rendering method provided in the above embodiment, and therefore can also solve the same technical problems and achieve the same technical effects.
[0077] This embodiment further provides an electronic device including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned decal rendering method. The electronic device can be a server or a terminal device.
[0078] See also Figure 8 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine executable instructions that can be executed by the processor 100. The processor 100 executes the machine executable instructions to implement the above-mentioned decal effect rendering method.
[0079] Furthermore, Figure 8 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0080] Among them, the memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 102 can be an ISA (Industry Standard Architecture, Industrial Standard Architecture) bus, PCI (Peripheral Component Interconnect, Peripheral Component Interconnect Standard) bus or EISA (Extended Industry Standard Architecture, Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0081] The processor 100 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 100 or by instructions in the form of software. The above-mentioned processor 100 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as a random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or register. The storage medium is located in the memory 101. The processor 100 reads the information in the memory 101 and, in conjunction with its hardware, completes the steps of the method of the aforementioned embodiment.
[0082] The processor in the electronic device may implement the following operations in the decal effect rendering method by executing machine-executable instructions:
[0083] An initial patch is created in a virtual scene; the initial patch is parallel to the horizontal plane of the virtual scene; the camera position of a virtual camera in the virtual scene is obtained; for each position point on the initial patch, the offset information of the position point is determined based on the projection position of the position point on the horizontal plane and the camera position; the position point is controlled to be offset based on the offset information to obtain a target patch after the offset; the target patch is reduced relative to the initial patch; UV sampling coordinates of a preset decal are generated based on the target patch, and the preset decal is rendered onto the target patch based on the UV sampling coordinates to obtain a decal effect; the decal effect is displayed in a target area on the horizontal plane, which is the projection area of the initial patch on the horizontal plane. In this method, a patch is constructed above the horizontal plane, and the offset information of each position point in the patch is determined using the view vector of the virtual camera. The patch is offset, and the offset patch always covers the range required for parallax mapping. After the patch is rendered, the decal effect is always in the target area on the horizontal plane. There is no need to construct a three-dimensional cube, which reduces performance consumption while ensuring visual effects.
[0084] The vertical distance between the virtual camera and the horizontal plane is greater than the vertical distance between the initial surface and the horizontal plane.
[0085] The above-mentioned step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position includes: determining a first vector from the projection position of the location point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determining a second vector from the location point to the first intersection point, and determining the offset information of the location point based on the second vector.
[0086] The above step of determining the offset information of the position point based on the second vector includes: determining the vector value of the second vector as the offset distance, determining the vector direction of the second vector as the offset direction; and determining the offset distance and the offset direction as the offset information.
[0087] The above-mentioned step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position includes: determining a first vector from the projection position of the location point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determining the offset distance of the location point based on the first vector and the first intersection point; determining a third vector from the location point to the camera position, and determining the offset direction of the location point based on the third vector; and determining the offset direction and the offset distance as the offset information.
[0088] The above-mentioned step of determining the offset distance of the position point based on the first vector and the first intersection point includes: calculating a first projection vector of the first vector in the target direction; wherein the target direction is perpendicular to the horizontal plane; calculating the first projection vector minus the target first vector to obtain a fourth vector; and determining the target distance between the position point and the first intersection point based on the vector value of the fourth vector through the principle of similar triangles, and determining the target distance as the offset distance of the position point.
[0089] Before the step of calculating the first projection vector of the first vector in the target direction, the method further includes: performing normalization processing on the first vector.
[0090] The above-mentioned step of determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector through the principle of similar triangles includes: determining the first triangle according to the first projection vector, the target first vector and the fourth vector; determining the second triangle according to the position point, the first intersection point and the projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane through the similarity between the first triangle and the second triangle, and determining the target distance as the offset distance of the position point.
[0091] The step of determining the offset direction of the position point according to the third vector includes: determining the vector direction of the third vector as the offset direction of the position point.
[0092] This embodiment further provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned decal effect rendering method.
[0093] The machine-executable instructions stored in the machine-readable storage medium can implement the following operations in the above-mentioned decal effect rendering method by executing the machine-executable instructions:
[0094] An initial patch is created in a virtual scene; the initial patch is parallel to the horizontal plane of the virtual scene; the camera position of a virtual camera in the virtual scene is obtained; for each position point on the initial patch, the offset information of the position point is determined based on the projection position of the position point on the horizontal plane and the camera position; the position point is controlled to be offset based on the offset information to obtain a target patch after the offset; the target patch is reduced relative to the initial patch; UV sampling coordinates of a preset decal are generated based on the target patch, and the preset decal is rendered onto the target patch based on the UV sampling coordinates to obtain a decal effect; the decal effect is displayed in a target area on the horizontal plane, which is the projection area of the initial patch on the horizontal plane. In this method, a patch is constructed above the horizontal plane, and the offset information of each position point in the patch is determined using the view vector of the virtual camera. The patch is offset, and the offset patch always covers the range required for parallax mapping. After the patch is rendered, the decal effect is always in the target area on the horizontal plane. There is no need to construct a three-dimensional cube, which reduces performance consumption while ensuring visual effects.
[0095] The vertical distance between the virtual camera and the horizontal plane is greater than the vertical distance between the initial surface and the horizontal plane.
[0096] The above-mentioned step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position includes: determining a first vector from the projection position of the location point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determining a second vector from the location point to the first intersection point, and determining the offset information of the location point based on the second vector.
[0097] The above step of determining the offset information of the position point based on the second vector includes: determining the vector value of the second vector as the offset distance, determining the vector direction of the second vector as the offset direction; and determining the offset distance and the offset direction as the offset information.
[0098] The above-mentioned step of determining the offset information of the location point based on the projection position of the location point on the horizontal plane and the camera position includes: determining a first vector from the projection position of the location point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determining the offset distance of the location point based on the first vector and the first intersection point; determining a third vector from the location point to the camera position, and determining the offset direction of the location point based on the third vector; and determining the offset direction and the offset distance as the offset information.
[0099] The above-mentioned step of determining the offset distance of the position point based on the first vector and the first intersection point includes: calculating a first projection vector of the first vector in the target direction; wherein the target direction is perpendicular to the horizontal plane; calculating the first projection vector minus the target first vector to obtain a fourth vector; and determining the target distance between the position point and the first intersection point based on the vector value of the fourth vector through the principle of similar triangles, and determining the target distance as the offset distance of the position point.
[0100] Before the step of calculating the first projection vector of the first vector in the target direction, the method further includes: performing normalization processing on the first vector.
[0101] The above-mentioned step of determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector through the principle of similar triangles includes: determining the first triangle according to the first projection vector, the target first vector and the fourth vector; determining the second triangle according to the position point, the first intersection point and the projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; determining the target distance between the position point and the first intersection point according to the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane through the similarity between the first triangle and the second triangle, and determining the target distance as the offset distance of the position point.
[0102] The step of determining the offset direction of the position point according to the third vector includes: determining the vector direction of the third vector as the offset direction of the position point.
[0103] The computer program products of the decal effect rendering method, device, electronic device, and system provided in the embodiments of the present disclosure include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. For specific implementation, please refer to the method embodiments and will not be repeated here.
[0104] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described systems and devices can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0105] In addition, in the description of the embodiments of the present disclosure, unless otherwise expressly specified or limited, the terms "installed," "connected," and "connected" should be understood in a broad sense. For example, they can refer to fixed connections, detachable connections, or integral connections; they can refer to mechanical connections or electrical connections; they can refer to direct connections or indirect connections through an intermediate medium; and they can refer to internal connections between two components. Those skilled in the art will understand the specific meanings of the above terms in the present disclosure based on the specific circumstances.
[0106] If the functions are implemented in the form of software functional units 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 disclosure, 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, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present disclosure. 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 (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0107] In the description of this disclosure, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate the description of this disclosure and simplify the description. They do not indicate or imply that the devices or components referred to must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on this disclosure. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0108] Finally, it should be noted that the above embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The scope of protection of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above embodiments within the technical scope disclosed in the present disclosure, or replace some of the technical features therein with equivalents. Such modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure should be based on the scope of protection of the claims.
Claims
1. A method for rendering a decal effect, characterized in that: The method comprises: Creating an initial surface patch in a virtual scene; wherein the initial surface patch is parallel to a horizontal plane of the virtual scene; Obtaining a camera position of a virtual camera in the virtual scene; For each position point on the initial patch, determine offset information of the position point according to a projection position of the position point on the horizontal plane and the camera position; Controlling the position point to shift based on the shift information of the position point to obtain a shifted target patch; wherein the target patch is reduced relative to the initial patch; According to the target surface, UV sampling coordinates of a preset decal are generated, and the preset decal is rendered onto the target surface based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area of the horizontal plane, and the target area is a projection area of the initial surface on the horizontal plane.
2. The method according to claim 1, characterized in that A vertical distance between the virtual camera and the horizontal plane is greater than a vertical distance between the initial surface and the horizontal plane.
3. The method according to claim 1, characterized in that The step of determining the offset information of the position point according to the projection position of the position point on the horizontal plane and the camera position includes: Determine a first vector from the projection position of the position point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; A second vector from the position point to the first intersection point is determined, and offset information of the position point is determined according to the second vector.
4. The method according to claim 3, characterized in that The step of determining the offset information of the position point according to the second vector includes: Determine the vector value of the second vector as the offset distance, and determine the vector direction of the second vector as the offset direction; The offset distance and the offset direction are determined as the offset information.
5. The method according to claim 1, wherein The step of determining the offset information of the position point according to the projection position of the position point on the horizontal plane and the camera position includes: Determine a first vector from the projection position of the position point on the horizontal plane to the camera position, and a first intersection point of the first vector and the initial horizontal plane; determining an offset distance of the position point according to the first vector and the first intersection point; Determine a third vector from the position point to the camera position, and determine an offset direction of the position point according to the third vector; The offset direction and the offset distance are determined as the offset information.
6. The method according to claim 5, characterized in that The step of determining the offset distance of the position point according to the first vector and the first intersection point includes: Calculating a first projection vector of the first vector in a target direction; wherein the target direction is perpendicular to the horizontal plane; Calculate the first projection vector minus the target first vector to obtain a fourth vector; By using the principle of similar triangles and according to the vector value of the fourth vector, a target distance between the position point and the first intersection point is determined, and the target distance is determined as the offset distance of the position point.
7. The method according to claim 6, characterized in that Before the step of calculating a first projection vector of the first vector in the target direction, the method further includes: Normalize the first vector.
8. The method according to claim 6, characterized in that The step of determining a target distance between the position point and the first intersection point according to the vector value of the fourth vector using the principle of similar triangles includes: Determine a first triangle according to the first projection vector, the target first vector and the fourth vector; determining a second triangle according to the position point, the first intersection point, and a projection position of the position point on the horizontal plane; wherein the first triangle and the second triangle are similar triangles; Based on the similarity between the first triangle and the second triangle, the target distance between the position point and the first intersection point is determined according to the vector value of the fourth vector, the vector value of the first projection vector and the vertical distance of the initial facet from the horizontal plane, and the target distance is determined as the offset distance of the position point.
9. The method according to claim 5, characterized in that The step of determining the offset direction of the position point according to the third vector includes: The vector direction of the third vector is determined as the offset direction of the position point.
10. A decal effect rendering device, characterized in that: The device comprises: An initial patch creation module, configured to create an initial patch in a virtual scene; wherein the initial patch is parallel to a horizontal plane of the virtual scene; A camera position acquisition module, used to acquire the camera position of the virtual camera in the virtual scene; an offset information determining module, configured to determine, for each position point on the initial patch, offset information of the position point according to a projection position of the position point on the horizontal plane and a camera position; a target patch determining module, configured to control the position point to shift based on the shift information of the position point to obtain a shifted target patch; wherein the target patch is reduced relative to the initial patch; A decal effect rendering module is used to generate UV sampling coordinates of a preset decal based on the target surface, and render the preset decal onto the target surface based on the UV sampling coordinates to obtain a decal effect; wherein the decal effect is displayed in a target area on the horizontal plane, and the target area is the projection area of the initial surface on the horizontal plane.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the decal effect rendering method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the decal effect rendering method according to any one of claims 1 to 9.