Rendering method and device for simulating diffraction effect on surface of object
By converting the line of sight vectors to tangent space in computer graphics rendering technology, adjusting the tone, combining noise textures and masks, the problem of high computing volume in the existing technology is solved, and efficient color diffraction rendering on the mobile terminal is achieved, which improves the Realism and performance of three-dimensional applications.
Patent Information
- Application Number
- CN202411378098.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-03
AI Technical Summary
When existing computer graphics rendering technology realizes the color diffraction effect of the surface of an object, the calculation amount is too large, making it difficult to render in real time on the mobile terminal, and cannot meet the realism and user experience needs of three-dimensional games.
By converting the line of sight vector from model space to tangent space, performing RGB color to HSV color conversion, and adjusting the tone according to the line of sight vector, combining noise texture and mask for superposition, dynamic color changes are achieved, avoiding complex real-time ray tracing calculations.
It creates complex visual effects while maintaining a good performance balance, suitable for three-dimensional applications on mobile terminals, real color diffraction effects.
Smart Images

Figure CN119251380A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer graphics rendering, and in particular to a rendering method and apparatus for simulating the diffraction effect of an object surface, a computing device, and a computer-readable storage medium. Background Art
[0002] In real life, when light passes through two thin layers of media with different refractive indices, diffraction occurs, producing ever-changing colors. For example, the oil layer in water or soap bubbles often shows this rainbow effect. In 3D game applications, there is also a need to render color diffraction effects on the surface of game objects to improve the realism of the game and user experience. However, the amount of physical calculations required by traditional computer graphics calculation methods is too large to be calculated in real time on mobile devices. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a rendering method and apparatus, a computing device, and a computer-readable storage medium for simulating the diffraction effect on the surface of an object to solve the technical defects existing in the prior art.
[0004] According to a first aspect of an embodiment of the present application, a rendering method for simulating a diffraction effect on a surface of an object is provided, comprising:
[0005] Get the sight vector of the object surface in the model space and convert it to the tangent space;
[0006] Normalizing the sight line vector in the tangent space to obtain a first sight line vector; converting the hue of the first RGB color according to the first sight line vector to obtain a second RGB color;
[0007] Superimposing the second RGB color with the noise texture to obtain a third RGB color;
[0008] The third RGB color is superimposed with the source color of the object and other target effect masks to obtain a final diffraction rendering effect.
[0009] According to a second aspect of an embodiment of the present application, a rendering device for simulating a diffraction effect on a surface of an object is provided, comprising:
[0010] A first conversion unit is used to obtain the sight line vector of the object surface in the model space and convert it into the tangent space;
[0011] A second conversion unit is used to normalize the sight line vector in the tangent space to obtain a first sight line vector; and convert the hue of the first RGB color according to the first sight line vector to obtain a second RGB color;
[0012] A first calculation unit, configured to superimpose the second RGB color with the noise texture to obtain a third RGB color;
[0013] The second calculation unit is used to superimpose the third RGB color with the source color of the object and other target effect masks to obtain a final diffraction rendering effect.
[0014] According to a third aspect of an embodiment of the present application, a computing device is provided, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the rendering method for simulating the diffraction effect on the surface of an object are implemented.
[0015] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and when the instructions are executed by a processor, the steps of the rendering method for simulating the diffraction effect of the surface of an object are implemented.
[0016] Through the method provided in the embodiment of the present application, after the sight vector is converted from the model space to the tangent space, the color is converted from the RGB to the HSV model when rendering the object, and only the color hue is adjusted to simulate the color diffraction following the viewing angle. The hue is offset by the sight vector in the tangent space, and then supplemented by various masks, a real color diffraction effect can be achieved. This solution achieves a dynamic color change effect by adjusting the hue, avoiding complex real-time ray tracing calculations, creating complex visual effects, while maintaining a good performance balance, and is suitable for mobile 3D applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a structural block diagram of a computing device provided in an embodiment of the present application;
[0018] Figure 2 It is a flowchart of a rendering method for simulating the diffraction effect on the surface of an object provided in an embodiment of the present application;
[0019] Figure 3a This is a schematic diagram of a color diffraction rendering effect simulating a follow-up viewing angle provided in an embodiment of the present application;
[0020] Figure 3b is another schematic diagram of a color diffraction rendering effect simulating a follow-viewing angle provided in an embodiment of the present application;
[0021] Figure 4a This is a schematic diagram of a noise texture effect provided by an embodiment of the present application;
[0022] Figure 4b This is a rendering schematic diagram of a superimposed color diffraction effect and a noise effect provided in an embodiment of the present application;
[0023] Figure 5 is a schematic diagram of the effect of the source color of an object provided in an embodiment of the present application;
[0024] Figure 6 is a schematic diagram of the effect of a mask texture for controlling a flash effect provided by an embodiment of the present application;
[0025] Figure 7 is a schematic diagram of the diffraction effect on the surface of an object achieved by the method provided in an embodiment of the present application;
[0026] Figure 8 It is a structural schematic diagram of a rendering device for simulating the diffraction effect on the surface of an object provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0028] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0029] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "in response to determination".
[0030] In the present application, a rendering method and apparatus, a computing device and a computer-readable storage medium for simulating the diffraction effect on the surface of an object are provided, which will be described in detail one by one in the following embodiments.
[0031] Figure 1The structure block diagram of a computing device 100 according to an embodiment of the present application is shown. The components of the computing device 100 include but are not limited to a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and the database 150 is used to store data.
[0032] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0033] In one embodiment of the present application, the above components of the computing device 100 and Figure 1 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 1 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0034] Computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC.
[0035] In the embodiments of the present application, Figure 2 A flowchart of a rendering method for simulating the diffraction effect on the surface of an object provided by the present application is shown, including steps 202 to 208.
[0036] Step 202: Obtain the sight line vector of the object surface in the model space, and convert it to the tangent space.
[0037] The view vector is a concept in 3D computer graphics, which is closely related to the geometric relationship between the observer (usually a camera) and the objects in the 3D scene. The view vector describes the direction from the camera position to the vertex of the object in the 3D scene. It is usually a unit vector (length 1) and is used for various lighting calculations and effects.
[0038] Tangent space is also an important concept in 3D computer graphics, especially when dealing with normal maps and lighting calculations. Tangent space is a local coordinate system defined at each point on the surface of a model. It consists of three mutually perpendicular vectors: tangent, bitangent (sometimes also called binormal) and normal.
[0039] In this step, the view vector of the object surface in the model space is obtained in the vertex shader, and then converted to the tangent space through matrix operation.
[0040] In one possible implementation, first create a transformation matrix from object space to tangent space. The first column of this matrix is the tangent (T), the second column is the bitangent (B), and the third column is the normal (N):
[0041] float3x3 objectToTangent=float3x3(v.tangent.xyz,cross(v.normal,v.tangent.xyz)*v.tangent.w*unity_WorldTransformParams.w,v.normal);
[0042] Here, a 3x3 matrix objectToTangent is constructed, which contains three vectors:
[0043] a) Tangent: v.tangent.xyz
[0044] b) Bitangent:cross(v.normal,v.tangent.xyz)*v.tangent.w*unity_WorldTransformParams.w
[0045] c) Normal: v.normal
[0046] Furthermore, the view vector is transformed to the tangent space by the matrix objectToTangent:
[0047] o.vDirTS=mul(objectToTangent,ObjSpaceViewDir(v.vertex));
[0048] ObjSpaceViewDir(v.vertex) calculates the direction vector from the vertex to the camera in model space, mul(objectToTangent,...) converts this direction vector from object space to tangent space, and stores the result in o.vDirTS.
[0049] Step 204: normalize the sight line vector in the tangent space to obtain a first sight line vector; convert the hue of the first RGB color according to the first sight line vector to obtain a second RGB color.
[0050] In one embodiment of the present application, keeping the saturation and brightness unchanged means that the "intensity" and "brightness" of the color remain unchanged and only the hue is adjusted. In this way, a smooth color gradient and dynamic color change effect are created, for example, a simulated rainbow effect or a circular color animation, without recalculating the saturation and brightness of each color. This can maintain the visual consistency of the color and reduce the amount of calculation and complexity.
[0051] Therefore, in a feasible way, the hue of the color is adjusted as follows. The target color is input into the function, and its hue adjustment value is controlled by the hueAdjustment parameter. The function mainly includes the following steps:
[0052] Extract the RGB components of the input color and convert them to the HSV model;
[0053] Calculate and maintain the color saturation S and brightness V;
[0054] Calculate the hue H of the color and adjust it according to the hue adjustment value hueAdjustment;
[0055] Convert the adjusted HSV color back to RGB color.
[0056] The schematic code is as follows:
[0057] float3 AdjustHue(float3 c, float hueAdjustment) / / The main function of the parameter hueAdjustment is to adjust the hue of the input color to achieve different color conversion effects
[0058] {
[0059] / / Extract RGB components
[0060] float r = cr;
[0061] float g = cg;
[0062] float b = cb;
[0063] / / Calculate the maximum and minimum components, and their difference
[0064] float maxVal=max(r,max(g,b));
[0065] float minVal=min(r,min(g,b));
[0066] float delta=maxVal-minVal;
[0067] / / Maintain saturation S and brightness V
[0068] float S=...; float V=..;
[0069] / / Calculate the hue H and perform an offset based on the viewing angle
[0070] float H=(maxVal==r)? (gb) / delta+(g <b?6.0:0.0)
[0071] :(maxVal==g)? (br) / delta+2.0
[0072] :(rg) / delta+4.0;
[0073] H = frac(H / 6.0+hueAdjustment); / / Normalize to the range [0,1] and adjust
[0074] / / Convert HSV back to RGB ...
[0076] return rgb;
[0077] }
[0078] Specifically, in this step, the sight line vector in the tangent space obtained in step 202 is first normalized in the fragment shader to obtain a first sight line vector:
[0079] i.vDirTS=normalize(i.vDirTS);
[0080] Furthermore, the first RGB color (not pure white or pure black) is converted from the RGB model to the HSV model through the above function, and after the adjustment of the hue H is completed, it is converted back to the RGB model to obtain the second RGB color. The hue H is adjusted according to the first sight vector, for example, the sum of the x and y components of the first sight vector is passed into the above function AdjustHue as the hue adjustment parameter to obtain the second RGB color, which can simulate the color diffraction following the viewing angle, such as Figure 3a and Figure 3b shown.
[0081] The schematic code is as follows:
[0082] float3 rainbowGlowColor = AdjustHue(fixed3(first RGB color), i.vDirTS.x+i.vDirTS.y);
[0083] Those skilled in the art should know that using the sum of the x and y components of the normalized line of sight vector as a hue adjustment parameter is only one of the feasible ways to adjust the hue. According to actual needs, it is expected that those skilled in the art can design the hue adjustment parameter based on the line of sight vector.
[0084] Step 206: superimpose the second RGB color and the noise to obtain a third RGB color.
[0085] In this step, the current diffraction effect is combined with random elements such as noise to create more realistic and interesting visual effects to improve visual quality and realism.
[0086] In one possible implementation, blue noise is a special type of noise whose spectral properties make it visually more uniform and less noticeable than white noise, and is often used to increase detail and break up regularity while maintaining visual smoothness, such as Figure 4a Therefore, in this step, you can sample from the blue noise texture to get the noise value of the current pixel:
[0087] fixed rainbowGlowNoise=tex2D(_BlueNoise,i.uv).x;
[0088] The second RGB color is then multiplied by the noise value to get the third RGB color.
[0089] rainbowGlowColor*=rainbowGlowNoise;
[0090] By multiplying the colored diffraction color with the noise, the intensity of the diffraction effect for each pixel will be slightly different depending on the noise value. This creates subtle variations and irregularities that simulate the subtle differences in the surface of materials in the real world, making the surface look more natural, avoiding the feeling of the rainbow effect being too perfect, and when viewed up close, you can see richer surface details, such as Figure 4b shown.
[0091] Step 208: superimpose the third RGB color, the source color of the object and other effect masks to obtain the final diffraction rendering effect.
[0092] In this step, first get the original texture sample of the object:
[0093] fixed4 MainCol = tex2D (_MainTex, i.uv); / / _MainTex is the source color or pattern of the object, such as Figure 5 shown.
[0094] Furthermore, other effect masks are obtained according to rendering requirements, such as masks used to control the glow effect:
[0095] fixed3 blin_mask = tex2D(_SingleGlowMask, i.uv); / / blin_mask is a glow mask texture used to control the distribution of star point flashes or other specific gloss effects, such as Figure 6 shown.
[0096] Furthermore, the third RGB color, the source color of the object and other effect masks are superimposed:
[0097] rainbowGlowColor*=MainCol*blin_mask;
[0098] This step adds together a variety of different elements to produce the final diffraction effect, such as Figure 7 As shown. The third RGB color rainbowGlowColor provides the basic diffraction color change; the object's source color MainColor ensures that the final effect retains the original color and pattern characteristics of the object, allowing the color effect to be more naturally integrated into the object design; and the flash mask blin_mask controls the distribution and intensity of the flash effect, which can create star-point flash or other specific gloss effects.
[0099] Those skilled in the art should be aware that the above-mentioned flash mask is only an example, and those skilled in the art can select different types of other effect masks according to rendering requirements, which will not be described in detail here.
[0100] In the above-mentioned embodiment of the present application, in order to efficiently simulate the color diffraction effect on the surface of an object on a mobile terminal, and to ensure that the rendering result is as realistic as possible without consuming too many hardware resources, the embodiment of the present application converts the sight vector from the model space to the tangent space, converts the color from the RGB to the HSV model, and only adjusts the hue to simulate the color diffraction following the viewing angle; then the hue is offset by the sight vector in the tangent space, and then various masks are used to achieve a real color diffraction effect. This solution achieves a dynamic color change effect by adjusting the hue, avoiding complex real-time ray tracing calculations, creating complex visual effects, and maintaining a good performance balance, which is suitable for three-dimensional applications on mobile terminals.
[0101] Corresponding to the above method embodiment, the present application also provides an embodiment of a rendering device for simulating the diffraction effect of an object surface, such as Figure 8 As shown, the device comprises:
[0102] A first conversion unit is used to obtain the sight line vector of the object surface in the model space and convert it into the tangent space;
[0103] A second conversion unit is used to normalize the sight line vector in the tangent space to obtain a first sight line vector; and convert the hue of the first RGB color according to the first sight line vector to obtain a second RGB color;
[0104] A first calculation unit, configured to superimpose the second RGB color with the noise texture to obtain a third RGB color;
[0105] The second calculation unit is used to superimpose the third RGB color with the source color of the object and other target effect masks to obtain a final diffraction rendering effect.
[0106] The above is a schematic scheme of a rendering device for simulating diffraction effect on the surface of an object in this embodiment. It should be noted that the technical scheme of the rendering device for simulating diffraction effect on the surface of an object and the technical scheme of the rendering method for simulating diffraction effect on the surface of an object belong to the same concept, and the details of the technical scheme of the rendering device for simulating diffraction effect on the surface of an object that are not described in detail can all be referred to the description of the technical scheme of the rendering method for simulating diffraction effect on the surface of an object.
[0107] In one embodiment of the present application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the rendering method for simulating the diffraction effect on the surface of an object are implemented.
[0108] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the rendering method for simulating the diffraction effect of the surface of an object are of the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the rendering method for simulating the diffraction effect of the surface of an object.
[0109] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the rendering method for simulating the diffraction effect of the surface of an object as described above.
[0110] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the rendering method for simulating the diffraction effect of the surface of an object belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the rendering method for simulating the diffraction effect of the surface of an object.
[0111] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0112] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0113] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0114] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0115] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A rendering method for simulating the diffraction effect of an object surface, characterized in that: include: Get the sight vector of the object surface in the model space and convert it to the tangent space; Normalizing the sight line vector in the tangent space to obtain a first sight line vector; converting the hue of the first RGB color according to the first sight line vector to obtain a second RGB color; Superimposing the second RGB color with the noise texture to obtain a third RGB color; The third RGB color is superimposed with the source color of the object and other target effect masks to obtain a final diffraction rendering effect.
2. The method according to claim 1, wherein: The converting the hue of the first RGB color to obtain the second RGB color according to the first sight vector includes: Extract the RGB components of the first RGB color and convert them to the HSV model; Calculate and maintain the saturation S and brightness V of the first RGB color; calculate the hue H of the first RGB color and add the hue adjustment value; convert the adjusted HSV color back to RGB color to obtain a second RGB color; The hue adjustment value is generated according to the first sight line vector.
3. The method according to claim 2, wherein: The hue adjustment value is generated according to the first sight line vector, comprising: The sum of the x and y components of the first sight line vector is used as a hue adjustment parameter.
4. The method according to claim 1, wherein: The second RGB color is superimposed with the noise to obtain a third RGB color including: The second RGB color is superimposed on the sampled blue noise texture to obtain a third RGB color.
5. The method according to claim 1, wherein: The third RGB color is superimposed with the source color of the object and other target effect masks to obtain the final diffraction rendering effect including: The third RGB color, the original texture sampling of the object and other target effect masks are multiplied to obtain the final diffraction rendering effect.
6. The method according to claim 1, wherein: The object is a virtual card.
7. A rendering device for simulating the diffraction effect of an object surface, characterized in that: include: A first conversion unit is used to obtain the sight line vector of the object surface in the model space and convert it into the tangent space; A second conversion unit is used to normalize the sight line vector in the tangent space to obtain a first sight line vector; and convert the hue of the first RGB color according to the first sight line vector to obtain a second RGB color; A first calculation unit, configured to superimpose the second RGB color with the noise texture to obtain a third RGB color; The second calculation unit is used to superimpose the third RGB color with the source color of the object and other target effect masks to obtain a final diffraction rendering effect.
8. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by a processor, the steps of the method described in any one of claims 1 to 6 are implemented.
