Post-processing point light source rendering method based on Cesium

By defining fragment shaders in Cesium and writing fragment shaders using GLSL, the problem of the Cesium rendering engine not supporting point light sources was solved, enabling multi-light source lighting and shadow effects, improving rendering efficiency and realism, and enhancing the user experience.

CN119273832AActive Publication Date: 2025-01-07QINGDAO FUSHENG TECHNOLOGY CO LTD
View PDF 12 Cites 0 Cited by

Patent Information

Application Number
CN202411563189.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-05
Publication Date
2025-01-07
Estimated Expiration
2044-11-05

AI Technical Summary

Technical Problem

The existing Cesium rendering engine does not support post-processing effects for point lights, resulting in performance bottlenecks, unrealistic rendering effects, limited light source processing capabilities, and insufficient customization and extensibility in complex lighting scenes, which affects user experience and the diversity of application scenarios.

Method used

By defining fragment shaders and writing fragment shaders using GLSL, we can handle multiple light sources with and without shadows, configure light source parameters and pass them to the shaders via uniforms, create custom shaders, and apply them to the Cesium scene to achieve multi-light source lighting and shadow effects.

Benefits of technology

It improves the flexibility and adaptability of light source configuration, enhances the realism and immersion of shadows, simplifies the light source management process, improves the efficiency and smoothness of rendering, and meets the multi-light source lighting needs in complex scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119273832A_ABST
    Figure CN119273832A_ABST
Patent Text Reader

Abstract

The invention provides a Cesium-based post-processing point light source rendering method, and the method comprises the following steps: S1, firstly defining a shader, calculating illumination and shadow through a fragment shader, compiling the fragment shader through GLSL, and respectively processing multiple light sources with shadow and without shadow; the input and constant of the shaders are defined through codes, color textures and depth textures are correspondingly processed, and data from the vertex shader to the fragment shader are transmitted through variables; s2, light source parameters are configured according to the processing state of the fragment shader, and the light source parameters are transmitted to the shader through uniform; defining association attributes of a light source in the scene when the light source parameters are configured, wherein the association attributes comprise the position, the intensity, the color and the shadow matrix of the light source and the placeholder of the shadow map; and S3, calculating an illumination effect according to the light source type, calculating a shadow effect by using the depth map, and determining whether the fragment shader is in the shadow.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of three-dimensional graphics rendering, and in particular relates to a post-processing point light source rendering method based on Cesium. Background Art

[0002] In computer graphics and 3D scene rendering, light sources are an important factor in improving scene realism and fidelity. As a lightweight open source JavaScript library, Cesium is widely used in the development of virtual scenes, such as flight simulation, 3DGIS, 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 scenes.

[0003] With the continuous development of computer graphics and 3D visualization technology, point light rendering, as an important method for achieving visual effects, is widely used in games, movies, virtual reality, augmented reality and other fields. As an open source 3D earth platform, Cesium provides powerful spatial data visualization capabilities. However, there are still some significant shortcomings in the point light rendering technology based on Cesium, which to a certain extent limit its effect and performance in practical applications. First of all, the existing point light rendering methods often show a large performance bottleneck when dealing with dynamic changes in light sources. Traditional rendering technology does not provide sufficient support for real-time updates and dynamic effects of light sources, especially in scenes where a large number of light sources need to be rendered, the performance degradation is particularly obvious. This performance bottleneck not only affects the smoothness of rendering, but also leads to a decline in user interaction experience.

[0004] Existing point light rendering technology has deficiencies in lighting 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 such as shadows, reflections and refractions. Although this simplified processing has improved the rendering speed to a certain extent, it sacrifices the authenticity of the rendering effect, resulting in less than ideal final visual effects. In addition, current technology also has limitations in the processing of the number and distribution of light sources. Due to performance and computing 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 rendering in complex scenes and cannot meet the needs of high-quality visualization.

[0005] There is often a trade-off between real-time and accuracy in existing rendering algorithms, which makes it difficult for the system to find the best 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 the scene to freeze, while for applications that pursue fine rendering effects, a smooth experience cannot be achieved due to excessive consumption of computing resources. Existing point light rendering technology also has shortcomings in user customization and scalability. Many systems cannot flexibly support users to customize light source parameters, which limits 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 rendering method based on Cesium is developed to solve the performance bottlenecks, insufficient effect authenticity, limited light source processing capabilities, and insufficient custom scalability in current technologies by introducing more efficient lighting calculation models and optimizing rendering algorithms, thereby providing higher quality visual effects and smoother user experience. This will provide important support for the widespread popularization and in-depth development of three-dimensional visualization applications. Therefore, a post-processing point light rendering method based on Cesium is urgently needed. Summary of the invention

[0006] The present invention proposes a post-processing point light rendering method based on Cesium. The current Cesium rendering engine does not directly support the post-processing effect of point light sources, so it needs to be realized by other methods. Point light sources need to consider the range and intensity of illumination, and the default rendering method of Cesium does not provide direct control of these parameters. It aims to write fragment shaders through GLSL to achieve efficient point light effects, and provide a flexible parameter adjustment interface to meet the needs of different scenarios.

[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 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;

[0009] 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;

[0010] S3: Calculate the lighting effect according to the light source type, calculate the shadow effect using the depth map, determine whether the fragment shader is in the shadow; and calculate the color value of each pixel using the fragment shader of the graphics rendering through the core code, 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, and implement 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.

[0012] Compared with existing technologies, this post-processing point light rendering method based on Cesium shows significant advantages and innovations. First of all, existing point light rendering technologies often rely on traditional fixed lighting models and lack the ability to flexibly handle multi-light environment. Many systems can only support simple light source configurations in the calculation of lighting effects and cannot effectively cope with the lighting requirements of multiple light sources in complex scenes. However, this method defines fragment shaders and uses flexible code written in GLSL to handle multiple light sources with and without shadows, greatly enhancing the configuration flexibility and adaptability of light sources. This flexibility enables developers to more easily implement complex lighting effects in various application scenarios to meet the needs of different users.

[0013] Current technologies usually use relatively simple algorithms for shadow processing, which often cannot accurately simulate the shadow characteristics in the real world, resulting in insufficient realism in the rendering effect. Many existing rendering methods rely on pre-generated shadow maps for shadow calculations, lacking dynamic adaptability, resulting in unnatural shadow effects in dynamic scenes. However, this method uses depth maps to calculate shadow effects, which can determine in real time whether a fragment is in the shadow, and achieve more realistic shadow performance through dynamic calculation. This real-time judgment capability makes the lighting effect more realistic and also enhances the user's sense of immersion.

[0014] Existing methods are often complex in configuring light source parameters and lack a unified management mechanism, which requires developers to perform tedious manual settings when adjusting light sources. In contrast, this method can easily configure the properties of light sources in fragment shaders, including position, intensity, color, etc., by passing light source parameters to shaders through uniforms. This design simplifies the light source management process, making the development process more efficient and reducing the probability of errors.

[0015] The design of this method in creating custom shaders also reflects its difference from existing technologies. Many traditional rendering systems have limitations in scalability and are difficult to meet specific needs. By creating custom shaders and passing light source parameters to the Cesium rendering pipeline, developers can flexibly adjust and expand rendering effects, fully utilize the performance advantages of GLSL, and ensure efficient and real-time rendering performance. This flexibility not only improves the convenience of development, but also provides a good foundation for subsequent functional expansion.

[0016] The improvement of the overall rendering effect is also a major advantage of this method. Existing technologies often face performance bottlenecks when dealing with multiple light sources and shadow effects, resulting in poor real-time rendering effects. This method implements multiple light source lighting and shadow effects in Cesium and uses the high-performance computing capabilities of GLSL to ensure efficient and smooth rendering. This allows users to obtain a more realistic visual experience when browsing three-dimensional scenes, enhancing the immersion and interactivity of the scene.

[0017] As a preferred implementation, 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 position of the fragment 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.

[0018] As a preferred implementation, when configuring the light source parameters, a 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, which contains x, y, z coordinates and a homogeneous coordinate w.

[0019] As a preferred implementation, the shadow matrix converts the light source coordinates into a shadow map space, and calculates the shadows of objects in the scene in the shadow map space. The shadow map is used to store depth information of objects in the scene relative to the light source.

[0020] As a preferred implementation, 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.

[0021] As a preferred implementation, when applying a custom shader to a Cesium scene, first create a new CesiumViewer instance and 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 customizing GLSL shaders, multi-light source lighting and shadow effects are realized, making the Cesium scene more realistic. The shadow effect is calculated using a depth map, which improves the accuracy and realism of the shadow. By using flexible code written by fragment shaders and GLSL, the method can effectively handle multi-light source situations with and without shadows, greatly enhances the configuration flexibility of the light source, and meets the multi-light source lighting requirements in complex scenes. Secondly, the ability to calculate shadow effects in real time improves the authenticity of the rendering, makes the lighting effects in the scene more natural, and enhances 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 development efficiency, and reduces the probability of error. Creating a custom shader and passing the light source parameters to the Cesium rendering pipeline allows developers to flexibly adjust and expand the rendering effect, improving the scalability and adaptability of the system. At the same time, the high-performance computing capabilities of GLSL are used to ensure the efficiency and smoothness of the rendering, so that users can obtain a more realistic visual experience when browsing three-dimensional scenes. Finally, this method enhances the realism and visual effects of the scene by improving the overall rendering effect, providing a more efficient and flexible solution for 3D visualization and graphics rendering, and promoting the further development and innovation of related applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0024] Figure 1 It is a schematic diagram of the overall structure of the present invention. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] Example:

[0027] like Figure 1 As shown, a post-processing point light source rendering method based on Cesium, the method comprises the following steps:

[0028] 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;

[0029] 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;

[0030] S3: Calculate the lighting effect according to the light source type, calculate the shadow effect using the depth map, determine whether the fragment shader is in the shadow; and calculate the color value of each pixel using the fragment shader of the graphics rendering through the core code, the core code is written in 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, and implement 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.

[0032] The working principle and operation steps of this Cesium-based post-processing point light rendering method can be described as follows:

[0033] First of all, defining the shader is the basis of the entire rendering process. Lighting and shadows are calculated through the fragment shader. The fragment shader written in GLSL (OpenGL Shading Language) is responsible for applying the influence of the light source to each pixel in the scene. The fragment shader handles multiple light sources with and without shadows. The input and constants of the shader are defined through code, so that the shader can receive the necessary texture data, such as color texture and depth texture. This step ensures that the calculation of lighting and shadows is accurate during the rendering process and can provide the required data for subsequent processing.

[0034] Next, configure the light parameters according to the processing state of the fragment shader and pass these parameters to the shader through a uniform. When configuring the light parameters, define the associated properties of the light in the scene, including the position, intensity, color, shadow matrix, and shadow map placeholders of the light. In this way, the characteristics of the light source can be flexibly adjusted to meet the needs of different scenes. This parametric design makes the adjustment and management of light sources more efficient and enables fast configuration of light sources when rendering different scenes.

[0035] Then, the lighting effect is calculated according to the light source type, the shadow effect is calculated using the depth map, and the fragment shader is determined whether it is in the shadow. This process involves using the depth map to determine which fragment in the scene is in the shadow. The fragment shader rendered by the core code uses graphics to calculate the color value of each pixel. This step is crucial because it determines the lighting quality and realism of the scene. Using GLSL to write the core code can make full use of the parallel processing capabilities of the GPU, thereby improving the efficiency and real-time performance of rendering.

[0036] Finally, create a custom shader, pass the light source parameters to the Cesium rendering pipeline, and apply the custom shader to the Cesium scene to achieve multi-light lighting effects. By calculating multi-light lighting and shadow effects in Cesium, the realism and visual effects of the scene can be significantly improved. Leverage the performance of GLSL to ensure that the rendering process is efficient and can be updated in real time. The implementation of custom shaders allows developers to adjust the lighting model according to specific needs, thereby achieving more complex lighting effects and visual performance.

