Light simulation method and device of virtual scene, computer device and storage medium

By constructing a virtual light structure and calculating lighting parameters, the problem of high hardware consumption in multi-light simulation was solved, and efficient light effect generation was achieved.

CN115393500BActive Publication Date: 2026-11-27NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211054253.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-31
Publication Date
2026-11-27
Estimated Expiration
2042-08-31

AI Technical Summary

Technical Problem

When using multiple dynamic lights to simulate lighting effects in a game scene, hardware performance is significantly consumed, affecting the lighting effects of the game scene.

Method used

By constructing a virtual light structure in a virtual scene and setting multiple attribute parameters, including illumination position, illumination radius, color, and intensity, the lighting parameters are calculated based on the pixel position and the distance of the light, reducing the consumption of scene processing resources.

Benefits of technology

No physical light source is required, reducing hardware resource consumption and achieving realistic lighting effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115393500B_ABST
    Figure CN115393500B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a light simulation method and device for a virtual scene, computer equipment and a computer readable storage medium. The present application constructs a virtual light structure in a PBR material system, sets a plurality of attribute parameters of the virtual light, including illumination position, illumination radius, color and intensity, etc.; determines a target pixel point illuminated by the virtual light from the virtual scene according to the illumination position and the position of the pixel point in the virtual scene, and then calculates the illuminated intensity of the target pixel point according to the distance between the target pixel point and the illumination position of the virtual light, and then calculates the illumination parameter of the target pixel based on the illuminated intensity and the color and intensity attributes of the virtual light. Finally, the target pixel is illuminated according to the illumination parameter of the target pixel to generate the illumination effect of the target pixel, without setting a light source in the virtual scene, which can reduce the consumption of scene processing resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a method, apparatus, computer device, and computer-readable storage medium for simulating lighting in a virtual scene. Background Technology

[0002] With the rapid development of game design technology, users' demands for game graphics are constantly increasing. In order to improve the quality of game graphics, simulating different lighting effects in game scenes has become a key point in game design.

[0003] In related technologies, when creating game scenes using a game engine, a dynamic light provided by the game engine is placed at a designated location within the game scene to simulate lighting effects. If multiple locations in the game scene require lighting effects, multiple dynamic lights need to be placed. However, applying multiple dynamic lights simultaneously consumes significant hardware resources, thus affecting the lighting effects of the game scene. Summary of the Invention

[0004] This application provides a method, apparatus, computer device, and computer-readable storage medium for simulating lighting in a virtual scene.

[0005] This application provides a method for simulating lighting in a virtual scene, including: Obtain the position of the scene to be illuminated in the virtual scene, and get the first position of the virtual light; Based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene, the pixel to be illuminated is determined from the pixels in the virtual scene; The illumination parameters of the pixel to be illuminated are determined based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. The pixels to be illuminated are illuminated based on the lighting parameters to generate a lighting effect in the scene to be illuminated.

[0006] Accordingly, embodiments of this application also provide a lighting simulation device for a virtual scene, including: The acquisition unit is used to acquire the position of the scene to be illuminated in the virtual scene, and obtain the first position of the virtual light; The first determining unit is configured to determine the pixel to be illuminated from the pixels in the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene. The second determining unit is used to determine the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. The processing unit is used to perform illumination processing on the pixel to be illuminated based on the illumination parameters, so as to generate a lighting effect in the scene to be illuminated.

[0007] This application embodiment constructs a virtual light structure in a PBR material system and sets multiple attribute parameters for the virtual light, including illumination position, illumination radius, color, and intensity. Based on the illumination position and the position of pixels in the virtual scene, the target pixel to be illuminated by the virtual light is determined. Then, the illumination intensity of the target pixel is calculated based on the distance between the target pixel and the illumination position of the virtual light. Next, the illumination parameters of the target pixel are calculated based on the illumination intensity and the color and intensity attributes of the virtual light. Finally, the target pixel is illuminated according to the illumination parameters to generate the illumination effect of the target pixel. This eliminates the need to set a light source in the virtual scene, which can reduce the consumption of scene processing resources. Attached Figure Description

[0008] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0009] Figure 1 This is a flowchart illustrating a method for simulating lighting in a virtual scene, as provided in an embodiment of this application.

[0010] Figure 2 This is a schematic diagram illustrating an application scenario of a virtual scene lighting simulation method provided in an embodiment of this application.

[0011] Figure 3 This is a flowchart illustrating another method for simulating lighting in a virtual scene, as provided in an embodiment of this application.

[0012] Figure 4 This is a structural block diagram of a lighting simulation device for a virtual scene provided in an embodiment of this application.

[0013] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation

[0014] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0015] This application provides a method, apparatus, computer-readable storage medium, and computer device for simulating lighting in a virtual scene. Specifically, the lighting simulation method for a virtual scene in this application can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet, laptop, touchscreen, personal computer (PC), personal digital assistant (PDA), or other terminal device. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0016] For example, the computer device can be a terminal that can obtain the position of the scene to be illuminated in a virtual scene and obtain the first position of the virtual light; based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene, determine the pixel to be illuminated from the pixels in the virtual scene; determine the illumination parameters of the pixel to be illuminated according to the distance between the position of the pixel to be illuminated and the first position, and the light parameter of the virtual light; and perform illumination processing on the pixel to be illuminated based on the illumination parameters to generate a light illumination effect in the scene to be illuminated.

[0017] Based on the above problems, embodiments of this application provide a first method, apparatus, computer device, and computer-readable storage medium for simulating lighting in a virtual scene.

[0018] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.

[0019] This application provides a method for simulating lighting in a virtual scene. This method can be executed by a terminal or a server. This application uses the example of a virtual scene lighting simulation method being executed by a terminal to illustrate the method.

[0020] Please see Figure 1 , Figure 1 This is a flowchart illustrating a method for simulating lighting in a virtual scene, provided in an embodiment of this application. The specific flow of this method is as follows: 101. Obtain the position of the scene to be illuminated in the virtual scene, and get the first position of the virtual light.

[0021] In this embodiment, the virtual scene can be a game scene, and the scene to be illuminated refers to the scene in the virtual scene that needs to be lit. Virtual lights are used to simulate lighting in the virtual scene.

[0022] Specifically, obtaining the location of the scene to be illuminated can be done in various ways. For example, if the scene in the virtual scene that needs to be illuminated is a fixed scene, that is, the scene to be illuminated is pre-set, then the location information of the pre-set scene to be illuminated can be obtained to get the location of the scene to be illuminated in the virtual scene, and the location of the scene to be illuminated can be used as the location of the virtual light, that is, the first location.

