Lighting color display method, device, electronic device and storage medium

By calculating the attenuation value, unit light vector and reflection value of point light sources in game scenes, and combining ambient light to calculate the light color, the problem of abrupt color at the intersection of point light sources is solved, the natural transition of multiple light sources is achieved, and the rendering effect is improved.

CN114723839BActive Publication Date: 2025-09-02SOUTH CHINA NORMAL UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210175328.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-24
Publication Date
2025-09-02
Estimated Expiration
2042-02-24

AI Technical Summary

Technical Problem

In game scenes, the color transition effect at the intersection of point light sources is abrupt, and the prior art cannot achieve a mixed transition of multiple light sources colors.

Method used

By obtaining the coordinates and colors of the point light source, calculate the attenuation value, unit light vector, diffuse reflection value and specular reflection value of each pixel point, calculate the lighting color in combination with predefined ambient light, and consider transparency during display, achieving a mixture of multiple light source colors.

Benefits of technology

Improve the coloring effect at the intersection of light sources in the game scene, avoiding the sudden transition of a single color, and achieving a more natural light source color mixing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114723839B_ABST
    Figure CN114723839B_ABST
Patent Text Reader

Abstract

The present invention relates to a method, device, electronic device and storage medium for displaying lighting colors. The lighting color display method described in the present invention includes: obtaining the coordinates and colors of all point light sources in a picture; for each pixel point of the lighting color to be displayed, calculating the attenuation value of each point light source corresponding to the pixel point according to the coordinates of the point light source; calculating the unit light vector of each point light source corresponding to each pixel point according to the coordinates and colors of all point light sources; calculating the diffuse reflection value and specular reflection value of each point light source corresponding to each pixel point according to the unit light vector; calculating the lighting color corresponding to each pixel point according to the diffuse reflection value, specular reflection value and predefined ambient light; obtaining the transparency value preset in the picture, and displaying the lighting color of the pixel point according to the transparency value and the lighting color corresponding to the pixel point. The lighting color display method described in the present invention mixes the colors of light at the intersection of light sources, thereby improving the final coloring effect of the scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of illumination rendering technology, and in particular to an illumination color display method, device, electronic device and storage medium. Background Art

[0002] When building a game scene, you often need to arrange various light sources. Different light sources can differ significantly from one another. The main difference between point lights and other light sources is that they only emit light in all directions from their point of origin, and their light intensity decreases as they travel farther from the point of origin.

[0003] The lighting settings in a game scene directly affect the overall rendering quality. For example, when encountering a special scene like a stage, a large number of point lights are required. However, when multiple point lights are placed around an object in the same scene, the object is only affected by the light source closest to it within a fixed range, making the final environment unable to achieve the desired effect.

[0004] The default material shader in Unity's Universal Render Pipeline (URP) only calculates the influence of the nearest point light. This means that objects are most affected by the closest point light. This results in a noticeable color transition where two point lights meet, with the color of the closest light appearing on the object. There's no color transition at the intersection of the two light sources; instead, the intersection area only displays the color closest to the object. This results in a sudden transition in the final color of the light source, creating a jarring effect. Summary of the Invention

[0005] Based on this, the purpose of the present invention is to provide a lighting color display method, device, electronic device and storage medium, which can make the transition color at the intersection of point light sources no longer just a monotonous color, but a mixed color of multiple light sources at the intersection.

[0006] In a first aspect, the present invention provides a method for displaying light colors, comprising the following steps:

[0007] Get the coordinates and colors of all point light sources in the picture;

[0008] For each pixel of the light color to be displayed, calculate the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source;

[0009] According to the coordinates and colors of all point light sources, calculate the unit light vector of each point light source corresponding to each pixel;

[0010] Calculating the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector;

[0011] Calculating the illumination color corresponding to each pixel according to the diffuse reflection value, the specular reflection value and the predefined ambient light;

[0012] Obtain a preset transparency value of the image, and display the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point.

[0013] Furthermore, the diffuse reflection value of each pixel corresponding to each point light source is calculated according to the unit light vector, including:

[0014] Calculate the diffuse reflectance value using the following formula:

[0015] D=a*L. xyz *saturate(dot(n,l))

