Image rendering method and related apparatus
By baking the particle trajectory map method, texture data is pre-generated to store particle positions, which solves the problem of high real-time position calculation overhead in particle road map rendering and improves rendering efficiency and performance.
Patent Information
- Application Number
- PCT/CN2022/117718
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2021-10-20
- Filing Date
- 2022-09-08
- Publication Date
- 2024-09-12
AI Technical Summary
In the existing technology, the rendering process of particle traffic maps requires real-time position calculation of a large number of particles, which results in high computing overhead on the central processor and affects rendering efficiency.
The baked particle trajectory map method is used to pre-generate texture data, including texel data for each road section in the particle traffic map, which is used to store reference sampling point position data on the particle movement trajectory, and the particle position is directly determined based on the texture data during rendering.
It significantly reduces the computing overhead of the CPU, improves the rendering efficiency of particle traffic maps, reduces data transmission time and rendering batches, and optimizes rendering performance.
Smart Images

Figure CN2022117718_12092024_PF_FP_ABST
Abstract
Description
Image rendering method and related device
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on October 20, 2021, with application number 2021112188990 and application name “An image rendering method and related device”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of maps, and in particular to image rendering technology. Background Art
[0003] Particle traffic maps use dynamic particles to simulate vehicles, visualizing road traffic conditions through particle speed, direction, color, and density. In practice, particle traffic maps simulate the movement of vehicles on the road through the flow of particles. To achieve this effect, the particle map's rendering typically requires continuous redrawing at a consistent frame rate, updating the particle positions within each frame.
[0004] In the related art, before redrawing the rendered particle traffic map, it is necessary to traverse and perform geometric operations on all particles in the particle traffic map to determine updated position data of all particles in the next frame.
[0005] Faced with a massive number of particles in a particle traffic map, the updated position data of all particles must be calculated before rendering the particle traffic map each time, which will bring a very large computational overhead to the central processing unit (CPU) and affect the rendering efficiency of the particle traffic map.
[0006] Summary of the Invention
[0007] The embodiments of the present application provide an image rendering method and related devices, which can reduce the computing overhead of the CPU to a certain extent and improve the rendering efficiency of the particle road condition map.
[0008] In view of this, a first aspect of the present application provides an image rendering method, which is performed by an electronic device, and the method includes:
[0009] Acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry position data of a reference sampling point on the corresponding road section;
[0010] When rendering each frame of the particle road map, determining the position data of each particle in the particle road map at the animation running time according to the animation running time corresponding to the frame and the texel data in the texture data;
[0011] According to the position data of each particle in the particle road condition graph at the time when the animation is running, the picture corresponding to the animation running time in the particle road condition graph is rendered.
[0012] A second aspect of the present application provides an image rendering device, the device comprising:
[0013] A texture data acquisition module is used to acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry the position data of the reference sampling point on the corresponding road section;
[0014] A position data determination module is configured to determine, when rendering each frame of the particle road map, the position data of each particle in the particle road map at the animation running time according to the animation running time corresponding to the frame and the texel data in the texture data;
[0015] The picture rendering module is used to render the picture corresponding to the animation running time in the particle road condition map according to the position data of each particle in the particle road condition map at the animation running time.
[0016] A third aspect of the present application provides an electronic device, the device comprising a processor and a memory:
[0017] The memory is used to store computer programs;
[0018] The processor is configured to execute the steps of the image rendering method described in the first aspect according to the computer program.
[0019] In a fourth aspect, the present application provides a computer-readable storage medium, which is used to store a computer program, and the computer program is used to execute the steps of the image rendering method described in the first aspect.
[0020] In a fifth aspect, the present application provides a computer program product or computer program, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of the image rendering method described in the first aspect.
[0021] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0022] An embodiment of the present application provides an image rendering method that innovatively uses a baked particle trajectory map to replace the real-time position calculation in the particle road map rendering process; the baked particle trajectory map is essentially the texture data corresponding to the pre-generated particle road map, and the texture data includes the texel data corresponding to each road section in the particle road map, and the texel data is used to carry the position data of the reference sampling point sampled from the particle motion trajectory supported by its corresponding road section. When rendering each frame of the particle road map, the position data of each particle in the particle road map at the time of the animation running corresponding to the frame can be directly determined based on the texel data in the texture data corresponding to the particle road map, and then, based on the position data of each particle in the particle road map at the time of the animation running, the frame of the particle road map is rendered. Compared with the rendering method of the particle traffic map in the related art, the embodiment of the present application does not need to calculate the position data of all particles in the particle traffic map in real time before rendering each frame of the particle traffic map. It can directly determine the current position data of each particle in the particle traffic map based on the position data carried by the texel data in the texture data corresponding to the particle traffic map, thereby greatly reducing the computing overhead required by the CPU during the particle traffic map rendering process. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] FIG1 is a schematic diagram of an application scenario of an image rendering method provided in an embodiment of the present application;
[0024] FIG2 is a schematic diagram of a flow chart of an image rendering method provided in an embodiment of the present application;
[0025] FIG3 is a schematic diagram of an exemplary particle road map provided in an embodiment of the present application;
[0026] FIG4 is a schematic diagram of a process for generating texture data corresponding to a particle road condition map according to an embodiment of the present application;
[0027] FIG5 is a schematic diagram illustrating an implementation of recording a starting point offset corresponding to a road segment according to an embodiment of the present application;
[0028] FIG6 is a schematic diagram of the implementation principle of calculating a reference texel index according to an embodiment of the present application;
[0029] FIG7 is a schematic diagram illustrating the implementation principle of sub-pixel shift processing provided in an embodiment of the present application;
[0030] FIG8 is a schematic diagram of the overall implementation process of the image rendering method provided in an embodiment of the present application;
[0031] FIG9 is a schematic structural diagram of an image rendering device provided in an embodiment of the present application;
[0032] FIG10 is a schematic structural diagram of another image rendering device provided in an embodiment of the present application;
[0033] FIG11 is a schematic structural diagram of another image rendering device provided in an embodiment of the present application;
[0034] FIG12 is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0035] FIG13 is a schematic diagram of the structure of the server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] In order to help those skilled in the art better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 those skilled in the art without creative work are within the scope of protection of this application.
[0037] The terms "first," "second," "third," "fourth," etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential sequence. It should be understood that the numbers used in this way are interchangeable where appropriate so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or apparatus.
[0038] The Intelligent Traffic System (ITS), also known as the Intelligent Transportation System, effectively integrates advanced science and technology (information technology, computer technology, data communication technology, sensor technology, electronic control technology, automatic control theory, operations research, artificial intelligence, etc.) into transportation, service control, and vehicle manufacturing, strengthening the connection between vehicles, roads, and users, thereby forming an integrated transportation system that ensures safety, improves efficiency, improves the environment, and conserves energy. The image rendering method provided in the embodiments of the present application can be used to render particle road condition maps related to the Intelligent Transportation System.
[0039] The image rendering method provided in the embodiments of the present application can be applied to any electronic device with image rendering capabilities, such as a terminal device or a server. Specifically, the terminal device can be a smartphone, a tablet computer, a computer, a personal digital assistant (PDA), an intelligent voice interaction device, a smart home appliance, an in-vehicle terminal, and the like. Specifically, the server can be an application server or a web server. In actual deployment, it can be a standalone server, a cluster server, or a cloud server.
[0040] To facilitate understanding of the image rendering method provided in the embodiments of the present application, the following uses a terminal device as an example to executor of the image rendering method to executor the image rendering method to executor the application scenario of the image rendering method.
[0041] See Figure 1, which is a schematic diagram of an application scenario of the image rendering method provided in an embodiment of the present application. As shown in Figure 1, the application scenario includes a server 110 and a terminal device 120, and the server 110 and the terminal device 120 can communicate through a network. Among them, the server 110 can be a background server of a target application for providing location services, and the target application supports the display of a particle road condition map; the target application is running on the terminal device 120, and the terminal device 120 can execute the image rendering method provided in an embodiment of the present application, and render and display the particle road condition map through the target application.
[0042] In actual applications, the server 110 can send texture data corresponding to the particle road condition map to the terminal device 120. The texture data includes the texel data corresponding to each road section in the particle road condition map. The texel data is used to carry the position data of the reference sampling point on the corresponding road section. The reference sampling point is obtained by sampling on the particle motion trajectory supported by the road section based on the reference frame rate.
[0043] For example, the terminal device 120 may send a request to the server 110 to display a particle traffic map. After receiving the request, the server 110 may generate texture data corresponding to the particle traffic map requested by the terminal device 120. Specifically, the server 110 may determine the geographic area corresponding to the particle traffic map requested by the terminal device 120 and obtain traffic information for the geographic area, such as the traffic status of each road section in the geographic area (e.g., unimpeded, slow-moving, congested, severely congested, etc.). Then, based on the traffic information of the geographic area, the server 110 may sample the particle motion trajectories supported by each road section in the geographic area at a reference frame rate (e.g., the frame rate of the image of the particle traffic map displayed by the terminal device 120), obtain reference sampling points on each road section, and determine the position data of the reference sampling points on each road section. Furthermore, the server 110 may write the position data of the reference sampling points on each road section in the geographic area into the texture data to obtain texture data corresponding to the particle traffic map, and send the texture data corresponding to the particle traffic map to the terminal device 120.
[0044] After the terminal device 120 obtains the texture data corresponding to the particle road condition map, it can render and display each frame of the particle road condition map based on the texture data corresponding to the particle road condition map.
[0045] When the terminal device 120 renders each frame of the particle traffic map, for each particle in the particle traffic map, the position data of the particle at the time of the animation running corresponding to the frame can be determined based on the texel data corresponding to the road section to which the particle belongs in the texture data corresponding to the particle traffic map. That is, the terminal device 120 can search for the texel data corresponding to the road section to which the particle belongs in the texture data corresponding to the particle traffic map, and then deduce the position data of the particle at the time of the animation running corresponding to the frame based on the position data carried by the found texel data. Based on this, the terminal device 120 can further render the frame of the particle traffic map based on the position data of each particle in the particle traffic map at the time of the animation running corresponding to the frame.
[0046] It should be understood that the application scenario shown in Figure 1 is only an example. In actual applications, the image rendering method provided by the embodiment of the present application can also be applied to other scenarios. For example, the image rendering method provided by the embodiment of the present application can also be independently executed by the server 110 or the terminal device 120, that is, the texture data corresponding to the particle road condition map is generated by the CPU in the server 110 or the terminal device 120, and the graphics processing unit (GPU) in the server 110 or the terminal device 120 renders each frame in the particle road condition map based on the texture data corresponding to the particle road condition map generated by the CPU. The image rendering method provided by the embodiment of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc., and the application scenario of the image rendering method provided by the embodiment of the present application is not limited in any way here.
[0047] The image rendering method provided by this application is introduced in detail below through method embodiments.
[0048] See Figure 2, which is a flow chart of the image rendering method provided in an embodiment of the present application. For ease of description, the following embodiment is still described using the execution subject of the image rendering method as a terminal device as an example. As shown in Figure 2, the image rendering method includes the following steps:
[0049] Step 201: Acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry the position data of the reference sampling point on the corresponding road section.
[0050] In an embodiment of the present application, before a terminal device renders and displays a particle road map, it is necessary to first obtain texture data corresponding to the particle road map. The texture data corresponding to the particle road map includes texel data corresponding to each road segment in the particle road map. The texel data is used to carry the position data of a reference sampling point on the corresponding road segment. The reference sampling point is obtained by sampling the particle motion trajectory supported by the road segment based on the reference frame rate.
[0051] As an example, the terminal device can obtain the texture data corresponding to the particle road condition map from the server; for example, the terminal device can send a particle road condition map display request to the server, and the particle road condition map display request can carry the geographical area corresponding to the particle road condition map requested to be displayed. The server responds to the particle road condition map display request and can generate the texture data corresponding to the particle road condition map according to the traffic conditions of the geographical area, and then return the texture data corresponding to the particle road condition map to the terminal device.
[0052] As another example, the terminal device may also autonomously generate texture data corresponding to the particle road condition map before rendering the particle road condition map; for example, the terminal device may obtain the traffic conditions of a certain geographical area from a server, and then, based on the traffic conditions of the geographical area, the CPU of the terminal device may generate texture data corresponding to the particle road condition map that reflects the traffic conditions of the geographical area, and then transmit the texture data corresponding to the particle road condition map to the GPU so that the GPU can obtain the position data of the particles therefrom when rendering the particle road condition map.
[0053] It should be noted that in the related art, the CPU usually calculates the updated position data of all particles before rendering the particle road map each time, and transmits the updated position data of all particles to the GPU, so that the GPU can render the next frame of the particle road map based on the updated position data of all particles. The amount of data required to be transmitted in this process is extremely large, which will result in a long transmission time and affect the rendering efficiency of the particle road map. In the embodiment of the present application, the texture data corresponding to the particle road map will be transmitted to the GPU before rendering the particle road map. Compared with the related art, the process of transmitting particle position data from the CPU to the GPU during the particle road map rendering process is omitted. Accordingly, the data transmission time during the particle road map rendering process can be reduced, thereby improving the rendering efficiency of the particle road map.
[0054] It should be understood that the above-mentioned implementation method of obtaining the texture data corresponding to the particle road condition map is only an example. In actual applications, the terminal device can also obtain the texture data corresponding to the particle road condition map through other methods. This application does not impose any restrictions on the method of obtaining the texture data corresponding to the particle road condition map.
[0055] It should be noted that a particle traffic map uses dynamic particles to simulate vehicles, and is a dynamic image that reflects road traffic conditions through at least one of the following information: particle speed, direction, color, and density. The particle flow effect in the particle traffic map is achieved by continuously redrawing the particle traffic map at a certain frame rate and updating the particle position in each frame. Figure 3 is a schematic diagram of an exemplary particle traffic map. As shown in Figure 3, the distribution of particles on sections with different traffic conditions varies. On congested sections, there are more particles and the particles are distributed more densely, thereby simulating a situation where the vehicle density is higher due to congestion. On unobstructed sections, there are fewer particles and the particles are distributed more sparsely, thereby simulating a situation where vehicles are traveling smoothly. In addition, the traffic condition of a section can be reflected by setting the color of the particles in the particle traffic map. For example, particles on congested sections can be set to red, particles on slow-moving sections can be set to yellow, particles on unobstructed sections can be set to green, and so on.
[0056] It should be noted that texture data is essentially a two-dimensional bitmap image, which is a commonly used data storage method in image rendering, in which each data bit stores a pixel of data. The embodiment of the present application innovatively uses texture data to store the position data of the reference sampling points on the particle motion trajectory in the particle road map; before rendering the particle road map, the texture data of the particle road map will be passed to the shader of the GPU. Accordingly, when the GPU renders the particle road map, it can directly read the particle position data from the texture data. On the one hand, it eliminates the process of transmitting the real-time position data of massive particles from the CPU to the GPU, thereby improving rendering efficiency; on the other hand, using texture data to store the position data of the reference sampling points on the particle motion trajectory can realize texture data sharing, reduce rendering batches, and optimize rendering performance.
[0057] In an embodiment of the present application, the texture data corresponding to the particle road condition map includes texel data that has a corresponding relationship with the road section in the particle road condition map, that is, a road section in the particle road condition map can correspond to multiple texel data in the texture data, and these texel data are used to carry the position data of multiple reference sampling points on the road section. The reference sampling point here is obtained by sampling the particle motion trajectory supported by the road section based on the reference frame rate. The reference frame rate can be determined based on the frame rate commonly used when the terminal device displays the particle road condition map; for example, assuming that the frame rate commonly used when the terminal device displays the particle road condition map is 30FPS to 50FPS, 30FPS can be determined as the reference frame rate. This application does not impose any restrictions on the reference frame rate.
[0058] The following is a detailed description of the method for generating the texture data corresponding to the particle road condition map described above, in conjunction with the process shown in FIG4 . It should be understood that the operation of generating the texture data corresponding to the particle road condition map can be performed by a server or a terminal device, and this application does not impose any restrictions on the execution entity of the operation of generating the texture data corresponding to the particle road condition map. As shown in FIG4 , the method for generating the texture data corresponding to the particle road condition map includes the following steps:
[0059] Step 401: Obtain a route data set corresponding to the particle road condition map; the route data set includes route data corresponding to each road section in the particle road condition map, and the route data includes road condition information of the road section and position data of multiple path points arranged in sequence on the road section.
[0060] Before generating the texture data corresponding to the particle road condition map, it is necessary to first obtain the route data set lineList corresponding to the particle road condition map. The route data set lineList includes the route data line corresponding to each road section in the particle road condition map; the route data line includes the road condition information t of the road section, and the position data path of multiple path points arranged in order on the road section; for example, the road condition information t included in the route data line can be used to reflect the traffic status of the road section, such as smooth, slow, congested, etc. The position data path of the multiple path points included in the route data line can be expressed as [p0x, p0y, p1x, p1y, ..., p n x, p n y], that is, multiple path points p0, p1, ..., p n The x-coordinates and y-coordinates are arranged in sequence.
[0061] Step 402: For each road section in the particle road condition map, determine the position data of each reference sampling point on the road section according to the reference frame rate and the route data corresponding to the road section.
[0062] After obtaining the route data set corresponding to the particle road condition map, the particle motion trajectory supported by each road section in the particle road condition map can be determined based on the position data of the path points included in the route data corresponding to the road section; and sampling is performed on the particle motion trajectory according to the reference frame rate to obtain the various reference sampling points on the road section, and the position data of each reference sampling point on the road section is determined accordingly.
[0063] In one possible implementation, the sub-segments and their respective lengths on a road segment can be determined based on the position data of every two adjacent path points in the route data. Here, the starting and ending points of a sub-segment are two adjacent path points in the route data, respectively. Then, for each sub-segment on the road segment, the number of reference sampling points on the sub-segment is determined based on the sub-segment's length, the reference frame rate, and the particle motion speed corresponding to the sub-segment. The particle motion speed is determined based on the road condition information in the route data corresponding to the sub-segment. Furthermore, for each sub-segment on the road segment, the position data of each reference sampling point on the sub-segment is determined based on the position data of the sub-segment's starting and ending points and the number of reference sampling points on the sub-segment.
[0064] For example, it is assumed that the route data corresponding to a certain road section includes the location data of n (n is an integer greater than 1) path points, and these n path points are p1, p2, ..., p n, and these n path points are arranged sequentially on the road segment; then every two adjacent path points among these n path points can form a sub-segment; for example, p1 and p2 form a sub-segment, p2 and p3 form a sub-segment, ..., p n-1 and p n This constitutes a sub-segment, and thus n-1 sub-segments are obtained.
[0065] Then, the length of each sub-segment can be calculated; for example, for the i-th sub-segment, its length can be calculated by formula (1): i :
[0066]
[0067] Furthermore, for each sub-segment, the number of reference sampling points on the sub-segment can be determined according to the length of the sub-segment, the reference frame rate, and the particle motion speed corresponding to the sub-segment. For example, for the i-th sub-segment, the number of reference sampling points N on it can be calculated by formula (2): i :
[0068]
[0069] Where ΔD = v / F, representing the distance between two adjacent reference sampling points on the i-th sub-segment. It should be understood that ΔD typically varies between sections with different traffic conditions: smoother sections have larger ΔD, while more congested sections have smaller ΔD. F represents the reference frame rate, which can be set based on actual conditions. For example, it can be set to 30 FPS, the base frame rate for smooth animation. The reference frame rate is essentially the frequency at which reference sampling points are collected along the particle trajectory. For example, at a reference frame rate of 30 FPS, the particle trajectory is sampled 30 times per second. v is the particle motion speed corresponding to the road section, which can be determined based on the road condition information in the route data corresponding to the road section; the particle motion speed is negatively correlated with the congestion degree reflected by the road condition information, that is, the more congested the road section reflected by the road condition information, the smaller the particle motion speed corresponding to the road section, and the smoother the road section reflected by the road condition information, the greater the particle motion speed corresponding to the road section; in this embodiment of the application, the correspondence between the particle motion speed and the road condition information can be pre-set, and then, when determining the number of reference sampling points on the sub-road section, the particle motion speed corresponding to the road section can be directly determined based on the correspondence; for example, the road condition information used to reflect the smoothness of the road section can be set to correspond to a particle motion speed of 80 pixels / second, and the road condition information used to reflect the congestion of the road section can be set to correspond to a particle motion speed of 10 pixels / second, and so on. The application does not make a specific limitation on the correspondence between the particle motion speed and the road condition information.
[0070] Furthermore, for each sub-segment on the road segment, a corresponding number of reference sampling points (i.e., the number determined by the above formula (2)) can be interpolated between the starting point and the end point of the sub-segment; for example, assuming that the number of reference sampling points on the i-th sub-segment is N i , then the reference sampling point p can be interpolated on the i-th sub-segment according to the position data of the starting and ending points of the i-th sub-segment through equations (3) and (4): ij , where j ranges from 0 to N i-1 :
[0071]
[0072]
[0073] Among them, p i x and p i y is the horizontal and vertical coordinates of the starting point of the i-th sub-segment, p i+1 x and p i+1 y is the horizontal and vertical coordinates of the end point of the i-th sub-segment.
[0074] Arrange the reference sampling points in all sub-sections of the road section in order, and you can get the particle motion trajectory trail supported by the road section. For example, the particle motion trajectory trail supported by a road section can be expressed as [p 00 , p 01 , p 02 ,…,p ij …].
[0075] Step 403: writing the position data of each reference sampling point on each road section in the particle road condition map into the initial texture data to obtain texture data corresponding to the particle road condition map.
[0076] After obtaining the position data of each reference sampling point on each road section in the particle road condition map through the above steps, the position data of each reference sampling point can be written into the initial texture data to obtain the texture data corresponding to the particle road condition map.
[0077] In one possible implementation, initial texture data can be created. The number of texels carried by this initial texture data should be greater than or equal to the total number of reference sampling points in the particle road map. The position data of each reference sampling point on each road segment in the particle road map is then converted into the reference channel value of the texel in the initial texture data, obtaining the reference channel value corresponding to each reference sampling point. Furthermore, the reference channel value corresponding to each reference sampling point is sequentially written into a reference position data sequence, and the texture data corresponding to the particle road map is generated based on this reference position data sequence.
[0078] For example, initial texture data can be created first, and a binary sequence matching the size of the initial texture data can be created as a reference position data sequence. For example, assuming the width of the created initial texture data is w and the height is h, then the number of texels that the initial texture data can carry is size = w * h. Since each texel is usually represented by four 8-bit unsigned integers RGBA (red, green, blue, alpha), a reference position data sequence matching the initial texture data can be created in the following format:
[0079] pointArray=new Uint8ClampedArray(w*h*4)
[0080] When generating texture data corresponding to the particle road map, each road segment in the particle road map can be traversed, and the position data of each reference sampling point on each road segment in the particle road map can be converted into the RGBA channel value of the texel in the initial texture data, thereby obtaining the RGBA channel value corresponding to each reference sampling point. Then, the RGBA channel value corresponding to each reference sampling point is sequentially written into the previously created reference position data sequence; further, the RGBA channel value corresponding to each reference sampling point in the reference position data sequence is correspondingly written into the texel data in the initial texture data, thereby obtaining the texture data corresponding to the particle road map.
[0081] In actual applications, when the size of the particle traffic condition map is large, for example, when the geographical area corresponding to the particle traffic condition map is large, the terminal device needs to render the particle traffic condition map in units of target size, that is, the terminal device needs to divide the particle traffic condition map in units of target size to obtain multiple sub-traffic condition maps, and then render each sub-traffic condition map one by one; exemplarily, the terminal device can load the data in the particle traffic condition map in units of tiles, and render the particle traffic condition map in units of tiles.
[0082] In this case, when creating the initial texture data, initial texture data corresponding to each sub-road condition map can be created. The sub-road condition map is obtained by dividing the particle road condition map based on the target size as described above. Then, for each sub-road condition map, the position data of each reference sampling point on each road section in the sub-road condition map can be converted into the reference channel value of the texel in the initial texture data corresponding to the sub-road condition map, and the reference channel value corresponding to each reference sampling point in the sub-road condition map can be obtained; the position data of each reference sampling point in the sub-road condition map is actually determined in the coordinate space corresponding to the sub-road condition map. Furthermore, for each sub-road condition map, the reference channel value corresponding to each reference sampling point is sequentially written into the reference position data sequence corresponding to the sub-road condition map, and the texture data corresponding to the sub-road condition map is generated based on the reference position data sequence corresponding to the sub-road condition map.
[0083] For example, in each sub-traffic map obtained by dividing the particle road condition map into tiles, the value range of the horizontal coordinate x and the vertical coordinate y of the reference sampling point can both be [-128, 383]. In this case, if each texel in the initial texture data corresponding to the sub-traffic map is expressed by four 8-bit unsigned integers of RGBA, then any two channel values in the texel can be used to carry the horizontal coordinate of the reference sampling point, and the remaining two channel values can be used to carry the vertical coordinate of the reference sampling point, thereby realizing the conversion of the position data of the reference sampling point to the reference channel value corresponding to the reference sampling point. Furthermore, the reference channel value corresponding to the converted reference sampling point is written into the reference position data sequence corresponding to the sub-road condition map. It should be understood that the reference position data sequence is constructed based on the initial texture data corresponding to the sub-road condition map, and matches the size of the initial texture data corresponding to the sub-road condition map; and according to the reference channel value corresponding to each reference sampling point in the reference position data sequence corresponding to the sub-road condition map, the texel data of each texel in the initial texture data corresponding to the sub-road condition map is determined accordingly, thereby obtaining the texture data corresponding to the sub-road condition map. It should be understood that the method of determining the texture data corresponding to the sub-road condition map is the same as the method of determining the texture data corresponding to the particle road condition map introduced above, and will not be repeated here.
[0084] In one possible implementation, the conversion of the position data of each reference sampling point in the particle road condition map into the reference channel value of the texel in the initial texture data can be achieved in the following manner: for the position data of each reference sampling point, the red channel value and the green channel value of the texel are determined according to the horizontal position data in the position data, and the blue channel value and the transparency channel value of the texel are determined according to the vertical position data in the position data; or, for the position data of each reference sampling point, the red channel value and the green channel value of the texel are determined according to the vertical position data in the position data, and the blue channel value and the transparency channel value of the texel are determined according to the horizontal position data in the position data.
[0085] For example, assuming that the particle traffic map is divided into multiple sub-traffic maps in units of tiles, and the x-coordinate and y-coordinate values of the reference sampling point in each sub-traffic map are both in the range of [-128, 383]; if each texel in the initial texture data corresponding to the sub-traffic map is represented by four 8-bit unsigned integers of RGBA, the position data of the reference sampling point can be converted into the RGBA channel value corresponding to the reference sampling point in the following way:
[0086] x'=x+128, y'=y+128
[0087] r=x'>256? (x'-256): 0
[0088] g=x'>256?256:x'
[0089] b=y'>256? (y'-256): 0
[0090] a=y'>256?256:y'
[0091] That is, considering that the value range of x and y is [-128,383], and the range of 8-bit unsigned integers is [0,256], we can first add 128 to the original values of x and y to obtain x' and y'. Then, determine whether x' is greater than 256. If so, determine the value of the texel R channel value to be (x'-256). If not, determine the value of the texel R channel value to be 0; determine whether x' is greater than 256. If so, determine the value of the texel G channel value to be 256. If not, determine the value of the texel G channel value to be x'; determine whether y' is greater than 256. If so, determine the value of the texel B channel value to be (y'-256). If not, determine the value of the texel B channel value to be 0; determine whether y' is greater than 256. If so, determine the value of the texel A channel value to be 256. If not, determine the value of the texel A channel value to be y'. In this way, the R channel value and the G channel value of the texel are used to carry the horizontal coordinate of the reference sampling point, and the B channel value and the A channel value of the texel are used to carry the vertical coordinate of the reference sampling point.
[0092] Alternatively, a similar method as above may be used to use the R channel value and the G channel value of the texel to carry the vertical coordinate of the reference sampling point, and use the B channel value and the A channel value of the texel to carry the horizontal coordinate of the reference sampling point.
[0093] Of course, in actual applications, other methods can also be used to use the RGBA channel values of the texel to carry the position data of the reference sampling point; for example, the R channel value and B channel value of the texel are used to carry the horizontal coordinate of the reference sampling point, and the G channel value and A channel value of the texel are used to carry the vertical coordinate of the reference sampling point, and so on; or, other algorithms can be used to realize the conversion between the position data and the RGBA channel value of the texel. This application does not impose any limitation on the implementation method of converting the position data of the reference sampling point into the RGBA channel value of the texel.
[0094] To facilitate the rapid retrieval of texel data corresponding to a road segment within the texture data corresponding to the particle road map during the rendering process, embodiments of the present application may also record the starting offset corresponding to each road segment in the particle road map during the generation of the texture data corresponding to the particle road map. That is, for each road segment in the particle road map, the starting offset corresponding to the road segment in the reference position data sequence is determined, and the correspondence between the road segment and the starting offset is recorded; the starting offset corresponding to the road segment here is the position of the reference channel value corresponding to the first reference sampling point on the road segment in the reference position data sequence.
[0095] FIG5 is a schematic diagram of the implementation of recording the starting offset corresponding to a road section. As shown in FIG5 , the reference position data sequence includes the reference channel values corresponding to each reference sampling point on each road section. For example, part 501 of the reference position data sequence is used to carry the reference channel values corresponding to each reference sampling point on road section line0, and part 502 of the reference position data sequence is used to carry the reference channel values corresponding to each reference sampling point on road section line1, and so on. When determining the starting offset corresponding to each road section in the particle road condition map, when writing the reference channel value corresponding to the first reference sampling point on the road section into the reference position data sequence, the position of the reference channel value corresponding to the first reference sampling point in the reference position data sequence can be recorded as the starting offset corresponding to the road section; as shown in FIG5 , start0 is the starting offset corresponding to road section line0, and start1 is the starting offset corresponding to road section line1.
[0096] The implementation code for recording the starting point offset corresponding to the road segment in the above manner is shown below:
[0097]
[0098] It should be understood that the implementation method of determining the starting point offset corresponding to the road section introduced above is only an example. In actual applications, the starting point offset corresponding to the road section can also be directly determined in the texture data corresponding to the particle road condition map; for example, for each road section in the particle road condition map, the index of the texel in the texture data used to carry the reference channel value corresponding to the first reference sampling point on the road section (which may include row index and column index) is used as the starting point offset corresponding to the road section; this application does not impose any limitation on the implementation method of determining the starting point offset corresponding to the road section.
[0099] Step 202: When rendering each frame of the particle traffic map, the position data of each particle in the particle traffic map at the animation running time is determined according to the animation running time corresponding to the frame and the texel data in the texture data.
[0100] After acquiring the texture data corresponding to the particle map, the terminal device can use its own GPU to render each frame of the particle map based on the texture data. When rendering each frame of the particle map, the GPU can determine the position data of each particle in the particle map at the time of the animation running according to the animation running time corresponding to the currently rendered frame and the texel data corresponding to the road section to which the particle belongs in the texture data.
[0101] It should be noted that the animation running time corresponding to the picture is the time difference between the playback time of the picture and the initial playback time of the particle road map (that is, the time when the first frame of the particle road map is played). The animation running time can determine the movement position of the particles in the particle road map.
[0102] In one possible implementation, a terminal device can determine the position data of a particle in a particle traffic map at the time of animation execution by: determining the particle's offset at the time of animation execution based on the animation execution time and the particle's initial offset on the road segment to which it belongs. Then, the index of the target texel is determined based on the particle's offset at the time of animation execution, the frame rate of the particle traffic map, the road condition information of the road segment to which the particle belongs, and the starting offset corresponding to the road segment to which the particle belongs. The starting offset corresponding to the road segment is used to indicate the distribution position of the position data of the reference sampling point belonging to the road segment in the texture data. Furthermore, the target texel data is searched in the texture data based on the target texel index, and the position data of the particle at the time of animation execution is determined based on the target texel data.
[0103] For example, in order to achieve the effect of particle flow in the particle road map, it is necessary to update the position of each particle in each frame of the particle road map. Therefore, before rendering each frame of the particle road map, the embodiment of the present application will pass an animation running time to the GPU. The animation running time is the animation running time corresponding to the picture currently to be rendered, that is, the time difference between the rendering time of the picture currently to be rendered and the rendering time of the first frame of the particle road map. Furthermore, the GPU can calculate the offset offsetNow of each particle in the particle road map at the animation running time by the following formula (5):
[0104] offsetNow=offset+v*t (5)
[0105] Wherein, offset is the initial offset of the particle on the road section to which it belongs, which is pre-configured for each particle in the particle road condition map. v is the particle movement speed corresponding to the road section to which the particle belongs, and the particle movement speed is determined based on the road condition information of the road section to which the particle belongs; for example, the correspondence between the particle movement speed and the road condition information can be pre-configured. Accordingly, when calculating the offset of each particle at a certain animation running moment, the particle movement speed corresponding to the road section to which the particle belongs can be directly determined based on the correspondence and the road condition information of the road section to which the particle belongs. t is the animation running moment corresponding to the current image to be rendered. It should be understood that the unit of the above v is pixels / second, and the units of the above offsetNow and offset are both pixels.
[0106] Furthermore, the terminal device can search for the target texel in the texture data corresponding to the particle road condition map based on the offset of the particle at the time of animation running, the current frame rate of the particle road condition map, the particle movement speed corresponding to the road section to which the particle belongs, and the starting point offset corresponding to the road section to which the particle belongs. The position data carried by the target texel has a high reference value for determining the position data of the particle at the time of animation running, that is, the position data carried by the target texel is the same as or similar to the position data of the particle at the time of animation running.
[0107] As an example, the terminal device can determine the index of the target texel by performing a modulo operation on the length of the road segment to which the particle belongs using the particle's offset at the time the animation is running. The particle's offset index is then determined based on the target offset, the current frame rate of the particle's road condition map, and the particle's motion speed corresponding to the road segment to which the particle belongs; the particle's motion speed corresponding to the road segment is determined based on the road condition information of the road segment. Furthermore, the horizontal and vertical indices of the reference texel are determined based on the particle's offset index and the starting point offset corresponding to the road segment to which the particle belongs. Sub-pixel offset processing is then performed on the horizontal and vertical indices of the reference texel to obtain the horizontal and vertical indices of the target texel.
[0108] Specifically, in the particle road condition diagram, the movement of particles on a road section is essentially a circular motion. That is, after each particle on the road section moves from its initial offset position on the road section to the end point of the road section, the particle needs to return to the starting point of the road section and re-move along the particle movement direction corresponding to the road section. In order to achieve this circular motion of particles on the road section, the embodiment of the present application needs to use the following formula (6) to perform a modulo operation on the length of the road section to which it belongs, using the offset of the particle at the time of animation running, to determine the actual offset of the particle on the road section to which it belongs, that is, the target offset offsetNow':
[0109] offsetNow'=offsetNow% length (6)
[0110] Wherein, offsetNow is the offset of the particle at the time of the animation run, determined by formula (5) above based on the initial offset of the particle on the road segment to which it belongs, the particle movement speed corresponding to the road segment to which the particle belongs, and the animation run time corresponding to the image to be rendered. length is the length of the road segment to which the particle belongs. When the offset offsetNow of the particle at a certain animation run time is less than the length of the road segment to which the particle belongs, the target offset offsetNow' of the particle on the road segment is offsetNow itself; when the offset offsetNow of the particle at a certain animation run time is greater than or equal to the length of the road segment to which the particle belongs, the target offset offsetNow' of the particle on the road segment is the remainder value of dividing offsetNow by length.
[0111] Then, the terminal device can use the target offset of the particle on the road section to which it belongs to divide by the current sampling interval distance of the road section to which the particle belongs to obtain the offset index of the particle. The current sampling interval distance of the road section is determined based on the current frame rate of the particle road condition map and the particle movement speed corresponding to the road section to which the particle belongs. It is used to characterize the movement distance of the same particle on the road section in two adjacent sampling operations. The offset index of the particle here represents the index of the reference texel in the texel corresponding to the road section to which the particle belongs. The position data carried by the reference texel has a high reference value for determining the position data at the target offset on the road section. Specifically, the terminal device can calculate the offset index step of the above particle by the following formula (7):
[0112]
[0113] Where offsetNow' is the target offset of the particle on the road segment to which it belongs. ΔD is the current sampling interval of the particle's road segment, ΔD = v / F; where F is the current frame rate of the particle road map, and v is the particle's velocity corresponding to the particle's road segment.
[0114] After calculating the offset index step of the particle, the terminal device can determine the horizontal index and vertical index of the reference texel based on the offset index of the particle and the starting offset corresponding to the road section to which the particle belongs. Taking the starting offset corresponding to the road section to which the particle belongs as the position of the reference channel value corresponding to the first reference sampling point on the road section in the reference position data sequence as an example, Figure 6 is a schematic diagram of the implementation principle of calculating the reference texel index in this case. As shown in Figure 6, after the terminal device calculates the offset index step of the particle, it can add the step to the starting offset start corresponding to the road section to which the particle belongs. The reference channel value carried at the position (start+step) in the reference position data sequence is the reference channel value of the reference texel. The position data based on which the reference channel value is converted has a high reference value for determining the position data at the target offset on the road section, that is, the position data based on which the reference channel value is converted may be the same or similar to the position data at the target offset on the road section. On this basis, the terminal device can further calculate the horizontal index (i.e., column index column) and vertical index (i.e., row index row) of the reference texel through equations (8) and (9):
[0115] column=(start+step)%w (8)
[0116]
[0117] Where w represents the width of the texture data corresponding to the particle road map; the horizontal index of the reference texel is obtained by taking the modulo of the texture data width w by (start + step). floor() is a floor function; the vertical index of the reference texel is obtained by taking the result of dividing (start + step) by w and rounding it down.
[0118] Considering that in many cases the reference texels determined by the above method may have deviations, for example, the horizontal index and vertical index of the determined reference texels are both too small. Accordingly, directly calculating the position data of the particle at the time of animation running based on the position data carried by the reference texel may cause the calculated position data to be inaccurate. In order to avoid this situation, after the embodiment of the present application calculates the horizontal index and vertical index of the reference texel, it can further perform sub-pixel offset processing on the horizontal index and vertical index of the reference texel to obtain the horizontal index and vertical index of the target texel. Here, the position data carried by the target texel is usually closer to the position data at the target offset on the road section than the position data carried by the reference texel, that is, the position data carried by the target texel is more valuable for reference than the position data carried by the reference texel. Exemplarily, the terminal device can perform sub-pixel offset processing on the horizontal index and vertical index of the reference texel through formula (10) and formula (11) respectively to obtain the horizontal index u and vertical index v of the target texel:
[0119]
[0120]
[0121] Figure 7 shows a schematic diagram of the implementation principle of the above-mentioned sub-pixel offset processing. As shown in Figure 7, the sub-pixel offset processing is implemented by the above-mentioned equations (10) and (11). In essence, it is to offset by 0.5 in the horizontal and vertical directions respectively, and then perform normalization processing. After this processing, the horizontal and vertical coordinates of the target pixel are obtained.
[0122] It should be understood that the above text introduces the implementation process of determining the index of the target texel by taking the position of the reference channel value corresponding to the first reference sampling point on the road section in the reference position data sequence as an example. When the starting point offset corresponding to the road section is in other forms of expression, the embodiment of the present application can also adopt a corresponding method to determine the index of the target texel based on the starting point offset. The present application does not impose any limitation on the implementation method of determining the index of the target texel.
[0123] After the terminal device determines the index of the target texel, it can search for the corresponding target texel data in the texture data based on the index of the target texel, and then determine the position data of the particle at the time of animation running based on the target texel data.
[0124] As an example, considering that the reference frame rate used when generating texture data may not fully match the frame rate of the actual display of the particle road map, the particle's position data may not correspond one-to-one with the position data carried by the texel during texture mapping in the shader, and may be located in the middle of the position data carried by two texels. To address this situation, the embodiments of the present application utilize texture bilinear interpolation processing supported by the shader to interpolate the texel data, thereby obtaining position data that accurately corresponds to the particle's position and ensuring smooth particle movement. That is, the terminal device can perform texture bilinear interpolation processing based on the target texel data to obtain interpolated texel data; then, based on the interpolated texel data, the particle's position data at the time the animation is running can be converted.
[0125] Bilinear interpolation is a texture mapping technique used to produce realistic images, and is often referred to as "bilinear filtering" or "bilinear texture mapping." The algorithm is used to map the position of a screen pixel to the corresponding point on the texture map, calculate the RGBA channel values of the four adjacent texels by weighted average, and then apply the calculated RGBA channel values to the screen pixel. In an embodiment of the present application, after the terminal device determines the target texel, it can use a bilinear interpolation algorithm to calculate the RGBA channel values of the interpolated texel based on the RGBA channel values of the texels adjacent to the target texel above, below, left, and right. Then, the RGBA channel values of the interpolated texel are converted to obtain the position data of the particle at the time of animation execution. For example, assuming that the R and G channels of the texel are used to carry the horizontal position data of the particle when generating the texel data, and the B and A channels of the texel are used to carry the vertical position data of the particle, then the horizontal position data of the particle can be determined based on the R and G channel values of the interpolated texel, and the vertical position data of the particle can be determined based on the B and A channel values of the interpolated texel.
[0126] Of course, in actual applications, the terminal device may not perform the above-mentioned texture bilinear interpolation processing, but directly convert the target texel data to obtain the position data of the particles at the time of animation running. This application does not impose any restrictions on the implementation method of converting the particle position data based on texel data.
[0127] Step 203: Rendering a picture corresponding to the animation running time in the particle road condition map according to the position data of each particle in the particle road condition map at the animation running time.
[0128] After the terminal device determines the position data of each particle in the particle traffic map at the animation running time corresponding to the required rendered picture, it can further render the frame picture in the particle traffic map based on the position data of each particle at the animation running time.
[0129] Optionally, given that a particle map typically contains a large number of particles with similar structures, to improve the rendering efficiency of the particle map, embodiments of the present application may employ instanced rendering to render each particle in the particle map. Specifically, the terminal device may obtain a target particle structure, which is the underlying structure shared by all particles in the particle map. Then, for each particle in the particle map, the terminal device renders the particle in the image of the particle map based on the target particle structure and the instance data corresponding to the particle. The instance data corresponding to the particle includes the position data of the particle at the time of the animation execution, as determined in step 202.
[0130] Instanced rendering is a technology that abstracts the common geometric structure of objects when processing a large number of similar objects, and calls a rendering instruction to draw all objects once; in the embodiment of the present application, when rendering particles in the particle traffic map, quadrilaterals can be used as the basic mesh surface (i.e., the target particle structure), supplemented by two-dimensional mapping to realize the construction of the particle shape. Specifically, in the embodiment of the present application, when the terminal device renders each frame of the particle traffic map, it can first obtain the basic structure shared by all particles in the particle traffic map, i.e., the target particle structure; then, for each particle in the particle traffic map, the particle is rendered and drawn according to the particle's own instance data and the target particle structure; the particle instance data here includes at least the particle position data determined by step 202, and can also include the particle's color, etc.
[0131] The image rendering method provided in the embodiments of the present application innovatively utilizes a baked particle trajectory map to replace the real-time position calculation during the particle traffic map rendering process. The baked particle trajectory map is essentially the texture data corresponding to the particle traffic map. Based on this, when rendering each frame of the particle traffic map in the embodiments of the present application, there is no need to calculate the position data of all particles in the particle traffic map in real time. Instead, the current position data of each particle in the particle traffic map can be determined directly based on the position data carried by the texel data in the texture data corresponding to the particle traffic map. This greatly reduces the computational overhead required by the CPU during the particle traffic map rendering process.
[0132] To facilitate further understanding of the image rendering method provided in the embodiment of the present application, the overall implementation process of the image rendering method is exemplarily described below in conjunction with Figure 8. The implementation of the image rendering method provided in the embodiment of the present application is mainly divided into two parts: particle trajectory map baking and particle instanced rendering. The method can be implemented based on the Open Graphics Library (OpenGL).
[0133] As shown in Figure 8, in the particle trajectory map baking stage, after data preprocessing, it is necessary to sample on the particle motion trajectory supported by the road section to obtain the position data of each reference sampling point on each road section, and then write the position data of each reference sampling point on each road section into the texture to obtain the texture data corresponding to the particle road condition map.
[0134] Specifically, when the client renders the particle traffic map, it needs to redraw the image of the particle traffic map at a certain frame rate to achieve the effect of particle flow, and the position of the particles in each frame will change. This process can actually be understood as sampling the particle motion trajectory at a certain frame rate. In this embodiment of the application, the sampling calculation is completed in one go during the data parsing phase and written into the texture for storage. This process is called particle trajectory map baking.
[0135] Data loading and data preprocessing are required before baking. Data preprocessing may include data decompression, merging, and other processing processes. After the above data preprocessing, a route data set LineList will be obtained. The route data set lineList includes the route data line corresponding to each road section in the particle road condition map. The route data line includes the road condition information t of the road section and the position data path of multiple path points arranged in sequence on the road section. The road condition information t is used to reflect the traffic status of the road section, such as smooth, slow, congested, etc. The position data path of multiple path points can be expressed as [p0x, p0y, p1x, p1y, ..., p n x, p n y], that is, multiple path points p0, p1, ..., p n The x-coordinates and y-coordinates are arranged in sequence.
[0136] Next, each road segment in the route data set lineList is traversed, the particle motion trajectory supported by each road segment is sampled, and the landing point coordinates are calculated on the particle motion trajectory supported by the road segment at a specific frequency.
[0137] In specific implementations, the sampling frequency F can be determined first. For example, the frame rate of a smooth animation, 30 FPS, can be used as the sampling frequency F, i.e., 30 samples per second. Next, the particle motion speed v corresponding to the road segment is determined. This particle motion speed v can be determined based on the road condition information t of the road segment. For example, the particle motion speed v corresponding to the road condition information t representing a smooth road segment can be 80 pixels / second, while the particle motion speed v corresponding to the road condition information t representing a congested road segment can be 10 pixels / second. The correspondence between the particle motion speed and the road condition information can be set based on actual conditions. Furthermore, the sub-segments formed by every two path points on the road segment are traversed, and interpolation processing is performed on each sub-segment to determine the position data of the reference sampling point on each sub-segment.
[0138] In the following, we take the i-th path point p i and the i+1th path point p i+1 Taking the interpolation on the i-th sub-segment as an example, the method of calculating the position data of each reference sampling point on the i-th sub-segment is introduced:
[0139] First calculate the length of the i-th sub-segment by the following formula: i ; In the following formula, p i x and p i y are the path points p i The horizontal and vertical coordinates, p i+1 x and p i+1 y are the path points p i+1 The horizontal and vertical coordinates of .
[0140]
[0141] Then, the number of reference sampling points N on the i-th sub-segment is calculated by the following formula: i :
[0142]
[0143] Then, N is obtained by interpolation on the i-th sub-segment through the following formula: i The value of the subscript j in the following formula ranges from 0 to N i-1 :
[0144]
[0145]
[0146] Finally, the reference sampling points on all the road sections in the particle road section graph are arranged in order to obtain the motion trajectory of the particle in the particle road condition graph, that is, [p 00 , p 01 , p 02 ,…,p ij ,…].
[0147] After obtaining the position data of the reference sampling points in the particle motion trajectory through the above method, the obtained position data of the reference sampling points needs to be written into the texture. Considering the rendering performance of massive particles, it is usually necessary to write the position data of the reference sampling points on all particle motion trajectories into one texture. The specific implementation is as follows:
[0148] First, create the initial texture data and a reference position data sequence that matches the size of the initial texture data. Specifically, if the width of the initial texture data is w and the height is h, then the number of texels that the initial texture data can carry is size = w * h. Since each texel is represented by four 8-bit unsigned integers of RGBA, the reference position data sequence created is as follows:
[0149] pointArray=new Uint8ClampedArray(w*h*4)
[0150] Traverse all particle motion trajectories, write the position data of the reference sampling points on the particle motion trajectory into the above reference position data sequence in sequence, and then convert the reference position data sequence into the corresponding texture data. For example, when the data in the particle road map is loaded in tiles, each reference sampling point p on the particle motion trajectory ij The x and y values are both in the range of [-128, 383], and need to be encoded and stored using 4 8-bit bits, that is, one texel stores the position coordinate value of a reference sampling point. The specific method of converting the position data into the RGBA channel value of the texel is as follows:
[0151] x'=x+128, y'=y+128
[0152] r=x'>256? (x'-256): 0
[0153] g=x'>256?256:x'
[0154] b=y'>256? (y'-256): 0
[0155] a=y'>256?256:y'
[0156] At the same time, it is also necessary to record the starting offset start of each road segment in the reference position data sequence. For example, the position of the RGBA channel value corresponding to the first reference sampling point on each particle motion trajectory in the reference position data sequence is recorded as the starting offset start corresponding to the road segment to which the particle motion trajectory belongs.
[0157] As shown in Figure 8, during the particle instance rendering phase, particle shapes are constructed using quadrilaterals as the base mesh surface, supplemented by two-dimensional textures. This base mesh surface is shared by all particles in the particle map. When rendering the particle map, each particle itself needs to be rendered based on its own instance data. This instance data can include the particle's color and its position at the time the animation is running. This position data is determined based on the trajectory of the particle's road section, the particle's speed, and its initial offset.
[0158] Since the particle flow effect requires updating the particle position in each frame, it is necessary to pass the animation running time corresponding to each frame to the GPU before rendering each frame. Then, the texture data corresponding to the previously generated particle road map is combined to perform texture addressing, find the corresponding texel data, and de-decode to obtain the particle position data corresponding to the animation running time of the frame. The specific implementation is as follows:
[0159] First, the offset Now of the particle at the time of the animation is calculated using the following formula based on the animation running time t, the particle movement speed v corresponding to the road section to which the particle belongs, and the initial offset of the particle:
[0160] offsetNow=offset+v*t
[0161] Then, the particle's offset at the time of the animation is used to perform a modulo operation on the length of the segment to which the particle belongs, to obtain the target offset of the particle on the segment to which it belongs. This modulo operation is used to support the particle's circular motion on the segment to which it belongs:
[0162] offsetNow'=offsetNow% length
[0163] Next, the target offset offsetNow' is divided by the sampling interval distance ΔD on the road segment to which the particle belongs to obtain the index value step of the texel corresponding to the target offset offsetNow' in the texel corresponding to the road segment:
[0164]
[0165] After that, the column index column and row index row of the texel corresponding to the target offset offsetNow' in the texture data are calculated according to the starting offset start corresponding to the road segment to which the particle belongs and the width of the texture using the following formula:
[0166] column=(start+step)%w
[0167]
[0168] Then, a sub-pixel offset process is performed in the horizontal and vertical directions respectively, and normalized to obtain the texture coordinates u and v of the target texel. The position data carried by the target texel is very close to the position data of the target offset on the road section:
[0169]
[0170]
[0171] Finally, texture bilinear interpolation is performed on the texel data of the target texel to obtain interpolated texel data, and then the interpolated texel data is decoded to obtain the position data of the particle at the time of animation running.
[0172] With respect to the image rendering method described above, the present application also provides a corresponding image rendering device, so that the above image rendering method can be applied and implemented in practice.
[0173] Referring to FIG9 , FIG9 is a schematic diagram of the structure of an image rendering device 900 corresponding to the image rendering method shown in FIG2 above. As shown in FIG9 , the image rendering device 900 includes:
[0174] The texture data acquisition module 901 is used to acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry the position data of the reference sampling point on the corresponding road section;
[0175] A position data determination module 902 is configured to determine, when rendering each frame of the particle road map, the position data of each particle in the particle road map at the animation running time according to the animation running time corresponding to the frame and the texel data in the texture data;
[0176] The picture rendering module 903 is used to render the picture corresponding to the animation running time in the particle road condition map according to the position data of each particle in the particle road condition map at the animation running time.
[0177] Optionally, based on the image rendering device shown in FIG9 , refer to FIG10 , which is a schematic structural diagram of another image rendering device 1000 provided in an embodiment of the present application. As shown in FIG10 , the image rendering device 1000 further includes: a texture data generation module 1001, which specifically includes:
[0178] The route data acquisition submodule 1002 is configured to acquire a route data set corresponding to the particle road condition map; the route data set includes route data corresponding to each road section in the particle road condition map, and the route data includes road condition information of the road section and position data of a plurality of path points arranged in sequence on the road section;
[0179] The position data sampling submodule 1003 is configured to determine, for each road section in the particle road condition map, the position data of each reference sampling point on the road section according to the reference frame rate and the route data corresponding to the road section;
[0180] The texture data writing submodule 1004 is used to write the position data of each reference sampling point on each road section in the particle road condition map into the initial texture data to obtain the texture data corresponding to the particle road condition map.
[0181] Optionally, based on the image rendering device shown in FIG10 , the position data sampling submodule 1003 is specifically configured to:
[0182] Determining each sub-segment on the road segment and its respective length based on the position data of each two adjacent waypoints in the route data; the starting and ending points of the sub-segment are respectively two adjacent waypoints;
[0183] For each sub-segment on the road segment, determining the number of reference sampling points on the sub-segment based on the length of the sub-segment, the reference frame rate, and the particle movement speed corresponding to the sub-segment; the particle movement speed is determined based on the road condition information in the route data;
[0184] For each sub-section on the road section, the position data of each reference sampling point on the sub-section is determined according to the position data of the starting and ending points of the sub-section and the number of reference sampling points on the sub-section.
[0185] Optionally, based on the image rendering device shown in FIG10 , the texture data writing submodule 1004 is specifically used for:
[0186] Creating initial texture data; the number of texels carried by the initial texture data is greater than or equal to the total number of reference sampling points in the particle road condition map;
[0187] Converting the position data of each reference sampling point on each road section in the particle road condition map into a reference channel value of a texel in the initial texture data to obtain a reference channel value corresponding to each reference sampling point;
[0188] The reference channel values corresponding to the respective reference sampling points are sequentially written into the reference position data sequence, and texture data corresponding to the particle road condition map is generated according to the reference position data sequence.
[0189] Optionally, based on the image rendering device shown in FIG10 , when the particle road map is rendered in units of target size, the texture data writing submodule 1004 is specifically used to:
[0190] Creating initial texture data corresponding to each sub-road condition map; the sub-road condition map is obtained by dividing the particle road condition map based on the target size;
[0191] For each of the sub-traffic maps, converting the position data of each reference sampling point on each road section in the sub-traffic map into a reference channel value of a texel in the initial texture data corresponding to the sub-traffic map, thereby obtaining a reference channel value corresponding to each reference sampling point in the sub-traffic map;
[0192] For each of the sub-road condition maps, the reference channel values corresponding to the reference sampling points are sequentially written into the reference position data sequence corresponding to the sub-road condition map; and the texture data corresponding to the sub-road condition map is generated according to the reference position data sequence corresponding to the sub-road condition map.
[0193] Optionally, based on the image rendering device shown in FIG10 , the texture data writing submodule 1004 is specifically configured to convert the reference channel value corresponding to the reference sampling point by any of the following methods:
[0194] For each reference sampling point position data, determine a red channel value and a green channel value of the texel according to the horizontal position data in the position data; and determine a blue channel value and a transparency channel value of the texel according to the vertical position data in the position data;
[0195] For the position data of each reference sampling point, the red channel value and the green channel value of the texel are determined according to the longitudinal position data in the position data; and the blue channel value and the transparency channel value of the texel are determined according to the horizontal position data in the position data.
[0196] Optionally, based on the image rendering device shown in FIG10 , the texture data generating module 1001 further includes:
[0197] The starting point offset recording submodule is used to determine, for each road section in the particle road condition map, the starting point offset corresponding to the road section in the reference position data sequence, and record the corresponding relationship between the road section and the starting point offset; the starting point offset corresponding to the road section is the position of the reference channel value corresponding to the first reference sampling point on the road section in the reference position data sequence.
[0198] Optionally, based on the image rendering device shown in FIG9 , refer to FIG11 , which is a schematic diagram of the structure of another image rendering device 1100 provided in an embodiment of the present application. As shown in FIG11 , the position data determination module 902 specifically includes:
[0199] The offset determination submodule 1101 is configured to determine, for each particle in the particle road condition map, an offset of the particle at the animation running time according to the animation running time and the initial offset of the particle on the road section to which it belongs;
[0200] The index determination submodule 1102 is configured to determine the index of the target texel based on the offset of the particle at the time the animation is running, the frame rate of the particle road condition map, the road condition information of the road section to which the particle belongs, and the starting offset corresponding to the road section to which the particle belongs; the starting offset corresponding to the road section is used to indicate the distribution position of the position data of the reference sampling point belonging to the road section in the texture data;
[0201] The position data determination submodule 1103 is configured to search for target texel data in the texture data according to the index of the target texel; and determine the position data of the particle at the time when the animation is running according to the target texel data.
[0202] Optionally, based on the image rendering device shown in FIG11 , the index determination submodule 1102 is specifically configured to:
[0203] performing a modulo operation on the length of the road section to which the particle belongs using the offset of the particle at the time when the animation is running, to determine a target offset;
[0204] Determining the offset index of the particle according to the target offset, the frame rate of the particle road condition map, and the particle movement speed corresponding to the road section to which the particle belongs; the particle movement speed corresponding to the road section is determined according to the road condition information of the road section;
[0205] Determine the horizontal index and the vertical index of the reference texel according to the offset index of the particle and the starting point offset corresponding to the road section to which the particle belongs;
[0206] Sub-pixel offset processing is performed on the horizontal index and the vertical index of the reference texel respectively to obtain the horizontal index and the vertical index of the target texel.
[0207] Optionally, based on the image rendering device shown in FIG11 , the position data determining submodule 1103 is specifically configured to:
[0208] Performing texture bilinear interpolation processing based on the target texel data to obtain interpolated texel data;
[0209] Based on the interpolated texel data, position data of the particle at the time when the animation is running is converted.
[0210] Optionally, based on the image rendering device shown in FIG9 , the image rendering module 903 is specifically configured to:
[0211] Obtain a target particle structure; the target particle structure is a basic structure shared by all particles in the particle road condition map;
[0212] For each particle in the particle road map, the particle in the picture is rendered according to the target particle structure and the instance data corresponding to the particle; the instance data includes the position data of the particle at the time when the animation is running.
[0213] The image rendering device provided in the embodiments of the present application innovatively utilizes a baked particle trajectory map to replace the real-time position calculation during the particle road map rendering process. The baked particle trajectory map is essentially the texture data corresponding to the particle road map. Based on this, when rendering each frame of the particle road map in the embodiments of the present application, there is no need to calculate the position data of all particles in the particle road map in real time. Instead, the current position data of each particle in the particle road map can be determined directly based on the position data carried by the texel data in the texture data corresponding to the particle road map. This greatly reduces the computational overhead required by the CPU during the particle road map rendering process.
[0214] An embodiment of the present application further provides an electronic device for rendering images, which may specifically be a terminal device or a server. The terminal device and server provided in the embodiment of the present application will be introduced below from the perspective of hardware instantiation.
[0215] See Figure 12, which is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. As shown in Figure 12, for ease of explanation, only the parts related to the embodiment of the present application are shown. For specific technical details not disclosed, please refer to the method section of the embodiment of the present application. The terminal can be any terminal device including a mobile phone, tablet computer, personal digital assistant, point of sales (POS), car computer, etc. For example, the terminal is a computer:
[0216] FIG12 is a block diagram showing a partial structure of a computer related to a terminal provided in an embodiment of the present application. Referring to FIG12 , the computer includes components such as a radio frequency (RF) circuit 1210, a memory 1220, an input unit 1230 (including a touch panel 1231 and other input devices 1232), a display unit 1240 (including a display panel 1241), a sensor 1250, an audio circuit 1260 (which can be connected to a speaker 1261 and a microphone 1262), a wireless fidelity (WiFi) module 1270, a processor 1280, and a power supply 1290. It will be understood by those skilled in the art that the computer structure shown in FIG12 does not constitute a limitation on the computer, and may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0217] Memory 1220 can be used to store software programs and modules. Processor 1280 executes the various computer functions and data processing by running the software programs and modules stored in memory 1220. Memory 1220 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as a sound playback function or an image playback function). The data storage area may store data generated based on the use of the computer (such as audio data, a phone book, etc.). Memory 1220 may also include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state memory device.
[0218] Processor 1280 is the computer's control center, connecting all computer components using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 1220 and accessing data stored in memory 1220, it performs various computer functions and processes data, thereby providing overall computer monitoring. Optionally, processor 1280 may include one or more processing units. Preferably, processor 1280 integrates an application processor and a modem processor, with the application processor primarily processing the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 1280.
[0219] In an embodiment of the present application, the processor 1280 included in the terminal is also used to execute the steps of any implementation method of the image rendering method provided in the embodiment of the present application.
[0220] Referring to Figure 13, Figure 13 is a structural diagram of a server 1300 provided in an embodiment of the present application. The server 1300 may have relatively large differences due to different configurations or performance, and may include one or more central processing units (CPU) 1322 (for example, one or more processors) and memory 1332, one or more storage media 1330 (for example, one or more mass storage devices) storing application programs 1342 or data 1344. Among them, the memory 1332 and the storage medium 1330 can be temporary storage or permanent storage. The program stored in the storage medium 1330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1322 can be configured to communicate with the storage medium 1330 to execute a series of instruction operations in the storage medium 1330 on the server 1300.
[0221] The server 1300 may also include one or more power supplies 1326, one or more wired or wireless network interfaces 1350, one or more input and output interfaces 1358, and / or one or more operating systems, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0222] The steps executed by the server in the above embodiment may be based on the server structure shown in FIG13 .
[0223] Among them, the CPU 1322 can also be used to execute the steps of any implementation method of the image rendering method provided in the embodiments of the present application.
[0224] An embodiment of the present application further provides a computer-readable storage medium for storing a computer program, wherein the computer program is used to execute any one of the implementations of the image rendering method described in the aforementioned embodiments.
[0225] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any one of the implementations of the image rendering method described in the aforementioned embodiments.
[0226] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0227] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An image rendering method, performed by an electronic device, the method comprising: Acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry the position data of the reference sampling point on the corresponding road section; When rendering each frame of the particle road condition map, determining the position data of each particle in the particle road condition map at the animation running time according to the animation running time corresponding to the frame and the texel data in the texture data; According to the position data of each particle in the particle road condition map at the time when the animation is running, the picture corresponding to the animation running time in the particle road condition map is rendered.
2. According to the method of claim 1, the texture data corresponding to the particle road condition map is generated by: Acquire a route data set corresponding to the particle road condition map; the route data set includes route data corresponding to each road section in the particle road condition map, and the route data includes road condition information of the road section and position data of a plurality of path points arranged in sequence on the road section; For each road section in the particle road condition map, determining the position data of each reference sampling point on the road section according to the reference frame rate and the route data corresponding to the road section; The position data of each reference sampling point on each road section in the particle road condition map is written into the initial texture data to obtain the texture data corresponding to the particle road condition map.
3. The method according to claim 2, wherein determining the position data of each reference sampling point on the road section according to the reference frame rate and the route data corresponding to the road section comprises: Determine each sub-section on the road section and their respective lengths according to the position data of every two adjacent waypoints in the route data; The starting and ending points of the sub-segment are two adjacent path points respectively; For each sub-segment on the road segment, determine the number of reference sampling points on the sub-segment according to the length of the sub-segment, the reference frame rate, and the particle movement speed corresponding to the road segment; The particle movement speed is determined according to the road condition information in the route data; For each sub-section on the road section, the position data of each reference sampling point on the sub-section is determined according to the position data of the starting and ending points of the sub-section and the number of reference sampling points on the sub-section.
4. The method according to claim 2, wherein the position data of each reference sampling point on each road section in the particle road condition map is written into the initial texture data to obtain the texture data corresponding to the particle road condition map, comprising: Creating the initial texture data; The number of texels carried by the initial texture data is greater than or equal to the total number of reference sampling points in the particle road condition map; Converting the position data of each reference sampling point on each road section in the particle road condition map into the reference channel value of the texel in the initial texture data to obtain the reference channel value corresponding to each reference sampling point; The reference channel values corresponding to the respective reference sampling points are sequentially written into the reference position data sequence, and the texture data corresponding to the particle road condition map is generated according to the reference position data sequence.
5. The method according to claim 4, when the image of the particle road condition map is rendered in units of target size, the creating of initial texture data comprises: Create initial texture data corresponding to each sub-road condition map; The sub-road condition map is obtained by dividing the particle road condition map based on the target size; The step of converting the position data of each reference sampling point on each road section in the particle road condition map into the reference channel value of the texel in the initial texture data to obtain the reference channel value corresponding to each reference sampling point includes: For each of the sub-traffic graphs, converting the position data of each reference sampling point on each road section in the sub-traffic graph into a reference channel value of a texel in the initial texture data corresponding to the sub-traffic graph, and obtaining a reference channel value corresponding to each reference sampling point in the sub-traffic graph; The step of writing the reference channel values corresponding to the reference sampling points into the reference position data sequence in sequence, and generating texture data corresponding to the particle road condition map according to the reference position data sequence, comprises: For each of the sub-road condition maps, the reference channel values corresponding to the reference sampling points are sequentially written into the reference position data sequence corresponding to the sub-road condition map; and according to the reference position data sequence corresponding to the sub-road condition map, the texture data corresponding to the sub-road condition map is generated.
6. The method according to claim 4 or 5, wherein the position data of each reference sampling point on each road section in the particle road condition map is converted into the reference channel value of the texel in the initial texture data to obtain the reference channel value corresponding to each reference sampling point, including any of the following: For the position data of each reference sampling point, determine the red channel value and the green channel value of the texel according to the horizontal position data in the position data; and determine the blue channel value and the transparency channel value of the texel according to the vertical position data in the position data; For the position data of each reference sampling point, the red channel value and the green channel value of the texel are determined according to the longitudinal position data in the position data; and the blue channel value and the transparency channel value of the texel are determined according to the transverse position data in the position data.
7. The method according to claim 4 or 5, further comprising: For each road section in the particle road condition map, determining a starting point offset corresponding to the road section in the reference position data sequence, and recording a corresponding relationship between the road section and the starting point offset; The starting point offset corresponding to the road section is the position of the reference channel value corresponding to the first reference sampling point on the road section in the reference position data sequence.
8. The method according to claim 1, wherein determining the position data of each particle in the particle road condition map at the animation running time according to the animation running time corresponding to the picture and the texel data in the texture data comprises: For each particle in the particle road condition map, determining the offset of the particle at the animation running time according to the animation running time and the initial offset of the particle on the road section to which it belongs; Determine the index of the target texel according to the offset of the particle at the time when the animation is running, the frame rate of the particle road condition map, the road condition information of the road section to which the particle belongs, and the starting point offset corresponding to the road section to which the particle belongs; the starting point offset corresponding to the road section is used to indicate the distribution position of the position data of the reference sampling point belonging to the road section in the texture data; According to the index of the target texel, the target texel data is searched in the texture data; according to the target texel data, the position data of the particle at the time when the animation is running is determined.
9. The method according to claim 8, wherein determining the index of the target texel according to the offset of the particle at the time when the animation is running, the frame rate of the particle road condition map, the road condition information of the section to which the particle belongs, and the starting point offset corresponding to the section to which the particle belongs comprises: Using the offset of the particle at the time when the animation is running, a modulo operation is performed on the length of the section to which the particle belongs to determine a target offset; Determine the offset index of the particle according to the target offset, the frame rate of the particle road condition map, and the particle movement speed corresponding to the road section to which the particle belongs; the particle movement speed corresponding to the road section is determined according to the road condition information of the road section; Determine the horizontal index and the vertical index of the reference texel according to the offset index of the particle and the starting point offset corresponding to the road section to which the particle belongs; Sub-pixel offset processing is performed on the horizontal index and the vertical index of the reference texel respectively to obtain the horizontal index and the vertical index of the target texel.
10. The method according to claim 8 or 9, wherein determining the position data of the particle at the time when the animation is running according to the target texel data comprises: Performing texture bilinear interpolation processing based on the target texel data to obtain interpolated texel data; Based on the interpolated texel data, the position data of the particle at the time when the animation is running is converted.
11. The method according to claim 1, wherein the rendering of the picture corresponding to the animation running time in the particle road condition map according to the position data of each particle in the particle road condition map at the animation running time comprises: Acquire a target particle structure; the target particle structure is a basic structure shared by all particles in the particle road condition map; For each particle in the particle road map, the particle in the picture is rendered according to the target particle structure and the instance data corresponding to the particle; the instance data includes the position data of the particle at the time when the animation is running.
12. The method according to claim 1, wherein the method is executed by a graphics processor (GPU) of the electronic device, and the texture data corresponding to the particle road condition map is determined by a CPU of the electronic device; the step of obtaining the texture data corresponding to the particle road condition map comprises: Acquire texture data corresponding to the particle road condition map transmitted by the CPU.
13. An image rendering device, the device comprising: A texture data acquisition module, used to acquire texture data corresponding to the particle road condition map; the texture data includes texel data corresponding to each road section in the particle road condition map, and the texel data is used to carry the position data of the reference sampling point on the corresponding road section; A position data determination module is used to determine the position data of each particle in the particle road condition map at the animation running time according to the animation running time corresponding to the picture and the texel data in the texture data when rendering each frame of the particle road condition map; The picture rendering module is used to render the picture corresponding to the animation running time in the particle road condition map according to the position data of each particle in the particle road condition map at the animation running time.
14. An electronic device, comprising a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the image rendering method according to any one of claims 1 to 12 according to the computer program. 15 . A computer-readable storage medium, the computer-readable storage medium being used to store a computer program, the computer program being used to execute the image rendering method according to claim 1 .
16. A computer program product, comprising a computer program or an instruction, wherein when the computer program or the instruction is executed by a processor, the image rendering method according to any one of claims 1 to 12 is implemented.