[0023] Alternatively, if the scene in the virtual scene that needs to be illuminated is a random scene, that is, the scene to be illuminated is randomly generated during the game, for example, when a cannonball in the virtual scene attacks other objects, the point of impact is randomly generated. If the point of impact is the scene that needs to be illuminated, then the position of the scene that needs to be illuminated can be obtained in real time during the game and that position can be used as the first position of the virtual light.

[0024] In this embodiment, the virtual light is implemented by: creating a virtual light structure and setting different attribute parameters of the virtual light. The specific implementation code can be as follows: <param Name="LightPos_1" Type="float4" UiLabel="LightPos_1" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_1" Type="float4"" UiLabel="Lightcolor_1”Desc=" 灯光1颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> The code above defines the lighting parameters for virtual light 1. Here, LightPos refers to the position variable of the virtual light, used to define the virtual light's position information in the virtual scene, and Lightcolor refers to the color variable of the virtual light, used to define the color and brightness information of the virtual light.

[0025] Specifically, the LightPos variable has four channels: RGB, A, and B. The RGB channel can be used to store the position coordinates of the virtual light, and the A channel can be used to store the radius of the virtual light. Utilizing each channel of the variable fully further saves performance. In Default="0,0,0,20", (0,0,0) represents the position coordinates of the virtual light, i.e., the initial position of the virtual light, which can be dynamically changed; 20 represents the radius of the virtual light, i.e., setting the distance between the edge of the illuminated area and the virtual light itself.

[0026] Specifically, the Lightcolor variable has four channels: RGB, A, and B. The RGB channels can be used to store the color data of the virtual light, and the A channels can be used to store the intensity data of the virtual light. In Default="1.0f, 0.0f, 0.5f, 0.0f", (1.0f, 0.0f, 0.5f) represent the color data of the virtual light, and 0.0f represents the intensity data of the virtual light.

[0027] In this embodiment of the application, the virtual scene can be rendered using a PBR (physics-based rendering) material system, and the lighting parameters of the virtual light can be constructed in the PBR material system.

[0028] In some embodiments, the virtual scene may include multiple scenes requiring lighting. For example, when a projectile in a virtual scene attacks other objects, multiple impact points can be generated. To achieve lighting effects for multiple scenes, this solution can construct multiple virtual lights, as follows: <param Name="LightPos_2" Type="float4" UiLabel="LightPos_2" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_2" Type="float4"" UiLabel="Lightcolor_2”Desc=" 灯光2颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_3" Type="float4" UiLabel="LightPos_3" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_3" Type="float4"" UiLabel="Lightcolor_3”Desc=" 灯光3颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_4" Type="float4" UiLabel="LightPos_4" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_4" Type="float4"" UiLabel="Lightcolor_4”Desc=" 灯光4颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_5" Type="float4" UiLabel="LightPos_5" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_5" Type="float4"" UiLabel="Lightcolor_5”Desc=" 灯光5颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> ... The code above defines the lighting parameters for virtual lights 2 through 5. Alternatively, other numbers of virtual lights can be defined according to the actual needs of the virtual scene; this is not limited here. This achieves the effect of simultaneously illuminating multiple areas within the virtual scene.

[0029] 102. Based on the first position, the illumination distance parameters of the virtual light, and the second position of the pixel in the virtual scene, determine the pixel to be illuminated from the pixels in the virtual scene.

[0030] The illumination distance parameter of the virtual light refers to the radius of the virtual light.

[0031] In this embodiment, the virtual scene is composed of multiple pixels. Specifically, based on the distance of each pixel to the virtual light, it is determined whether the distance exceeds the radius of the virtual light, thereby identifying the pixels that can be illuminated by the virtual light, i.e., the pixels to be illuminated.

[0032] In some embodiments, the step "determining the pixel to be illuminated from the pixels in the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene" may include the following operations: Calculate the distance from the first position of each pixel to the virtual light based on the second and first positions of each pixel in the virtual scene; The pixels to be illuminated are obtained based on the pixels whose positional distance from the virtual light is less than the illumination distance parameter.

[0033] For example, pixels in a virtual scene can include: first pixel, second pixel, third pixel, fourth pixel, etc. The positions of each pixel are obtained, resulting in the positions of the first pixel as (x1, y1, z1), the second pixel as (x2, y2, z2), the third pixel as (x3, y3, z3), and the fourth pixel as (x4, y4, z4). The first position of the virtual light can be (x0, y0, z0). Then, the distances L1 between (x1, y1, z1) and (x0, y0, z0), L2 between (x2, y2, z2) and (x0, y0, z0), L3 between (x3, y3, z3) and (x0, y0, z0), and L4 between (x4, y4, z4) and (x0, y0, z0) are calculated to obtain the first position distances between each pixel and the virtual light.

[0034] Furthermore, the distance values ​​L1, L2, L3 are compared with the radius of the virtual light, and the distance values ​​greater than the radius are selected, such as distance values ​​L1 and L2. Then the pixels to be illuminated are determined to be the first pixel and the second pixel.

[0035] In some embodiments, the method of determining the pixel to be illuminated may further include: dividing a circular area from the virtual scene according to the position and radius of the virtual light to obtain the area to be illuminated, and then obtaining the pixel points located in the area to be illuminated to obtain the pixel points to be illuminated.

[0036] 103. Determine the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, as well as the illumination parameters of the virtual light.

[0037] The lighting parameters of the virtual lights can be preset and used to simulate lighting effects.

[0038] In some embodiments, to improve the lighting effect of the virtual light, the step of "determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light" may include the following operations: Obtain the distance from the pixel to be illuminated to the second position of the virtual light; The distance to the second position is normalized to obtain the illumination intensity of the pixel to be illuminated. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters.

[0039] The distance between each pixel in the virtual scene and the virtual light has been calculated in the above steps. Then, the position of the pixel to be illuminated and the virtual light can be filtered from multiple distance values ​​to obtain the second position distance.

[0040] The illumination intensity refers to the intensity of the virtual light illuminating the pixel to be illuminated. It can be determined based on the distance between the pixel to be illuminated and the virtual light. For example, the farther the distance, the lower the intensity of the virtual light illuminating the pixel to be illuminated; the closer the distance, the higher the intensity of the virtual light illuminating the pixel to be illuminated. This can achieve a transition effect in the illumination intensity of the virtual light.

[0041] In some embodiments, the step "normalizing the second position distance to obtain the illumination intensity of the pixel to be illuminated" may include the following steps: Calculate the ratio of the distance to the second position to the lighting distance parameter; The intensity of illumination of the pixel to be illuminated by the virtual light is determined based on the ratio.

[0042] The intensity of lighting can be expressed as a percentage, such as 10%, 20%, etc.

[0043] Specifically, the implementation code for calculating the illumination intensity of the pixel to be illuminated based on the illumination distance parameter of the virtual light and the second position distance can be as follows: float spheramask = min(max((1 - sqrt(dot(pos - light_ pos.xyz, pos -light_pos.xyz)) / max(0.00001, light_pos.a)) (1.0 / max(1.0 - hardness, 0.0001)), 0), 1); Here, pos refers to the position of a pixel in the virtual scene, light_pos.xyz refers to the position of the virtual light, and hardness represents the edge hardness of the circle.

[0044] For example, when the distance between the pixel to be illuminated and the virtual light is 0, the illumination intensity of the pixel to be illuminated can be 100%; when the distance between the pixel to be illuminated and the virtual light is half of the illumination distance parameter, the illumination intensity of the pixel to be illuminated can be 50%, etc.

[0045] In some embodiments, the lighting parameters include lighting color values ​​and lighting intensity values. The step "obtaining lighting parameters based on the product of lighting intensity and lighting parameters" may include the following operations: Calculate the product of lighting intensity and light color value to obtain the lighting color parameter; Calculate the product of the lighting intensity and the light intensity value to obtain the lighting intensity parameter; The lighting parameters are obtained based on the lighting color parameters and lighting intensity parameters.

[0046] The light color value can be composed of red, green, and blue values, and the light intensity value can be a brightness value. Both the light color and intensity values ​​can be preset default values ​​or generated based on the actual situation of the virtual scene; no specific restrictions are imposed here.

[0047] Specifically, the product of the illumination intensity and the light color value is calculated to obtain the color intensity value of the pixel to be illuminated by the virtual light, which is used as the illumination color parameter of the pixel to be illuminated; the product of the illumination intensity and the light intensity value is calculated to obtain the brightness intensity value of the pixel to be illuminated by the virtual light, which is used as the illumination intensity parameter of the pixel to be illuminated; and then the illumination color parameter and the illumination intensity parameter are used as the illumination parameters of the pixel to be illuminated.

[0048] In some embodiments, to reduce the consumption of processing resources, the following steps may also be included: If the light intensity value is greater than the preset threshold, then the step of determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light, is executed.

[0049] In this embodiment, a preset threshold is set in advance, which is also the light intensity threshold. This light intensity threshold is used to detect whether the virtual light is activated to achieve the lighting effect.

[0050] Specifically, the light intensity value of the virtual light is compared with a preset threshold. If the light intensity value is greater than the preset threshold, it means that the virtual light is activated, and the step of determining the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, as well as the light parameters of the virtual light, can be executed. If the light intensity value is not greater than the preset threshold, it means that the virtual light is not activated, and the operation can be terminated.

[0051] In some embodiments, the virtual scene is a three-dimensional scene. To ensure the realism of the lighting effect of the virtual lights, the following steps may be included before the step "obtaining the lighting parameters based on the product of the lighting intensity and the lighting parameters": Obtain the first direction from the pixel to be illuminated to the virtual light, and the normal direction of the plane containing the pixel to be illuminated; The light intensity of the pixel to be illuminated is determined based on the first direction and the normal direction.

[0052] In this embodiment of the application, since the virtual scene is a three-dimensional scene, the planes on which different pixels to be illuminated are located may be different, that is, the surface orientation may be different. Therefore, it is necessary to consider the influence of the surface orientation of the pixels to be illuminated on the light.

[0053] The first direction refers to the direction from the pixel to be illuminated to the position of the virtual light, and the normal direction is the normal direction of the plane where the pixel to be illuminated is located.

[0054] In some embodiments, the step "determining the light intensity of the pixel to be illuminated based on the first direction and the normal direction" may include the following operations: Calculate the dot product of the first direction and the normal direction to obtain the light intensity of the pixel to be illuminated facing the plane of the virtual light.

[0055] Specifically, determining the light intensity of the pixel to be illuminated based on the first direction and the normal direction can be achieved by determining the light intensity of the pixel to be illuminated based on the angle between the first direction and the normal direction. For example, the smaller the angle, the greater the light intensity; the larger the angle, the smaller the light intensity.

[0056] Specifically, the code for determining the light intensity of the pixel to be illuminated can be as follows: float3 virtual_light_ dir = normalize(light_ pos - pos); float normal_factor = dot(normal, virtual_light_ dir); normal_factor = max(normal_factor, 0.0); Here, virtual_light_dir is defined as the first direction from the pixel to be illuminated to the position of the virtual light, which can be calculated based on the position of the virtual light and the position of the pixel to be illuminated; normal is defined as the normal direction of the plane where the pixel to be illuminated is located; dot(normal, virtual_light_dir) represents the dot product of the first direction and the normal direction. The dot product is used as a parameter to control the light intensity received by the pixel facing the plane, so as to make the lighting calculation conform to the real physical world.

[0057] The step "obtaining lighting parameters based on the product of lighting intensity and lighting parameters" can include the following operations: The lighting parameters are obtained by multiplying the lighting intensity, the received light intensity, and the light parameters.

[0058] Specifically, the product of illumination intensity, received light intensity, and light color value is calculated to obtain the color intensity value of the pixel to be illuminated by the virtual light, which is used as the illumination color parameter of the pixel to be illuminated; the product of illumination intensity, received light intensity, and light intensity value is calculated to obtain the brightness intensity value of the pixel to be illuminated by the virtual light, which is used as the illumination intensity parameter of the pixel to be illuminated, and then the illumination color parameter and illumination intensity parameter are used as the illumination parameters of the pixel to be illuminated.

[0059] 104. Perform lighting processing on the pixels to be illuminated based on the lighting parameters, so as to generate a lighting effect in the scene to be illuminated.

[0060] In some embodiments, the step "Illuminate the pixel to be illuminated based on illumination parameters" may include the following operations: The lighting parameters are superimposed onto the self-illuminating channel of the pixel to be illuminated to obtain the lighting effect of the pixel.

[0061] The self-illuminating channel refers to the self-illuminating channel in the PBR material. In PBR materials, the self-illuminating channel is an inherent property, with a default value of 0, meaning it does not emit light. When programmed and assigned a value greater than 0, the self-illuminating channel is activated and begins to emit light.