[0016] Where D is the diffuse reflection value of the point light source corresponding to the pixel, a is the diffuse reflection coefficient, L.xyz is the position of the incident light source, n is the unit normal vector, and l is the unit light vector. The dot() function represents the dot product operation of the unit normal vector and the unit light vector, and the saturate() function represents the return value of the dot product operation between 0 and 1.

[0017] Furthermore, calculating the specular reflection value of each pixel corresponding to each point light source according to the unit light vector includes:

[0018] Calculate the specular value using the following formula:

[0019] S=K*a*saturate(dot(n,l))*(pow(max(dot(reflect(-l,n),v),0)) shininess

[0020] Among them, S is the specular reflection value of the point light source corresponding to the pixel point, K is the highlight color reflected by the material, a is the diffuse reflection coefficient, n is the unit normal vector, and l is the unit light vector; the dot() function represents the dot product operation of the unit normal vector and the unit light vector, the saturate() function represents returning the value of the dot product operation between 0 and 1, the reflect() function is the function for calculating reflection, the max() function represents taking the maximum value, the pow() function is used to calculate the value of x to the power of y, and shininess is the exponent for adjusting the glossiness.

[0021] Furthermore, based on the coordinates and colors of all point light sources, the unit light vector of each point light source corresponding to each pixel is calculated, including:

[0022] Use the GetMainLight() function to get the main light source;

[0023] In the Additional Pass, the coordinates of the pixel and the point light source are obtained by subtracting the position in the fragment shader from the position of the current light source.

[0024] The coordinates are normalized to obtain a unit light vector corresponding to the point light source at the pixel point.

[0025] Furthermore, normalizing the coordinates includes:

[0026] The normalize() function is used to perform normalization processing on the incident light vector from the point light source to the pixel point, and the normalize() function is used to perform normalization processing to obtain a unit light vector with a length of 1.

[0027] Furthermore, calculating the illumination color corresponding to each pixel point according to the diffuse reflection value, the specular reflection value and the predefined ambient light includes:

[0028] Use the following formula to calculate the light color corresponding to each pixel:

[0029] f=(D+S+_GlossyEnvironmentColor+m)*col. rgb

[0030] Among them, f is the light color, D is the diffuse reflection value, S is the specular reflection value, col.rgb refers to the color of this calculated point light source, _GlossyEnvironmentColor is the ambient light predefined by URP, and m is a variable used to adjust the effect.

[0031] Furthermore, the preset transparency is 1.0.

[0032] In a second aspect, the present invention further provides a light color display device, comprising:

[0033] Point light source acquisition module, used to obtain the coordinates and colors of all point light sources in the picture;

[0034] an attenuation value calculation module, configured to calculate, for each pixel of the light color to be displayed, the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source;

[0035] The unit light vector calculation module is used to calculate the unit light vector of each point light source corresponding to each pixel point based on the coordinates and colors of all point light sources;

[0036] A reflection value calculation module, configured to calculate the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector;

[0037] A lighting color calculation module, configured to calculate the lighting color corresponding to each pixel point based on the diffuse reflection value, the specular reflection value, and predefined ambient light;

[0038] The display module is used to obtain a transparency value preset for the image, and display the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point.

[0039] In a third aspect, the present invention further provides an electronic device, characterized in that it includes:

[0040] at least one memory and at least one processor;

[0041] The memory is used to store one or more programs;

[0042] When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the illumination color display method as described in any one of the first aspects of the present invention.

[0043] In a fourth aspect, the present invention further provides a computer-readable storage medium, characterized in that:

[0044] The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the illumination color display method as described in any one of the first aspects of the present invention are implemented.

[0045] The present invention provides a lighting color display method, device, electronic device and storage medium, which can make the transition color at the intersection of point light sources no longer just a monotonous color, but instead integrate the mixed colors of multiple light sources at the intersection, mixing the colors of multiple lights at the intersection of light sources, thereby improving the final coloring effect of the scene.

[0046] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A schematic flow chart of a light color display method provided by the present invention;

[0048] Figure 2 A schematic structural diagram of a light color display device provided by the present invention;

[0049] Figure 3 A grayscale diagram showing a schematic diagram of lighting color effects in one embodiment of the present invention. DETAILED DESCRIPTION

[0050] In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be described in further detail below with reference to the accompanying drawings.

[0051] It should be clear that the embodiments described are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments of the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the embodiments of the present application.

[0052] The terms used in the embodiments of the present application are for the purpose of describing specific embodiments only and are not intended to limit the embodiments of the present application. The singular forms "a," "the," and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0053] When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims. In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances.

