Water conservancy twin model rendering optimization method for dynamically generating grayscale image frames based on view cone
The rendering of water conservancy digital twin models is optimized through dynamic frustum cropping and off-screen rendering technology, which solves the problem of rendering freezes in large-scale water conservancy models and realizes efficient, cross-platform water conservancy scene rendering and hydrological feature visualization.
Patent Information
- Application Number
- CN202510816703.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-09-26
AI Technical Summary
The rendering of water conservancy digital twin models suffers from lag and high GPU load due to large data volume and complex calculations. The existing solutions fail to effectively balance rendering efficiency and resource utilization.
The dynamic cropping technology of the viewing cone is used to reduce invalid rendering data. Combined with off-screen rendering, grid processing and time-domain frame multiplexing mechanism, optimized grayscale/gradient images are generated. The contrast is adjusted through an adaptive feature enhancement algorithm to achieve frame multiplexing of static areas and real-time rendering of dynamic areas.
Significantly reduce GPU computing load, improve rendering efficiency, ensure water conservancy scene accuracy and hydrological feature visualization, reduce hardware deployment costs, and achieve cross-platform deployment capabilities.
Smart Images

Figure CN120707716A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of intersection of computer graphics and digital twins, and specifically relates to a water conservancy twin model rendering optimization method based on dynamically generating grayscale image frames based on a viewing cone. Background Art
[0002] With the deep integration of digital twin technology into the water conservancy industry, it has become a core technical tool supporting watershed management, project scheduling, and disaster early warning. A typical characteristic of a water conservancy digital twin scenario is the need to integrate multi-source heterogeneous data to build an integrated "sky, ground, water, and engineering" data platform. Upstream, satellite remote sensing imagery and drone oblique photography data are required to capture large-scale surface morphology; midstream, BIM models of water conservancy projects (such as dams and pumping stations) must be integrated to restore physical structures; and downstream, ground-based hydrological stations (such as water level, flow, and sediment concentration sensors) and IoT monitoring data must be integrated to reflect real-time status. After spatial and temporal alignment and standardized formatting, these data are ultimately transformed into a high-resolution digital twin model covering all elements of the watershed / project. The underlying layer typically uses grayscale or gradient images to represent key hydrological characteristics such as topographic relief and flow gradients.
[0003] In the rendering and simulation applications of twin models, the technical challenges are mainly reflected in two aspects: first, the complexity of the model has increased significantly - basin-level simulation needs to process tens of millions of computing grids, and engineering-level rendering needs to support BIM model details with sub-meter accuracy, resulting in a single-frame rendering data volume of up to GB; second, the demand for dynamic interaction has increased - the twin system needs to support real-time previews (such as flood evolution simulations), multiple scheme comparisons (such as water level changes under different scheduling strategies) and other scenarios, which puts strict requirements on rendering smoothness (usually ≥30 frames / second) and response speed (user operation delay ≤200ms).
[0004] Existing technologies mainly attempt to optimize from the following directions: Hardware resource expansion: Computing power is increased through GPU-accelerated computing (such as using CUDA parallel processing rendering pipelines) and distributed computing architecture (splitting rendering tasks across cluster nodes). However, the cost increases exponentially with model size, and due to network bandwidth limitations, the synchronization delay problem of distributed rendering remains difficult to completely resolve. Cloud-edge collaborative architecture: High-frequency static data (such as basic terrain grayscale maps) is stored on edge nodes, while dynamically changing data (such as flood evolution gradient maps) is calculated in real time by the cloud. Although this solution reduces the cloud load, the storage and computing capabilities of edge nodes are limited, and complex scenarios still require frequent calls to cloud resources. Dynamic update and compression: AI-based algorithms are used to identify scene change areas (such as local watersheds affected by rising water levels) and only dynamically render the changed areas. Intelligent compression technology (such as lossy compression based on gradient maps) is used to reduce the amount of transmitted data. However, it relies on well-trained AI models and is not adaptable enough to unlabeled emergency scenarios (such as dam breaks).
[0005] In summary, existing solutions either focus on "extensive" expansion of hardware resources or rely on "local" optimization under specific conditions. A universal solution that balances rendering efficiency and resource utilization has yet to emerge. To meet the real-time rendering requirements of highly complex models in water conservancy digital twin scenarios, an "endogenous" optimization method, from data representation to rendering, is urgently needed. Summary of the Invention
[0006] In response to the problems of lag and high GPU load caused by large data volume and complex calculations in the existing water conservancy digital twin model rendering, the present invention provides a water conservancy twin model rendering optimization method based on the dynamic generation of grayscale image frames based on the viewing cone. Its core innovation lies in the "endogenous" optimization from data representation to rendering process: first, invisible objects are eliminated through the dynamic cutting model of the view frustum combined with hierarchical spatial indexing, reducing invalid rendering data at the source; then, off-screen rendering technology is used to create multi-layer rendering targets (color / vertex / depth buffers) in the GPU video memory, isolating the calculation process from the screen display to reduce the pressure of real-time rendering; then, the intermediate frame data of off-screen rendering is gridded (divided into 32×32 to 1024×1024 grid units), and a basic grayscale image is generated by desaturation. The contrast weight is dynamically adjusted based on the statistical mean, standard deviation and hyperbolic tangent function to enhance the hydrological characteristics and generate an optimized grayscale image or gradient image; finally, through the time-domain frame multiplexing mechanism, the optimized grayscale / gradient image is simultaneously applied to the post-processing analysis of the current frame and the pre-loaded rendering of the next frame. The static area reuses the historical frame data, and the dynamic area triggers real-time rendering. This method effectively balances rendering quality and computing load through the full-process collaboration of "dynamic cropping-off-screen rendering-feature enhancement-time domain multiplexing", providing a universal solution for real-time and smooth rendering of water conservancy digital twin models.
[0007] The technical solution specifically adopted by the present invention to solve the technical problem is: A water conservancy twin model rendering optimization method based on dynamic generation of grayscale image frames based on a viewing cone, comprising: Get the model data of the visible area after dynamic clipping of the current frustum; Outputting the visible area model data to a multi-layer rendering target including a color buffer, a vertex buffer, and a depth buffer through off-screen rendering to generate intermediate frame data isolated from screen display; Performing gridding processing on the intermediate frame data, dividing the image into N×N grid cells according to the physical range size of the water conservancy project or watershed scene and the resolution of the display device, where N is an integer not less than 32; Calculating the average color value of each grid cell and performing desaturation processing to generate a basic grayscale image, and performing adaptive feature enhancement processing on the basic grayscale image to generate an optimized grayscale image or gradient image; The optimized grayscale image or gradient image is input into the GPU rendering pipeline and acts on: (a) Hydrological feature analysis of the current frame post-processing stage, (b) Preloaded data source for the next frame twin model rendering, The static area reuses historical frame data through motion detection, and the dynamic area triggers real-time rendering.
[0008] Furthermore, the off-screen rendering includes: Create a multi-layer render target containing a color buffer, a vertex buffer, and a depth buffer; Perform coordinate transformation from model space to screen space through vertex shader; Fill each buffer data through the fragment shader.
[0009] Furthermore, the determination of the number N of grid units includes: Get the spatial range size after dynamic clipping of the viewing frustum; The number of basic grids is calculated based on the ratio of the long side size of the spatial range to the pixel density of the display device; Constrain the number of base meshes to be within the range of 32 to 1024.
[0010] Furthermore, the adaptive feature enhancement process dynamically adjusts the brightness coefficient according to the frustum camera parameters, including: Calculate the statistical mean and standard deviation of the grayscale values of all grid cells; Dynamically set the contrast enhancement weight based on the deviation between the grayscale value of each grid cell and the statistical mean; Apply the weights to update the grayscale values of the grid cells.
[0011] Furthermore, the calculation of the contrast enhancement weight includes: Calculate the absolute deviation between the grid cell grayscale value and the overall statistical mean; Mapping the absolute deviation value through a hyperbolic tangent function; Constrain the mapping result to be between the preset minimum and maximum weight values.
[0012] Furthermore, the process of generating a gradient map includes: For the enhanced grayscale image grid unit; Calculate the grayscale gradient values of adjacent grids in the horizontal direction and the grayscale gradient values of adjacent grids in the vertical direction respectively; A gradient intensity map is generated based on the horizontal gradient value and the vertical gradient value, and the gradient intensity map is used for collision detection in flood evolution simulation of water conservancy projects.
[0013] Furthermore, the static area multiplexing historical frame data and the dynamic area triggering real-time rendering include: Calculate the motion vector between the current frame and the historical frame; When the motion amplitude is lower than the fixed threshold of 0.15, the corresponding area is marked as a static area and n-1 frames of grayscale image / gradient image data are read from the frame buffer pool; When the motion amplitude reaches or exceeds the threshold, the corresponding area is marked as a dynamic area and the real-time rendering pipeline is triggered; Integrate historical frame data of static areas and real-time rendering data of dynamic areas to generate complete output frames; Write the current output frame data into the frame buffer pool; When the number of frames stored in the frame buffer pool exceeds the threshold K, the longest unused frame is eliminated according to the LRU strategy.
[0014] Furthermore, it also includes: Dynamically adjust off-screen rendering resolution based on GPU memory capacity; And the upper limit of resolution is set to 2048×2048 pixels; The visible area model data is obtained through a spatial index based on LOD2 grading rules.
[0015] And, a water conservancy twin model rendering optimization system based on dynamic generation of grayscale image frames based on a viewing cone, comprising: The spatial optimization module is used to obtain the visible area model data after dynamic clipping of the current viewing cone; an off-screen rendering module configured to generate intermediate frame data isolated from screen display through a multi-layer rendering target, wherein the multi-layer rendering target includes a color buffer, a vertex buffer, and a depth buffer; The grid processing module is configured to: According to the physical range size of the water conservancy project or watershed scene and the resolution of the display device, the intermediate frame data is divided into N×N grid units, N≥32; Calculate the average color value of the grid cells and desaturate to generate a basic grayscale image; Adaptively enhance the basic grayscale image to generate an optimized grayscale image or gradient image; Time domain multiplexing module, configured as: Input the optimized grayscale image or gradient image into the GPU rendering pipeline; Multiplexing historical frame data through motion detection in static areas; Trigger real-time rendering in dynamic areas; The output results are used for both hydrological feature analysis of the current frame and preloading data sources for the next frame.
[0016] And, a computer device includes a memory, a processor and a computer program stored in the memory, and the processor implements the above method when executing the computer program.
[0017] A non-transitory computer-readable storage medium stores a computer program, which implements the method described above when executed by a processor.
[0018] Compared with the prior art, the present invention and its preferred embodiments have at least the following beneficial effects: 1. Breakthrough optimization of rendering efficiency and resource consumption Through the time-domain grayscale frame multiplexing mechanism (dynamic and static area separation + frame assembler + LRU cache), the GPU computing load is significantly reduced while ensuring visual effects, solving the rendering lag problem of large-scale water conservancy twin models.
[0019] 2. Specialized precision assurance for water conservancy scenarios Based on spatially adaptive grid processing technology (grid density is linked to the long axis length of the cropped area), accurate dynamic adaptation of key elements such as river topography and dam structure is achieved, eliminating the edge distortion problem of hydraulic structures caused by traditional compression technology.
[0020] 3. Enhanced visualization of hydrological characteristics The grayscale adaptive enhancement algorithm based on the hyperbolic tangent weight model is used to effectively enhance the light and dark contrast of key hydrological features such as flood inundation areas and water flow gradients, thereby improving the accuracy of decision-making analysis.
[0021] 4. Dynamic adaptation of hardware resources Through the memory-aware resolution adjustment mechanism and cache elimination strategy, cross-platform deployment capabilities from high-performance workstations to mobile edge devices are achieved, significantly reducing hardware deployment costs.
[0022] 5. Full-process computing load balancing A four-stage pipeline consisting of spatial optimization → off-screen rendering → feature enhancement → temporal multiplexing is constructed to overcome the technical bottleneck of the mutual exclusion between rendering accuracy and real-time performance in traditional solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments: Figure 1 This is a grayscale image after dynamic rendering according to an embodiment of the present invention; Figure 2This is a diagram illustrating an architecture for implementing time-domain grayscale frame multiplexing in an embodiment of the present invention; Figure 3 This is a diagram of the overall architecture of an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the features and advantages of the present invention more clearly understood, the following embodiments are given for detailed description: It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used in this specification have the same meanings as those commonly understood by those skilled in the art to which this application belongs.
[0025] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0026] The primary purpose of the solution provided by the embodiment of the present invention is to realize a fast real-time dynamic recognition of image frames based on the far and near clipping surfaces of the viewing cone, and perform off-screen rendering on them to generate a grayscale image or gradient image. Through the optimal visualization effect of the twin watershed, water conservancy project size and simulation model, the brightness coefficient and desaturation coefficient of the grayscale image or gradient image are automatically adjusted to generate a grayscale image or gradient image suitable for the twin watershed and water conservancy project under the current hardware resource configuration.
[0027] Subsequently, the pre-rendered off-screen rendering result of the previous frame serves as the basis for the next frame's twin rendering, reducing GPU rendering and loading resource consumption, achieving optimal rendering results for model simulation business applications. This solution aims to significantly alleviate the problem of rendering frame rate lag in large-scale scenarios such as water conservancy projects and water conservancy basins with limited device hardware resources. By dynamically adjusting the current effective and effectively reducing GPU rendering pressure, it improves the dynamic changes of ultra-long-range, long-range, mid-range, and close-range digital twin models of large-scale water conservancy projects and watersheds, and performs visual rendering of the real physical world.
[0028] For the ultra-long-range, long-range, medium-range and near-range twin models of water conservancy projects and river basins within the viewing cone area, fast real-time dynamic identification is achieved based on the far and near clipping surfaces within the visible range of the viewing cone, the real-time image frame within the current range is determined, and off-screen rendering is performed on the image. The brightness coefficient and desaturation coefficient of the grayscale image or gradient image are automatically adjusted and processed into a grayscale image or gradient image. The pre-rendered off-screen rendering result image of the previous frame is used for the twin rendering of the next stitch.
[0029] In view of the defects of the existing technology such as high hardware resource consumption and poor adaptability to dynamic scenes, this embodiment provides a water conservancy twin model rendering optimization method based on the dynamic generation of grayscale image frames based on the view cone, and realizes the dynamic balance of resources and precision through a four-stage pipeline architecture. Figure 3 As shown: Spatial optimization layer: Uses frustum culling technology to accurately screen visible areas, dynamically calculates camera parameters based on the characteristics of water conservancy scenes (with the far plane extended to 3000m), and constructs a quadtree spatial index, reducing invalid rendering data at the source by 50%; Off-screen processing layer: Create a three-buffer structure (color / vertex / depth buffer) for intermediate frame rendering, and generate a hydrological feature-enhanced grayscale / gradient map through gridding (1024×1024 units) and adaptive grayscale enhancement (hyperbolic tangent weight mapping); Temporal multiplexing layer: Innovative mechanism for separating static and dynamic areas. The static area reuses historical frame data (motion threshold 0.15), while the dynamic area is rendered in real time and integrated and outputted by the frame assembler. Resource adaptation layer: Dynamically adjusts the resolution (up to 2048×2048) and cache pool (using the LRU strategy to eliminate old frames) based on GPU memory, supporting WebGL / mobile deployment.
[0030] To achieve efficient visualization of large-scale twin models, the core technical path of this solution is as follows: 1. View Frustum Dynamic Range Clipping In view of the large spatial span of water conservancy scenes (rivers stretching for several kilometers and reservoirs with complex terrain), a camera parameter-driven dynamic cropping model is established, combined with hierarchical spatial indexing to achieve sub-millisecond invisible object culling, reducing more than 50% of invalid rendering data at the source.
[0031] To achieve efficient rendering of water conservancy scenes, this solution relies on dynamic frustum culling technology. This technology supports the following key operations: (1) Dynamic camera parameter calculation: According to the distance d between the camera position and the target scene and the radius r of the scene bounding sphere, the near plane distance near and the far plane distance far are calculated in real time: near=max(0.1,0.01d) (to avoid clipping errors on steep slopes caused by the near plane being too close) far=min(1000.0,d+2r) (to ensure that the entire water conservancy project model is visible) Water conservancy scenario-specific parameters: Due to the characteristic of rivers stretching for several kilometers, the far plane is dynamically expanded to the range of far∈[1000.0,3000.0].
[0032] (2) Hierarchical spatial index construction: Based on the LOD2 classification rule of the water conservancy project BIM model (grid density is divided according to structural importance), a quadtree spatial index structure is constructed.
[0033] Index node storage rules: Copy Copy node level division threshold = the visual accuracy of the model at this viewing distance (for example: Level 1 (ultra-long-range): The model is simplified to 5% of the original number of faces; Level 2 (long-range): retain the outline of the dam, accounting for 15% of the total area; Level 3 (midground): complete structure + texture, 60% of the faces; (3) Sub-millisecond cutting process: Frustum space division: Divide the frustum into 3×3 grids along the depth direction and calculate the dynamic offset of each grid; Object visibility determination: If the object's bounding box intersects any sub-mesh of the viewing frustum → mark it as visible; Otherwise → add to the elimination queue (reduce ≥50% invalid data); Water conservancy scenario optimization: For narrow river areas, additional axial detection along the direction of water flow is added to avoid accidental removal of embankment models.
[0034] 2. Off-screen rendering and image processing Off-screen rendering creates a multi-layer render target (MRT) in GPU memory to avoid direct output to the screen. This solution uses three buffers: a color buffer, a vertex buffer, and a depth buffer. A pre-renderer is created, buffer data is filled, and the buffer data is drawn to complete the off-screen image assembly. The main implementation steps are as follows: / / Create vertex buffer function createVertexBuffer(gl, vertices) { / / Create a buffer object const vertexBuffer = gl.createBuffer(); / / Bind buffer gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); / / Write data to the buffer gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices),gl.STATIC_DRAW); return vertexBuffer; } / / Create a color buffer function createColorBuffer(gl, colors) { const colorBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors),gl.STATIC_DRAW); return colorBuffer; } / / Example const vertices = [ -0.5, -0.5, 0.0, / / Vertex 1 0.5, -0.5, 0.0, / / Vertex 2 0.0, 0.5, 0.0 / / Vertex 3 ]; const colors = [ 1.0, 0.0, 0.0, / / red 0.0, 1.0, 0.0, / / Green 0.0, 0.0, 1.0 / / Blue ]; const vertexBuffer = createVertexBuffer(gl, vertices); const colorBuffer = createColorBuffer(gl, colors); 3. Off-screen rendering is processed into grayscale or gradient images, and hydrological feature grayscale and gradient extraction This step first performs gridding on a frame of off-screen rendered image to determine the image size. Based on the current watershed or water conservancy project size, the large screen resolution, and the values of the near and far cross-sections, the image is split into grids of corresponding proportions, such as 1024*1024. The main implementation process is as follows: class GridRenderer { constructor(gl, width = 1024, height = 1024, gridSize = 32) { this.gl = gl; this.width = width; this.height = height; this.gridSize = gridSize; this.initFramebuffer(); this.initShaders(); this.initBuffers(); } / / Initialize the frame buffer initFramebuffer() { const gl = this.gl; / / Create a frame buffer this.frameBuffer = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer); / / Create texture attachment this.texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, this.texture); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width,this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); / / Attach the texture to the frame buffer gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); } / / Mesh shader initShaders() { const vertexShaderSource = ` attribute vec2 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = vec4(a_position, 0.0, 1.0); v_texCoord = a_texCoord; } `; const fragmentShaderSource = ` precision mediump float;[[ID=3s5]] uniform sampler2D u_image; uniform vec2 u_gridSize; varying vec2 v_texCoord; void main() { vec2 gridCoord = floor(v_texCoord * u_gridSize) / u_gridSize; vec4 color = texture2D(u_image, gridCoord); / / Add grid lines vec2 gridPosition = fract(v_texCoord * u_gridSize); float lineWidth = 0.02; if (gridPosition.x <lineWidth || gridPosition.y<lineWidth) { color = vec4(0.0, 0.0, 0.0, 1.0); } gl_FragColor = color; } `; / / Compile shader code... (implementation omitted) this.program = createProgram(gl, vertexShaderSource, fragmentShaderSource); } / / Render a frame render(sourceTexture) { const gl = this.gl; gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer); gl.viewport(0, 0, this.width, this.height); gl.useProgram(this.program); / / Set the grid size const gridSizeLocation = gl.getUniformLocation(this.program, 'u_gridSize'); gl.uniform2f(gridSizeLocation, this.width / this.gridSize, this.height / this.gridSize); / / Bind the source texture gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, sourceTexture); / / Draw gl.drawArrays(gl.TRIANGLES, 0, 6); } } The second step is to traverse from the upper left corner or the lower left corner based on the total number of grids obtained to obtain the color value of each grid; Desaturate the color value to obtain a basic grayscale image. The main process of its implementation is as follows: initShaders() { / / Vertex shader const vertexShaderSource = `#version 300 es in vec2 a_position; in vec2 a_texCoord; out vec2 v_texCoord; void main() { gl_Position = vec4(a_position, 0.0, 1.0); v_texCoord = a_texCoord; } `; / / Fragment shader (grid sampling and grayscale conversion) const fragmentShaderSource = `#version 300 es precision highp float; uniform sampler2D u_image; uniform vec2 u_gridSize; uniform vec2 u_textureSize; in vec2 v_texCoord; out vec4 outColor; vec4 getGridAverage(vec2 gridIndex) { vec2 pixelSize = 1.0 / u_textureSize; vec2 gridPixelSize = u_textureSize / u_gridSize; vec2 startUV = gridIndex / u_gridSize; vec4 sum = vec4(0.0); float count = 0.0; for(float y = 0.0; y <gridPixelSize.y; y++) { for(float x = 0.0; x <gridPixelSize.x; x++) { vec2offset = vec2(x, y) * pixelSize; sum += texture(u_image, startUV + offset); count += 1.0; } } return sum / count; } / / Convert to grayscale float toGrayscale(vec3 color) { return dot(color, vec3(0.299, 0.587, 0.114)); } void main() { vec2 gridIndex = floor(v_texCoord * u_gridSize); vec4 gridColor = getGridAverage(gridIndex); float gray = toGrayscale(gridColor.rgb); outColor = vec4(vec3(gray), 1.0); } `; / / Create shader program... (implementation omitted) this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource); } / / Process the image and get the mesh data processImage(sourceTexture) { const gl = this.gl; const totalGrids = this.gridSize * this.gridSize; const gridColors = new Float32Array(totalGrids * 4); / / RGBA foreach grid / / Set up the frame buffer gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer); gl.viewport(0, 0, this.width, this.height); / / Use the shader program gl.useProgram(this.program); / / Set uniforms gl.uniform2f( gl.getUniformLocation(this.program, 'u_gridSize'), this.gridSize, this.gridSize ); gl.uniform2f( gl.getUniformLocation(this.program, 'u_textureSize'), this.width, this.height ); / / Render to the framebuffer gl.drawArrays(gl.TRIANGLES, 0, 6); / / Read pixel data gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.FLOAT,gridColors); return this.processGridColors(gridColors); } / / Process grid color data processGridColors(gridColors) { const grids = []; / / Start from the upper left corner for(let y = this.gridSize - 1; y>= 0; y--) { for(let x = 0; x <this.gridSize; x++) { const index = (y * this.gridSize + x) * 4; grids.push({ x, y, color: gridColors.slice(index, index + 4), grayValue: gridColors[index] / / Already converted to grayscale in the shader }); } } return grids; } The third step is to add contrast weights. According to the deviation of the grayscale image, set the corresponding intensity coefficient, dynamically adjust the contrast and weight, and finally synthesize it into a grayscale or gradient image. It is suitable for the light and dark contrast grayscale or gradient images of the twin models of different hydrological basins and water conservancy projects. The effect is as follows: Figure 1 As shown, it can be used for flood evolution collision detection (height map) and Tyndall volumetric light depth detection (depth map). The main process of its implementation is as follows: class AdaptiveContrastProcessor { constructor(width = 1024, height = 1024, gridSize = 32) { this.width = width; this.height = height; this.gridSize = gridSize; this.cellWidth = width / gridSize; this.cellHeight = height / gridSize; / / Contrast parameter this.contrastParams = { minContrast: 0.2, maxContrast: 2.0, adaptiveThreshold: 0.1 }; this.initProcessing(); } initProcessing() { / / Initialize the processing pipeline this.histogram = new Array(256).fill(0); this.cumulativeHist = new Array(256).fill(0); } / / Calculate image statistics calculateStatistics(grids) { let sum = 0; let sumSquared = 0; const values = []; grids.forEach(grid =>{ sum += grid.grayValue; sumSquared += grid.grayValue * grid.grayValue; values.push(grid.grayValue); / / Update the histogram const binIndex = Math.floor(grid.grayValue * 255); this.histogram[binIndex]++; }); const mean = sum / grids.length; const variance = (sumSquared / grids.length) - (mean * mean); const stdDev = Math.sqrt(variance); return { mean, stdDev, values}; } / / Calculate adaptive weight calculateAdaptiveWeight(value, mean, stdDev) { const deviation = Math.abs(value - mean) / stdDev; const weight = 1.0 + Math.tanh(deviation - this.contrastParams.adaptiveThreshold); return Math.max(this.contrastParams.minContrast, Math.min(this.contrastParams.maxContrast,weight)); } / / Enhance hydrological features enhanceHydrologicalFeatures(grids) { const stats = this.calculateStatistics(grids); / / Calculate cumulative histogram let sum = 0; for(let i = 0; i<256; i++) { sum += this.histogram[i]; this.cumulativeHist[i]= sum; } return grids.map(grid =>{ const weight = this.calculateAdaptiveWeight( grid.grayValue, stats.mean, stats.stdDev ); / / Apply histogram equalization and weights const normalizedValue = this.cumulativeHist[Math.floor(grid.grayValue * 255)] / this.cumulativeHist
[255] ; return { ...grid, enhancedValue: normalizedValue * weight, weight }; }); } / / Generate gradient map generateGradientMap(enhancedGrids) { const gradientMap = []; for(let y = 0; y <this.gridSize; y++) { for(let x = 0; x <this.gridSize; x++) { const currentIndex = y * this.gridSize + x; const current = enhancedGrids[currentIndex].enhancedValue; / / Calculate horizontal and vertical gradients const rightIndex = x <this.gridSize - 1 ? currentIndex+ 1 : currentIndex; const bottomIndex = y <this.gridSize - 1 ?currentIndex + this.gridSize : currentIndex; const dx = enhancedGrids[rightIndex].enhancedValue -current; const dy = enhancedGrids[bottomIndex].enhancedValue -current; / / Calculate gradient strength and direction const gradientMagnitude = Math.sqrt(dx * dx + dy *dy); const gradientDirection = Math.atan2(dy, dx); gradientMap.push({ x, y, magnitude: gradientMagnitude, direction: gradientDirection, value: current }); } } return gradientMap; } } 4. Time domain grayscale frame multiplexing This step calls the GPU rendering pipeline process for a frame of grayscale image or gradient image generated in the third step, which can be used in the post-processing stage and pre-rendering of the next frame.
[0035] Its implementation mechanism is as follows Figure 2 As shown, including: (a) Motion detection: Calculate the motion vector between the current frame and the previous frames. If the motion amplitude is lower than a fixed threshold of 0.15, it is marked as a static area; otherwise, it is marked as a dynamic area. (b) Frame Assembler: The static area data source points to the n-1 frame grayscale image / gradient image cache; Dynamic region data sources trigger the real-time rendering pipeline; Output the complete frame after integrating the dynamic and static areas; (c) Cache Management: Write the current frame output data into the frame buffer pool; When the number of cached frames exceeds the threshold K (K ≥ 3), the least recently used frames are eliminated according to the LRU strategy.
[0036] Motion detection algorithm uniform sampler2D prevGray; / / Previous grayscale image uniform sampler2D motionMap; / / motion vector map void main() { vec2 uv = gl_FragCoord.xy / resolution; vec2 motionVec = texture(motionMap, uv).xy; / / Calculate the movement amplitude (0-1) float motionLevel = length(motionVec) * 10.0; if (motionLevel<0.15) { / / static area / / Trilinear filtering improves multiplexing quality fragColor = textureLod(prevGray, uv, 1.0); } else { / / dynamic area fragColor = realtimeRender(uv); } } The technical solution provided in the above embodiment uses dynamic cropping of the viewing cone to accurately screen the visible area to reduce invalid rendering, uses off-screen rendering to separate calculations, dynamically adjusts the brightness coefficient and desaturation coefficient to output the grayscale / gradient map, and extracts the core features after grayscale / gradient map conversion. It innovatively introduces an inter-frame multiplexing mechanism to apply the preprocessing results to subsequent frame rendering, which can greatly reduce the consumption of hardware resources. While ensuring the visual effect, it achieves significant optimization effects of more than 40% increase in frame rate and 35% reduction in GPU load. It is particularly suitable for real-time rendering needs of large-scale dynamic scenes such as river basins and digital twins of large-scale water conservancy projects.
[0037] Based on the same inventive concept, the present invention also provides a computer device, which includes: one or more processors, and a memory for storing one or more computer programs; the program includes program instructions, and the processor is used to execute the program instructions stored in the memory. The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is used to implement one or more instructions, specifically for loading and executing one or more instructions in a computer storage medium to implement the above method.
[0038] It should be further explained that, based on the same inventive concept, the present invention also provides a computer storage medium having a computer program stored thereon, which, when executed by a processor, performs the above-described method. The storage medium may be any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0039] It should be noted that, unless otherwise defined, the technical or scientific terms used in the present invention should have the usual meanings understood by people with ordinary skills in the field to which the present invention belongs. The "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the object being described changes, the relative positional relationship may also change accordingly.
[0040] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any other manner. Any person skilled in the art may utilize the above-disclosed technical content to modify or modify the present invention into equivalent embodiments. However, any simple modifications, equivalent variations, and modifications to the above embodiments that do not depart from the technical content of the present invention and are based on the technical essence of the present invention remain within the scope of protection of the present invention.
[0041] The present invention is not limited to the above-mentioned optimal implementation mode. Anyone can derive other forms of hydraulic twin model rendering optimization methods based on the dynamic generation of grayscale image frames based on the viewing cone under the inspiration of the present invention. All equal changes and modifications made according to the scope of the patent application of the present invention should be covered by the scope of the present invention.
Claims
1. A water conservancy twin model rendering optimization method based on dynamic generation of grayscale image frames based on a viewing cone, characterized in that: include: Get the model data of the visible area after dynamic clipping of the current frustum; Outputting the visible area model data to a multi-layer rendering target including a color buffer, a vertex buffer, and a depth buffer through off-screen rendering to generate intermediate frame data isolated from screen display; Performing gridding processing on the intermediate frame data, dividing the image into N×N grid cells according to the physical range size of the water conservancy project or watershed scene and the resolution of the display device, where N is an integer not less than 32; Calculating the average color value of each grid cell and performing desaturation processing to generate a basic grayscale image, and performing adaptive feature enhancement processing on the basic grayscale image to generate an optimized grayscale image or gradient image; The optimized grayscale image or gradient image is input into the GPU rendering pipeline and acts on: (a) Hydrological feature analysis of the current frame post-processing stage, (b) Preloaded data source for the next frame twin model rendering, The static area reuses historical frame data through motion detection, and the dynamic area triggers real-time rendering.
2. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: The off-screen rendering includes: Create a multi-layer render target containing a color buffer, a vertex buffer, and a depth buffer; Perform coordinate transformation from model space to screen space through vertex shader; Fill each buffer data through the fragment shader.
3. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: The determination of the number N of grid units includes: Get the spatial range size after dynamic clipping of the viewing frustum; The number of basic grids is calculated based on the ratio of the long side size of the spatial range to the pixel density of the display device; Constrain the number of base meshes to be within the range of 32 to 1024.
4. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: The adaptive feature enhancement process dynamically adjusts the brightness coefficient according to the frustum camera parameters, including: Calculate the statistical mean and standard deviation of the grayscale values of all grid cells; Dynamically set the contrast enhancement weight based on the deviation between the grayscale value of each grid cell and the statistical mean; Apply the weights to update the grayscale values of the grid cells.
5. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 4, characterized in that: The calculation of the contrast enhancement weight includes: Calculate the absolute deviation between the grid cell grayscale value and the overall statistical mean; Mapping the absolute deviation value through a hyperbolic tangent function; Constrain the mapping result to be between the preset minimum and maximum weight values.
6. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: The process of generating a gradient map includes: For the enhanced grayscale image grid unit; Calculate the grayscale gradient values of adjacent grids in the horizontal direction and the grayscale gradient values of adjacent grids in the vertical direction respectively; A gradient intensity map is generated based on the horizontal gradient value and the vertical gradient value, and the gradient intensity map is used for collision detection in flood evolution simulation of water conservancy projects.
7. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: The static area multiplexing historical frame data and the dynamic area triggering real-time rendering include: Calculate the motion vector between the current frame and the historical frame; When the motion amplitude is lower than the fixed threshold of 0.15, the corresponding area is marked as a static area and n-1 frames of grayscale image / gradient image data are read from the frame buffer pool; When the motion amplitude reaches or exceeds the threshold, the corresponding area is marked as a dynamic area and the real-time rendering pipeline is triggered; Integrate historical frame data of static areas and real-time rendering data of dynamic areas to generate complete output frames; Write the current output frame data into the frame buffer pool; When the number of frames stored in the frame buffer pool exceeds the threshold K, the longest unused frame is eliminated according to the LRU strategy.
8. The method for optimizing the rendering of a hydraulic twin model based on dynamic generation of grayscale image frames based on a viewing cone according to claim 1, characterized in that: Also includes: Dynamically adjust off-screen rendering resolution based on GPU memory capacity; And the upper limit of resolution is set to 2048×2048 pixels; The visible area model data is obtained through a spatial index based on LOD2 grading rules.
9. A water conservancy twin model rendering optimization system based on dynamic generation of grayscale image frames based on a viewing cone, characterized in that: include: The spatial optimization module is used to obtain the visible area model data after dynamic clipping of the current viewing cone; an off-screen rendering module configured to generate intermediate frame data isolated from screen display through a multi-layer rendering target, wherein the multi-layer rendering target includes a color buffer, a vertex buffer, and a depth buffer; The grid processing module is configured to: According to the physical range size of the water conservancy project or watershed scene and the resolution of the display device, the intermediate frame data is divided into N×N grid units, N≥32; Calculate the average color value of the grid cells and desaturate to generate a basic grayscale image; Adaptively enhance the basic grayscale image to generate an optimized grayscale image or gradient image; Time domain multiplexing module, configured as: Input the optimized grayscale image or gradient image into the GPU rendering pipeline; Multiplexing historical frame data through motion detection in static areas; Trigger real-time rendering in dynamic areas; The output results are used for both hydrological feature analysis of the current frame and preloading data sources for the next frame.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Dynamic model differentiation rendering optimization method driven by GPU (Graphics Processing Unit)
CN121564163A