[0062] Specifically, the lighting parameters of the pixels to be illuminated, namely the lighting color parameters and lighting intensity parameters, calculated in the above steps, are superimposed on the self-illuminating channel to light it. This generates a lighting effect in the scene to be illuminated. By adjusting the color and brightness values ​​of the pixels, the lighting effect can be simulated without setting up physical light sources in the virtual scene, thus reducing hardware resource consumption.

[0063] In some embodiments, multiple virtual lights may be set, and the same pixel to be illuminated may be within the illumination range of multiple virtual lights. To improve the illumination effect, the step "Illuminate the pixel to be illuminated based on illumination parameters" may include the following operations: The lighting parameters of the pixel to be illuminated in each virtual light are superimposed to obtain the superimposed lighting parameters. Illumination processing is performed on the pixels to be illuminated based on the superimposed illumination parameters.

[0064] For example, multiple virtual lights include: virtual light 1, virtual light 2, virtual light 3, virtual light 4, virtual light 5, virtual light 6, virtual light 7, virtual light 8, and virtual light 9. The illumination range of each virtual light is determined based on its position and radius. Virtual lights whose illumination ranges intersect can be identified as: virtual light 1, virtual light 2, and virtual light 3. The pixels to be illuminated located within the intersecting illumination ranges can be identified as: pixel A, etc.

[0065] Furthermore, the first illumination parameter of pixel A in virtual light 1, the second illumination parameter of pixel A in virtual light 2, and the third illumination parameter of pixel A in virtual light 3 are calculated respectively. Then, the sum of the first illumination parameter, the second illumination parameter, and the third illumination parameter is calculated to obtain the final illumination parameter of pixel A, that is, the superimposed illumination parameter. Then, the pixel A is illuminated according to the superimposed illumination parameter.

[0066] For example, if virtual light 1 illuminates pixel A by 25%, virtual light 2 illuminates pixel A by 15%, and virtual light 3 illuminates pixel A by 5%, then the total illumination intensity of pixel A can be 45%.

[0067] In some embodiments, multiple virtual lights can be set. In this case, the illumination result of each virtual light on the pixel to be illuminated needs to be calculated sequentially. The implementation code can be as follows: float3 virtual_color = float3(0, 0, 0); #if HIT_LIGHT / / frag.position_world / / frag. normal float3 world_pos = (frag. position_world).xyz; float3 pixel_ normal = frag.normal; float inten_threshold = 0.01; / / Light intensity threshold; the light will not be active if the intensity is less than this value. if(Lightcolor_1.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_pos, pixel_normal, LightPos_1, Lightcolor_1);} if(Lightcolor_2.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_pos,pixel_normal,LightPos_2,Lightcolor_2);} if(Lightcolor_3.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_pos, pixel_normal, LightPos_3, Lightcolor_3);} ... The `if(Lightcolor_1.a>int_threshold)` method checks if the intensity of each virtual light is greater than the preset intensity. If the intensity of a virtual light is greater than the preset intensity, the light is activated. The illumination parameters for the pixel to be illuminated can then be calculated using `{virtual_color += virtual_1ight(wor1d_pos, pixel_normal, LightPos_1, Lightcolor_1);}`. The specific implementation is as follows: float3 virtual_light(float3 pos, float3 normal, float4 light_ pos, float4 color) { float hardness = 0; float spheramask = min(max((1 - sqrt(dot(pos - light_ pos.xyz, pos -light_pos.xyz)) / max(0.00001, light_pos.a)) (1.0 / max(1.0 - hardness, 0.0001)), 0), 1); float3 virtual_light_ dir = normalize(light_ pos - pos); float normal_factor = dot(normal, virtual_light_ dir); normal_factor = max(normal_factor, 0.0); float3 result = lerp(float3(0, 0, 0), color.xyz, spheramask); result = normal_factor; / / result = color.a; / / Intensity parameter factor, normal intensity factor return result; } Here, result refers to the illumination parameters of the pixel to be illuminated.

[0068] In some embodiments, the parameters of the virtual lights can also be controlled by the user.

[0069] For example, please see Figure 2 , Figure 2 This is a schematic diagram illustrating an application scenario of a virtual scene lighting simulation method provided in an embodiment of this application. Figure 2 The parameter control interface shown includes a virtual scene display area and a lighting parameter adjustment area. The virtual scene display area can show objects in the virtual scene, while the lighting parameter adjustment area can be used by users to set virtual lights and adjust their parameters.

[0070] Specifically, for each virtual light, position and color parameters can be set. The position parameters include position coordinate data (x, y, z) and light illumination radius data; the color parameters include color data (r, g, b) and light intensity data. Users can enter data in the input boxes corresponding to each parameter in the light parameter adjustment area to adjust the light parameters and meet different user needs.

[0071] This application discloses a method for simulating lighting in a virtual scene. The method includes: obtaining the position of the scene to be illuminated in the virtual scene to obtain a first position of the virtual light; determining a pixel to be illuminated from the pixels in the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixels in the virtual scene; determining the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light; and performing illumination processing on the pixel to be illuminated based on the illumination parameters to generate a lighting effect in the scene to be illuminated, thereby reducing the consumption of scene processing resources.

[0072] Based on the above description, the following examples will further illustrate the lighting simulation method for virtual scenes in this application. Please refer to...Figure 3 , Figure 3 This is a flowchart illustrating another method for simulating lighting in a virtual scene provided in this application embodiment. Taking the application of this method to a terminal as an example, the specific process can be as follows: 201. The terminal constructs virtual lighting parameters in the PBR material based on user input.

[0073] Among them, PBR material: physics-based rendering, is a rendering method based on real-world physical properties. This application's embodiment further optimizes the existing PBR rendering scheme to achieve multiple dynamic light source illumination effects.

