Ambient lighting rendering method, system, electronic device and storage medium
By creating a temporary sphere in the Unity engine for Skybox texture editing and ambient lighting calculations, the existing technology's problems of complex ambient lighting editing and low rendering efficiency are solved, achieving efficient and convenient lighting editing and consistent rendering effects, and avoiding the need for gaming Stuttering during runtime.
Patent Information
- Application Number
- CN202411104025.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-08-13
AI Technical Summary
The environmental lighting editing and rendering process in the existing Unity engine is complex and inefficient. It is impossible to preview the modification effects in real time in the game scene. Real-time calculation of spherical harmonic coefficients consumes CPU resources and causes lags. In addition, different devices support the Skybox texture compression format inconsistently, resulting in rendering. The effect loses consistency.
Create a temporary sphere in the Unity engine, use the preset skybox material to display the Skybox map, and allow developers to select and modify the color of the lighting area on the surface of the sphere, recalculate the environment lighting in real time, use the precalculated SH coefficient and serialize it to save Avoid double counting while the game is running.
It realizes efficient and convenient environment lighting editing within the engine, enhances the real-time visual preview of lighting effects, avoids lags when the game is running, and ensures the consistency of rendering results on different devices.
Smart Images

Figure CN118625984B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of image rendering technology, and in particular to an environment lighting rendering method, system, electronic device, and computer storage medium. Background Art
[0002] The Unity engine is a powerful game engine that is widely used to develop various types of games, including 2D games, 3D games, VR games, and AR games. Unity believes that the world will be a better place with more creators, and its values include user first, creativity first, unity, and courage. The Unity engine supports cross-platform development, covering multiple platforms such as PC, Mac, Linux, iOS, Android, and game consoles, allowing developers to easily create multi-terminal games. It uses C# as the main scripting language, allowing developers to control the behavior of game objects by writing code. Unity has strong cross-platform performance and rich resources. It has a large developer community and a rich resource store, allowing developers to learn and obtain the tools and resources they need faster.
[0003] Ambient light (also called diffuse ambient light) is the light that exists around the scene and does not come from any specific light source object. It can be an important factor affecting the overall appearance and brightness of the scene. Ambient lighting is a very important part of 3D real-time rendering, which directly affects the realism and immersion of the scene. In mainstream 3D game engines such as Unity, the calculation of ambient lighting usually adopts the spherical harmonics approximation method.
[0004] The existing Unity engine environment lighting workflow is as follows:
[0005] Use Skybox map as ambient light data. In Unity, Skybox map is used to simulate the skybox in the real world. It is a box-shaped texture that surrounds the entire scene. The color distribution of this texture represents the ambient light intensity in all directions of the scene. Developers need to use professional image editing software to open the Skybox map file, manually adjust the pixel color or use filters and other functions to edit the map. After editing, you need to export the modified new map file and reload it in the Unity engine.
[0006] The disadvantages of this method are: the operation is complicated, it requires the use of additional software tools outside the game engine, the modified effects need to be frequently loaded and viewed in the game, which is inefficient, and the modified lighting effects cannot be viewed directly in the game scene.
[0007] When the game is loaded, in order to efficiently color the ambient lighting of objects in the scene, Unity uses the approximate method of spherical harmonics. When the scene is loaded, the engine will obtain a set of spherical harmonic coefficients (SH Coefficients, hereinafter referred to as SH coefficients) based on the color distribution of the Skybox map through a special integral operation. These coefficients are actually a finite-term approximation of the infinite-dimensional lighting signal. When the game is running, the pre-calculated SH coefficients are used to approximate the ambient lighting. After calculating the SH coefficients, these coefficients can be used to quickly calculate the ambient lighting for each object in the scene during the real-time rendering of the game. Specifically, for each object, the engine will approximate the ambient lighting intensity of the point based on its surface normal direction and the pre-calculated SH coefficients, and multiply the intensity value by the object's own reflectivity to obtain the final ambient lighting color.
[0008] However, there are some disadvantages in the real-time calculation of spherical harmonic coefficients in current games. One is that the inconsistent compression format of the Skybox map leads to differences in SH data calculation. In mobile game development, in order to save memory and loading time, Skybox maps are usually stored in the ASTC texture compression format that supports HDR. However, the degree of support for the ASTC format varies from mobile device to mobile device. For models that do not support ASTC, the Unity engine will automatically decode and convert it to a supported format, such as RGBA32, and this decoding and conversion process may introduce some color information loss. The second is that the real-time calculation process of SH consumes a lot of CPU resources and may cause game lag. The real-time calculation process of SH coefficients includes many mathematical operations such as spherical surface integrals, and the amount of calculation is relatively large. Therefore, it is usually completed as a time-consuming operation during the loading stage of the game scene. However, in some cases, players need to switch frequently between different scenes, and the ambient lighting of these scenes is different, which will cause SH to be recalculated when switching scenes. On mobile devices with relatively poor performance, a single SH calculation may block the CPU for hundreds of milliseconds, causing the game to be significantly lag during this period, seriously affecting the game experience.
[0009] In the Unity engine, the existing environment lighting editing and rendering process has the following defects:
[0010] 1. The editing and modification of Skybox maps requires the use of external image editing software, which is complicated to operate, lacks intuitive lighting effect preview feedback, is separated from the game engine, and lacks efficient and convenient real-time preview capabilities.
[0011] 2. When switching Skybox or modifying related parameters while the game is running, the spherical harmonic coefficients (SHCoefficients) need to be recalculated in real time. This calculation process consumes a lot of CPU resources and may cause the game to be obviously stuck for more than 1 second, giving players a very bad experience.
[0012] 3. Different mobile devices have different support for the Skybox texture compression format, which may result in different results when calculating the SH coefficient in real time, and the ambient lighting rendering effect loses consistency.
[0013] Therefore, it is necessary to propose a new technical solution to solve the above-mentioned pain points in efficiency, quality, experience and other aspects of the existing Unity environment lighting process, so as to significantly optimize the editing and rendering effects of environment lighting. Summary of the invention
[0014] The purpose of the embodiments of the present disclosure is to provide an environment lighting rendering method, system, electronic device and computer storage medium, so as to solve the above-mentioned problems existing in the prior art.
[0015] In order to achieve the above objectives, the technical solutions adopted by the embodiments of the present disclosure are as follows:
[0016] On the one hand, an embodiment of the present disclosure provides an environment lighting rendering method, the method comprising:
[0017] Open the scene whose lighting is to be edited;
[0018] Creating a temporary sphere that wraps the scene, using a preset skybox material on the surface of the sphere to display a skybox map; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and within the scene skybox;
[0019] Selecting an area and a color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area;
[0020] The selected area in the Skybox map on the surface of the sphere is modified to the target color, and the corresponding area between the original skybox map and the selected area in the Skybox map on the surface of the sphere is modified to the target color;
[0021] Recalculate the scene ambient lighting based on the modified skybox map.
[0022] Optionally, selecting an area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area, includes:
[0023] Use the selection tool to select the area and color of the lighting to be edited in the Skybox map on the surface of the sphere. The area selected for the lighting to be edited includes the selection width, selection height, and selection edge width.
[0024] Taking the current position of the tool as the starting point, emitting a ray along the camera line of sight, calculating the intersection of the ray and the sphere, and obtaining the world space position of the intersection, wherein the starting point is the center point of the selection area;
[0025] Set five parameters, namely, the intersection position, the selection width, the selection height, the selection color and the selection edge width, to the sphere material, wherein the sphere material is a pre-set skybox material;
[0026] The sphere material displays the selected area using the selected color according to the intersection position, the selected area width, the selected area height, the selected area color, and the selected area edge width.
[0027] Optionally, the sphere surface uses a preset skybox material to display a skybox map.
[0028] include:
[0029] Use the DirectionToUV function to convert the direction vector inside the sphere into UV coordinates;
[0030] Render the surface of the sphere in real time according to the color in the texture map corresponding to the UV coordinates.
[0031] Optionally, modifying the selected area in the Skybox map on the surface of the sphere to the target color, and modifying the corresponding area of the original skybox map and the selected area of the Skybox map on the surface of the sphere to the target color, includes:
[0032] Back up the Skybox texture, which is used to cancel the color modification and restore the selected area;
[0033] Call UnityEngine.Texture2D.GetPixels() to save the color of each pixel in the Skybox map loaded into memory in an array;
[0034] Use a double loop to traverse the entire array, and calculate the distance from each pixel in the array to the center of the selection according to the coordinates of each pixel. If the pixel is within the selection, change the color corresponding to the pixel in the array to the target color of the selection;
[0035] Call UnityEngine.Texture2D.SetPixels(Color[] colors) function and UnityEngine.Texture2D.Apply() function to apply the modified color array to the Skybox map in memory;
[0036] Call UnityEngine.Texture2D.EncodeToEXR() to encode the modified Skybox texture in memory into a byte array;
[0037] Call the System.IO.File.WriteAllBytes() function to save the byte array in the memory to the Skybox map file on the hard disk.
[0038] Optionally, after recalculating the scene ambient lighting, the method further includes:
[0039] Evaluate the lighting effect, and decide whether to accept or cancel the current lighting rendering edit based on the evaluation results;
[0040] Repeat the steps of selecting the area and color of the lighting to be edited on the Skybox map on the surface of the sphere and the subsequent steps until a preset ambient lighting result is obtained in the scene.
[0041] Optionally, after obtaining the preset ambient lighting result, the method further includes:
[0042] Open the scene with pre-calculated SH coefficients;
[0043] Add a pre-configured environment lighting management class as a component to the scene, wherein the member methods of the environment lighting management class include a ChangeEnvLight method and a Save method;
[0044] Calculate the SH coefficient corresponding to each skybox in the scene
[0045] The Save method saves the objects containing the SH coefficients corresponding to each skybox in the scene to the preset ambient lighting management class. Along with the saving of the scene, the SH coefficients are serialized and saved in the scene file. This is used when the scene skybox is switched during the actual running of the relevant application. The ChangeEnvLight method uses the corresponding SH coefficients saved in advance to overwrite the Unity engine variables.
[0046] Optionally, the calculating the SH coefficient corresponding to each skybox in the scene and saving it to a preset ambient lighting management class includes:
[0047] When the scene switches the skybox manually or programmatically, if the skybox is switched manually, the Unity editor will automatically recalculate the SH coefficient; if the skybox is switched programmatically, the corresponding interface will be called to calculate the SH coefficient.
[0048] Another aspect of the present disclosure provides a system for rendering ambient lighting using a Unity engine, the system comprising:
[0049] Open module, used to open the scene to be edited;
[0050] Skybox texture editor, used to create a temporary sphere that wraps the scene, and use a preset skybox material on the surface of the sphere to display the skybox texture; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and inside the scene skybox;
[0051] It is also used to select the area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area;
[0052] It is also used to modify the selected area in the skybox map on the surface of the sphere to the target color, and at the same time, the corresponding area between the original skybox map and the selected area of the skybox map on the surface of the sphere is modified to the target color;
[0053] The ambient lighting calculation module is used to recalculate the scene ambient lighting according to the modified skybox map.
[0054] Optionally, the system further includes:
[0055] An ambient lighting management class, wherein the member methods of the ambient lighting management class include a ChangeEnvLight method and a Save method;
[0056] The Save function is used to save the SH coefficients corresponding to each skybox in the scene calculated by the SH coefficient pre-calculation module.
[0057] In the actual running process of the relevant application, when the scene skybox is switched, the ChangeEnvLight method is used to overwrite the Unity engine variable with the corresponding SH coefficient saved in advance.
[0058] Another aspect of the disclosed embodiment provides a computer device, which includes: a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded by the processor to execute the lighting rendering method as described above.
[0059] On the other hand, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement the lighting rendering method as described above.
[0060] The beneficial effects of the embodiments of the present disclosure are:
[0061] The lighting rendering method of the disclosed embodiment is simple and quick to operate, and can modify the Skybox map in the engine, thus realizing efficient and convenient environmental lighting editing capabilities. The color value of pixels in any area on the Skybox map can be modified in the engine, and the selected range can be highlighted in real time, and the modified lighting effect can be observed visually in real time to enhance the experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 It is a schematic diagram of a flow chart of an environment lighting rendering method according to an embodiment of the present disclosure;
[0063] Figure 2 1 is a schematic diagram of the scene layout of the Unity editor to be edited in the embodiment of the present disclosure. The scene includes a character, a sheet model and a Skybox map. The sheet model is the solid color rectangle on the right, and the Skybox map is the wall, relief, chair and door in the distance;
[0064] Figure 3 is a schematic diagram of the scene layout after adding a Skybox texture editor to the scene to be edited in the embodiment of the present disclosure;
[0065] Figure 4 is a schematic diagram of the external layout of a temporary sphere that wraps a scene and is created by a Skybox texture editor in an embodiment of the present disclosure, wherein the temporary sphere is located between an object of the scene and the Skybox, the object being, for example, a character / model;
[0066] Figure 5 It is a schematic diagram of the internal layout of a temporary sphere that wraps a scene created by the Skybox texture editor in an embodiment of the present disclosure, wherein the interior of the temporary sphere is visually consistent with the Skybox, and there is a light-colored grid on the surface of the temporary sphere to distinguish it from the Skybox;
[0067] Figure 6 Yes Figure 5 A schematic diagram of the interface for selecting an area on a temporary sphere;
[0068] Figure 7 is Figure 6 A schematic diagram of the modified Skybox map obtained by modifying the color of the selected area.
[0069] Figure 8is a schematic diagram of directional information of each order of SH coefficients in an embodiment of the present disclosure;
[0070] Fig. 9 It is a schematic diagram of the structure of an environment lighting rendering system according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the embodiment of the present disclosure more clear, the embodiment of the present disclosure is further described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation methods described here are only used to explain the embodiment of the present disclosure and are not used to limit the embodiment of the present disclosure.
[0072] like Figure 1 As shown, the embodiment of the present disclosure provides an environment lighting rendering method, which is applied to the Unity editor. The method includes:
[0073] Step S100: Open the scene whose lighting is to be edited.
[0074] In the embodiment of the present disclosure, before opening the scene to be edited in the Unity editor, a client supporting a virtual environment is run. The scene refers to the virtual environment in which the character is located. The lighting rendering method of the embodiment of the present disclosure designs a Skybox texture editor that can be added to the Unity engine for the Unity engine; when applied, Figure 2 As shown, the developer opens the scene to be edited in the Unity editor. At this time, the cube map of the skybox is imported and displayed in the scene to be edited. The skybox map will be saved in the Assets folder of the hard disk project. When Unity loads resources such as the skybox map and uses them in the scene, the skybox map and other resources will be loaded into the memory. After opening the scene to be edited, as shown in the figure below, the skybox map will be loaded into the memory. Figure 3 As shown, add the Skybox Texture Editor as a component to the scene. You need to add the Skybox Texture Editor related components to the Unity project file in advance.
[0075] Step S200, creating a temporary sphere that wraps the scene, using a preset skybox material on the surface of the sphere to display a Skybox map; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and within the scene skybox.
[0076] After the Skybox texture editor is added in step S100 of the disclosed embodiment, it is necessary to open the Skybox texture editor first, and the Skybox texture editor creates a temporary sphere that wraps the scene, and uses the pre-set skybox material to display the Skybox texture on the surface of the sphere. The Skybox texture displayed on the surface of the sphere is exactly the same as the skybox texture displayed by the scene. The pre-set skybox material refers to the skybox material that has been configured and ready to use in the Skybox texture editor. The pre-set skybox material is associated with a pre-set skybox Shader, i.e., InverseCullCubeMapShader, which can quickly add a preview or default skybox texture to the sphere. It should be noted that there is only one skybox material in the scene of the Unity editor of the disclosed embodiment, so that the Skybox texture editor captures the same parameters of the skybox material used in the current scene for the pre-configured skybox material, i.e., the surface properties of the object, such as color, texture, etc., and the texture is the data formed by loading the texture into the memory. Therefore, the Skybox texture displayed on the surface of the sphere can be exactly the same as the skybox texture displayed by the scene. The pre-set skybox shader in the pre-set skybox material used by the Skybox Texture Editor is different from the Unity default shader in the scene. The pre-set skybox shader makes the skybox texture appear on the surface of the sphere, and can also modify the color of the texture. Figure 4 As shown, the Skybox texture editor creates a temporary sphere. The sphere is concentric with the scene and smaller than the skybox of the scene. The temporary sphere is wrapped around the objects in the scene, but inside the skybox that comes with the Unity engine. If there are characters in the scene, the characters are inside the temporary sphere. Each position and direction on the surface of the sphere can completely correspond to the scene Skybox, and there is a one-to-one mapping relationship. There are multiple layout formats for cube maps. The Unity engine will automatically identify the format and perform corresponding processing during rendering so that the cube map can be correctly rendered on the model. The cube map layout used in the disclosed embodiment is LatLong (latitude / longitude, sometimes called a cylinder). Under this layout, if the selection is close to the top or bottom of the sphere, the shape of the selection will be distorted into a trapezoid or fan, but the user can still achieve the desired effect by controlling the width and height of the selection and combining multiple modifications. Figure 5As shown in the figure, when the camera is inside the sphere, the observed inner surface of the sphere is visually consistent with the scene skybox texture. The sphere can be regarded as a reduced version of the scene skybox. To distinguish it from the skybox, there is a light-colored grid on the temporary sphere surface. The skybox material is referred to as the sphere material. The pre-set skybox material includes the pre-set skybox shader. The pre-set skybox material is configured in the Skybox texture editor and works with the Skybox texture editor.
[0077] The pre-set skybox material is associated with a pre-set skybox shader, which realizes the conversion of the direction vector in the 3D space into UV coordinates, that is, texture coordinates. That is, by realizing the DirectionToUV function, the direction vector in the scene is converted into texture coordinates.
[0078] The input of the DirectionToUV function is a three-dimensional floating point number, which is used to represent the direction vector; the output is a two-dimensional floating point number, which is used to represent the uv coordinate. The specific logic process is as follows:
[0079] Step S210: normalize the direction vector first to ensure that the length of the direction vector is 1, which is a necessary condition for converting the Cartesian coordinate system to the spherical coordinate system.
[0080] It should be noted that a direction vector refers to a three-dimensional vector that defines a specific direction in 3D space. This vector usually does not have a fixed starting point, but represents a specific direction and possible length starting from the origin. In 3D graphics and game development, such vectors are often used to represent the direction of the camera, the direction of the light source, or the normal direction of the surface of an object. Here, 3D space refers to the scene world space.
[0081] Step S220: Convert from Cartesian coordinate system to spherical coordinate system. Use atan2 and acos functions to convert the direction (x, y, z) coordinates in the Cartesian coordinate system to the spherical coordinate system coordinates (theta, phi), where theta represents longitude and phi represents latitude.
[0082] Step S230: Map (theta, phi) to the range of [0, 1], that is, convert from the spherical coordinate system to the uv coordinate system. Map the longitude theta from [-π, π] to [0, 1]; map the latitude phi from [0, π] to [0, 1].
[0083] Step S240: pass the uv coordinate in the format of a two-dimensional floating point number as a return value out of the function.
[0084] The code is implemented as follows:
[0085] float2 DirectionToUV(float3 direction)
[0086] {
[0087] / / Normalize the direction vector
[0088] direction = normalize(direction);
[0089] / / Convert Cartesian coordinates to sphericalcoordinates
[0090] float theta = atan2(direction.z, direction.x); / / Longitude
[0091] float phi = acos(direction.y); / / Latitude
[0092] / / Convert spherical coordinates to UV coordinates
[0093] float u = (theta + UNITY_PI) / (2.0 * UNITY_PI);
[0094] float v = phi / UNITY_PI;
[0095] return float2(u, v);
[0096] }
[0097] The UV coordinates can then be used to look up color information from the texture map to correctly apply the texture on the sphere surface. This conversion is used in real-time rendering of the sphere surface and lighting calculations, mapping the direction vector to the UV coordinates, and dynamically adjusting the appearance of the sphere surface under different viewing angles and lighting conditions.
[0098] Step S300: Selecting the area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area.
[0099] It should be noted that the selected area is the area to be edited. The pre-set skybox shader is used to render the scene skybox on the surface of the sphere. Figure 1The Skybox textures displayed on the surface of the sphere in steps S200 and S300 are all Skybox textures in the memory.
[0100] like Figure 6 As shown, before selecting the area and color of the lighting to be edited on the sphere, move the camera to the inside of the sphere and perform regional selection on the Skybox map on the surface of the sphere. In the method of the disclosed embodiment, the mouse and keyboard shortcuts can be used to select a specified area and color on the Skybox map on the surface of the sphere. The area is determined by the position, height and width, hereinafter referred to as the selection area, and the selection area can move with the mouse pointing. Displaying the selection area with the selected color plays a brightening role, making the selected area look brighter than the unselected area. The position of the selection area can be locked and unlocked using keyboard shortcuts. Locking makes the selection area no longer follow the mouse movement and unlocking. Unlocking makes the selection area continue to follow the mouse movement. The shortcut keys are set as follows: the selection area is unlocked by default. After unlocking, the selection area can be moved. Under unlocking, press the keyboard Ctrl and the right mouse button at the same time to lock the selection area position. In the locked state, press the keyboard Ctrl and the right mouse button at the same time to unlock. The width and height of the selection can also be adjusted using shortcut keys, which are set as follows: Press the keyboard Shift and the left mouse button at the same time, and move the mouse left and right to adjust the width of the selection. Move the mouse left to reduce the width and move the mouse right to increase the width. Similarly, press the keyboard Shift and the left mouse button at the same time, and move the mouse up and down to adjust the height of the selection. Move up to increase the height and move down to reduce the height. Then, select the color of the selection in the panel of the Skybox texture editor. The width, height and color of the selected area can also be adjusted in the panel of the Skybox texture editor. The position and size of the area of the lighting to be edited described in the disclosed embodiment can be arbitrarily selected according to actual conditions. In order to improve the lighting rendering effect, it is generally necessary to determine the area of the lighting to be edited multiple times.
[0101] Implement the highlight selection function. The highlight function is implemented by calculating the distance between the UV coordinates of any pixel and the center point HighLightUV of the highlight area in the screen space. If this distance is within a specified range, that is, the UV coordinates of any pixel are within the highlighted selection, that is, the X-axis coordinate distance from the pixel to the center point HighLightUV is less than or equal to AreaParams.x / 2+AreaParams.z, and the Y-axis direction from the pixel to the center point HighLightUV is less than or equal to AreaParams.y / 2+AreaParams.z, then the pixel is considered to be within the range of the highlight area, and the color of the pixel will be adjusted. _HighLightUV is the intersection position, the x, y, and z of _AreaParams are the selection width, selection height, and selection edge width, respectively, and _HDRColor is the selection color. Any point refers to a pixel on the screen.
[0102] The pre-set skybox material used on the surface of the sphere in the disclosed embodiment is improved based on the ordinary skybox (hereinafter referred to as the sphere material). The "sphere material" refers to the material specially made for the sphere, which includes the pre-set shader. The skybox texture editor captures the surface properties of objects with the same skybox material as the scene, such as color, texture, etc. The skybox shader is usually used to render the sky of the scene background to create the effect of a distant environment. The improved skybox shader can not only present the skybox image in the scene on the surface of the sphere, but also highlight the selected area with the selected color, enhancing visual feedback and interactivity.
[0103] The pre-set skybox shader is named InverseCullCubeMapShader, and works with the Skybox texture editor. The working principle is as follows:
[0104] Step S310, move the camera into the sphere, and use a selection tool to select the area and color of the lighting to be edited in the Skybox map on the surface of the sphere. The tool can be a mouse or keyboard, etc., wherein the area selected for the lighting to be edited includes the selection width, selection height, and selection edge width.
[0105] Step S320: The Skybox texture editor uses the current mouse position as the starting point, emits a ray along the camera's line of sight, intersects the ray with the sphere that wraps the scene, and obtains the world space position of the intersection.
[0106] Step S320, Skybox map editor sets the five parameters of intersection position, selection width, selection height, selection color, and selection edge width to the sphere material through the UnityEngine.Material.SetVector interface. The pre-set skybox shader used by the sphere material, namely InverseCullCubeMapShader, uses these parameters to calculate the selection generated by the specified area on the sphere, and highlights the selection using the selection color. The specified area is the area that the developer wants to specify, which can be understood as a set of parameters such as intersection position, selection width, and selection height. The selection generated by the mouse on the sphere is displayed on the screen at the same time after being calculated by the pre-set skybox shader.
[0107] It should be noted that the skybox shader is a program for graphics rendering that determines how to calculate and display the color and appearance of each pixel of an object. The preset skybox shader also has an additional function, which is the ability to identify and highlight the area selected by the user. When the user selects a part on the sphere, this part will be displayed in a specified color different from other areas to facilitate distinction or emphasis. This is very useful in interactive applications or editors, and can help users intuitively see the impact of selections or operations. In other words, based on the area selected by the developer on the surface of the sphere, the preset skybox shader calculates the highlighted area and displays it. The selection and color information are set to the material through the UnityMaterial.SetVector interface, and the special shader performs color overlay in the selection based on this information to achieve a highlight effect.
[0108] Step S400: modify the selected area in the Skybox map on the surface of the sphere to the target color, and modify the corresponding area between the original skybox map and the selected area of the Skybox map on the surface of the sphere to the target color.
[0109] The function of modifying the original skybox texture is implemented by the Skybox Texture Editor. The specific implementation method is as follows:
[0110] Step S410: Create a backup copy based on the original skybox texture for use in restoring the selected area.
[0111] In step S410, if there is no backup of the original skybox texture, the Skybox texture editor copies a backup according to the original skybox texture, and the backup file name is suffixed with "_Backup" for subsequent use when canceling the modification and restoring the selected area. Here, the backup is the skybox texture saved in the Assets folder of the hard disk project. The backup is also saved in the Assets folder of the hard disk project.
[0112] Step S420, calling UnityEngine.Texture2D.GetPixels() function to save the color of each pixel in the Skybox map loaded into the memory in an array.
[0113] In step S420, the Skybox texture editor calls UnityEngine.Texture2D.GetPixels() function to obtain the color of each pixel from the Skybox texture in memory and save it in an array. Here, the color of the Skybox texture loaded into memory is saved in the color array.
[0114] Step S430, using a double loop to traverse the entire array, calculate the distance from each pixel in the array to the center of the selection area according to the coordinates of each pixel, and if the pixel is within the selection area, change the color corresponding to the pixel in the array to the target color of the selection area.
[0115] In step S430, the Skybox texture editor uses a double loop to traverse the entire array and calculate the distance from each pixel in the array to the center of the selection area on the X and Y coordinate axes. If the X-axis distance is less than the sum of 1 / 2 of the selection area width and the width of the selection area edge and the Y-axis distance is less than the sum of 1 / 2 of the selection area height and the width of the selection area edge, that is, if the distance between the horizontal coordinate of the pixel and the horizontal coordinate of the selection area center is less than the sum of 1 / 2 of the selection area width and the width of the selection area edge and the distance between the vertical coordinate of the pixel and the vertical coordinate of the selection area center is less than 1 / 2 of the selection area height and the width of the selection area edge, then the pixel is considered to be within the selection area, and the color corresponding to the pixel in the array is changed to the target color of the selection area. It should be noted that step S430 only modifies the color values corresponding to each pixel in the selection area in the array, and does not modify the texture.
[0116] Step S440, calling UnityEngine.Texture2D.SetPixels(Color[] colors) function and UnityEngine.Texture2D.Apply() function to apply the color-modified array to the Skybox texture in memory.
[0117] After completing the traversal of the pixel color array in step S440, the Skybox texture editor calls the UnityEngine.Texture2D.SetPixels(Color[] colors) function and the UnityEngine.Texture2D.Apply() function to apply the modified color array to the Skybox texture in memory, completing the modification of the Skybox texture in memory. At this point, the selection of the modified skybox texture in memory has been modified to the target color, but the skybox texture file on the hard disk remains unmodified.
[0118] Step S450, calling UnityEngine.Texture2D.EncodeToEXR() function to encode the modified Skybox texture in the memory into a byte array.
[0119] In step S450, the Skybox texture editor also calls UnityEngine.Texture2D.Encode
[0120] deToEXR() converts the modified Skybox texture in memory into a byte array for easy saving to disk.
[0121] Step S460, call the System.IO.File.WriteAllBytes() function to save the byte array in the memory to the Skybox map file on the hard disk.
[0122] Specifically, the Skybox texture editor calls System.IO.File.WriteAllBytes() to save the encoded skybox texture byte array in memory as a .exr format skybox texture file on the hard disk, overwriting the original skybox texture on the hard disk, thus completing the modification of the original texture.
[0123] All functions starting with UnityEngine. mentioned in the above steps S410 to S460 are provided by the Unity engine. Functions starting with System. are provided by the programming language. The texture files saved here are consistent with the original texture format and can be imported into the Unity engine as cubemaps, and can also be correctly recognized and opened by other external tools.
[0124] In step S300 of the disclosed embodiment, a pre-set skybox shader is used to locate the area where the lighting needs to be modified. In step S400, the Skybox texture editor is used to modify the selected area in the Skybox texture on the surface of the sphere, and the original skybox texture and the corresponding area of the Skybox texture on the surface of the sphere are modified to the same color. Then, the colors of the scene skybox texture and the corresponding area of the selected area in the Skybox texture on the surface of the sphere will change at the same time. What is modified here is the color of the pixels corresponding to the selected area, and the ambient lighting information can be calculated based on the color. After modifying the color of the selected area in the Skybox texture on the surface of the sphere, use the "Apply Selected Area" of the Skybox texture editor to modify the color of the selected area of the sphere Skybox texture. At the same time, the Shader program samples the modified skybox texture, so that the color of the scene surface and the corresponding area of the selected area also changes accordingly, such as Figure 7 shown.
[0125] Step S500: recalculate the scene environment lighting according to the modified skybox map to redisplay the scene environment.
[0126] In the disclosed embodiment, the Unity engine applies the scene skybox map modified in step S400, calls the DynamicGI.UpdateEnvironment interface to recalculate the ambient lighting, and after the scene ambient lighting is recalculated in step S500, the scene ambient lighting also changes accordingly, that is, the object lighting also changes, resulting in the lighting effect after modifying the color of the corresponding area of the scene skybox map.
[0127] Step S600: Evaluate the lighting effect, and determine whether to accept or cancel the current lighting rendering editing according to the evaluation result.
[0128] Developers visually evaluate the lighting effect. During the evaluation, the camera is still inside the sphere. The developer can move the camera to observe the changes in the scene's lighting environment. After evaluating the lighting effect, the developer can decide whether to accept or cancel the edit. To cancel the edit, select the area to be canceled and click the "Restore Selected Area" button on the Skybox Editor to cancel the edit. If the "Restore Selected Area" button is not clicked and the next step is performed directly, the edit is accepted.
[0129] Step S700: repeat steps S300 to S600 once or multiple times until a preset ambient lighting result is obtained in the scene.
[0130] Specifically, the developer manually repeats step S300 to step S600 once or multiple times until a satisfactory ambient lighting result is obtained in the scene. The lighting rendering method of the disclosed embodiment can be used to modify each skybox map in the scene. When the Skybox map editor is closed, the temporary sphere disappears. The temporary sphere is equivalent to a virtual sphere, which provides a visually observable change effect for modifying the scene skybox map.
[0131] As an example of lighting rendering, after obtaining a satisfactory environmental lighting result, the method further includes:
[0132] Step S800: In the Unity editor, open the scene for pre-calculating SH coefficients.
[0133] Specifically, in step S800, in the Unity editor, open the scene edited in step S700 after lighting.
[0134] , add the pre-configured environment lighting management class Class EnvironmentLight as a component to the scene, that is, add the pre-configured environment lighting management class related components to the Unity engine project file.
[0135] Step S900: Add the pre-configured environment lighting management class as a component to the scene.
[0136] The disclosed embodiment uses C# to implement an environment lighting management class EnvironmentLight, and ClassEnvironmentLight can be abbreviated as EnvironmentLight; the member variables of the environment lighting management class include serializable SH (UnityEngine.Rendering.Spherical HarmonicsL2) coefficients, skybox, environment sky color, environment lighting intensity, default reflection mode, custom environment reflection map, reflection intensity and number of reflections, etc. These parameters are basically consistent with the options of the Environment tab in the Lighting window of the Unity editor. The above parameters may be different in different versions of the Unity editor. These parameters are settings related to the environment lighting effect of the current scene. The member methods of the environment lighting management class EnvironmentLight include the ChangeEnvLight method and the Save method. The Save method is used to save the SH coefficients corresponding to each skybox in the scene.
[0137] Step S900A, calculate the SH coefficient corresponding to each skybox in the scene.
[0138] It should be noted that the SH coefficient corresponding to each skybox in the scene is calculated by the SH coefficient pre-calculation module in the Unity engine.
[0139] Step S900B, the Save method saves the objects containing the SH coefficients and related parameters corresponding to each skybox in the scene to the preset environment lighting management class EnvironmentLight, so that when the scene skybox is switched in actual application, the preset ChangeEnvLight method is used to overwrite the Unity engine variables with the pre-saved corresponding SH coefficients, thereby calculating the corresponding environment lighting.
[0140] After calculating the SH coefficients corresponding to each skybox in the scene, the Save method saves the SH coefficients corresponding to each skybox in the scene to the preset environment light management class EnvironmentLight. The Save method is only called in the Unity editor, and can save the environment light related parameters in the current scene to the environment light management class EnvironmentLight, so that all parameters including the SH coefficient are saved with the scene. The environment light related parameters refer to the above SH coefficient, skybox, environment sky color, environment light intensity, default reflection mode, custom environment reflection map, reflection intensity and number of reflections.
[0141] After the SH coefficients corresponding to each skybox in the scene are calculated and saved in the preset environment lighting management class of the Unity editor during the development process of the above step S900A, during the actual application of the game or 3D model, the ChangeEnvLight method can apply the parameters including the SH coefficients pre-saved in the EnvironmentLight class to RenderSettings, which is the Unity engine variable and contains a series of rendering-related variables. The ChangeEnvLight method can be called both when the game is running and in the Unity editor, and the modification of the engine's RenderSettings will immediately affect the lighting of the game scene.
[0142] SH coefficient pre-calculation module, used for SH coefficient calculation, serialization and application in Unity engine. This module uses the third-order polynomial SH representation defined by Unity, also known as L2 spherical harmonic function, such as Figure 8As shown. They are stored using 27 floating point values, of which the 0th order does not use floating point values, the 1st order uses 12 floating point values, and the 2nd order uses 15 floating point values. The calculation of the SH coefficient refers to the calculation of the integral of the spherical harmonic function on the six faces of the skybox map. The pseudo code for the integral calculation is as follows:
[0143] float f[],s[];
[0144] float fWtSum=0;
[0145] Foreach(cube map face)
[0146] Foreach(texel)
[0147] float fTmp = 1 + u^2+v^2;
[0148] float fWt = 4 / (sqrt(fTmp)*fTmp);
[0149] EvalSHBasis(texel,s);
[0150] f += t(texel)*fWt*s;
[0151] fWtSum += fWt;
[0152] f *= 4*Pi / fWtSum;
[0153] The L2 spherical harmonic function only uses the 2nd order, which has the advantage that the 2nd order is sufficient to represent the low-frequency illumination information in all directions, and the number of SH coefficients is small, which is convenient for calculation and storage; the SH used by the Unity engine by default is the 2nd order. In the method of the disclosed embodiment, the SH coefficient pre-calculation module does not modify the principle of SH calculation and application, but changes the timing of SH calculation, calculates the SH coefficient in advance and saves it. When the client runs the application, it directly calls the pre-stored SH coefficient to calculate the ambient illumination of the corresponding scene, thereby improving the performance of the game when it is running.
[0154] As a specific example of calculating the SH coefficient corresponding to each skybox in the scene, the SH coefficient corresponding to each skybox in the scene is calculated and saved to a preset ambient light management class, including:
[0155] When the scene is switched to the required skybox manually or programmatically, if the skybox is switched manually, the Unity engine will automatically recalculate SH; if the skybox is switched programmatically, the DynamicGI.UpdateEnvironment interface needs to be called again to calculate SH; when the game is running, there is no Unity editor panel, and manual switching is not possible. You can only use programmatic switching, and then manually call the DynamicGI.UpdateEnvironment interface to trigger SH recalculation.
[0156] After adjusting the ambient lighting effect of the scene to a satisfactory effect, manually call the Save method of the ambient lighting management class once to save the UnityEngine.Rendering.SphericalHarmonicsL2 object containing the SH coefficient and other parameters to the pre-set ambient lighting management class. When the developer saves the scene, it will be serialized and saved in the scene file.
[0157] Serializing SH into the scene helps the game run directly to apply the saved SH coefficients instead of recalculating the SH coefficients from the Skybox map. Every time the game switches scenes, the ChangeEnvLight method of the ambient lighting management class is called to overwrite RenderSettings.ambientProbe, the Unity engine variable, with the pre-calculated and saved SH coefficients in the ambient lighting management class, and the ambient lighting can be successfully applied and take effect immediately.
[0158] The disclosed embodiment creatively provides a real-time Skybox map editor integrated in the Unity editor. This editor allows developers to modify the color values of any range of pixels on the Skybox map directly in the engine without the help of external tools, and highlight the selected range and the modified lighting effect in real time, thus achieving efficient and convenient environmental lighting editing capabilities.
[0159] The disclosed embodiment also creatively provides a technical solution for serializing pre-calculated SH coefficient data and applying it to the game runtime. In order to avoid the performance overhead caused by real-time calculation of SH at runtime, the disclosed embodiment serializes the pre-calculated SH data and directly uses these serialized data for environmental lighting rendering when the game is running, avoiding lag and also avoiding the lighting data differences caused by differences in device texture compression format support when calculating SH in real time.
[0160] like Fig. 9 As shown, another aspect of the present disclosure provides an environment lighting rendering system, which is applied to the Unity editor. The system includes:
[0161] An opening module 100 is used to open a scene of lighting to be edited;
[0162] Skybox texture editor 200, used to create a temporary sphere that wraps the scene, and use a preset skybox material on the surface of the sphere to display the skybox texture; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and within the scene skybox;
[0163] It is also used to select the area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area;
[0164] It is also used to modify the selected area in the skybox map on the surface of the sphere to the target color, and at the same time, the corresponding area between the original skybox map and the selected area of the skybox map on the surface of the sphere is modified to the target color;
[0165] The ambient lighting calculation module 300 is further used to recalculate the scene ambient lighting according to the modified skybox map.
[0166] In the system of the embodiment of the present disclosure, the opening module 100 and the ambient lighting calculation module 300 both belong to the original Unity editor. The Skybox map editor 200 is a component newly added to the Unity editor. The opening module 100 is also used to open the scene of pre-calculated SH coefficients in the Unity editor. The SH coefficient pre-calculation module is used to calculate the SH coefficients corresponding to each skybox in the scene.
[0167] The system further comprises: an ambient lighting management class, wherein the member methods of the ambient lighting management class comprise a ChangeEnvLight method and a Save method;
[0168] The Save method is used to save the objects containing SH coefficients and related parameters corresponding to each skybox in the scene calculated by the SH coefficient pre-calculation module to a preset ambient lighting management class.
[0169] In the actual running of the relevant application, when the scene skybox is switched, the ChangeEnvLight method is used to overwrite the Unity engine variable with the corresponding SH coefficient saved in advance. The adding module is used to add the pre-designed Skybox map editor 200 to the scene, and is also used to add the pre-configured environment lighting management class as a component to the scene.
[0170] The workflow of the environment lighting editing and application provided by the embodiment of the present disclosure is as follows, which uses a skybox texture editor module and an SH coefficient pre-calculation module. Among them, the skybox texture editor module belongs to the improvement of the embodiment of the present disclosure, and the SH coefficient pre-calculation module belongs to the application of the prior art.
[0171] Another aspect of the disclosed embodiment provides a computer device, which includes: a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded by the processor to execute the lighting rendering method as described above.
[0172] On the other hand, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement the lighting rendering method as described above.
[0173] The Skybox texture editor module is used to edit the Skybox texture in the Unity editor and preview the ambient lighting effect it produces in real time. The steps for ambient lighting editing are as follows:
[0174] Step 1: Open the scene where you want to edit lighting in the Unity editor and click the button from the Unity toolbar to add the Skybox Texture Editor to the scene.
[0175] Step 2: The Skybox Editor creates a temporary sphere that can wrap the scene. On the surface of the sphere, a special skybox shader material (hereinafter referred to as the sphere material) based on the ordinary skybox shader is used to display the skybox map and highlight the selected area with the specified color. This special shader is named InverseCullCubeMapShader and works with the Skybox Editor. The working principle is as follows:
[0176] The Skybox Editor uses the current mouse position as the starting point, emits a ray along the camera direction, and intersects the ray with the sphere that wraps the scene. After obtaining the world space position of the intersection point, the Skybox Editor sets the five parameters of the intersection point position, selection width, selection height, selection color, and selection edge width to the sphere material through the UnityEngine.Material.SetVector interface. The InverseCullCubeMapShader used by the sphere material uses these parameters to calculate the selection area generated by the specified area on the sphere and highlight the selection area using the selection color.
[0177] Step 3: The developer uses a special shader to quickly locate the area that needs to be modified. Use the "Apply to Selected Area" button or keyboard shortcuts in the Skybox Texture Editor to modify the color of the sphere's Skybox texture selection. At the same time, make the same modification to the color of the corresponding area of the original skybox texture and the Skybox texture selection on the sphere's surface.
[0178] Step 4: The Unity engine applies the scene skybox map modified in step 3 and calls the DynamicGI.UpdateEnvironment interface to recalculate the ambient lighting. After evaluating the lighting effect, the developer chooses to accept or cancel the edit, selects the area to be canceled, and clicks the "Restore Selected Area" button on the Skybox Editor.
[0179] Step 5: The developer manually repeats steps 2 to 4 one or more times until a satisfactory ambient lighting result is obtained in the scene.
[0180] SH coefficient pre-calculation module, used for SH coefficient calculation, serialization and application in Unity engine. This module uses the third-order polynomial SH representation defined by Unity (also known as L2 spherical harmonics). They are stored in 27 floating-point values, of which the 0th order does not use floating-point values, the 1st order uses 12 floating-point values, and the 2nd order uses 15 floating-point values.
[0181] The calculation of the SH coefficient refers to the calculation of the integral of the spherical harmonics on the six surfaces of the skybox map. The pseudo code for the integral calculation is as follows:
[0182] float f[],s[];
[0183] float fWtSum=0;
[0184] Foreach(cube map face)
[0185] Foreach(texel)
[0186] float fTmp = 1 + u^2+v^2;
[0187] float fWt = 4 / (sqrt(fTmp)*fTmp);
[0188] EvalSHBasis(texel,s);
[0189] f += t(texel)*fWt*s;
[0190] fWtSum += fWt;
[0191] f *= 4*Pi / fWtSum;
[0192] This module does not modify the principles of SH calculation and application, but changes the timing of SH calculation to improve the performance of the game when it is running. The working steps are as follows:
[0193] Step 1: Use C# to implement an environment lighting management class (Class EnvironmentLight). The member variables of this class include serializable UnityEngine.Rendering.SphericalHarmonicsL2 (SH coefficient) and parameters such as environment lighting intensity, environment reflection intensity, and custom environment reflection map. The member methods of this class include ChangeEnvLight and Save. The Save method is only called in the Unity editor. It can save the environment lighting related parameters in the current scene to the EnvironmentLight class, so that the parameters including the SH coefficient are saved with the scene. The ChangeEnvLight method can be called in the Unity editor and when the game is running. The parameters including the SH coefficient saved in the EnvironmentLight class can be applied to the RenderSettings (Unity engine variables, containing a series of rendering-related variables). Modifications to the engine's RenderSettings will immediately affect the lighting of the game scene.
[0194] Step 2: In the Unity editor, open the scene that needs to precalculate the SH coefficient and add the ambient lighting management class as a component to the scene.
[0195] Step 3: Manually / programmatically switch the scene to the required skybox: If you manually switch the skybox, the Unity engine will automatically recalculate SH; if you programmatically switch the skybox, you need to call the DynamicGI.UpdateEnvironment interface again to calculate SH.
[0196] Step 4: The artist adjusts the ambient lighting effect of the scene. During the adjustment process, the Unity editor automatically recalculates SH. After obtaining a satisfactory effect, manually call the Save method of the ambient lighting management class once, and the UnityEngine.Rendering.SphericalHarmonicsL2 object containing the SH coefficient will be saved to the ambient lighting management class and serialized into the scene along with the scene. Serializing SH into the scene helps the game run directly to apply the saved SH coefficient instead of recalculating the SH coefficient from the skybox map.
[0197] Step 5: Every time you switch scenes during game operation, call the ChangeEnvLight method of the ambient lighting management class, and overwrite RenderSettings.ambientProbe (Unity engine variable) with the SH coefficient pre-calculated and saved in the ambient lighting management class, so that ambient lighting can be successfully applied and take effect immediately.
[0198] By adopting the above technical solution disclosed in the embodiment of the present disclosure, the following beneficial effects are obtained:
[0199] 1. Solved the problem of low efficiency in Skybox texture editing. By implementing a real-time Skybox texture editor, developers can modify the color of any pixel in the Skybox texture directly and efficiently in the Unity engine without using external image editing software. Enhanced the real-time visual preview capability of lighting effects, the editor that integrates Skybox editing and SH pre-calculation functions enables developers to view the impact of texture editing effects on ambient lighting in real time, greatly enhancing the intuitiveness and real-time feedback capabilities of lighting editing, and greatly improving the editing experience and efficiency.
[0200] 2. Effectively avoids the problem of freezing during game operation. Since the technical solution of the disclosed embodiment pre-calculates and caches the spherical harmonic coefficient data of ambient lighting, when switching Skybox or adjusting related parameters during game operation, it will no longer trigger the resource-consuming real-time SH recalculation process, which fundamentally eliminates the occurrence of freezing problems and greatly improves the operation experience.
[0201] 3. Ensure the consistency of ambient lighting rendering results on different devices. In view of the differences in mobile devices' support for Skybox map compression formats, the technical solution of the disclosed embodiment uses uncompressed raw data for unified SH pre-calculation, so that the ambient lighting rendering results of all devices are highly consistent, improving the portability of the game.
[0202] The above is only a preferred implementation of the embodiment of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the embodiment of the present disclosure. These improvements and modifications should also be considered as the protection scope of the embodiment of the present disclosure.
Claims
1. An ambient lighting rendering method, characterized in that: The method comprises: Open the scene whose lighting is to be edited; Creating a temporary sphere that wraps the scene, using a preset skybox material on the surface of the sphere to display a skybox map; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and within the scene skybox; Selecting an area and a color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area; The selected area in the Skybox map on the surface of the sphere is modified to the target color, and the corresponding area between the original skybox map and the selected area of the Skybox map on the surface of the sphere is modified to the target color; Recalculate the scene ambient lighting based on the modified skybox map.
2. The method according to claim 1, characterized in that The step of selecting the area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area, includes: Use the selection tool to select the area and color of the lighting to be edited in the Skybox map on the surface of the sphere. The area selected for the lighting to be edited includes the selection width, selection height, and selection edge width. Taking the current position of the tool as the starting point, emitting a ray along the camera line of sight, calculating the intersection of the ray and the sphere, and obtaining the world space position of the intersection, wherein the starting point is the center point of the selection area; Set five parameters, namely, the intersection position, the selection width, the selection height, the selection color and the selection edge width, to the sphere material, wherein the sphere material is a pre-set skybox material; The sphere material displays the selected area using the selected color according to the intersection position, the selected area width, the selected area height, the selected area color, and the selected area edge width.
3. The method according to claim 1, characterized in that: The method of using a preset skybox material on the surface of the sphere to display a skybox map includes: Use the DirectionToUV function to convert the direction vector inside the sphere into UV coordinates; Render the surface of the sphere in real time according to the color in the texture map corresponding to the UV coordinates.
4. The method according to any one of claims 1 to 3, characterized in that The step of modifying the selected area in the Skybox map on the surface of the sphere to the target color, and modifying the corresponding area between the original skybox map and the selected area in the Skybox map on the surface of the sphere to the target color, includes: Back up the Skybox texture, which is used to cancel the color modification and restore the selected area; Call UnityEngine.Texture2D.GetPixels() to save the color of each pixel in the Skybox map loaded into memory in an array; Use a double loop to traverse the entire array, and calculate the distance from each pixel in the array to the center of the selection according to the coordinates of each pixel. If the pixel is within the selection, change the color corresponding to the pixel in the array to the target color of the selection; Call UnityEngine.Texture2D.SetPixels(Color[] colors) function and UnityEngine.Texture2D.Apply() function to apply the modified color array to the Skybox map in memory; Call UnityEngine.Texture2D.EncodeToEXR() to encode the modified Skybox texture in memory into a byte array; Call the System.IO.File.WriteAllBytes() function to save the byte array in the memory to the Skybox map file on the hard disk.
5. The method according to any one of claims 1 to 3, characterized in that: After recalculating the scene ambient lighting, the method further includes: Evaluate the lighting effect, and decide whether to accept or cancel the current lighting rendering edit based on the evaluation results; Repeat the steps of selecting the area and color of the lighting to be edited on the Skybox map on the surface of the sphere and the subsequent steps until a preset ambient lighting result is obtained in the scene.
6. The method according to claim 5, characterized in that After obtaining the preset ambient lighting result, the method further includes: Open the scene with pre-calculated SH coefficients; Add a pre-configured environment lighting management class as a component to the scene, wherein the member methods of the environment lighting management class include a ChangeEnvLight method and a Save method; Calculate the SH coefficient corresponding to each skybox in the scene; The Save method saves the objects containing the SH coefficients corresponding to each skybox in the scene to the preset ambient lighting management class. Along with the saving of the scene, the SH coefficients are serialized and saved in the scene file. This is used when the scene skybox is switched during the actual running of related applications. The ChangeEnvLight method uses the corresponding SH coefficients saved in advance to overwrite the Unity engine variables.
7. The method according to claim 6, characterized in that The SH coefficients corresponding to each skybox in the calculation scene include: When the scene switches the skybox manually or programmatically, if the skybox is switched manually, the Unity editor will automatically recalculate the SH coefficient; if the skybox is switched programmatically, the corresponding interface will be called to calculate the SH coefficient.
8. An ambient lighting rendering system, characterized in that: The system comprises: Open module, used to open the scene to be edited; Skybox texture editor, used to create a temporary sphere that wraps the scene, and use a preset skybox material on the surface of the sphere to display the skybox texture; wherein the temporary sphere coincides with the center of the scene, and wraps around the objects in the scene and inside the scene skybox; It is also used to select the area and color of the lighting to be edited on the Skybox map on the surface of the sphere, wherein the color is used to display the selected area; It is also used to modify the selected area in the Skybox map on the surface of the sphere to the target color, and at the same time, the corresponding area between the original skybox map and the selected area of the Skybox map on the surface of the sphere is modified to the target color; The ambient lighting calculation module is used to recalculate the scene ambient lighting according to the modified skybox map.
9. A computer device, characterized in that: The computer device comprises: a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded by the processor and executes the illumination rendering method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement the lighting rendering method according to any one of claims 1 to 7.