[0054] In addition, in this application, unless otherwise specified, "plurality" refers to two or more. "And / or" describes the relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.

[0055] In a specific embodiment, the present invention provides a lighting color display method that is implemented during the process of building a game scene in Unity.

[0056] Before implementing the lighting color display method provided by the present invention, a stage and a point light source are first created in Unity.

[0057] The following steps are involved:

[0058] In the first step, package the resources you need, open Unity Hub and create a new Unity URP project template in the project, and then import the packaged resources into the Assets folder through the Package Manager. After importing the materials, the materials may become invalid. This problem is mainly because URP cannot correctly identify the previous shader of the material. Therefore, you need to change its category. You only need to use Upgrade Project Materials to Universal IRP Materials to replace it with one click. This method is not applicable to all shaders. When encountering a handwritten shader, it will fail, and we need to modify it manually.

[0059] In the second step, select the two figures in DAZ Studio, Genesis 8 Female and Genesis 8 Male, and add the corresponding clothing. Then, export the two character models using FBX Export Options. Drag the exported files directly into the Assets folder. When importing the character models, you may encounter problems with the material's previous shader being correctly recognized. This can be resolved by following the steps in the first step.

[0060] The third step is to use the imported objects to create the required stage scene, and place the two characters in the middle of the stage while leaving enough space for the point light source.

[0061] In the fourth step, add four point lights of different colors to the soles of the feet and the tops of the heads of the two characters. Here, a superposition method is adopted, and the point lights are added to the scene one by one. Add the prepared C# file for adding point lights through Add Component, and manually add the light source by clicking Add in the Inspector. In addition, it is necessary to modify the maximum number of point lights that each plane supports. Because the Unity URP pipeline is different from the ordinary pipeline, unlike the ordinary pipeline, the number can be set directly in Quality. Therefore, it is necessary to directly select Per Object Light in the URP resource and adjust the number of supported point lights to a maximum of 8.

[0062] Based on the stage and light source created above, and in response to the problems in the background technology, the embodiment of the present application provides a method for displaying light colors, such as Figure 1 As shown, the method includes the following steps:

[0063] S01: Get the coordinates and colors of all point light sources in the image.

[0064] In a specific embodiment, a shader is manually written using forward rendering. Two passes are used to process light sources: a base pass to calculate the primary light source and an additional pass to process other light sources. The format of the point light source determines the number of times the additional pass is called. In this embodiment, 16 point lights are arranged, so 16 additional passes are called.

[0065] S02: For each pixel of the light color to be displayed, calculate the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source.

[0066] If you want to change the color at the intersection of light sources, you need to modify the attenuation factor. The attenuation of a point light source is carried out along the point, so if you want to get the attenuation value from a certain point to the light source, you must get the position of the point. In Unity, the URP pipeline will only calculate non-primary light sources within a limited number, so the present invention uses a superposition method to add the excess parts one by one. On the other hand, because when the scene contains directional light, the position actually calculated by the function for calculating the position of the light source contains the directional light source, so it is necessary to calculate the position of a special point light source. Therefore, the light source color and position in the C# file for adding the point light source are passed into the Shader, and then the position in the world space is converted to the light source space using the transformation matrix, so that the coordinate value of the point is obtained.

[0067] Then determine whether it is parallel light. If so, directly square the distance using the square of the coordinate modulus, and call UNITY_ATTEN_CHANNEL on the obtained value to calculate the final attenuation value. If not, the final attenuation value needs to be calculated using the linear method based on the above.

[0068] S03: Calculate the unit light vector of each point light source corresponding to each pixel according to the coordinates and colors of all point light sources.

[0069] To calculate the light source direction, in the Base Pass, use the GetMainLight() method to obtain the current light source's position to determine the main light source's direction. In the Additional Pass, the point light's direction needs to change with the viewing angle, so the current light source's position minus the fragment shader's position is used. These coordinates are then normalized.