[0074] Specifically, the code for constructing virtual light parameters can be as follows: <param Name="LightPos_1" Type="float4" UiLabel="LightPos_1" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_1" Type="float4"" UiLabel="Lightcolor_1”Desc=" 灯光1颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_2" Type="float4" UiLabel="LightPos_2" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_2" Type="float4"" UiLabel="Lightcolor_2”Desc=" 灯光2颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_3" Type="float4" UiLabel="LightPos_3" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_3" Type="float4"" UiLabel="Lightcolor_3”Desc=" 灯光3颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_4" Type="float4" UiLabel="LightPos_4" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_4" Type="float4"" UiLabel="Lightcolor_4”Desc=" 灯光4颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_5" Type="float4" UiLabel="LightPos_5" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_5" Type="float4"" UiLabel="Lightcolor_5”Desc=" 灯光5颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_6" Type="float4" UiLabel="LightPos_6" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_6" Type="float4"" UiLabel="Lightcolor_6”Desc=" 灯光6颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_7" Type="float4" UiLabel="LightPos_7" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_7" Type="float4"" UiLabel="Lightcolor_7”Desc=" 灯光7颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_8" Type="float4" UiLabel="LightPos_8" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_8" Type="float4"" UiLabel="Lightcolor_8”Desc=" 灯光8颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> <param Name="LightPos_9" Type="float4" UiLabel="LightPos_9" UiControl="Float4Picker" Default="0,0,0,20" UiGroup="Hit Light"> <param Name="Lightcolor_9" Type="float4"" UiLabel="Lightcolor_9”Desc=" 灯光9颜色" UiControl="ColorPicker" Default="1.0f,0.0f,0.5f,0.0f" UiGroup="HitLight"> The code above uses 9 dynamic virtual lights as an example (users can flexibly add a maximum number of lights according to actual project needs). The `LightPos` variable has four channels: `rgb`, `a`, and `b`. The `rgb` channel stores the position coordinates of the dynamic virtual lights, and the `a` channel stores the light radius. This fully utilizes each channel of the variable, further saving performance. The `LightColor` variable also has four channels: `rgb`, `a`, and `b`. The `rgb` channel stores the color of the dynamic virtual lights, and the `a` channel stores the intensity of the dynamic virtual lights.

[0075] 202. The terminal determines the target pixels illuminated by each virtual light from the virtual scene based on the parameters of each virtual light.

[0076] Specifically, based on the position coordinates and radius of the virtual light parameters, as well as the positions of each pixel in the virtual scene, the pixels illuminated by the virtual light are determined from the virtual scene, thus obtaining the target pixel. The implementation code can be as follows: float3 virtual_light(float3 pos, float3 normal, float4 light_ pos, float4 color) { float hardness = 0; float spheramask = min(max((1 - sqrt(dot(pos - light_ pos.xyz, pos -light_pos.xyz)) / max(0.00001, light_pos.a)) (1.0 / max(1.0 - hardness, 0.0001)), 0), 1); float3 virtual_light_ dir = normalize(light_ pos - pos); float normal_factor = dot(normal, virtual_light_ dir); normal_factor = max(normal_factor, 0.0); float3 result = lerp(float3(0, 0, 0), color.xyz, spheramask); result = normal_factor; / / result = color.a; / / Intensity parameter factor, normal intensity factor return result; } The specific calculation process of the above code is as follows: First, calculate the distance from each pixel in the virtual scene to the virtual light, where `pos` is the pixel position and `light_pos` is the virtual light position. Then, determine whether the distance exceeds the set light radius. If it exceeds the radius, the pixel is not illuminated; if it does not exceed the radius, the pixel is illuminated. Then, based on the distance from the pixel to the virtual light, normalize the distance to the range of 0-1 and use it as the intensity parameter. For example, when the distance between the pixel and the virtual light is 0, the intensity of the pixel's illumination can be 100%; when the distance between the pixel and the virtual light is half the radius, the intensity of the pixel's illumination can be 50%, and so on.

[0077] Here, `virtual_light_dir` represents the direction from the pixel to the virtual light source; `normal` represents the normal direction of the plane containing the pixel. After calculating the pixel's illumination intensity based on the distance between the pixel and the virtual light, the influence of the model's surface orientation on the virtual light's illumination also needs to be considered. Under the same light source, because the angle between `virtual_light_dir` and `normal` is inconsistent, the smaller the angle, the stronger the light. Therefore, in the code above, the dot product of the normal and `virtual_light_dir` is used as a parameter to control the light intensity on planes with different orientations, thereby ensuring that the lighting calculation conforms to the real physical world.

[0078] 203. The terminal calculates the lighting parameters of the target pixel under each virtual light based on the distance from each virtual light to the target pixel.

[0079] In this embodiment, the implementation code for calculating the illumination parameters of the target pixel is as follows: float3 virtual_color = float3(0, 0, 0); #if HIT_LIGHT / / frag.position_world / / frag. normal float3 world_pos = (frag. position_world).xyz; float3 pixel_ normal = frag.normal; float inten_threshold = 0.01; / / Light intensity threshold; the light will not be active if the intensity is less than this value. if(Lightcolor_1.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_1,Lightcolor_1);} if(Lightcolor_2.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_2,Lightcolor_2);} if(Lightcolor_3.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_3,Lightcolor_3);} if(Lightcolor_4.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_4,Lightcolor_4);} if(Lightcolor_5.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_5,Lightcolor_5);} if(Lightcolor_6.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_6,Lightcolor_6);} if(Lightcolor_7.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_ pos,pixel_normal,LightPos_7,Lightcolor_7);} if(Lightcolor_8.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_pos,pixel_normal,LightPos_8,Lightcolor_8);} if(Lightcolor_9.a>inten_threshold) {virtual_color += virtual_1ight(wor1d_pos,pixel_normal,LightPos_9,Lightcolor_9);} The code above works as follows: Based on the input intensity of the virtual light, if the intensity value is greater than 0.01, the virtual light is considered activated. Then, based on the position of the input virtual light, the degree to which the target pixel is illuminated by the virtual light is calculated, including chroma and luminance. This yields the illumination results of each target virtual pixel by each virtual light.

[0080] 204. The terminal superimposes multiple illumination parameters of the target pixel and performs illumination processing on the target pixel based on the superimposed illumination parameters.

[0081] Finally, the illumination results of multiple targets are superimposed to obtain the target illumination result of the target pixel, thus obtaining the final illumination result of each target pixel. Then, the final illumination result of each target pixel is connected to the self-illuminating channel of the PBR material system to complete the illumination processing of the target virtual pixel, so as to realize the lighting effect of multiple lights in the virtual scene.

[0082] This application discloses a method for simulating lighting in a virtual scene. The method includes: a terminal constructing virtual lighting parameters in a PBR material based on user input; determining target pixels illuminated by each virtual light in the virtual scene based on these virtual lighting parameters; calculating the illumination parameters of the target pixels under each virtual light based on the distance from each virtual light to the target pixels; superimposing the multiple illumination parameters of the target pixels; and performing lighting processing on the target pixels based on the superimposed illumination parameters. This reduces the consumption of scene processing resources.

