[go: up one dir, main page]

CN114432695A - Particle system rendering method, apparatus, electronic device and readable storage medium - Google Patents

Particle system rendering method, apparatus, electronic device and readable storage medium Download PDF

Info

Publication number
CN114432695A
CN114432695A CN202111648569.5A CN202111648569A CN114432695A CN 114432695 A CN114432695 A CN 114432695A CN 202111648569 A CN202111648569 A CN 202111648569A CN 114432695 A CN114432695 A CN 114432695A
Authority
CN
China
Prior art keywords
particle
preset
time
particles
attribute
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111648569.5A
Other languages
Chinese (zh)
Other versions
CN114432695B (en
Inventor
孟欣
乔禹之
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Pixel Software Technology Co Ltd
Original Assignee
Beijing Pixel Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Pixel Software Technology Co Ltd filed Critical Beijing Pixel Software Technology Co Ltd
Priority to CN202111648569.5A priority Critical patent/CN114432695B/en
Publication of CN114432695A publication Critical patent/CN114432695A/en
Application granted granted Critical
Publication of CN114432695B publication Critical patent/CN114432695B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/50Controlling the output signals based on the game progress
    • A63F13/52Controlling the output signals based on the game progress involving aspects of the displayed game scene
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T13/00Animation
    • G06T13/203D [Three Dimensional] animation
    • G06T13/603D [Three Dimensional] animation of natural phenomena, e.g. rain, snow, water or plants
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/003D [Three Dimensional] image rendering
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/003D [Three Dimensional] image rendering
    • G06T15/04Texture mapping
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/60Methods for processing data by generating or executing the game program
    • A63F2300/66Methods for processing data by generating or executing the game program for rendering three dimensional images
    • A63F2300/6638Methods for processing data by generating or executing the game program for rendering three dimensional images for simulating particle systems, e.g. explosion, fireworks

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Multimedia (AREA)
  • Computer Graphics (AREA)
  • Image Generation (AREA)

Abstract

The embodiment of the invention discloses a particle system rendering method, a particle system rendering device, electronic equipment and a readable storage medium, wherein the particle system rendering method comprises the following steps: classifying and storing the attributes of the particles in the preset particle cluster, and storing the attributes which dynamically change along with time in a preset container; performing function calculation respectively for a first updating strategy without time sequence and a second updating strategy with time sequence to obtain a first parameter and a second parameter for calculating the value of the attribute which dynamically changes along with time; and processing all attributes in the preset container in batch through a preset image processing algorithm, selecting particles in a survival state and a visible state to write into the vertex cache region, reading the particles in the vertex cache region through a shader, and calculating the attribute value of each particle through other constant parameters in the shader. By the flexible use of the shader and the classification processing of the updating strategy, the particle attribute rendering efficiency is effectively improved.

Description

粒子系统渲染方法、装置、电子设备及可读存储介质Particle system rendering method, apparatus, electronic device and readable storage medium

技术领域technical field

本发明涉及数据处理领域,尤其涉及一种粒子系统渲染方法、装置、电子设备及可读存储介质。The present invention relates to the field of data processing, and in particular, to a particle system rendering method, device, electronic device and readable storage medium.

背景技术Background technique

在现实中存在许多包含了大量行为相似的微小粒子的现象,像是烟火、落叶、水流、云雾等,在3D游戏中使用粒子系统去模拟这些现象,由于粒子的几何特征比较简单,可以使用四边形进行渲染,再通过实时更新粒子系统的位置、姿态、尺寸和纹理来达成想要的效果。但是当粒子规模增大时,粒子的更新会对计算机的性能有苛刻的要求,如果计算的速度跟不上,就会无法达到实时渲染的效果。In reality, there are many phenomena that contain a large number of tiny particles with similar behaviors, such as fireworks, leaves, water, clouds, etc. In 3D games, particle systems are used to simulate these phenomena. Since the geometric characteristics of particles are relatively simple, quadrilaterals can be used. Render, and then achieve the desired effect by updating the position, pose, size and texture of the particle system in real time. However, when the particle size increases, the update of the particles will have strict requirements on the performance of the computer. If the calculation speed cannot keep up, the effect of real-time rendering will not be achieved.

可见,现有的渲染方案存在无法适应大规模粒子的渲染需求。It can be seen that the existing rendering schemes cannot meet the rendering needs of large-scale particles.

发明内容SUMMARY OF THE INVENTION

为了解决上述技术问题,本申请实施例提供了一种粒子系统渲染方法、装置、电子设备及可读存储介质,具体方案如下:In order to solve the above technical problems, the embodiments of the present application provide a particle system rendering method, device, electronic device, and readable storage medium, and the specific solutions are as follows:

第一方面,本申请实施例提供了一种粒子系统渲染方法,所述粒子系统渲染方法包括:In a first aspect, an embodiment of the present application provides a particle system rendering method, where the particle system rendering method includes:

对预设粒子簇中的各粒子的属性进行分类存储,其中,随时间动态变化的属性存储在预设容器中,所述预设粒子簇包括同类粒子和各粒子的更新策略,所述更新策略包括不具有时间序列的第一更新策略和具有时间序列的第二更新策略;The attributes of each particle in the preset particle cluster are classified and stored, wherein the attributes that change dynamically with time are stored in a preset container, and the preset particle cluster includes the same particle and the update strategy of each particle, and the update strategy Including a first update strategy without time series and a second update strategy with time series;

基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数;Calculate the first parameter corresponding to the first preset function based on the execution start point and execution end point of the first update strategy;

基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数;Calculate the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series;

基于预设图像处理算法批量处理所述预设容器中的所有属性,并将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;Batch process all attributes in the preset container based on the preset image processing algorithm, and write the particles in the alive state and the visible state at the current time into the vertex buffer;

在着色器中,根据所述第一参数、第一预设函数、所述第二参数、第二预设函数以及所述当前时间计算所述顶点缓存区内各粒子的全部属性值;In the shader, calculate all attribute values of each particle in the vertex buffer according to the first parameter, the first preset function, the second parameter, the second preset function and the current time;

根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染。Attribute rendering is performed on all particles in the preset particle cluster according to all attribute values of each particle.

根据本申请实施例的一种具体实施方式,所述预设容器为SOA_VECTOR容器,对预设粒子簇中的各粒子的属性进行分类存储的步骤,包括:According to a specific implementation of the embodiment of the present application, the preset container is a SOA_VECTOR container, and the step of classifying and storing the attributes of each particle in the preset particle cluster includes:

将所述预设粒子簇中各粒子的属性划分为随时间变化的属性和常量属性;dividing the attributes of each particle in the preset particle cluster into attributes that change with time and constant attributes;

将所述预设粒子簇中全部粒子的常量属性整合为一份结构体,并将结构体的指针存储在所述预设粒子簇中的各粒子对象中;Integrate the constant attributes of all particles in the preset particle cluster into a structure, and store the pointer of the structure in each particle object in the preset particle cluster;

将所有随时间变化的属性存储在所述SOA_VECTOR容器中。Store all time-varying properties in the SOA_VECTOR container.

根据本申请实施例的一种具体实施方式,所述第一预设函数为一元一次函数,其中因变量为属性值,自变量为时间,基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数的步骤,包括:According to a specific implementation of the embodiment of the present application, the first preset function is a one-dimensional linear function, wherein the dependent variable is an attribute value, and the independent variable is time, and is calculated based on the execution start point and execution end point of the first update strategy The step corresponding to the first parameter of the first preset function includes:

若当前的第一更新策略的所述执行起点和所述执行终点的时间相同,则根据第一规则获取第一系数组,并将所述第一系数组作为采用当前第一更新策略时的第一参数;If the execution start point and execution end point of the current first update strategy are at the same time, the first coefficient group is acquired according to the first rule, and the first coefficient group is used as the first coefficient group when the current first update strategy is adopted. a parameter;

若当前的第一更新策略的所述执行起点和所述执行终点的时间不同,则根据第二规则获取第二系数组,并将所述第二系数组作为采用当前第一更新策略时的第一参数。If the time of the execution start point and the execution end point of the current first update strategy are different, a second coefficient group is obtained according to the second rule, and the second coefficient group is used as the first update strategy when the current first update strategy is adopted. a parameter.

根据本申请实施例的一种具体实施方式,所述第二预设函数为与所述第二更新策略的时间结点数量的一元多次多项式,其中,因变量为属性值,自变量为时间;According to a specific implementation of the embodiment of the present application, the second preset function is a polynomial multi-degree polynomial with the number of time nodes of the second update strategy, wherein the dependent variable is an attribute value, and the independent variable is time ;

基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数的步骤,包括:The step of calculating the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series includes:

采用最小二乘法对所述一元多次多项式进行拟合,以得到对应所述时间序列的时间矩阵和属性值向量;The least squares method is used to fit the multi-order polynomial in one variable, so as to obtain a time matrix and an attribute value vector corresponding to the time series;

根据预设的计算公式ATAx=ATB计算所述第二参数,其中,A为时间矩阵,B为属性值向量,x为第二参数。The second parameter is calculated according to a preset calculation formula A T Ax=A T B, where A is a time matrix, B is an attribute value vector, and x is the second parameter.

根据本申请实施例的一种具体实施方式,根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染的步骤之前,所述方法还包括:According to a specific implementation of the embodiment of the present application, before the step of performing attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle, the method further includes:

根据实际场景参数,计算观察变换矩阵和投影变换矩阵,所述实际场景参数包括摄像机参数、观察点参数以及屏幕参数;Calculate the observation transformation matrix and the projection transformation matrix according to the actual scene parameters, where the actual scene parameters include camera parameters, observation point parameters and screen parameters;

将所述观察变换矩阵和所述投影变换矩阵写入所述着色器中,以使所述着色器根据所述观察变换矩阵和所述投影变换矩阵进行粒子渲染。The viewing transformation matrix and the projection transformation matrix are written into the shader, so that the shader performs particle rendering according to the viewing transformation matrix and the projection transformation matrix.

根据本申请实施例的一种具体实施方式,根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染的步骤之后,所述方法包括:According to a specific implementation of the embodiment of the present application, after the step of performing attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle, the method includes:

将所述当前时间替换为所述当前时间的下一次更新时间;Replace the current time with the next update time of the current time;

跳转至所述基于预设图像处理算法批量处理所述预设容器中的属性数据步骤,并执行后续更新渲染步骤直至到达预设时刻。Jump to the step of batch processing the attribute data in the preset container based on the preset image processing algorithm, and perform the subsequent update rendering step until the preset time is reached.

根据本申请实施例的一种具体实施方式,所述预设的图像处理算法为SIMD算法,所述预设容器中的属性数据包括粒子的存活性、可见性和粒子结构变换,基于预设图像处理算法批量处理所述预设容器中的属性数据的步骤,包括:According to a specific implementation of the embodiment of the present application, the preset image processing algorithm is a SIMD algorithm, and the attribute data in the preset container includes particle survivability, visibility, and particle structure transformation. Based on the preset image The step of processing the attribute data in the preset container in batches by the processing algorithm includes:

根据粒子的存活性、可见性和粒子结构变换判断所述粒子在当前时间的状态;Judging the state of the particle at the current time according to the particle's survivability, visibility and particle structure transformation;

将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;Write the particles that are alive and visible at the current time to the vertex buffer;

将当前时间下处于死亡状态的粒子初始化,并存放在预设容器中。Initialize the particles that are in the dead state at the current time and store them in the preset container.

第二方面,本申请实施例提供了一种粒子系统渲染装置,所述粒子系统渲染装置包括:In a second aspect, an embodiment of the present application provides a particle system rendering device, where the particle system rendering device includes:

分类存储模块,用于对预设粒子簇中的各粒子的属性进行分类存储,其中,随时间动态变化的属性存储在预设容器中,所述预设粒子簇包括同类粒子和各粒子的更新策略,所述更新策略包括不具有时间序列的第一更新策略和具有时间序列的第二更新策略;The classification storage module is used to classify and store the attributes of each particle in the preset particle cluster, wherein the attributes that change dynamically with time are stored in the preset container, and the preset particle cluster includes the same particle and the update of each particle a strategy, the update strategy includes a first update strategy without a time series and a second update strategy with a time series;

第一计算模块,用于基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数,其中,所述第一更新策略为不具有时间序列的更新策略;a first calculation module, configured to calculate a first parameter corresponding to a first preset function based on an execution start point and an execution end point of the first update strategy, wherein the first update strategy is an update strategy without a time series;

第二计算模块,用于基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数,其中,所述第二更新策略为具有时间序列的更新策略;The second calculation module is configured to calculate the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series, wherein the second update The strategy is an update strategy with time series;

处理模块,用于基于预设图像处理算法批量处理所述预设容器中的所有属性,并将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;a processing module, configured to batch process all attributes in the preset container based on a preset image processing algorithm, and write the particles that are in the alive state and the visible state at the current time into the vertex buffer;

第三计算模块,用于在着色器中,根据所述第一参数、第一预设函数、所述第二参数、第二预设函数以及所述当前时间计算所述顶点缓存区内各粒子的全部属性值;A third calculation module, configured to calculate, in the shader, each particle in the vertex buffer according to the first parameter, the first preset function, the second parameter, the second preset function and the current time All attribute values of ;

渲染模块,用于根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染。The rendering module is configured to perform attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle.

第三方面,本申请实施例提供了一种电子设备,所述电子设备包括处理器和存储器,所述存储器存储有计算机程序,所述计算机程序在所述处理器上运行时执行第一方面所述的粒子系统渲染方法。In a third aspect, an embodiment of the present application provides an electronic device, the electronic device includes a processor and a memory, the memory stores a computer program, and the computer program executes the first aspect when running on the processor. The described particle system rendering method.

第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,所述计算机程序在处理器上运行时执行第一方面所述的粒子系统渲染方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program executes the particle system described in the first aspect when running on a processor render method.

本申请实施例提供了一种粒子系统渲染方法、装置、电子设备及可读存储介质,所述粒子系统渲染方法包括:对预设粒子簇中的各粒子的属性进行分类存储,将随时间动态变化的属性存储在预设容器中;分别针对不具有时间序列的第一更新策略和具有时间序列的第二更新策略进行函数计算,以得到用于计算随时间动态变化的属性的值的第一参数和第二参数;通过预设图像处理算法批量处理所述预设容器中的所有属性,选择处于存活状态和可见状态的粒子写入顶点缓存区,从而能够通过着色器读取所述顶点缓存区中的粒子,并通过着色器中的其它常量参数计算各粒子的属性值。通过着色器的灵活使用和更新策略的分类处理,有效提升了粒子属性渲染的效率。Embodiments of the present application provide a particle system rendering method, device, electronic device, and readable storage medium, where the particle system rendering method includes: classifying and storing attributes of each particle in a preset particle cluster, The changed attributes are stored in the preset container; the function calculation is respectively performed for the first update strategy without time series and the second update strategy with time series to obtain the first update strategy for calculating the value of the attribute that changes dynamically with time. parameter and the second parameter; batch process all the attributes in the preset container through the preset image processing algorithm, select the particles in the alive state and the visible state to write to the vertex buffer area, so that the vertex buffer can be read through the shader Particles in the area, and calculate the attribute values of each particle through other constant parameters in the shader. Through the flexible use of shaders and the classification of update strategies, the efficiency of particle attribute rendering is effectively improved.

附图说明Description of drawings

为了更清楚地说明本发明的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,应当理解,以下附图仅示出了本发明的某些实施例,因此不应被看作是对本发明保护范围的限定。在各个附图中,类似的构成部分采用类似的编号。In order to illustrate the technical solutions of the present invention more clearly, the accompanying drawings required in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention, and therefore should not be It is regarded as the limitation of the protection scope of the present invention. In the various figures, similar components are numbered similarly.

图1示出了本申请实施例提供的一种粒子系统渲染方法的方法流程示意图;FIG. 1 shows a schematic flowchart of a method for rendering a particle system provided by an embodiment of the present application;

图2示出了本申请实施例提供的一种粒子系统渲染方法中SOA_VECTOR容器存储数据类型的效果示意图;2 shows a schematic diagram of the effect of SOA_VECTOR container storage data types in a particle system rendering method provided by an embodiment of the present application;

图3示出了本申请实施例提供的一种粒子渲染系统渲染装置的装置模块示意图。FIG. 3 shows a schematic diagram of device modules of a rendering device for a particle rendering system provided by an embodiment of the present application.

具体实施方式Detailed ways

下面将结合本发明实施例中附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of the embodiments.

通常在此处附图中描述和示出的本发明实施例的组件可以以各种不同的配置来布置和设计。因此,以下对在附图中提供的本发明的实施例的详细描述并非旨在限制要求保护的本发明的范围,而是仅仅表示本发明的选定实施例。基于本发明的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。The components of the embodiments of the invention generally described and illustrated in the drawings herein may be arranged and designed in a variety of different configurations. Thus, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the invention as claimed, but is merely representative of selected embodiments of the invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present invention.

在下文中,可在本发明的各种实施例中使用的术语“包括”、“具有”及其同源词仅意在表示特定特征、数字、步骤、操作、元件、组件或前述项的组合,并且不应被理解为首先排除一个或更多个其它特征、数字、步骤、操作、元件、组件或前述项的组合的存在或增加一个或更多个特征、数字、步骤、操作、元件、组件或前述项的组合的可能性。Hereinafter, the terms "comprising", "having" and their cognates, which may be used in various embodiments of the present invention, are only intended to denote particular features, numbers, steps, operations, elements, components, or combinations of the foregoing, and should not be construed as first excluding the presence of or adding one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing or the possibility of a combination of the foregoing.

此外,术语“第一”、“第二”、“第三”等仅用于区分描述,而不能理解为指示或暗示相对重要性。Furthermore, the terms "first", "second", "third", etc. are only used to differentiate the description and should not be construed as indicating or implying relative importance.

除非另有限定,否则在这里使用的所有术语(包括技术术语和科学术语)具有与本发明的各种实施例所属领域普通技术人员通常理解的含义相同的含义。所述术语(诸如在一般使用的词典中限定的术语)将被解释为具有与在相关技术领域中的语境含义相同的含义并且将不被解释为具有理想化的含义或过于正式的含义,除非在本发明的各种实施例中被清楚地限定。Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of this invention belong. The terms (such as those defined in commonly used dictionaries) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized or overly formal meaning, unless explicitly defined in the various embodiments of the present invention.

参考图1,为本申请实施例提供的一种粒子系统渲染方法的方法流程示意图,本申请实施例提供的粒子系统渲染方法,如图1所示,所述粒子系统渲染方法包括:Referring to FIG. 1 , a schematic flowchart of a method for rendering a particle system provided by an embodiment of the present application is provided. In the method for rendering a particle system provided by an embodiment of the present application, as shown in FIG. 1 , the particle system rendering method includes:

步骤S101,对预设粒子簇中的各粒子的属性进行分类存储,其中,随时间动态变化的属性存储在预设容器中,所述预设粒子簇包括同类粒子和各粒子的更新策略,所述更新策略包括不具有时间序列的第一更新策略和具有时间序列的第二更新策略;Step S101, classify and store the attributes of each particle in the preset particle cluster, wherein the attributes that change dynamically with time are stored in a preset container, and the preset particle cluster includes the same type of particles and the update strategy of each particle, so The update strategy includes a first update strategy without time series and a second update strategy with time series;

在具体实施例中,粒子对象通常包括两种类型的属性数据,第一类型的属性数据为用户在粒子运行前,已经为粒子对象设置好的固定属性数据。所述第一类型的属性数据在粒子运行过程中不会改变。具有第一类型的属性数据的粒子对象往往关联着不具有时间序列的第一更新策略。In a specific embodiment, a particle object generally includes two types of attribute data. The first type of attribute data is fixed attribute data that has been set for the particle object by the user before the particle runs. The first type of attribute data does not change during particle operation. Particle objects with attribute data of the first type are often associated with a first update strategy that does not have time series.

第二类型的属性数据为会在粒子对象运行过程中随时间不断变化的属性数据,例如当前的位置、缩放倍数、纹理坐标、受力范围和速度等。所述第二类型的属性数据的值由更新策略和时间序列决定。具有第二类型的属性数据的粒子对象往往关联着具有时间序列的第二更新策略。The second type of attribute data is the attribute data that will change with time during the running of the particle object, such as the current position, zoom factor, texture coordinates, force range and speed, etc. The value of the second type of attribute data is determined by the update strategy and the time series. Particle objects with attribute data of the second type are often associated with a second update strategy with time series.

在实际运行过程中,每一粒子对象会在不同的时间点被多次克隆,克隆出的新粒子对象与原粒子对象的属性和更新策略完全相同。但由于新粒子对象和原粒子对象出现的时间点不同,所以在后续进行模拟计算时的属性值也会不相同。In the actual running process, each particle object will be cloned multiple times at different time points, and the new cloned particle object has exactly the same attributes and update strategy as the original particle object. However, since the new particle object and the original particle object appear at different time points, the attribute values during subsequent simulation calculations will also be different.

在本实施例中,将对应每一粒子对象及其被克隆的新粒子对象集合组成一个粒子簇,并针对所述粒子簇中的粒子对象的属性数据进行分类划分,按照所述粒子对象的属性数据的类型进行相应的存储。In this embodiment, a set of new particle objects corresponding to each particle object and its cloned particle objects is formed into a particle cluster, and the attribute data of the particle objects in the particle cluster is classified and divided, according to the attributes of the particle objects. The type of data is stored accordingly.

根据本申请实施例的一种具体实施方式,所述预设容器为SOA_VECTOR容器,对预设粒子簇中的各粒子的属性进行分类存储的步骤,包括:According to a specific implementation of the embodiment of the present application, the preset container is a SOA_VECTOR container, and the step of classifying and storing the attributes of each particle in the preset particle cluster includes:

将所述预设粒子簇中各粒子的属性划分为随时间变化的属性和常量属性;dividing the attributes of each particle in the preset particle cluster into attributes that change with time and constant attributes;

将所述预设粒子簇中全部粒子的常量属性整合为一份结构体,并将结构体的指针存储在所述预设粒子簇中的各粒子对象中;Integrate the constant attributes of all particles in the preset particle cluster into a structure, and store the pointer of the structure in each particle object in the preset particle cluster;

将所有随时间变化的属性存储在所述SOA_VECTOR容器中。Store all time-varying properties in the SOA_VECTOR container.

在具体实施例中,所述预设容器采用SOA_VECTOR容器,所述SOA_VECTOR容器的实现方法可以采用现有方法进行实现,在本实施例中不作赘述。In a specific embodiment, the preset container adopts a SOA_VECTOR container, and an implementation method of the SOA_VECTOR container may be implemented by using an existing method, which is not repeated in this embodiment.

SOA_VECTOR容器是一种将粒子对象中的属性分开存储为一个属性数组的存储容器,不同于VECTOR容器将粒子对象作为一个整体进行存储。The SOA_VECTOR container is a storage container that stores the attributes in the particle object separately as an attribute array, which is different from the VECTOR container which stores the particle object as a whole.

如图2所示,当粒子对象的属性包括a、b、c、d时,VECTOR在存储粒子对象的属性数据时,是按照完整粒子对象进行属性存储。当用户从VECTOR调用属性数据时,只能调用一个完整的粒子对象。As shown in Figure 2, when the attributes of the particle object include a, b, c, and d, when VECTOR stores the attribute data of the particle object, it stores the attributes according to the complete particle object. When the user calls attribute data from VECTOR, only a complete particle object can be called.

而SOA_VECTOR容器在存储所述粒子对象时,会将各粒子对象的属性分开存储为一个属性数组,如图2中所述SOA_VECTOR容器包括的a属性数组、b属性数组、c属性数组和d属性数组。When the SOA_VECTOR container stores the particle objects, the attributes of each particle object are separately stored as an attribute array. As shown in Figure 2, the SOA_VECTOR container includes a attribute array, b attribute array, c attribute array and d attribute array. .

本实施例中将随时间变化的属性数据存储在SOA_VECTOR。具体的,用户在创建SOA_VECTOR容器时可以设置单个属性和属性数组的内存对齐数、共同计算的对象数量。在添加对象时,SOA_VECTOR会将对象的属性分别存入对应的内存区,并保证所有数据的内容地址符合要求,访问数据时用户可以通过SOA_VECTOR提供的指针单独读取所有对象的某个属性。In this embodiment, the attribute data that changes with time is stored in SOA_VECTOR. Specifically, when creating a SOA_VECTOR container, the user can set the memory alignment number of a single attribute and attribute array, and the number of objects to be calculated together. When adding an object, SOA_VECTOR will store the attributes of the object in the corresponding memory areas, and ensure that the content addresses of all data meet the requirements. When accessing data, users can read a certain attribute of all objects individually through the pointer provided by SOA_VECTOR.

举例来说,如图2中所述的SOA_VECTOR容器设置了4类属性的存储地址,在处理器从SOA_VECTOR容器中调用属性时,可以单独读取所有对象的a属性数组。For example, the SOA_VECTOR container described in Figure 2 sets the storage addresses of 4 types of attributes. When the processor calls the attributes from the SOA_VECTOR container, the a attribute array of all objects can be read individually.

对于常量属性,本实施例的所述粒子簇中存储的是同类的粒子和各粒子的更新策略,在同一粒子簇中,各粒子对象之间存储的常量属性均相同。对于同一粒子簇,将所有常量属性整合为一份结构体,在每一粒子对象中存储所述结构体的指针。For constant attributes, the particle clusters in this embodiment store the same kind of particles and the update policies of each particle, and in the same particle cluster, the constant attributes stored among the particle objects are all the same. For the same particle cluster, all constant attributes are integrated into a structure, and a pointer to the structure is stored in each particle object.

具体的,所述结构体是由一批数据组合而成的结构型数据,将常量数据整合为一份结构体,并在粒子对象中存放指针的存储方法,能够最大程度节省粒子对象的存储空间。Specifically, the structure is structured data composed of a batch of data, the constant data is integrated into a structure, and the storage method of storing the pointer in the particle object can save the storage space of the particle object to the greatest extent. .

步骤S102,基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数;Step S102, calculating a first parameter corresponding to the first preset function based on the execution start point and execution end point of the first update strategy;

在具体实施例中,针对不具有时间序列的第一更新策略,本实施例使用第一预设函数替换所述第一更新策略,并根据所述第一更新策略自带的执行起点和执行终点计算对应所述第一预设函数的系数。In a specific embodiment, for the first update strategy that does not have a time series, this embodiment uses a first preset function to replace the first update strategy, and according to the execution start point and execution end point of the first update strategy A coefficient corresponding to the first preset function is calculated.

所述第一更新策略包括粒子自转、纹理自转、纹理镜等不具有时间序列的更新策略。The first update strategy includes particle rotation, texture rotation, texture mirror and other update strategies that do not have time series.

其中,所述执行起点和执行终点的选择可以由用户根据实际应用场景进行自适应设置,例如,用户可以自行选择第一更新策略执行的函数区间,所述执行起点和执行终点即所述函数区间的左右端点。The selection of the execution starting point and the execution end point can be adaptively set by the user according to the actual application scenario. For example, the user can select the function interval for executing the first update strategy by himself, and the execution starting point and the execution end point are the function interval. the left and right endpoints.

举例来说,粒子对象从0秒开始自转,从90度旋转到180度,速度为每秒30度,那么可以设置执行起点为(0,90),设置执行终点为(3,180)。For example, the particle object rotates from 0 seconds, from 90 degrees to 180 degrees, and the speed is 30 degrees per second, then you can set the execution start point to (0, 90), and set the execution end point to (3, 180).

根据本申请实施例的一种具体实施方式,所述第一预设函数为一元一次函数,其中因变量为属性值,自变量为时间,基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数的步骤,包括:According to a specific implementation of the embodiment of the present application, the first preset function is a one-dimensional linear function, wherein the dependent variable is an attribute value, and the independent variable is time, and is calculated based on the execution start point and execution end point of the first update strategy The step corresponding to the first parameter of the first preset function includes:

若当前的第一更新策略的所述执行起点和所述执行终点的时间相同,则根据第一规则获取第一系数组,并将所述第一系数组作为采用当前第一更新策略时的第一参数;If the execution start point and execution end point of the current first update strategy are at the same time, the first coefficient group is acquired according to the first rule, and the first coefficient group is used as the first coefficient group when the current first update strategy is adopted. a parameter;

若当前的第一更新策略的所述执行起点和所述执行终点的时间不同,则根据第二规则获取第二系数组,并将所述第二系数组作为采用当前第一更新策略时的第一参数。If the time of the execution start point and the execution end point of the current first update strategy are different, a second coefficient group is obtained according to the second rule, and the second coefficient group is used as the first update strategy when the current first update strategy is adopted. a parameter.

在具体实施例中,采用一元一次函数aX+b=Y代替所述第一更新策略,其中X为时间,Y为属性值,a和b为第一参数。In a specific embodiment, a univariate linear function aX+b=Y is used instead of the first update strategy, where X is time, Y is attribute value, and a and b are first parameters.

当所述第一更新策略的执行起点和执行终点的时间相同时,则根据预设计算公式

Figure BDA0003445864540000091
b=Y1-aX1;(X1≠X2)计算所述第一参数。When the execution start point and execution end point of the first update strategy are at the same time, according to the preset calculation formula
Figure BDA0003445864540000091
b=Y1-aX1; (X1≠X2) calculate the first parameter.

当所述第一更新策略的执行起点和执行终点的时间不同时,则根据预设计算公式a=0;b=Y1;(X1=X2)计算所述第一参数。When the time of the execution start point and the execution end point of the first update strategy are different, the first parameter is calculated according to the preset calculation formula a=0; b=Y1; (X1=X2).

具体的,所述执行起点和所述执行终点是自定义选取的一个函数区间,对于所述粒子在所述函数区间外的更新策略部分,可以通过将区间外的时间取余映射到区间内进行计算。Specifically, the execution start point and the execution end point are a function interval selected by yourself. For the update strategy part of the particle outside the function interval, the time remainder outside the interval can be mapped to the interval. calculate.

步骤S103,基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数;Step S103, calculating the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series;

在具体实施例中,所述第二更新策略包括位置、颜色、旋转、缩放等具有时间序列的更新策略。具体的,对于具有时间序列的更新策略,均具有数量不等的时间结点。所述第二更新策略的函数为具有对应时间结点数量的分段函数。In a specific embodiment, the second update strategy includes a time series update strategy such as position, color, rotation, and zoom. Specifically, for the update strategy with time series, there are different time nodes. The function of the second update strategy is a piecewise function with a corresponding number of time nodes.

针对所述第二更新策略,采用一元多次多项式替代时间序列所组成的分段函数。举例来说,对于时间结点数量为三个的第二更新策略,本实施例采用三次多项式cX3+dX2+eX+f=Y替代所述第二更新策略,其中X为时间,Y为属性值,c、d、e、f为第二参数。For the second update strategy, a multi-degree polynomial of one variable is used to replace the piecewise function formed by the time series. For example, for the second update strategy with three time nodes, this embodiment uses a cubic polynomial cX 3 +dX 2 +eX+f=Y to replace the second update strategy, where X is time and Y is Attribute value, c, d, e, f are the second parameters.

在获取了对应第二更新策略的多次多项式后,即可以根据每一时间结点对应的属性值计算所述多次多项式的第二参数。After the multi-order polynomial corresponding to the second update strategy is obtained, the second parameter of the multi-order polynomial can be calculated according to the attribute value corresponding to each time node.

根据本申请实施例的一种具体实施方式,所述第二预设函数为与所述第二更新策略的时间结点数量的一元多次多项式,其中,因变量为属性值,自变量为时间;According to a specific implementation of the embodiment of the present application, the second preset function is a polynomial multi-degree polynomial with the number of time nodes of the second update strategy, wherein the dependent variable is an attribute value, and the independent variable is time ;

基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数的步骤,包括:The step of calculating the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series includes:

采用最小二乘法对所述一元多次多项式进行拟合,以得到对应所述时间序列的时间矩阵和属性值向量;The least squares method is used to fit the multi-order polynomial in one variable, so as to obtain a time matrix and an attribute value vector corresponding to the time series;

根据预设的计算公式ATAx=ATB计算所述第二参数,其中,A为时间矩阵,B为属性值向量,x为第二参数。The second parameter is calculated according to a preset calculation formula A T Ax=A T B, where A is a time matrix, B is an attribute value vector, and x is the second parameter.

在具体实施例中,所述一元多次多项式的选择可以参考上述实施方式,此处不再赘述。In a specific embodiment, for the selection of the multi-degree polynomial in one variable, reference may be made to the foregoing implementation manner, and details are not described herein again.

在获得对应时间序列中各时间结点的时间值和属性值后,可以基于最小二乘法对所述一元多次多项式进行拟合,以得到对应的时间序列的矩阵和向量形式。基于最小二乘法对所述三次多项式进行拟合,可以将排序后的时间序列写为A矩阵和B向量的形式,其中,

Figure BDA0003445864540000111
B=(Y1,Y2,···,Yn),其中A矩阵为对应所述时间序列的时间矩阵,B向量为对应所述时间序列的属性值向量。After obtaining the time value and attribute value of each time node in the corresponding time series, the one-variable multi-degree polynomial can be fitted based on the least squares method to obtain the matrix and vector forms of the corresponding time series. By fitting the cubic polynomial based on the least squares method, the sorted time series can be written in the form of A matrix and B vector, where,
Figure BDA0003445864540000111
B=(Y1, Y2, ···, Yn), wherein the A matrix is a time matrix corresponding to the time series, and the B vector is an attribute value vector corresponding to the time series.

在得到所述时间矩阵和属性值向量后,根据公式ATAx=ATB计算所述第二更新策略的第二参数x,其中第二参数x为对应所述第二参数数量的多维向量。例如对应三次多项式的系数(c,d,e,f)。After obtaining the time matrix and the attribute value vector, calculate the second parameter x of the second update strategy according to the formula A T Ax=A T B, where the second parameter x is a multi-dimensional vector corresponding to the number of the second parameters . For example, it corresponds to the coefficients (c, d, e, f) of a cubic polynomial.

对于上述第一更新策略对应的第一参数和第二更新策略对应的第二参数,在粒子更新过程中参数值不会再发生变化,本实施例的粒子渲染装置调用API接口,将所述第一参数和所述第二参数写入图形处理器(graphics processing unit,简称GPU)的着色器的常量中。For the first parameter corresponding to the first update strategy and the second parameter corresponding to the second update strategy, the parameter value will not change during the particle update process. A parameter and the second parameter are written into constants of a shader of a graphics processing unit (GPU for short).

具体的,中央处理器(central processing unit,简称CPU)与图形处理器GPU均可进行计算任务,但应用场景不同。CPU面向通用性任务,需要处理各种不同的数据类型,以及支持逻辑判断所带来的大量分支跳转和中断处理,内部结构复杂。Specifically, both a central processing unit (central processing unit, CPU for short) and a graphics processing unit GPU can perform computing tasks, but the application scenarios are different. The CPU is oriented to general-purpose tasks, needs to deal with various data types, and supports a large number of branch jumps and interrupt processing brought by logical judgment, and the internal structure is complex.

而GPU只面向图形计算任务,需要处理的数据类型高度统一且相互无依赖,并且不需要考虑计算被中断,内部结构简单。所以GPU在特定的计算任务上,效率远远高于CPU。着色器Shader是指在GPU上运行的一段程序。The GPU is only oriented to graphics computing tasks, the data types to be processed are highly uniform and independent of each other, and there is no need to consider the interruption of computing, and the internal structure is simple. Therefore, the efficiency of GPU is much higher than that of CPU in specific computing tasks. Shader Shader refers to a program running on the GPU.

步骤S104,基于预设图像处理算法批量处理所述预设容器中的所有属性,并将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;Step S104, batch process all attributes in the preset container based on a preset image processing algorithm, and write the particles in the alive state and the visible state at the current time into the vertex buffer;

在具体实施例中,预设图像处理算法可以采用单指令多数据流(SingleInstruction Multiple Data,简称SIMD)的图像处理算法。In a specific embodiment, the preset image processing algorithm may use a single instruction multiple data stream (Single Instruction Multiple Data, SIMD for short) image processing algorithm.

具体的,所述SIMD图像处理算法能够用同样的时间计算多倍的数据,从而加快中央处理器处理所述预设容器中属性的计算效率。Specifically, the SIMD image processing algorithm can calculate multiple data in the same time, thereby speeding up the calculation efficiency of the central processing unit for processing the attributes in the preset container.

具体的,所述预设图像处理方法处理的属性包括粒子的存活性、可见性、粒子结构变换等无法放入着色器中进行计算的属性。Specifically, the attributes processed by the preset image processing method include the survivability, visibility, particle structure transformation and other attributes that cannot be put into the shader for calculation.

所述预设的图像处理算法可以从所述SOA_VECTOR容器中调用对应的属性值,并设置在一次运算中可同时处理的属性数量,从而得到粒子的存活性和可见性等变换属性值。The preset image processing algorithm can call corresponding attribute values from the SOA_VECTOR container, and set the number of attributes that can be processed simultaneously in one operation, thereby obtaining transformed attribute values such as particle survivability and visibility.

根据本申请实施例的一种具体实施方式,所述预设的图像处理算法为SIMD算法,所述预设容器中的属性数据包括粒子的存活性、可见性和粒子结构变换,基于预设图像处理算法批量处理所述预设容器中的属性数据的步骤,包括:According to a specific implementation of the embodiment of the present application, the preset image processing algorithm is a SIMD algorithm, and the attribute data in the preset container includes particle survivability, visibility, and particle structure transformation. Based on the preset image The step of processing the attribute data in the preset container in batches by the processing algorithm includes:

根据粒子的存活性、可见性和粒子结构变换判断所述粒子在当前时间的状态;Judging the state of the particle at the current time according to the particle's survivability, visibility and particle structure transformation;

将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;Write the particles that are alive and visible at the current time to the vertex buffer;

将当前时间下处于死亡状态的粒子初始化,并存放在预设容器中。Initialize the particles that are in the dead state at the current time and store them in the preset container.

在具体实施例中,所述中央处理器在处理完所述SOA_VECTOR容器中无法放入着色器中的所有属性后,将在当前时间下处于存活状态和可见状态的粒子写入顶点缓存区,以供图形处理器从所述顶点缓存区调用。In a specific embodiment, after processing all the attributes that cannot be put into the shader in the SOA_VECTOR container, the central processing unit writes the particles in the alive state and the visible state at the current time into the vertex buffer area to For the graphics processor to call from the vertex buffer.

对于当前时间下处于死亡状态的粒子,将所述粒子对象的各属性值置为初始值,并再次存放在所述SOA_VECTOR容器中,以供下一次更新时中央处理器进行调用。For the particles that are in the dead state at the current time, set each attribute value of the particle object as the initial value, and store it in the SOA_VECTOR container again for the central processor to call in the next update.

步骤S105,在着色器中,根据所述第一参数、第一预设函数、所述第二参数、第二预设函数以及所述当前时间计算所述顶点缓存区内各粒子的全部属性值;Step S105, in the shader, calculate all attribute values of each particle in the vertex buffer according to the first parameter, the first preset function, the second parameter, the second preset function and the current time ;

在具体实施例中,所述第一预设函数为aX+b=Y,所述第二预设函数为cX3+dX2+eX+f=Y,在上述实施例的处理过程中,已经将第一参数(a,b)和第二参数(c,d,e,f)存入所述着色器中。In a specific embodiment, the first preset function is aX+b=Y, and the second preset function is cX 3 +dX 2 +eX+f=Y. The first parameter (a, b) and the second parameter (c, d, e, f) are stored in the shader.

而在上述实施例的处理过程中,中央处理器根据预设的图像处理算法处理完各粒子的变化属性值,并将处于存活状态和处于可见状态的粒子存放在所述顶点缓存区中。In the processing process of the above embodiment, the central processing unit processes the changing attribute values of each particle according to the preset image processing algorithm, and stores the particles in the alive state and the visible state in the vertex buffer area.

在GPU的着色器中,即可以根据所述第一参数、第一预设函数、所述第二参数和第二预设函数计算所述顶点缓存区中储存的所有粒子的所有相关属性值,例如位置、颜色、旋转、缩放、纹理坐标等属性值。In the shader of the GPU, all relevant attribute values of all particles stored in the vertex buffer area can be calculated according to the first parameter, the first preset function, the second parameter and the second preset function, Property values such as position, color, rotation, scale, texture coordinates, etc.

根据本申请实施例的一种具体实施方式,根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染的步骤之前,所述方法还包括:According to a specific implementation of the embodiment of the present application, before the step of performing attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle, the method further includes:

根据实际场景参数,计算观察变换矩阵和投影变换矩阵,所述实际场景参数包括摄像机参数、观察点参数以及屏幕参数;Calculate the observation transformation matrix and the projection transformation matrix according to the actual scene parameters, where the actual scene parameters include camera parameters, observation point parameters and screen parameters;

将所述观察变换矩阵和所述投影变换矩阵写入所述着色器中,以使所述着色器根据所述观察变换矩阵和所述投影变换矩阵进行粒子渲染。The viewing transformation matrix and the projection transformation matrix are written into the shader, so that the shader performs particle rendering according to the viewing transformation matrix and the projection transformation matrix.

在具体实施例中,在对各粒子对象进行渲染前,还需要根据进行渲染的实际场景,计算观察变换矩阵和投影变换矩阵。具体的,所述观察变换矩阵和所述投影变换矩阵的计算方式均可以采用现有技术中的计算方法,此处不作赘述。In a specific embodiment, before rendering each particle object, the observation transformation matrix and the projection transformation matrix also need to be calculated according to the actual scene for rendering. Specifically, the calculation methods of the observation transformation matrix and the projection transformation matrix may adopt the calculation methods in the prior art, which will not be repeated here.

具体的,所述实际场景参数包括摄像机参数、观察点参数和屏幕宽高参数等。Specifically, the actual scene parameters include camera parameters, observation point parameters, screen width and height parameters, and the like.

将所述观察变换矩阵和所述投影变换矩阵作为常量输入至所述着色器中,从而所述着色器可以根据实际场景的渲染需要对各粒子进行实时渲染。The observation transformation matrix and the projection transformation matrix are input into the shader as constants, so that the shader can perform real-time rendering of each particle according to actual scene rendering requirements.

步骤S106,根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染。Step S106: Perform attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle.

在具体实施例中,通过着色器计算完顶点缓存区中的各粒子的全部属性值后,即能够根据上述实施例中计算出的观察变换矩阵、投影变换矩阵以及各粒子的全部属性值对粒子簇中的全部粒子进行渲染。In a specific embodiment, after calculating all the attribute values of each particle in the vertex buffer by the shader, the particle can be determined according to the observation transformation matrix, the projection transformation matrix and all the attribute values of each particle calculated in the above-mentioned embodiment. All particles in the cluster are rendered.

具体的,在使用着色器完成上述属性计算步骤后,进行渲染的步骤可以采用常规的粒子渲染步骤,此处不作赘述。Specifically, after using the shader to complete the above-mentioned attribute calculation step, the step of rendering may use a conventional particle rendering step, which will not be repeated here.

根据本申请实施例的一种具体实施方式,根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染的步骤之后,所述方法包括:According to a specific implementation of the embodiment of the present application, after the step of performing attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle, the method includes:

将所述当前时间替换为所述当前时间的下一次更新时间;Replace the current time with the next update time of the current time;

跳转至所述基于预设图像处理算法批量处理所述预设容器中的属性数据步骤,并执行后续更新渲染步骤直至到达预设时刻。Jump to the step of batch processing the attribute data in the preset container based on the preset image processing algorithm, and perform the subsequent update rendering step until the preset time is reached.

在具体实施例中,进行渲染的时间点是不断更新的,当对当前时间点的所有粒子的渲染步骤完成后,即将当前时间替换为下一次更新的时间。具体的,所述下一次更新的时间可以根据实际应用场景进行设置,本实施例中不作具体限定。In a specific embodiment, the time point for rendering is continuously updated, and when the step of rendering all particles at the current time point is completed, the current time is replaced with the time of the next update. Specifically, the time for the next update may be set according to an actual application scenario, which is not specifically limited in this embodiment.

在替换完当前时间后,跳转至上述实施例中计算预设容器中的属性数据的步骤,以检测在下一次更新的时间点的粒子存活情况和可见情况,并根据粒子的存活情况和可见情况进行下一次渲染计算。After replacing the current time, jump to the step of calculating the attribute data in the preset container in the above embodiment, so as to detect the survival and visibility of the particles at the time point of the next update, and according to the survival and visibility of the particles Do the next rendering calculation.

在上述实施例中,步骤S101-步骤S104均是在中央处理器中进行的,步骤S105和步骤S106是在图形处理器的图形处理器中执行的。In the above embodiment, steps S101 to S104 are all performed in a central processing unit, and steps S105 and S106 are performed in a graphics processor of a graphics processor.

本实施例提供的粒子系统渲染方法,通过将粒子属性的计算进行分类替换,将粒子属性的计算转换为可以在着色器中计算的函数和所述函数对应的参数,从而可以降低中央处理器内存空间的占用,并减少在中央处理器中频繁的地址变动和在同一时间执行多条指令,提升了中央处理器的利用率。通过图形处理器计算粒子的部分属性更新,提高了粒子效果的渲染效率。The particle system rendering method provided by this embodiment converts the calculation of particle attributes into functions that can be calculated in the shader and parameters corresponding to the functions by classifying and replacing the calculation of particle attributes, thereby reducing the memory of the central processing unit. The space occupied, and the frequent address changes in the central processing unit are reduced and multiple instructions are executed at the same time, which improves the utilization rate of the central processing unit. Some attribute updates of particles are calculated by the graphics processor, which improves the rendering efficiency of particle effects.

参考图3,为本申请实施例提供的一种粒子系统渲染装置300的装置模块示意图,本申请实施例提供的粒子系统渲染装置300,如图1所示,所述粒子系统渲染装置300包括:Referring to FIG. 3 , which is a schematic diagram of a device module of a particle system rendering apparatus 300 provided by an embodiment of the present application, the particle system rendering apparatus 300 provided by an embodiment of the present application, as shown in FIG. 1 , the particle system rendering apparatus 300 includes:

分类存储模块301,用于对预设粒子簇中的各粒子的属性进行分类存储,其中,随时间动态变化的属性存储在预设容器中,所述预设粒子簇包括同类粒子和各粒子的更新策略,所述更新策略包括不具有时间序列的第一更新策略和具有时间序列的第二更新策略;The classification storage module 301 is used to classify and store the attributes of each particle in the preset particle cluster, wherein the attributes that change dynamically with time are stored in a preset container, and the preset particle cluster includes the same particle and the attributes of each particle. an update strategy, the update strategy includes a first update strategy without a time series and a second update strategy with a time series;

第一计算模块302,用于基于所述第一更新策略的执行起点和执行终点计算对应第一预设函数的第一参数,其中,所述第一更新策略为不具有时间序列的更新策略;a first calculation module 302, configured to calculate a first parameter corresponding to a first preset function based on an execution start point and an execution end point of the first update strategy, wherein the first update strategy is an update strategy without a time series;

第二计算模块303,用于基于所述第二更新策略的时间序列以及对应所述时间序列中每一时间结点的数值计算对应第二预设函数的第二参数,其中,所述第二更新策略为具有时间序列的更新策略;The second calculation module 303 is configured to calculate the second parameter corresponding to the second preset function based on the time series of the second update strategy and the value corresponding to each time node in the time series, wherein the second The update strategy is an update strategy with time series;

处理模块304,用于基于预设图像处理算法批量处理所述预设容器中的所有属性,并将当前时间下处于存活状态和可见状态的粒子写入顶点缓存区;The processing module 304 is configured to batch process all attributes in the preset container based on a preset image processing algorithm, and write the particles in the alive state and the visible state at the current time into the vertex buffer;

第三计算模块305,用于在着色器中,根据所述第一参数、第一预设函数、所述第二参数、第二预设函数以及所述当前时间计算所述顶点缓存区内各粒子的全部属性值;The third calculation module 305 is configured to, in the shader, calculate each element in the vertex buffer according to the first parameter, the first preset function, the second parameter, the second preset function and the current time. All attribute values of the particle;

渲染模块306,用于根据各粒子的全部属性值对所述预设粒子簇中的全部粒子分别进行属性渲染。The rendering module 306 is configured to perform attribute rendering for all particles in the preset particle cluster according to all attribute values of each particle.

另外,本申请实施例还提供的一种电子设备,所述电子设备包括处理器和存储器,所述存储器存储有计算机程序,所述计算机程序在所述处理器上运行时执行上述实施例中的粒子系统渲染方法。In addition, an embodiment of the present application further provides an electronic device, the electronic device includes a processor and a memory, the memory stores a computer program, and the computer program executes the above-mentioned embodiments when running on the processor. Particle system rendering method.

本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,所述计算机程序在处理器上运行时执行上述实施例中的粒子系统渲染方法。An embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program executes the particle system rendering method in the foregoing embodiment when running on a processor.

综上所述,本申请实施例提供了一种粒子系统渲染方法、装置、电子设备及存储介质,本申请实施例提供的粒子系统渲染方法通过CPU将粒子和更新策略的部分属性转换为函数和参数的方式,存放在着色器中,以通过所述着色器计算部分属性的属性值,从而继续在GPU中完成渲染,减少了在CPU中频繁的地址变动和在同一时间执行多条指令,提升了CPU的利用率,降低了内存空间的占用。通过使用GPU计算部分粒子更新,提高了粒子效果的渲染效率。另外,上述实施例中提到的粒子系统渲染装置、电子设备及计算机可读存储介质的具体实施过程,可以参见上述方法实施例的具体实施过程,在此不再一一赘述。To sum up, the embodiments of the present application provide a particle system rendering method, device, electronic device, and storage medium. The particle system rendering method provided by the embodiments of the present application converts some attributes of particles and update strategies into functions and The method of parameters is stored in the shader to calculate the attribute values of some attributes through the shader, so as to continue to complete the rendering in the GPU, reducing the frequent address changes in the CPU and executing multiple instructions at the same time, improving the CPU utilization is reduced and memory space usage is reduced. Improved rendering efficiency of particle effects by using the GPU to compute partial particle updates. In addition, for the specific implementation process of the particle system rendering apparatus, the electronic device, and the computer-readable storage medium mentioned in the foregoing embodiments, reference may be made to the specific implementation process of the foregoing method embodiments, which will not be repeated here.

在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和结构图显示了根据本发明的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,结构图和/或流程图中的每个方框、以及结构图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may also be implemented in other manners. The apparatus embodiments described above are only schematic, for example, the flowcharts and structural diagrams in the accompanying drawings show the possible implementation architectures and functions of the apparatuses, methods and computer program products according to various embodiments of the present invention and operation. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more functions for implementing the specified logical function(s) executable instructions. It should also be noted that, in alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart diagrams, can be implemented using dedicated hardware-based systems that perform the specified functions or actions. be implemented, or may be implemented in a combination of special purpose hardware and computer instructions.

另外,在本发明各个实施例中的各功能模块或单元可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或更多个模块集成形成一个独立的部分。In addition, each functional module or unit in each embodiment of the present invention may be integrated to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.

所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是智能手机、个人计算机、服务器、或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the functions are implemented in the form of software function modules and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention can be embodied in the form of a software product in essence, or the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including Several instructions are used to cause a computer device (which may be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: U disk, removable hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes .

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention. should be included within the protection scope of the present invention.

Claims (10)

1. A particle system rendering method, comprising:
classifying and storing the attributes of each particle in a preset particle cluster, wherein the attributes which dynamically change along with time are stored in a preset container, the preset particle cluster comprises the same type of particles and the updating strategies of each particle, and the updating strategies comprise a first updating strategy without a time sequence and a second updating strategy with the time sequence;
calculating a first parameter corresponding to a first preset function based on the execution starting point and the execution end point of the first updating strategy;
calculating a second parameter corresponding to a second preset function based on the time series of the second updating strategy and the numerical value corresponding to each time node in the time series;
processing all attributes in the preset container in batches based on a preset image processing algorithm, and writing the particles in a survival state and a visible state at the current time into a vertex cache region;
in a shader, calculating all attribute values of each particle in the vertex cache region according to the first parameter, the first preset function, the second parameter, the second preset function and the current time;
and respectively performing attribute rendering on all the particles in the preset particle cluster according to all the attribute values of all the particles.
2. The particle system rendering method according to claim 1, wherein the preset container is an SOA _ VECTOR container, and the step of storing the attributes of the particles in the preset particle cluster in a classified manner includes:
dividing the attribute of each particle in the preset particle cluster into an attribute which changes along with time and a constant attribute;
integrating the constant attributes of all the particles in the preset particle cluster into a structural body, and storing a pointer of the structural body in each particle object in the preset particle cluster;
storing all time-varying attributes in the SOA _ VECTOR container.
3. The particle system rendering method according to claim 1, wherein the first preset function is a unary linear function, wherein the dependent variable is an attribute value, the independent variable is a time, and the step of calculating the first parameter corresponding to the first preset function based on the execution start point and the execution end point of the first update strategy comprises:
if the time of the execution starting point and the execution ending point of the current first updating strategy is the same, acquiring a first coefficient group according to a first rule, and taking the first coefficient group as a first parameter when the current first updating strategy is adopted;
and if the execution starting point and the execution ending point of the current first updating strategy are different in time, acquiring a second coefficient group according to a second rule, and taking the second coefficient group as a first parameter when the current first updating strategy is adopted.
4. The particle system rendering method of claim 1, wherein the second predetermined function is a univariate polynomial of the number of time nodes of the second update strategy, wherein a dependent variable is an attribute value and an independent variable is time;
calculating a second parameter corresponding to a second preset function based on the time series of the second update strategy and the numerical value corresponding to each time node in the time series, wherein the step comprises the following steps:
fitting the unary multiple polynomial by adopting a least square method to obtain a time matrix and an attribute value vector corresponding to the time sequence;
according to a preset calculation formula ATAx=ATAnd B, calculating the second parameter, wherein A is a time matrix, B is an attribute value vector, and x is the second parameter.
5. The particle system rendering method according to claim 1, wherein before the step of performing the attribute rendering on all the particles in the preset particle cluster according to all the attribute values of the particles, the method further comprises:
calculating an observation transformation matrix and a projection transformation matrix according to actual scene parameters, wherein the actual scene parameters comprise camera parameters, observation point parameters and screen parameters;
and writing the observation transformation matrix and the projection transformation matrix into the shader so that the shader performs particle rendering according to the observation transformation matrix and the projection transformation matrix.
6. The particle system rendering method according to claim 1, wherein after the step of performing attribute rendering on all particles in the preset particle cluster according to all attribute values of each particle, the method comprises:
replacing the current time with a next update time of the current time;
skipping to the step of processing the attribute data in the preset container in batch based on the preset image processing algorithm, and executing the subsequent updating and rendering step until the preset moment is reached.
7. The particle system rendering method according to claim 1, wherein the preset image processing algorithm is a SIMD algorithm, the attribute data in the preset container includes survivability, visibility, and particle structure transformation of the particles, and the step of batch processing the attribute data in the preset container based on the preset image processing algorithm includes:
judging the state of the particle at the current time according to the survivability, the visibility and the particle structure transformation of the particle;
writing the particles in the survival state and the visible state in the current time into a vertex cache region;
initializing the particles in the death state at the current time, and storing the particles in a preset container.
8. A particle system rendering apparatus, characterized in that the particle system rendering apparatus comprises:
the classified storage module is used for classified storage of attributes of each particle in a preset particle cluster, wherein the attributes which dynamically change along with time are stored in a preset container, the preset particle cluster comprises the same type of particles and update strategies of each particle, and the update strategies comprise a first update strategy without a time sequence and a second update strategy with the time sequence;
a first calculating module, configured to calculate a first parameter corresponding to a first preset function based on an execution start point and an execution end point of the first update policy, where the first update policy is an update policy without a time sequence;
the second calculation module is used for calculating a second parameter corresponding to a second preset function based on the time sequence of the second updating strategy and the numerical value corresponding to each time node in the time sequence, wherein the second updating strategy is an updating strategy with the time sequence;
the processing module is used for processing all attributes in the preset container in batches based on a preset image processing algorithm and writing the particles in a survival state and a visible state at the current time into a vertex cache region;
a third calculating module, configured to calculate, in a shader, all attribute values of each particle in the vertex cache region according to the first parameter, the first preset function, the second parameter, the second preset function, and the current time;
and the rendering module is used for respectively performing attribute rendering on all the particles in the preset particle cluster according to all the attribute values of all the particles.
9. An electronic device, characterized in that the electronic device comprises a processor and a memory, the memory storing a computer program which, when run on the processor, performs the particle system rendering method of any of claims 1 to 7.
10. A computer-readable storage medium, in which a computer program is stored which, when run on a processor, performs the particle system rendering method of any one of claims 1 to 7.
CN202111648569.5A 2021-12-30 2021-12-30 Particle system rendering method, device, electronic device and readable storage medium Active CN114432695B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111648569.5A CN114432695B (en) 2021-12-30 2021-12-30 Particle system rendering method, device, electronic device and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111648569.5A CN114432695B (en) 2021-12-30 2021-12-30 Particle system rendering method, device, electronic device and readable storage medium

Publications (2)

Publication Number Publication Date
CN114432695A true CN114432695A (en) 2022-05-06
CN114432695B CN114432695B (en) 2025-09-02

Family

ID=81366683

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111648569.5A Active CN114432695B (en) 2021-12-30 2021-12-30 Particle system rendering method, device, electronic device and readable storage medium

Country Status (1)

Country Link
CN (1) CN114432695B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119292780A (en) * 2024-09-30 2025-01-10 浙江大学 A data-oriented particle system task design and scheduling method and device

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103714568A (en) * 2013-12-31 2014-04-09 北京像素软件科技股份有限公司 Method for achieving large-scale particle system
CN105335923A (en) * 2014-08-03 2016-02-17 联发科技(新加坡)私人有限公司 Graphics processing system and related graphics processing method
US20190114819A1 (en) * 2017-10-13 2019-04-18 Microsoft Technology Licensing, Llc Dimensional content surface rendering
CN110681155A (en) * 2019-09-29 2020-01-14 Oppo广东移动通信有限公司 Game optimization method, game optimization device and mobile terminal
CN111127610A (en) * 2019-12-23 2020-05-08 武汉真蓝三维科技有限公司 Point cloud data three-dimensional visualization rendering method and calculation method
CN111540035A (en) * 2020-05-07 2020-08-14 支付宝(杭州)信息技术有限公司 Particle rendering method, device and device
CN111754614A (en) * 2020-06-30 2020-10-09 平安国际智慧城市科技股份有限公司 Video rendering method and device based on VR (virtual reality), electronic equipment and storage medium
CN112652044A (en) * 2021-01-05 2021-04-13 网易(杭州)网络有限公司 Particle special effect rendering method, device and equipment and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103714568A (en) * 2013-12-31 2014-04-09 北京像素软件科技股份有限公司 Method for achieving large-scale particle system
CN105335923A (en) * 2014-08-03 2016-02-17 联发科技(新加坡)私人有限公司 Graphics processing system and related graphics processing method
US20190114819A1 (en) * 2017-10-13 2019-04-18 Microsoft Technology Licensing, Llc Dimensional content surface rendering
CN110681155A (en) * 2019-09-29 2020-01-14 Oppo广东移动通信有限公司 Game optimization method, game optimization device and mobile terminal
CN111127610A (en) * 2019-12-23 2020-05-08 武汉真蓝三维科技有限公司 Point cloud data three-dimensional visualization rendering method and calculation method
CN111540035A (en) * 2020-05-07 2020-08-14 支付宝(杭州)信息技术有限公司 Particle rendering method, device and device
CN111754614A (en) * 2020-06-30 2020-10-09 平安国际智慧城市科技股份有限公司 Video rendering method and device based on VR (virtual reality), electronic equipment and storage medium
CN112652044A (en) * 2021-01-05 2021-04-13 网易(杭州)网络有限公司 Particle special effect rendering method, device and equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119292780A (en) * 2024-09-30 2025-01-10 浙江大学 A data-oriented particle system task design and scheduling method and device

Also Published As

Publication number Publication date
CN114432695B (en) 2025-09-02

Similar Documents

Publication Publication Date Title
US9886792B2 (en) Adaptive mesh refinement
CN111063032B (en) Model rendering method, system and electronic device
US11488347B2 (en) Method for instant rendering of voxels
CN114375464B (en) Ray tracing of dynamic cells in virtual space using bounding volume representation
KR20180056316A (en) Method and apparatus for performing tile-based rendering
KR20170038525A (en) Graphic Processing Apparatus and Operating Method thereof
CN115222879A (en) A model surface reduction processing method, device, electronic device and storage medium
CN115814407A (en) Information processing method, information processing apparatus, storage medium, and electronic apparatus
US10636210B2 (en) Dynamic contour volume deformation
CN110706149A (en) Lightning particle rendering method and device
WO2024037116A9 (en) Three-dimensional model rendering method and apparatus, electronic device and storage medium
CN113769382A (en) Method, device and equipment for eliminating model in game scene and storage medium
US9489771B2 (en) Techniques for spatially sorting graphics information
JP7419522B2 (en) Volume data reduction while preserving visual fidelity
CN114432695A (en) Particle system rendering method, apparatus, electronic device and readable storage medium
WO2024183288A1 (en) Shadow rendering method and apparatus, computer device, and storage medium
US9582247B1 (en) Preserving data correlation in asynchronous collaborative authoring systems
CN114399421A (en) Storage method, device and equipment for three-dimensional model visibility data and storage medium
US20240104847A1 (en) Techniques for parallel edge decimation of a mesh
CN117710563A (en) Method for rasterizing-based differentiable renderer of semitransparent objects
CN110570504B (en) Closed symbol drawing method and device, electronic equipment and storage medium
CN113706675A (en) Mirror image processing method, mirror image processing device, storage medium and electronic device
CN114064304A (en) Data processing method and device, computer equipment and storage medium
CN114299203A (en) Method and device for processing virtual model
US20250209566A1 (en) Image scaling methods and systems

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant