A Post-Processing Point Light Source Rendering Method Based on Cesium
By defining GLSL cimal shaders and custom shaders in Cesium, the bottlenecks in point light source rendering performance and insufficient effect authenticity in the existing technology are solved, and efficient and real multi-light lighting and shadow effects are achieved, improving the quality and user experience of three-dimensional visualization.
Patent Information
- Application Number
- CN202411563189.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2044-11-05
AI Technical Summary
The existing Cesium-based point light source rendering technology has problems such as performance bottlenecks, insufficient effect authenticity, limited light source processing capabilities and insufficient custom scalability, making it difficult to achieve high-quality lighting effects in complex scenarios.
By defining the fragment shader written in GLSL, efficient point light source rendering is achieved and flexible parameter adjustment interface is provided. This method includes configuring light source parameters, calculating shadow effects using depth maps, and creating custom shaders to suit different scenario needs.
It realizes efficient rendering of multi-light lighting and shadow effects, improves the realism and visual effects of the scene, enhances the immersion of users, and simplifies the light source management process, improves the development efficiency and system scalability.
Smart Images

Figure CN119273832B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of three-dimensional graphics rendering, and particularly relates to a post-processing point light source rendering method based on Cesium. Background Art
[0002] In computer graphics and three-dimensional scene rendering, light sources are important factors for enhancing the realism and vividness of scenes. As a lightweight open-source JavaScript library, Cesium is widely used in the development of virtual scenes, such as flight simulations, 3D GIS, etc. However, Cesium's rendering engine does not directly support the post-processing effects of point light sources, which limits its application in complex lighting scenarios.
[0003] With the continuous development of computer graphics and three-dimensional visualization technologies, point light source rendering, as an important method for realizing visual effects, is widely used in fields such as games, movies, virtual reality, and augmented reality. As an open-source three-dimensional earth platform, Cesium provides powerful spatial data visualization capabilities. However, there are still some significant drawbacks in the current point light source rendering technology based on Cesium, which to a certain extent limit its effects and performance in practical applications. First, existing point light source rendering methods often show significant performance bottlenecks when dealing with dynamic changes in light sources. Traditional rendering technologies lack support for real-time updates and dynamic effects of light sources, especially in scenarios where a large number of light sources need to be rendered, and the performance degradation is particularly obvious. This performance bottleneck not only affects the smoothness of rendering but also leads to a decline in the user interaction experience.
[0004] Existing point light source rendering technologies have deficiencies in light calculation and effect performance. Many traditional methods use simple lighting models and cannot accurately simulate lighting effects in the real world, such as complex lighting phenomena like shadows, reflections, and refractions. Although this simplified processing improves the rendering speed to a certain extent, it sacrifices the authenticity of the rendering effect, resulting in an unsatisfactory final visual effect. In addition, current technologies also have limitations in the processing of the number and distribution of light sources. Due to performance and computational limitations, many systems can only handle a limited number of light sources and cannot achieve realistic lighting effects in large scenes. This limitation restricts the application of point light source rendering in complex scenes and cannot meet the requirements of high-quality visualization.
[0005] Existing rendering algorithms often involve a trade-off between real-time performance and accuracy, making it difficult for the system to find the optimal balance in different application scenarios. For applications that require high real-time performance, such as virtual reality and interactive games, overly complex lighting calculations will cause stuttering in the scene. For applications that pursue fine rendering effects, a smooth experience cannot be achieved due to excessive consumption of computing resources. Existing point light source rendering technologies also have deficiencies in user customization and scalability. Many systems cannot flexibly support users in customizing light source parameters, restricting users' creativity and the diversity of application scenarios. This is particularly inconvenient for professional application scenarios that require specific lighting effects. Therefore, a post-processing point light source rendering method based on Cesium is developed, aiming to solve the performance bottlenecks, insufficient authenticity of effects, limited light source processing capabilities, and insufficient custom scalability in current technologies by introducing a more efficient lighting calculation model and optimizing the rendering algorithm, thereby providing higher-quality visual effects and a smoother user experience. This will provide important support for the wide popularization and in-depth development of 3D visualization applications. Therefore, there is an urgent need for a post-processing point light source rendering method based on Cesium. Summary of the Invention
[0006] The present invention proposes a post-processing point light source rendering method based on Cesium. Currently, Cesium's rendering engine does not directly support the post-processing effect of point light sources, so other methods need to be used to achieve it. Point light sources need to consider the range and intensity of light, while Cesium's default rendering method does not provide direct control over these parameters. It aims to write a fragment shader in GLSL to achieve an efficient point light source effect and provide a flexible parameter adjustment interface to adapt to different scene requirements.
[0007] The technical solution of the present invention is implemented as follows: A post-processing point light source rendering method based on Cesium, the method comprising the following steps:
[0008] S1: First, define a shader. Calculate lighting and shadows through a fragment shader. Write the fragment shader in GLSL to process multiple light sources with and without shadows respectively; define the inputs and constants of the shader through code, perform corresponding processing on the color texture and depth texture, and pass the data from the vertex shader to the fragment shader through variables;
[0009] S2: Configure the light source parameters according to the processing status of the fragment shader, and pass the light source parameters to the shader through uniform; define the associated attributes of the light sources in the scene when configuring the light source parameters, and the associated attributes include the position, intensity, color, shadow matrix, and placeholders for shadow maps of the light sources;
[0010] S3: Calculate the lighting effect according to the light source type, calculate the shadow effect using the depth map, and determine whether the fragment shader is in the shadow; and use the fragment shader for graphics rendering through the core code to calculate the color value of each pixel, where the core code is written in GLSL.
[0011] S4: Create a custom shader, pass the light source parameters to the Cesium rendering pipeline, apply the custom shader to the Cesium scene to achieve multi-light source lighting effects. By performing multi-light source lighting and shadow effects in Cesium, enhance the realism and visual effects of the scene and utilize the performance of GLSL to ensure efficient and real-time rendering.
[0012] Compared with the existing technologies, this post-processing point light source rendering method based on Cesium demonstrates significant advantages and innovations. First of all, the existing point light source rendering technologies often rely on traditional fixed lighting models and lack the flexible processing ability for multi-light source environments. Many systems can only support simple light source configurations in the calculation of lighting effects and cannot effectively handle the multi-light source lighting requirements in complex scenes. However, this method can handle multi-light source situations with and without shadows by defining the fragment shader and using flexible code written in GLSL, greatly enhancing the flexibility and adaptability of light source configuration. This flexibility enables developers to more easily achieve complex lighting effects in various application scenarios and meet different user needs.
[0013] The current technologies usually adopt relatively simple algorithms in shadow processing and often cannot accurately simulate the shadow characteristics in the real world, resulting in insufficient authenticity of the rendering effect. Many existing rendering methods rely on pre-generated shadow maps in shadow calculation and lack dynamic adaptation ability, resulting in unnatural shadow effects in dynamic scenes. However, this method can calculate the shadow effect using the depth map, can judge in real time whether the fragment is in the shadow, and achieves a more realistic shadow performance through dynamic calculation. This real-time judgment ability makes the lighting effect more realistic and also enhances the user's immersion.
[0014] The existing methods are often complex in the configuration of light source parameters and lack a unified management mechanism, resulting in cumbersome manual settings for developers when adjusting the light source. In contrast, this method can conveniently configure the attributes of the light source, including position, intensity, color, etc. in the fragment shader by passing the light source parameters to the shader through uniform. Such a design simplifies the light source management process, makes the development process more efficient, and also reduces the error rate.
[0015] The design of this method in creating custom shaders also reflects its difference from the prior art. Many traditional rendering systems have limitations in scalability and are difficult to meet specific requirements. By creating custom shaders and passing light source parameters to the Cesium rendering pipeline, developers can flexibly adjust and expand the rendering effects, make full use of the performance advantages of GLSL, and ensure efficient and real-time rendering performance. This flexibility not only improves the development convenience but also provides a good foundation for subsequent function expansion.
[0016] The improvement of the overall rendering effect is also a major advantage of this method. When the prior art processes multi-light sources and shadow effects, it often faces performance bottlenecks, resulting in poor real-time rendering effects. However, this method realizes multi-light source illumination and shadow effects in Cesium and utilizes the high-performance computing ability of GLSL to ensure the efficiency and smoothness of rendering. This enables users to obtain a more realistic visual experience when browsing the 3D scene, enhancing the immersion and interactivity of the scene.
[0017] As a preferred embodiment, the fragment shader data includes texture coordinates, normals, and positions. Constants and arrays of the light source are defined through the shader data. The position of the fragment is transformed into the shadow coordinate system through the shadow matrix of the light source, and perspective division is performed to obtain the corresponding depth value from the shadow map and compare it with the depth of the current fragment.
[0018] As a preferred embodiment, when configuring the light source parameters, an array of light source positions is first defined. The array contains the positions of four light sources, each position is represented by an object, and a four-dimensional vector is set. The four-dimensional vector contains the x, y, z coordinates and the homogeneous coordinate w.
[0019] As a preferred embodiment, the shadow matrix transforms the light source coordinates into the shadow map space, and calculates the shadows of the objects in the scene in the shadow map space. The shadow map is used to store the depth information of the objects in the scene relative to the light source.
[0020] As a preferred embodiment, when the core code is written in GLSL, the shadow effect of a specific light source is calculated through a function. The position of the current fragment is transformed into the coordinates in the shadow coordinate system by using the elements in the function, and the shadow coordinates are transformed into the normalized device coordinates; in the main shading function, the base color of the current fragment is obtained through the color texture, then its color components are extracted, and the normal vector is normalized. By looping through all the light sources, the contribution of each light source to the current fragment is calculated.
[0021] As a preferred embodiment, when applying a custom shader to a Cesium scene, first create a new CesiumViewer instance, attach it to an HTML element, obtain the scene object of the current Viewer, and control the rendering details by accessing the scene object.
[0022] After adopting the above technical solution, the beneficial effects of the present invention are as follows: Through the custom GLSL shader, multi-light source illumination and shadow effects are achieved, making the Cesium scene more realistic. Using the depth map to calculate the shadow effect improves the accuracy and realism of the shadow. By using the flexible code written in the fragment shader and GLSL, this method can effectively handle the multi-light source situations with and without shadows, greatly enhancing the flexibility of light source configuration and meeting the multi-light source illumination requirements in complex scenes. Secondly, the ability to calculate the shadow effect in real time improves the realism of the rendering, making the lighting effect in the scene more natural and enhancing the user's immersion. In addition, the design of passing the light source parameters to the shader through uniform simplifies the light source management process, improves the development efficiency, and reduces the error rate. Creating a custom shader and passing the light source parameters to the Cesium rendering pipeline enables developers to flexibly adjust and expand the rendering effect, enhancing the scalability and adaptability of the system. At the same time, using the high-performance computing power of GLSL ensures the efficiency and smoothness of the rendering, enabling users to obtain a more realistic visual experience when browsing the 3D scene. Finally, by improving the overall rendering effect, this method enhances the realism and visual effect of the scene, provides a more efficient and flexible solution for 3D visualization and graphics rendering, and promotes the further development and innovation of related applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0024] Figure 1 It is a schematic diagram of the overall structure of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, rather than all of them. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.
[0026] Example:
[0027] As Figure 1 shown, a post - processing point light source rendering method based on Cesium, the method comprising the following steps:
[0028] S1: First, define the shader. Calculate lighting and shadows through the fragment shader. Write the fragment shader using GLSL to handle multiple light sources with and without shadows respectively. Define the inputs and constants of the shader through code, perform corresponding processing on the color texture and depth texture, and pass the data from the vertex shader to the fragment shader through variables;
[0029] S2: Configure the light source parameters according to the processing status of the fragment shader, and pass the light source parameters to the shader through uniform. Define the associated attributes of the light sources in the scene when configuring the light source parameters. The associated attributes include the position, intensity, color, shadow matrix, and placeholder for the shadow map of the light source;
[0030] S3: Calculate the lighting effect according to the light source type, calculate the shadow effect using the depth map, and determine whether the fragment shader is in the shadow. Calculate the color value of each pixel using the fragment shader for graphics rendering through the core code, and the core code is written using GLSL;
[0031] S4: Create a custom shader, pass the light source parameters to the Cesium rendering pipeline, apply the custom shader to the Cesium scene to achieve the multi - light source lighting effect. Improve the realism and visual effect of the scene by performing multi - light source lighting and shadow effects in Cesium, and utilize the performance of GLSL to ensure the efficiency and real - time nature of the rendering.
[0032] The working principle and operation steps of this post - processing point light source rendering method based on Cesium can be specifically described as follows:
[0033] First of all, defining the shader is the basis of the entire rendering process. Calculate lighting and shadows through the fragment shader. The fragment shader written using GLSL (OpenGL Shading Language) is responsible for applying the influence of the light source to each pixel in the scene. The fragment shader handles the cases of multiple light sources with and without shadows. Define the inputs and constants of the shader through code, enabling the shader to receive the necessary texture data, such as color texture and depth texture. This step ensures that during the rendering process, the calculation of lighting and shadows is accurate and can provide the required data for subsequent processing.
[0034] Next, configure the light source parameters according to the processing status of the fragment shader and pass these parameters to the shader through uniform. When configuring the light source parameters, define the associated attributes of the light source in the scene, including the position, intensity, color, shadow matrix, and placeholder for the shadow map of the light source. In this way, the characteristics of the light source can be adjusted flexibly to meet the requirements of different scenes. This parameterized design makes the adjustment and management of the light source more efficient and enables rapid light source configuration when rendering different scenes.
[0035] Then, calculate the lighting effect according to the light source type, calculate the shadow effect using the depth map, and determine whether the fragment shader is in the shadow. This process involves using the depth map to determine which fragments in the scene are in the shadow. The core code uses the fragment shader of graphics rendering to calculate the color value of each pixel. This step is crucial because it determines the lighting quality and realism of the scene. Writing the core code in GLSL can make full use of the parallel processing power of the GPU, thereby improving the rendering efficiency and real-time performance.
[0036] Finally, create a custom shader, pass the light source parameters to the Cesium rendering pipeline, apply the custom shader to the Cesium scene, and achieve the multi-light source lighting effect. By calculating the multi-light source lighting and shadow effects in Cesium, the realism and visual effect of the scene can be significantly improved. Utilize the performance of GLSL to ensure efficient rendering and real-time updates. The implementation of the custom shader enables developers to adjust the lighting model according to specific requirements, thereby achieving more complex lighting effects and visual performances.
[0037] There are several important reasons for the setting and operation of this method: Flexibility: By defining the shader and configuring the light source parameters, developers can adjust flexibly according to the requirements of different scenes and adapt to various lighting conditions; Performance optimization: The shader written in GLSL can make full use of the computing power of the GPU, improve the rendering efficiency, and ensure real-time performance; Enhanced realism: The multi-light source lighting and shadow effects can significantly enhance the realism of the scene, making the visualization effect more natural and realistic; Scalability: The design of the custom shader allows new light source types to be added or the existing lighting model to be improved according to future needs, with good scalability; Efficient data management: Passing the light source parameters through uniform ensures the efficiency and simplicity of data transfer, avoiding excessive state switching and data transfer overhead; Shadow processing: The use of the depth map makes shadow calculation efficient and controllable, enabling high-quality shadow effects while maintaining performance.
[0038] The specific explanations for the specific operation steps of this application document are as follows
[0039] The specific operation part of step S1:
[0040] The multi - light illumination, shadow calculation, and final color output are processed through a fragment shader program for graphics rendering. The code follows the syntax of the OpenGL Shading Language (GLSL). By calculating the input texture, light source information, and the normal vector of the object, the final color value is generated.
[0041] First, the code defines some inputs and constants of the shader. The uniform sampler2D colorTexture; and uniform sampler2D depthTexture; are used to receive the color texture and depth texture respectively. The varying variables are used to transfer data from the vertex shader to the fragment shader, including texture coordinates, normals, and positions.
[0042] Next, constants and arrays related to light sources are defined. const int LightNum = 4; indicates that up to four light sources are supported. The uniform vec4 lightPositionEC[LightNum]; array stores the positions of the light sources in the eye coordinate system, the uniform float intensity[LightNum]; array stores the intensity of each light source, the uniform vec3 lightColor[LightNum]; array stores the color of each light source, the uniform mat4 shadowMatrix[LightNum]; array stores the shadow matrix of each light source, and the uniform sampler2D shadowMap[LightNum]; array is used to receive the shadow map of each light source.
[0043] float calculateShadow(int lightIndex) is a function for calculating shadows. It transforms the position of the fragment into the shadow coordinate system according to the shadow matrix of the light source and performs perspective division. Then, the corresponding depth value is obtained from the shadow map and compared with the depth of the current fragment to determine whether the fragment is in the shadow. The return value of the function is 0.0 (in the shadow) or 1.0 (not in the shadow), and a small offset is used to prevent the self - shadow problem of the shadow (i.e., "shadow acne").
[0044] In the main() function, first, the color of the fragment is obtained through texture coordinates, and then the normal and position are extracted. Then, enter a loop to iterate through all light sources. For each light source, first calculate the light direction lightDirection, and then calculate NdotL using the dot product of the normal and the light direction. This represents the angular relationship between the light source and the surface, ensuring that the color value is only increased when illuminated by the light source. Subsequently, call the calculateShadow(i) function to obtain the shadow value, and combine it with the light intensity, light color, and NdotL, and superimpose it on the final color value colorValue. The code outputs the calculated color value through gl_FragColor = vec4(colorValue, 1.0); for rendering to the screen.
[0045] In step S2, the following code is used for specific operations. By defining the relevant attributes of the light sources in the scene, including the positions, intensities, colors of the light sources, as well as the placeholders for the shadow matrix and shadow map. The code uses relevant objects of the Cesium library and is applicable to visualization applications in 3D graphics and Geographic Information System (GIS). The following is a detailed description of each part.
[0046] First, const lightPositionEC = [...] defines an array of light source positions. This array contains the positions of four light sources, and each position is represented by a Cartesian4 object. Cartesian4 is a four-dimensional vector that contains the x, y, z coordinates and a homogeneous coordinate w. In this context, the value of w is 1.0, indicating that these light sources are point light sources. The positions of the four light sources are set at (10.0, 10.0, 10.0), (-10.0, -10.0, 10.0), (10.0, -10.0, 10.0), and (-10.0, 10.0, 10.0) respectively. These positions are distributed in three-dimensional space, providing multi-angle lighting effects for the scene and helping to generate rich light and shadow variations.
[0047] Next, const intensity = [1.0, 0.8, 0.6, 0.4]; defines an array of light source intensities. This array corresponds one-to-one with the light source position array and specifies the intensity values of each light source. The intensity of the first light source is 1.0, indicating that it is the brightest light source, and the intensities of the subsequent light sources decrease in turn. This setting can be used to simulate real-world lighting effects and emphasize that some light sources are more important than others.
[0048] Then, const lightColor = [...] defines an array of light source colors. The color of each light source is represented using the Cesium.Color object. The first light source is red (1.0, 0.0, 0.0), the second is green (0.0, 1.0, 0.0), the third is blue (0.0, 0.0, 1.0), and the fourth is yellow (1.0, 1.0, 0.0). This diverse color configuration makes the scene have a richer visual effect and can produce more attractive light and shadow effects during rendering.
[0049] The following const shadowMatrix = [...] and const shadowMap = [...] respectively define the arrays of the shadow matrix and the shadow map. Currently, these two arrays are empty, indicating that the specific shadow matrix and shadow map have not been defined yet. The shadow matrix is usually used to transform the light source coordinates into the shadow map space for calculating the shadows of the objects in the scene. The shadow map is used to store the depth information of the objects in the scene relative to the light source to determine which areas are illuminated by the light source and which areas are in the shadow. These two parts are crucial in implementing realistic shadow effects, so corresponding configurations are required in the subsequent code.
[0050] In step S3, the following code is used for actual operation:
[0051] Calculate the color value of each pixel, taking into account the influence of multiple light sources and the shadow effect. The code is written in OpenGL Shading Language (GLSL), and the following is a detailed description of it.
[0052] First, the function `float calculateShadow(int lightIndex)` is used to calculate the shadow effect of a specific light source. At the beginning of the function, the position `v_positionEC` of the current fragment is transformed into the coordinates in the shadow coordinate system through `shadowMatrix[lightIndex]`. The line of code `vec4 shadowCoord = shadowMatrix[lightIndex] * vec4(v_positionEC, 1.0);` multiplies the fragment position by the shadow matrix to obtain the shadow coordinates. Then, perspective division is performed through `shadowCoord / = shadowCoord.w;` to convert the shadow coordinates into normalized device coordinates (NDC) for subsequent lookups in the shadow map. The line of code `float shadowDepth = texture2D(shadowMap[lightIndex], shadowCoord.xy).r;` is used to obtain the depth value of the current fragment in the shadow coordinate system from the shadow map. The shadow map stores the depth information of each pixel in the scene from the perspective of the light source, allowing the rendering system to determine whether a certain fragment is illuminated by the light source.
[0053] The function determines whether the current fragment is in the shadow through `return shadowCoord.z > shadowDepth + 0.005? 0.0 : 1.0;`. If the depth value `shadowCoord.z` of the current fragment is greater than the depth value `shadowDepth` obtained from the shadow map plus a small offset value (0.005), it is considered that the fragment is in the shadow and the return value is 0.0; otherwise, the return value is 1.0, indicating that the fragment is illuminated by the light source.
[0054] In the main shading function `void main()`, first, the base color of the current fragment is obtained from the color texture through `vec4 color = texture2D(colorTexture, v_textureCoordinates);`. Then, its color components are extracted into `colorValue`, and the normal vector is normalized for subsequent calculations. Then, by looping through all light sources, the contribution of each light source to the current fragment is calculated.
[0055] Inside the loop, first calculate the light direction: vec3 lightDirection = normalize(lightPositionEC[i].xyz - position); Then calculate the dot product between the normal and the light direction through float NdotL = max(dot(normal, lightDirection), 0.0); to get the NdotL value, which represents the illumination intensity of the light source and ensures that it is not negative.
[0056] Call float shadow = calculateShadow(i); to calculate the shadow effect of light source i on the current fragment, that is, call the previously defined calculateShadow function. Finally, combine the illumination, intensity, color, and shadow effect of the light source through colorValue += NdotL * intensity[i] * lightColor[i] * shadow; and add them to the final color value.
[0057] gl_FragColor = vec4(colorValue, 1.0); outputs the calculated color value to the screen to form the final rendering effect. Here, 1.0 represents the opacity.
[0058] The specific implementation of step S4 uses the following code. Set a custom shader to achieve complex lighting and shadow effects. The following is a detailed description of each part of the code.
[0059] First, const viewer = new Cesium.Viewer('cesiumContainer'); This line of code creates a new Cesium Viewer instance and attaches it to the HTML element named cesiumContainer. Viewer is a core component in the Cesium library, which is responsible for managing functions such as scene rendering, camera control, and user interaction. By instantiating the Viewer, users can view and operate the 3D earth or scene in real time on the web page.
[0060] Next, const scene = viewer.scene; This line of code obtains the scene object of the current Viewer. The scene object is an important part of Cesium and is responsible for handling all graphics rendering, including elements such as terrain, buildings, light sources, and shadows. By accessing the scene object, developers can have more in-depth control over the details of the rendering.
[0061] Subsequently, the line of code const customShader = new Cesium.CustomShader({...}) creates an instance of a custom shader. CustomShader allows developers to implement custom shading logic in Cesium, which can override the default rendering process to achieve more complex visual effects. In the configuration of CustomShader, the uniforms section defines variables related to the shader, and these variables can be used in the shader. Specifically, the following uniform variables are defined:
[0062] colorTexture: Used to obtain the color texture of the scene.
[0063] depthTexture: Used to obtain depth information for shadow and depth testing.
[0064] lightPositionEC: Stores the position of the light source in the eye coordinate system, which affects the calculation of lighting.
[0065] intensity: Stores the lighting intensity of each light source, which affects the final color value.
[0066] lightColor: Stores the color of each light source, which is used to calculate the final lighting effect.
[0067] shadowMatrix: Stores the shadow matrix of each light source, which is used for shadow calculation.
[0068] shadowMap: Stores the shadow map, which is used to determine whether an object is illuminated by a light source.
[0069] The settings of these uniform variables enable the shader to dynamically calculate lighting and shadow effects based on the light sources and objects in the scene.
[0070] fragmentShaderText: MultipleLightShader specifies the fragment shader code to be used. MultipleLightShader is a string that contains GLSL code defining lighting and shadow calculations. By using this shader in combination with CustomShader, developers can achieve multi-light source lighting effects and consider the impact of shadows.
[0071] scene.customShader = customShader; This line of code assigns the newly created custom shader instance to the customShader property of the scene object. This operation activates the custom rendering logic, causing the scene to use the new shader instead of the default rendering method when rendering. In this way, users can observe scenes with custom lighting and shadow effects in Cesium.
[0072] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A post-processing point light source rendering method based on Cesium, characterized in that: The method comprises the following steps: S1: First, define the shader, calculate the lighting and shadows through the fragment shader, use GLSL to write the fragment shader, and process multiple light sources with and without shadows respectively; define the input and constants of the shader through code, process the color texture and depth texture accordingly, and pass the data from the vertex shader to the fragment shader through variables; S2: configure light source parameters according to the processing state of the fragment shader, and pass the light source parameters to the shader through uniform; define the associated properties of the light source in the scene when configuring the light source parameters, and the associated properties include the position, intensity, color, shadow matrix and shadow map placeholder of the light source; S3: Calculate the lighting effect according to the light source type, use the depth map to calculate the shadow effect, and determine whether the fragment shader is in the shadow; And using the fragment shader of graphics rendering through core code to calculate the color value of each pixel, the core code is written in GLSL; S4: Create a custom shader, pass the light source parameters to the Cesium rendering pipeline, apply the custom shader to the Cesium scene, and achieve multi-light lighting effects. By performing multi-light lighting and shadow effects in Cesium, the realism and visual effects of the scene are improved, and the performance of GLSL is used to ensure efficient and real-time rendering. When the core code is written in GLSL, the shadow effect of a specific light source is calculated through a function, the elements in the function are used to convert the position of the current fragment into coordinates in the shadow coordinate system, and the shadow coordinates are converted into standardized device coordinates; in the main shading function, the base color of the current fragment is obtained through the color texture, and then its color components are extracted, and the normal vector is normalized, and all light sources are looped through to calculate the contribution of each light source to the current fragment.
2. A post-processing point light source rendering method based on Cesium as claimed in claim 1, characterized in that: The fragment shader data includes texture coordinates, normals and positions. The constants and arrays of the light source are defined through the shader data. The fragment position is converted to the shadow coordinate system through the shadow matrix of the light source, and perspective division is performed to obtain the corresponding depth value from the shadow map and compare it with the depth of the current fragment.
3. A post-processing point light source rendering method based on Cesium as claimed in claim 1, characterized in that: When configuring the light source parameters, the light source position array is first defined. The array contains the positions of four light sources. Each position is represented by an object, and a four-dimensional vector is set. The four-dimensional vector contains x, y, z coordinates and a homogeneous coordinate w.
4. A post-processing point light source rendering method based on Cesium as claimed in claim 1, characterized in that: The shadow matrix converts the light source coordinates into the shadow map space, and calculates the shadows of objects in the scene in the shadow map space. The shadow map is used to store the depth information of the objects in the scene relative to the light source.
5. A post-processing point light source rendering method based on Cesium as claimed in claim 1, characterized in that: When applying a custom shader to a Cesium scene, first create a new Cesium Viewer instance and attach it to the HTML element, obtain the scene object of the current Viewer, and control the details of the rendering by accessing the scene object.
Citation Information
Patent Citations
Illumination rendering method and device, equipment and storage medium
CN117671125A