[0083] To facilitate better implementation of the virtual scene lighting simulation method provided in this application embodiment, this application embodiment also provides a virtual scene lighting simulation device based on the above-described virtual scene lighting simulation method. The meanings of the terms used are the same as in the virtual scene lighting simulation method described above, and specific implementation details can be found in the descriptions in the method embodiments.

[0084] Please see Figure 4 , Figure 4 A structural block diagram of a lighting simulation device for a virtual scene provided in this application embodiment, the device comprising: The acquisition unit 301 is used to acquire the position of the scene to be illuminated in the virtual scene and obtain the first position of the virtual light. The first determining unit 302 is used to determine the pixel to be illuminated from the pixels in the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene. The second determining unit 303 is used to determine the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. The processing unit 304 is used to perform illumination processing on the pixel to be illuminated based on the illumination parameters, so as to generate a lighting effect in the scene to be illuminated.

[0085] In some embodiments, the first determining unit 302 may include: The calculation subunit is used to calculate the distance from each pixel to the first position of the virtual light based on the second position and the first position of each pixel in the virtual scene; The first determining subunit is used to obtain the pixel to be illuminated based on the pixel whose positional distance from the virtual light is less than the illumination distance parameter.

[0086] In some embodiments, the second determining unit 303 may include: The first acquisition subunit is used to acquire the second position distance from the pixel to be illuminated to the virtual light; The first processing subunit is used to normalize the second position distance to obtain the illumination intensity of the pixel to be illuminated. The second determining subunit is used to obtain the lighting parameters based on the product of the lighting intensity and the lighting parameters.

[0087] In some embodiments, the second determining subunit may specifically be used for: The lighting color parameter is obtained by calculating the product of the lighting intensity and the light color value. The illumination intensity parameter is obtained by multiplying the illumination intensity by the light intensity value. The lighting parameters are obtained based on the lighting color parameters and the lighting intensity parameters.

[0088] In some embodiments, the device may further include: An execution unit is configured to, if the light intensity value is greater than a preset threshold, perform the step of determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light.

[0089] In some embodiments, the second determining unit 303 may further include: The second acquisition subunit is used to acquire the first direction from the pixel to be illuminated to the virtual light, and the normal direction of the plane where the pixel to be illuminated is located; The third determining subunit is used to determine the light intensity of the pixel to be illuminated based on the first direction and the normal direction.

[0090] In some embodiments, the second determining subunit may specifically be used for: The lighting parameters are obtained based on the product of the lighting intensity, the received light intensity, and the light parameters.

[0091] In some embodiments, the third determining subunit is specifically used for: Calculate the dot product of the first direction and the normal direction to obtain the light intensity of the pixel to be illuminated facing the plane of the virtual light.

[0092] In some embodiments, the first processing subunit may specifically be used for: Calculate the ratio of the second location distance to the lighting distance parameter; The illumination intensity of the pixel to be illuminated by the virtual light is determined based on the ratio.

[0093] In some embodiments, the processing unit 304 may include: The second processing subunit is used to superimpose the lighting parameters onto the self-illuminating channel of the pixel to be illuminated to obtain the lighting effect of the pixel to be illuminated.

[0094] In some embodiments, the processing unit 304 may include: The third processing subunit is used to superimpose the lighting parameters of the pixel to be illuminated in each virtual light to obtain superimposed lighting parameters. The fourth processing subunit is used to perform illumination processing on the pixel to be illuminated based on the superimposed illumination parameters.

[0095] This application discloses a lighting simulation device for a virtual scene. An acquisition unit 301 acquires the position of the scene to be illuminated in the virtual scene, obtaining a first position of the virtual light. A first determination unit 302 determines a pixel to be illuminated from the pixels of the virtual scene based on the first position, the illumination distance parameter of the virtual light, and a second position of a pixel in the virtual scene. A second determination unit 303 determines the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. A processing unit 304 performs illumination processing on the pixel to be illuminated based on the illumination parameters to generate a lighting effect in the scene to be illuminated. This reduces the consumption of scene processing resources.

[0096] Accordingly, embodiments of this application also provide a computer device, which can be a terminal. For example... Figure 5 As shown, Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 500 includes a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, and a computer program stored on the memory 502 and executable on the processor. The processor 501 and the memory 502 are electrically connected. Those skilled in the art will understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0097] The processor 501 is the control center of the computer device 500. It connects various parts of the computer device 500 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 502, and calling data stored in the memory 502, it performs various functions of the computer device 500 and processes data, thereby monitoring the computer device 500 as a whole.

[0098] In this embodiment, the processor 501 in the computer device 500 loads the instructions corresponding to the processes of one or more applications into the memory 502 according to the following steps, and the processor 501 runs the applications stored in the memory 502 to achieve various functions: Obtain the position of the scene to be illuminated in the virtual scene, and get the first position of the virtual light; Based on the first position, the illumination distance parameters of the virtual light, and the second position of the pixel in the virtual scene, the pixel to be illuminated is determined from the pixels in the virtual scene; The illumination parameters of the pixel to be illuminated are determined based on the distance between the position of the pixel to be illuminated and the first position, as well as the illumination parameters of the virtual light. Lighting processing is performed on the pixels to be illuminated based on the lighting parameters, so as to generate a lighting effect in the scene to be illuminated.

[0099] In some embodiments, determining the pixel to be illuminated from the pixels of the virtual scene based on a first position, the illumination distance parameter of the virtual light, and a second position of the pixel in the virtual scene includes: Calculate the distance from the first position of each pixel to the virtual light based on the second and first positions of each pixel in the virtual scene; The pixels to be illuminated are obtained based on the pixels whose positional distance from the virtual light is less than the illumination distance parameter.

[0100] In some embodiments, determining the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light, includes: Obtain the distance from the pixel to be illuminated to the second position of the virtual light; The distance to the second position is normalized to obtain the illumination intensity of the pixel to be illuminated. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters.

[0101] In some embodiments, the lighting parameters include lighting color values ​​and lighting intensity values; The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters, including: Calculate the product of lighting intensity and light color value to obtain the lighting color parameter; Calculate the product of the lighting intensity and the light intensity value to obtain the lighting intensity parameter; The lighting parameters are obtained based on the lighting color parameters and lighting intensity parameters.

[0102] In some embodiments, the method further includes: If the light intensity value is greater than the preset threshold, then the step of determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light, is executed.