[0037] There are several important reasons for the setup and operation of this method: Flexibility: By defining shaders and configuring light parameters, developers can flexibly adjust according to the needs of different scenes and adapt to a variety of lighting conditions; Performance optimization: Shaders written in GLSL can make full use of the computing power of the GPU, improve rendering efficiency, and ensure real-time performance; Enhanced realism: Multi-light lighting and shadow effects can significantly improve the realism of the scene, making the visualization more natural and realistic; Scalability: The design of custom shaders allows new light types to be added or existing lighting models to be improved as needed in the future, and has good scalability; Efficient data management: The light source parameters are passed through uniforms, which ensures the efficiency and simplicity of data transmission and avoids excessive state switching and data transmission overhead; Shadow processing: The use of depth maps makes shadow calculations efficient and controllable, and can achieve high-quality shadow effects while maintaining performance.

[0038] The specific explanations of the specific operation steps of this application document are as follows

[0039] The specific operation part of step S1 is as follows:

[0040] The fragment shader program used for graphics rendering handles multi-light source lighting, shadow calculation, and the final output of color. The code follows the syntax of OpenGL Shading Language (GLSL) and generates the final color value by calculating the input texture, light source information, and the object's normal vector.

[0041] First, the code defines some shader inputs and constants. Uniform sampler2DcolorTexture; and uniform sampler2D depthTexture; are used to receive color texture and depth texture respectively. Varying variables are used to pass 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. uniform vec4 lightPositionEC[LightNum]; the array stores the position of the light source in the eye coordinate system, uniform float intensity[LightNum]; the array stores the intensity of each light source, uniform vec3lightColor[LightNum]; the array stores the color of each light source, uniform mat4shadowMatrix[LightNum]; the array stores the shadow matrix of each light source, uniform sampler2DshadowMap[LightNum]; the array is used to receive the shadow map of each light source.

[0043] float calculateShadow(int lightIndex) is a function that calculates shadows. It transforms the fragment's position into the shadow coordinate system according to the light source's shadow matrix and performs perspective division. Then, it gets the corresponding depth value from the shadow map and compares it with the depth of the current fragment to determine whether the fragment is in the shadow. The function returns a value of 0.0 (in the shadow) or 1.0 (not in the shadow), and a small offset is used to prevent the self-shadowing problem of the shadow (ie "shadow contact").

[0044] In the main() function, first get the color of the fragment through the texture coordinates, then extract the normal and position. Then enter a loop to traverse all light sources. For each light source, first calculate the light direction lightDirection, and then use the dot product of the normal and the light direction to calculate NdotL, which represents the angle between the light source and the surface, ensuring that the color value is increased only when the light source is shining. Then call the calculateShadow(i) function to get 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 to perform specific operations, by defining the relevant properties of the light source in the scene, including the position, intensity, color of the light source, and the placeholders of the shadow matrix and shadow map. The code uses the relevant objects of the Cesium library and is suitable for visualization applications in 3D graphics and geographic information systems (GIS). The following is a detailed description of each part.

[0046] First, const lightPositionEC = [...] defines an array of light positions. This array contains the positions of four light sources, each represented by a Cartesian4 object. Cartesian4 is a four-dimensional vector containing 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 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). These positions are distributed in three-dimensional space, providing multi-angle lighting effects for the scene, which helps to produce rich light and shadow changes.

[0047] Next, const intensity = [1.0, 0.8, 0.6, 0.4] defines an array of light intensity. This array corresponds to the array of light positions one by one, specifying the intensity value of each light source. The intensity of the first light source is 1.0, indicating that it is the brightest light source, and the intensity of the subsequent light sources decreases in sequence. This setting can be used to simulate the lighting effect in reality, emphasizing that some light sources are more important than others.

[0048] Then, const lightColor = [...] defines an array of light colors. The color of each light is represented by a Cesium.Color object. The first light 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 when rendering.

[0049] The following const shadowMatrix=[...] and const shadowMap=[...] define the arrays of shadow matrix and shadow map respectively. 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 convert the light source coordinates to the shadow map space in order to calculate the shadows of objects in the scene. The shadow map is used to store the depth information of 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 achieving a realistic shadow effect, so they need to be configured accordingly in the subsequent code.