[0070] Preferably, the incident light vector from the point light source to the pixel point is normalized using a normalize() function to obtain a unit light vector with a length of 1.

[0071] S04: Calculating the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector.

[0072] Diffuse reflection is the phenomenon in which light projected onto a rough surface is reflected in all directions. When a parallel beam of incident light strikes a rough surface, the surface reflects the light in all directions. Therefore, even though the incident rays are parallel, the inconsistency of the normals at each point causes the reflected light to be reflected irregularly in different directions. This type of reflection is called diffuse reflection or diffuse light. This reflected light is called diffuse light.

[0073] Preferably, diffuse reflection is calculated as follows:

[0074] The calculation method for diffuse reflection is the same for both main light sources and point light sources. The formula after improving the Lambert diffuse lighting model is used for calculation. The diffuse reflection value is obtained by multiplying the following three variables.

[0075] D=a*L. xyz *saturate(dot(n,l))

[0076] Where D is the diffuse reflection value of the point light source corresponding to the pixel, a is the diffuse reflection coefficient, L.xyz is the position of the incident light source, n is the unit normal vector, and l is the unit light vector. The dot() function represents the dot product operation of the unit normal vector and the unit light vector, and the saturate() function represents the return value of the dot product operation between 0 and 1.

[0077] In order to prevent the value of the dot product between the normal vector and the light vector from being negative, the saturate function is used to fix the obtained value to between [0, 1].

[0078] The principle of specular reflection is that light, after hitting an object, reflects and scatters, then strikes a reflective surface and reaches the human eye through specular reflection. Based on the principle of rectilinear propagation of light, it can be inferred that the observation result at the specular reflection point is the same as the rendering result at the virtual observation point (the observation point is symmetrical about the reflective plane). This is also the principle of the sampled reflection camera rendering method.

[0079] Preferably, the specular reflection is calculated as follows:

[0080] Calculate the specular value using the following formula:

[0081] S=K*a*saturate(dot(n,l))*(pow(max(dot(reflect(-l,n),v),0)) shininess

[0082] Among them, S is the specular reflection value of the point light source corresponding to the pixel point, K is the highlight color reflected by the material, a is the diffuse reflection coefficient, n is the unit normal vector, l is the unit light vector, and v is the observation vector, that is, the unit vector pointing from the pixel point to the observer; the dot() function represents the dot product operation of the unit normal vector and the unit light vector, the saturate() function represents returning the value of the dot product operation between 0 and 1, the reflect() function is the function for calculating reflection, the max() function represents taking the maximum value, the pow() function is used to calculate the value of x to the power of y, and shininess is the exponent for adjusting the glossiness.

[0083] The reason why the max function is used to make the value not less than 0 when calculating the specular reflection value is to avoid lighting in places where there should be no lighting.

[0084] S05: Calculate the illumination color corresponding to each pixel point according to the diffuse reflection value, the specular reflection value and the predefined ambient light.

[0085] In a preferred embodiment, the following formula is used to calculate the illumination color corresponding to each pixel:

[0086] f=(D+S+_GlossyEnvironmentColor+m)*col. rgb

[0087] Among them, f is the light color, D is the diffuse reflection value, S is the specular reflection value, col.rgb refers to the color of this calculated point light source, _GlossyEnvironmentColor is the ambient light predefined by URP, and m is a variable used to adjust the effect.

[0088] S06: Obtaining a preset transparency value of the image, and displaying the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point.

[0089] The transparency value is set manually to make the final lighting effect better.

[0090] In a preferred embodiment, the transparency is set to 1.0.

[0091] like Figure 3 As shown, compared with the current technology for processing multiple point light sources in Unity, the present invention proposes a lighting color display method. By modifying the code for calculating lighting in the shader, the colors of multiple lights at the intersection of the light sources are mixed, thereby improving the final shading effect of the scene.

[0092] The present application also provides a light color display device, such as Figure 2 As shown, the illumination color display device 400 includes:

[0093] Point light source acquisition module 401, used to obtain the coordinates and colors of all point light sources in the picture;

[0094] An attenuation value calculation module 402 is configured to calculate, for each pixel of the light color to be displayed, the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source;

[0095] The unit light vector calculation module 403 is used to calculate the unit light vector of each point light source corresponding to each pixel point according to the coordinates and colors of all point light sources;

[0096] A reflection value calculation module 404 is used to calculate the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector;

[0097] The illumination color calculation module 405 is used to calculate the illumination color corresponding to each pixel according to the diffuse reflection value, the specular reflection value and the predefined ambient light;

[0098] The display module 406 is configured to obtain a preset transparency value of the image, and display the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point.

[0099] Preferably, the reflection value calculation module includes:

[0100] The diffuse reflection value calculation unit is used to calculate the diffuse reflection value using the following formula:

[0101] D=a*L. xyz *saturate(dot(n,l))

[0102] Where D is the diffuse reflection value of the point light source corresponding to the pixel, a is the diffuse reflection coefficient, L.xyz is the position of the incident light source, n is the unit normal vector, and l is the unit light vector. The dot() function represents the dot product operation of the unit normal vector and the unit light vector, and the saturate() function represents the return value of the dot product operation between 0 and 1.

[0103] Preferably, the reflection value calculation module further includes:

[0104] The specular reflection value calculation unit is used to calculate the specular reflection value using the following formula:

[0105] S=K*a*saturate(dot(n,l))*(pow(max(dot(reflect(-l,n),v),0)) shininess

[0106] Among them, S is the specular reflection value of the point light source corresponding to the pixel point, K is the highlight color reflected by the material, a is the diffuse reflection coefficient, n is the unit normal vector, and l is the unit light vector; the dot() function represents the dot product operation of the unit normal vector and the unit light vector, the saturate() function represents returning the value of the dot product operation between 0 and 1, the reflect() function is the function for calculating reflection, the max() function represents taking the maximum value, the pow() function is used to calculate the value of x to the power of y, and shininess is the exponent for adjusting the glossiness.

[0107] Preferably, the unit light vector calculation module includes:

[0108] The main light source acquisition unit is used to obtain the main light source using the GetMainLight() function;

[0109] A coordinate calculation unit, configured to obtain the coordinates of the pixel and the point light source by subtracting the position in the fragment shader from the position of the current light source in the Additional Pass;

[0110] A normalization unit is used to perform normalization processing on the coordinates to obtain a unit light vector corresponding to the point light source at the pixel point.

[0111] Preferably, the normalization unit performs normalization processing on the incident light vector from the point light source to the pixel point using a normalize() function to obtain a unit light vector with a length of 1.

[0112] Preferably, the illumination color calculation module is used to calculate the illumination color corresponding to each pixel using the following formula:

[0113] f=(D+S+_GlossyEnvironmentColor+m)*col. rgb

[0114] Among them, f is the light color, D is the diffuse reflection value, S is the specular reflection value, col.rgb refers to the color of this calculated point light source, _GlossyEnvironmentColor is the ambient light predefined by URP, and m is a variable used to adjust the effect.

[0115] Preferably, the preset transparency is 1.0.

[0116] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units. Those skilled in the art will clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0117] An embodiment of the present application further provides an electronic device, including:

[0118] at least one memory and at least one processor;

[0119] The memory is used to store one or more programs;

[0120] When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the aforementioned illumination color display method.

[0121] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the components described as separate parts may or may not be physically separated, and the parts displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the disclosed solution. A person of ordinary skill in the art can understand and implement it without expending creative work.

[0122] The present application also provides a computer-readable storage medium.

[0123] The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned illumination color display method are implemented.

[0124] Computer-usable storage media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to: phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device.

[0125] The present invention provides a lighting color display method, device, electronic device and storage medium, which can make the transition color at the intersection of point light sources no longer just a monotonous color, but instead integrate the mixed colors of multiple light sources at the intersection, mixing the colors of multiple lights at the intersection of light sources, thereby improving the final coloring effect of the scene.

[0126] The above-described embodiments merely illustrate several implementations of the present invention. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, and all such variations and improvements fall within the scope of protection of the present invention.

Claims

1. A method for displaying light color, characterized in that: The following steps are involved: Get the coordinates and colors of all point light sources in the picture; For each pixel of the light color to be displayed, calculate the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source; According to the coordinates and colors of all point light sources, calculate the unit light vector of each point light source corresponding to each pixel; Calculating the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector; Calculating the illumination color corresponding to each pixel according to the diffuse reflection value, the specular reflection value and the predefined ambient light; Obtaining a preset transparency value of the image, and displaying the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point; Calculate the diffuse reflectance value using the following formula: D=a*L. xyz *saturate(dot(n,l)) Where D is the diffuse reflection value of the point light source corresponding to the pixel, a is the diffuse reflection coefficient, L.xyz is the position of the incident light source, n is the unit normal vector, and l is the unit light vector. The dot() function represents the dot product operation of the unit normal vector and the unit light vector, and the saturate() function represents the return value of the dot product operation between 0 and 1.

2. The method for displaying light color according to claim 1, wherein: Calculating the specular reflection value of each pixel corresponding to each point light source according to the unit light vector includes: Calculate the specular value using the following formula: S=K*a*saturate(dot(n,l))*(pow(max(dot(reflect(-l,n),v),0)) shininess Among them, S is the specular reflection value of the point light source corresponding to the pixel point, K is the highlight color reflected by the material, a is the diffuse reflection coefficient, n is the unit normal vector, l is the unit light vector, and v is the observation vector; the dot() function represents the dot product operation of the unit normal vector and the unit light vector, the saturate() function represents returning the value of the dot product operation between 0 and 1, the reflect() function is the function for calculating reflection, the max() function represents taking the maximum value, the pow() function is used to calculate the value of x to the power of y, and shininess is the exponent for adjusting the glossiness.

3. The method for displaying light color according to claim 2, wherein: According to the coordinates and colors of all point light sources, the unit light vector of each point light source corresponding to each pixel is calculated, including: Use the GetMainLight() function to get the main light source; In the Additional Pass, the coordinates of the pixel and the point light source are obtained by subtracting the position in the fragment shader from the position of the current light source. The coordinates are normalized to obtain a unit light vector corresponding to the point light source at the pixel point.

4. The method for displaying light color according to claim 3, wherein: Normalizing the coordinates includes: The incident light vector from the point light source to the pixel point is normalized using the normalize() function to obtain a unit light vector with a length of 1.

5. The method for displaying light color according to claim 4, wherein: Calculating the illumination color corresponding to each pixel according to the diffuse reflection value, the specular reflection value, and the predefined ambient light, including: Use the following formula to calculate the lighting color corresponding to each pixel: f=(D+S+_GlossyEnvironmentColor+m)*col. rgb Among them, f is the light color, D is the diffuse reflection value, S is the specular reflection value, col.rgb refers to the color of this calculated point light source, _GlossyEnvironmentColor is the ambient light predefined by URP, and m is a variable used to adjust the effect.

6. The method for displaying light color according to claim 1, wherein: The preset transparency is 1.

0.

7. A light color display device, characterized in that: include: Point light source acquisition module, used to obtain the coordinates and colors of all point light sources in the picture; an attenuation value calculation module, configured to calculate, for each pixel of the light color to be displayed, the attenuation value of each point light source corresponding to the pixel according to the coordinates of the point light source; The unit light vector calculation module is used to calculate the unit light vector of each point light source corresponding to each pixel point based on the coordinates and colors of all point light sources; A reflection value calculation module, configured to calculate the diffuse reflection value and the specular reflection value of each pixel corresponding to each point light source according to the unit light vector; Calculate the diffuse reflectance value using the following formula: D=a*L. xyz *saturate(dot(n,l)) Where D is the diffuse reflection value of the point light source corresponding to the pixel, a is the diffuse reflection coefficient, L.xyz is the position of the incident light source, n is the unit normal vector, and l is the unit light vector; the dot() function represents the dot product operation of the unit normal vector and the unit light vector, and the saturate() function represents the return value of the dot product operation between 0 and 1; A lighting color calculation module, configured to calculate the lighting color corresponding to each pixel point based on the diffuse reflection value, the specular reflection value, and predefined ambient light; The display module is used to obtain a transparency value preset for the image, and display the illumination color of the pixel point according to the transparency value and the illumination color corresponding to the pixel point.

8. An electronic device, characterized in that: include: at least one memory and at least one processor; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the at least one processor implements the steps of the lighting color display method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the light color display method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Computer-generated hologram generation method and device for representing real illumination on voxels

    CN111830810A