[0103] In some embodiments, the virtual scene is a three-dimensional scene; Before obtaining the lighting parameters based on the product of lighting intensity and lighting parameters, the following steps are also included: Obtain the first direction from the pixel to be illuminated to the virtual light, and the normal direction of the plane containing the pixel to be illuminated; The light intensity of the pixel to be illuminated is determined based on the first direction and the normal direction. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters, including: The lighting parameters are obtained by multiplying the lighting intensity, the received light intensity, and the light parameters.

[0104] In some embodiments, determining the light intensity of a pixel to be illuminated based on a first direction and a normal direction includes: Calculate the dot product of the first direction and the normal direction to obtain the light intensity of the pixel to be illuminated facing the plane of the virtual light.

[0105] In some embodiments, normalizing the second position distance to obtain the illumination intensity of the pixel to be illuminated includes: Calculate the ratio of the distance to the second position to the lighting distance parameter; The intensity of illumination of the pixel to be illuminated by the virtual light is determined based on the ratio.

[0106] In some embodiments, illumination processing is performed on the pixels to be illuminated based on illumination parameters, including: The lighting parameters are superimposed onto the self-illuminating channel of the pixel to be illuminated to obtain the lighting effect of the pixel.

[0107] In some embodiments, the pixel to be illuminated is within the illumination range of multiple virtual lights; Illumination processing is performed on the pixels to be illuminated based on illumination parameters, including: The lighting parameters of the pixel to be illuminated in each virtual light are superimposed to obtain the superimposed lighting parameters. Illumination processing is performed on the pixels to be illuminated based on the superimposed illumination parameters.

[0108] This application embodiment constructs a virtual light structure in a PBR material system and sets multiple attribute parameters for the virtual light, including illumination position, illumination radius, color, and intensity. Based on the illumination position and the position of pixels in the virtual scene, the target pixel to be illuminated by the virtual light is determined. Then, the illumination intensity of the target pixel is calculated based on the distance between the target pixel and the illumination position of the virtual light. Next, the illumination parameters of the target pixel are calculated based on the illumination intensity and the color and intensity attributes of the virtual light. Finally, the target pixel is illuminated according to the illumination parameters to generate the illumination effect of the target pixel. This eliminates the need to set a light source in the virtual scene, which can reduce the consumption of scene processing resources.

[0109] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0110] Optional, such as Figure 5As shown, the computer device 500 also includes: a touch screen display 503, a radio frequency circuit 504, an audio circuit 505, an input unit 506, and a power supply 507. The processor 501 is electrically connected to the touch screen display 503, the radio frequency circuit 504, the audio circuit 505, the input unit 506, and the power supply 507. Those skilled in the art will understand that... Figure 5 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0111] The touch display screen 503 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 503 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the computer device. These graphical user interfaces can be composed of graphics, guidance information, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 501. It can also receive and execute commands from the processor 501. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 501 to determine the type of touch event. Subsequently, the processor 501 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 503 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 503 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 503 can also be used as part of the input unit 506 to achieve input functions.

[0112] The radio frequency circuit 504 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other computer devices, and to transmit and receive signals with network devices or other computer devices.

[0113] Audio circuitry 505 can be used to provide an audio interface between a user and a computer device via a speaker and a microphone. Audio circuitry 505 converts received audio data into electrical signals, transmits them to the speaker, and the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 505, converted back into audio data, and output to processor 501 for processing. The audio data is then transmitted via radio frequency circuitry 504 to, for example, another computer device, or output to memory 502 for further processing. Audio circuitry 505 may also include an earphone jack to facilitate communication between peripheral headphones and the computer device.

[0114] The input unit 506 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.

[0115] Power supply 507 is used to supply power to various components of computer device 500. Optionally, power supply 507 can be logically connected to processor 501 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 507 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0116] although Figure 5 As not shown in the diagram, the computer device 500 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.

[0117] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0118] As can be seen from the above, the computer device provided in this embodiment can obtain the position of the scene to be illuminated in the virtual scene and obtain the first position of the virtual light; based on the first position, the illumination distance parameter of the virtual light and the second position of the pixel in the virtual scene, determine the pixel to be illuminated from the pixels of the virtual scene; determine the illumination parameters of the pixel to be illuminated according to the distance between the position of the pixel to be illuminated and the first position and the light parameter of the virtual light; and perform illumination processing on the pixel to be illuminated based on the illumination parameters so as to generate a light illumination effect in the scene to be illuminated.

[0119] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0120] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple computer programs that can be loaded by a processor to execute steps in any of the virtual scene lighting simulation methods provided in this application. For example, the computer program can execute the following steps: Obtain the position of the scene to be illuminated in the virtual scene, and get the first position of the virtual light; Based on the first position, the illumination distance parameters of the virtual light, and the second position of the pixel in the virtual scene, the pixel to be illuminated is determined from the pixels in the virtual scene; The illumination parameters of the pixel to be illuminated are determined based on the distance between the position of the pixel to be illuminated and the first position, as well as the illumination parameters of the virtual light. Lighting processing is performed on the pixels to be illuminated based on the lighting parameters, so as to generate a lighting effect in the scene to be illuminated.

[0121] In some embodiments, determining the pixel to be illuminated from the pixels of the virtual scene based on a first position, the illumination distance parameter of the virtual light, and a second position of the pixel in the virtual scene includes: Calculate the distance from the first position of each pixel to the virtual light based on the second and first positions of each pixel in the virtual scene; The pixels to be illuminated are obtained based on the pixels whose positional distance from the virtual light is less than the illumination distance parameter.

[0122] In some embodiments, determining the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light, includes: Obtain the distance from the pixel to be illuminated to the second position of the virtual light; The distance to the second position is normalized to obtain the illumination intensity of the pixel to be illuminated. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters.

[0123] In some embodiments, the lighting parameters include lighting color values ​​and lighting intensity values; The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters, including: Calculate the product of lighting intensity and light color value to obtain the lighting color parameter; Calculate the product of the lighting intensity and the light intensity value to obtain the lighting intensity parameter; The lighting parameters are obtained based on the lighting color parameters and lighting intensity parameters.

[0124] In some embodiments, the method further includes: If the light intensity value is greater than the preset threshold, then the step of determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light, is executed.

[0125] In some embodiments, the virtual scene is a three-dimensional scene; Before obtaining the lighting parameters based on the product of lighting intensity and lighting parameters, the following steps are also included: Obtain the first direction from the pixel to be illuminated to the virtual light, and the normal direction of the plane containing the pixel to be illuminated; The light intensity of the pixel to be illuminated is determined based on the first direction and the normal direction. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters, including: The lighting parameters are obtained by multiplying the lighting intensity, the received light intensity, and the light parameters.