[0050] The following code is used in step S3 for actual operation:

[0051] Calculate the color value of each pixel, taking into account the influence of multiple light sources and shadow effects. The code is written in OpenGL Shading Language (GLSL), and the following is a detailed description of it.

[0052] First, the float calculateShadow(int lightIndex) function is used to calculate the shadow effect for a specific light source. At the beginning of the function, the current fragment's position v_positionEC is converted to coordinates in the shadow coordinate system using shadowMatrix[lightIndex]. This line of code multiplies the fragment position with the shadow matrix to obtain the shadow coordinates. Next, perspective division is performed using shadowCoord / =shadowCoord.w; to convert the shadow coordinates to normalized device coordinates (NDC) for subsequent lookups in the shadow map. The line of code uses float shadowDepth=texture2D(shadowMap[lightIndex],shadowCoord.xy).r; to get 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 fragment is illuminated by a light source.

[0053] The function returns shadowCoord.z>shadowDepth+0.005?0.0:1.0 to determine whether the current fragment is in the shadow. 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), the fragment is considered to be 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 get the base color of the current fragment from the color texture through vec4 color = texture2D (colorTexture, v_textureCoordinates); then extract its color components into colorValue and normalize the normal vector for subsequent calculations. Then, loop through all light sources and calculate the contribution of each light source to the current fragment.

[0055] Inside the loop, first calculate the light source direction vec3 lightDirection = normalize(lightPositionEC[i].xyz-position);, then calculate the dot product between the normal and the light source direction through float NdotL = max(dot(normal,lightDirection),0.0); to get the NdotL value, which represents the 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 calculateShadow function defined above. Finally, through colorValue + = NdotL*intensity[i]*lightColor[i]*shadow; the illumination, intensity, color and shadow effect of the light source are combined and superimposed on the final color value.

[0057] gl_FragColor = vec4(colorValue, 1.0); Output the calculated color value to the screen to form the final rendering effect. Here 1.0 represents opacity.

[0058] The step S4 is specifically implemented using the following code to 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 an HTML element called cesiumContainer. Viewer is a core component in the Cesium library that manages scene rendering, camera control, and user interaction. By instantiating the Viewer, users can view and manipulate 3D globes or scenes in real time on a web page.

[0060] Next, const scene = viewer.scene; This line of code gets the scene object of the current Viewer. The scene object is an important part of Cesium, 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 rendering.

[0061] Then, const customShader = new Cesium.CustomShader({...}); This line of code creates a custom shader instance. 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 CustomShader configuration, the uniforms section defines shader-related variables that can be used in the shader. Specifically, the following uniform variables are defined:

[0062] colorTexture: used to get 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, affecting the calculation of lighting.

[0065] intensity: Stores the light intensity of each light source, affecting the final color value.

[0066] lightColor: stores the color of each light source and is used to calculate the final effect of lighting.

[0067] shadowMatrix: Stores the shadow matrix of each light source for shadow calculation.

[0068] shadowMap: stores shadow maps, which are 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 shading effects based on the light sources and objects in the scene.

[0070] fragmentShaderText:MultipleLightShader specifies the fragment shader code used. MultipleLightShader is a string containing the GLSL code that defines the lighting and shadow calculations. By combining this shader with CustomShader, developers can achieve multi-light lighting effects and take into account the effects of shadows.

[0071] scene.customShader = customShader; This line of code assigns the custom shader instance just created to the customShader property of the scene object. This operation activates the custom rendering logic, so that the scene will use the new shader instead of the default rendering method when rendering. In this way, users can observe scenes based on custom lighting and shadow effects in Cesium.

[0072] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in 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 implement 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.

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 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.

6. 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

  • Dynamic water body rendering method based on WebGL

    CN117197329A

  • Sunlight analysis method for urban live-action three-dimensional scene

    CN117456080A

  • Illumination rendering method and device, equipment and storage medium

    CN117671125A

  • Quadtree light source cutting method based on cesium three-dimensional engine grid

    CN117830499A

  • System, method, and computer program product for dynamic shader generation

    US20060082577A1