[0126] In some embodiments, determining the light intensity of a pixel to be illuminated based on a first direction and a normal direction includes: Calculate the dot product of the first direction and the normal direction to obtain the light intensity of the pixel to be illuminated facing the plane of the virtual light.

[0127] In some embodiments, normalizing the second position distance to obtain the illumination intensity of the pixel to be illuminated includes: Calculate the ratio of the distance to the second position to the lighting distance parameter; The intensity of illumination of the pixel to be illuminated by the virtual light is determined based on the ratio.

[0128] In some embodiments, illumination processing is performed on the pixels to be illuminated based on illumination parameters, including: The lighting parameters are superimposed onto the self-illuminating channel of the pixel to be illuminated to obtain the lighting effect of the pixel.

[0129] In some embodiments, the pixel to be illuminated is within the illumination range of multiple virtual lights; Illumination processing is performed on the pixels to be illuminated based on illumination parameters, including: The lighting parameters of the pixel to be illuminated in each virtual light are superimposed to obtain the superimposed lighting parameters. Illumination processing is performed on the pixels to be illuminated based on the superimposed illumination parameters.

[0130] This application embodiment constructs a virtual light structure in a PBR material system and sets multiple attribute parameters for the virtual light, including illumination position, illumination radius, color, and intensity. Based on the illumination position and the position of pixels in the virtual scene, the target pixel to be illuminated by the virtual light is determined. Then, the illumination intensity of the target pixel is calculated based on the distance between the target pixel and the illumination position of the virtual light. Next, the illumination parameters of the target pixel are calculated based on the illumination intensity and the color and intensity attributes of the virtual light. Finally, the target pixel is illuminated according to the illumination parameters to generate the illumination effect of the target pixel. This eliminates the need to set a light source in the virtual scene, which can reduce the consumption of scene processing resources.

[0131] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0132] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0133] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the virtual scene lighting simulation methods provided in the embodiments of this application, the beneficial effects that any of the virtual scene lighting simulation methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0134] The above provides a detailed description of a virtual scene lighting simulation method, apparatus, computer-readable storage medium, and computer device provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for simulating lighting in a virtual scene, characterized in that, The method includes: Obtain the position of the scene to be illuminated in the virtual scene, and get the first position of the virtual light; Based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene, the pixel to be illuminated is determined from the pixels in the virtual scene; The illumination parameters of the pixel to be illuminated are determined based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. The pixels to be illuminated are illuminated based on the lighting parameters to generate a lighting effect in the scene to be illuminated. The step of performing illumination processing on the pixel to be illuminated based on the illumination parameters includes: superimposing the illumination parameters onto the self-illuminating channel of the pixel to be illuminated to obtain the illumination effect of the pixel to be illuminated.

2. The method according to claim 1, characterized in that, The step of determining the pixel to be illuminated from the pixels of the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene includes: Calculate the distance from each pixel to the first position of the virtual light based on the second position and the first position of each pixel in the virtual scene; The pixels to be illuminated are obtained based on the pixels whose positional distance from the virtual light is less than the illumination distance parameter.

3. The method according to claim 1, characterized in that, Determining the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light, includes: Obtain the second position distance from the pixel to be illuminated to the virtual light; The second position distance is normalized to obtain the illumination intensity of the pixel to be illuminated. The lighting parameters are obtained by multiplying the lighting intensity by the lighting parameters.

4. The method according to claim 3, characterized in that, The lighting parameters include light color value and light intensity value; The process of obtaining the lighting parameters based on the product of the lighting intensity and the lighting parameters includes: The lighting color parameter is obtained by calculating the product of the lighting intensity and the light color value. The illumination intensity parameter is obtained by multiplying the illumination intensity by the light intensity value. The lighting parameters are obtained based on the lighting color parameters and the lighting intensity parameters.

5. The method according to claim 4, characterized in that, The method further includes: If the light intensity value is greater than a preset threshold, then the step of determining the lighting parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the lighting parameters of the virtual light, is executed.

6. The method according to claim 3, characterized in that, The virtual scene is a three-dimensional scene; Before obtaining the lighting parameters based on the product of the lighting intensity and the lighting parameters, the method further includes: Obtain the first direction from the pixel to be illuminated to the virtual light, and the normal direction of the plane where the pixel to be illuminated is located; Calculate the dot product of the first direction and the normal direction to obtain the light intensity of the pixel to be illuminated facing the plane of the virtual light. The process of obtaining the lighting parameters based on the product of the lighting intensity and the lighting parameters includes: The lighting parameters are obtained based on the product of the lighting intensity, the received light intensity, and the light parameters.

7. The method according to claim 3, characterized in that, The normalization process for the second position distance to obtain the illumination intensity of the pixel to be illuminated includes: Calculate the ratio of the second location distance to the lighting distance parameter; The illumination intensity of the pixel to be illuminated by the virtual light is determined based on the ratio.

8. The method according to claim 1, characterized in that, The pixel to be illuminated is within the illumination range of multiple virtual lights; The illumination processing of the pixels to be illuminated based on the illumination parameters includes: The lighting parameters of the pixel to be illuminated in each virtual light are superimposed to obtain the superimposed lighting parameters. The pixels to be illuminated are illuminated based on the superimposed illumination parameters.

9. A lighting simulation device for a virtual scene, characterized in that, The device includes: The acquisition unit is used to acquire the position of the scene to be illuminated in the virtual scene, and obtain the first position of the virtual light; The first determining unit is configured to determine the pixel to be illuminated from the pixels in the virtual scene based on the first position, the illumination distance parameter of the virtual light, and the second position of the pixel in the virtual scene. The second determining unit is used to determine the illumination parameters of the pixel to be illuminated based on the distance between the position of the pixel to be illuminated and the first position, and the illumination parameters of the virtual light. The processing unit is configured to perform illumination processing on the pixel to be illuminated based on the illumination parameters, so as to generate a lighting effect in the scene to be illuminated; The processing unit is further configured to superimpose the lighting parameters onto the self-illuminating channel of the pixel to be illuminated, thereby obtaining the lighting effect of the pixel to be illuminated.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein, When the processor executes the program, it implements the lighting simulation method for the virtual scene as described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to execute the lighting simulation method for a virtual scene according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Picture rendering method and device, storage medium and electronic device

    CN110211218A

  • Illumination rendering method and device, storage medium and electronic device

    CN110288692A