[go: up one dir, main page]

CN100388318C - A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets - Google Patents

A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets Download PDF

Info

Publication number
CN100388318C
CN100388318C CNB2005101262163A CN200510126216A CN100388318C CN 100388318 C CN100388318 C CN 100388318C CN B2005101262163 A CNB2005101262163 A CN B2005101262163A CN 200510126216 A CN200510126216 A CN 200510126216A CN 100388318 C CN100388318 C CN 100388318C
Authority
CN
China
Prior art keywords
array
shader
information
state
rendered object
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.)
Expired - Fee Related
Application number
CNB2005101262163A
Other languages
Chinese (zh)
Other versions
CN1851753A (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.)
Beihang University
Original Assignee
Beihang University
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 Beihang University filed Critical Beihang University
Priority to CNB2005101262163A priority Critical patent/CN100388318C/en
Publication of CN1851753A publication Critical patent/CN1851753A/en
Application granted granted Critical
Publication of CN100388318C publication Critical patent/CN100388318C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Image Generation (AREA)

Abstract

The present invention relates to a Shader three-dimensional graph drawing frame based on a state set and a drawing method. Model information, texture information, sound information and corresponding Shader codes of a drawing object are uniformly packed and described in Materials Description files before being called into a scene graph; the model information, the texture information, the sound information and the corresponding Shader codes of the drawing object are respectively called into a rendering object by a Material Loader and a Media Loader in a data storage structure of the scene graph; meanwhile, static and dynamic optimization is carried out to the model information, the texture information, the sound information and the corresponding Shader codes of the drawing object according to the order of Shader information. Then, the optimized drawing state information is sent into a drawing engine to draw, wherein the drawing engine is composed of drawing control and state control which are matched with each other to complete a drawing process of the drawing object. The present invention effectively manages a Vertex Shader and a Pixel Shader, and fully uses the state package and arrangement functions of the state set; the present invention not only enhances drawing efficiency, but also simplifies interface call and is convenient for programmer to develop.

Description

一种基于状态集的Shader三维图形绘制系统和绘制方法 A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets

技术领域 technical field

本发明涉及一种三维图形引擎框架,特别是一种基于状态集的Shader(着色器)三维图形绘制系统和绘制方法。The invention relates to a three-dimensional graphics engine framework, in particular to a Shader (shader) three-dimensional graphics drawing system and a drawing method based on a state set.

背景技术 Background technique

随着硬件设计和工艺水平的提高,图形处理单元(Graphic ProcessingUnit,GPU)成为图形实时渲染过程中的核心角色。利用GPU可以将CPU(中央处理器)的负载转移,缓解CPU和AGP在图形渲染过程中造成的数据传输瓶颈,同时增加可编程特性,可以对输入物体的形状、外观和运动提供可编程控制。With the improvement of hardware design and technology level, the graphics processing unit (Graphic Processing Unit, GPU) has become the core role in the process of real-time rendering of graphics. Utilizing the GPU can transfer the load of the CPU (Central Processing Unit), relieve the data transmission bottleneck caused by the CPU and AGP in the graphics rendering process, and increase the programmable feature, which can provide programmable control for the shape, appearance and movement of the input object.

图形处理单元提供了两种可编程模块,通过运行特殊Shader程序完成渲染对象的逐顶点per-vertex以及逐像素per-pixel的并行运算。这些在主程序中被指定并在运行时由渲染管线自动调用。基于GPU的绘制过程首先是程序输入绘制物体的顶点、颜色和纹理等信息,这些数据将被顶点控制器程序VertexShader处理,其结果包含最新变换后的顶点进而完成图元装配和光栅化。随后,像素控制器程序Pixel Shader提供逐像素的操作,其结果将被送入帧缓存显示。这种绘制方式的高效率得益于其并行化的计算,这不仅能够提高程序实时渲染的速度,还拓展了实时渲染程序的特效内容,如高动态渲染、凹凸贴图、柔和阴影等效果。The graphics processing unit provides two kinds of programmable modules, and completes the per-vertex per-vertex and per-pixel per-pixel parallel operation of the rendered object by running a special Shader program. These are specified in the main program and automatically called by the rendering pipeline at runtime. The GPU-based drawing process starts with the program inputting information such as vertices, colors, and textures of the drawn object. These data will be processed by the vertex controller program VertexShader, and the results include the latest transformed vertices to complete the primitive assembly and rasterization. Subsequently, the pixel controller program Pixel Shader provides pixel-by-pixel operations, and the results will be sent to the frame buffer for display. The high efficiency of this drawing method benefits from its parallel computing, which not only improves the real-time rendering speed of the program, but also expands the special effects content of the real-time rendering program, such as high dynamic rendering, bump map, soft shadow and other effects.

利用GPU进行实时图形渲染计算是近年来军事仿真和电脑游戏也竞相选择的编程方式。伴随着GPU硬件的不断更新,从早期的游戏极品飞车到最新的DOOM III,甚至于利用最先进设备制作的数字电影,越来越多的逼真渲染实时计算使用了GPU这一利器。Utilizing GPU for real-time graphics rendering calculation is a programming method that military simulations and computer games are competing to choose in recent years. With the continuous update of GPU hardware, from the early game Need for Speed to the latest DOOM III, and even digital movies made with the most advanced equipment, more and more real-time calculations of realistic rendering use GPU as a powerful tool.

虽然,对GPU执行的Shader程序的管理整合到现有的图形引擎有助于进一步提高绘制效率、提高渲染逼真性,但随之产生的负面影响是渲染环境状态数量的增加和切换的频繁。目前,对状态的描述和管理一般采用状态集的概念,以往有多种Shader整合方法,传统采用最多的是回调函数,如图1所示。这种方式在渲染前提供接口声明Shader程序对象和绘制状态,没有考虑到渲染对象之间在状态上的关系,不能进行状态合并,从而限制了绘制效率。Although the integration of the management of the Shader program executed by the GPU into the existing graphics engine helps to further improve the rendering efficiency and rendering fidelity, the negative impact is the increase in the number of rendering environment states and the frequent switching. At present, the concept of state set is generally used for state description and management. In the past, there were many Shader integration methods, and the callback function is the most commonly used traditionally, as shown in Figure 1. This method provides an interface to declare the Shader program object and the drawing state before rendering. It does not consider the state relationship between the rendering objects and cannot perform state merging, thus limiting the drawing efficiency.

发明内容 Contents of the invention

本发明的技术解决问题是:克服现有技术的不足,提供一种基于状态集的Shader图形绘制系统和绘制方法,它对Vertex Shader和Pixel Shader进行了有效管理,充分利用状态集的状态封装和排序功能,在提高了绘制效率的同时,简化了接口调用,方便了程序员的开发。The technical solution problem of the present invention is: overcome the deficiencies in the prior art, provide a kind of Shader graphic drawing system and drawing method based on state set, it has carried out effective management to Vertex Shader and Pixel Shader, fully utilizes the state encapsulation and state set of state set The sorting function, while improving the drawing efficiency, simplifies the interface call and facilitates the programmer's development.

本发明的技术解决方案:一种基于状态集的Shader三维图形绘制系统,由绘制对象描述接口文件Materials Description、场景图SceneGraph、渲染对象、绘制引擎Render Engine组成,其特征在于:Technical solution of the present invention: a kind of Shader three-dimensional graphics drawing system based on state set, is made up of drawing object description interface file Materials Description, scene graph SceneGraph, rendering object, drawing engine Render Engine, is characterized in that:

所述的Materials Description通过xml文件进行定义,对绘制对象的模型信息、纹理信息、声音信息、Shader文件或代码内容以及绘制所需状态信息进行统一封装和描述;The Materials Description is defined through an xml file, and uniformly encapsulates and describes the model information, texture information, sound information, Shader file or code content of the drawn object, and the state information required for drawing;

所述的场景图的内存存贮结构分为材质载入器Material Loader和介质载入器Media Loader两部分,Material Loader负责读取对象整体描述及绘制状态信息,同时对绘制状态信息以Shader信息排序进行静态优化,并调入渲染对象的状态集中,Media Loader负责读取顶点、纹理、音频以及Shader代码绘制对象本身的几何信息,同时建立全局交叉数组并辅以索引数组,并调入渲染对象的数据集中;The memory storage structure of the scene graph is divided into two parts: Material Loader and Media Loader. Material Loader is responsible for reading the overall description of the object and drawing status information, and sorting the drawing status information with Shader information. Perform static optimization and call into the state set of the rendering object. Media Loader is responsible for reading the geometric information of the vertex, texture, audio and Shader code drawing object itself. data set;

所述的渲染对象,分为状态集和数据集,状态集包括顶点描述VertexDescription和像素描述Pixel Description,在渲染过程中,状态集对绘制状态信息按照Shader信息继续排序进行动态优化,数据集对全局交叉数组和索引数组的进行更新保存;The rendering object is divided into a state set and a data set. The state set includes a vertex description VertexDescription and a pixel description Pixel Description. During the rendering process, the state set dynamically optimizes the drawing state information according to Shader information. Update and save the intersection array and index array;

所述的绘制引擎由绘制控制和状态控制构成,绘制控制是对渲染对象进行绘制过程中的控制,它根据渲染对象的数据集中几何信息分发给OpenGL或硬件代码进行绘制;状态控制,是对渲染对象进行绘制过程中有关绘制状态的控制,绘制控制和状态控制两者配合完成一个绘制对象的绘制过程。The drawing engine is composed of drawing control and state control, and the drawing control is the control in the process of drawing the rendering object, which is distributed to OpenGL or hardware codes for drawing according to the geometric information in the data set of the rendering object; the state control is for rendering The control related to the drawing state during the drawing process of the object, the drawing control and the state control cooperate to complete the drawing process of a drawing object.

所述的绘制状态信息以Shader信息排序进行静态优化绘制状态的静态优化过程为:The rendering state information is sorted by Shader information for static optimization. The static optimization process of the rendering state is:

(1)初始化全局交叉数组,数组结构采用标准库Array模版,每单元内容为OpenGL的枚举型T2_C4_N3_V3结构;(1) Initialize the global intersection array, the array structure adopts the standard library Array template, and the content of each unit is the enumerated T2_C4_N3_V3 structure of OpenGL;

(2)初始化全局索引数组,数组结构采用标准库Array模版,每单元内容为长整形结构;(2) Initialize the global index array, the array structure adopts the standard library Array template, and the content of each unit is a long integer structure;

(3)当有新的绘制对象加入场景图后,分别完成如下操作:(3) When a new drawing object is added to the scene graph, complete the following operations:

a.获得绘制对象的纹理、颜色、法向量、位置数组指针;a. Obtain the texture, color, normal vector, and position array pointer of the drawn object;

b.进行索引生成,保证每一个顶点在交叉数组中只出现一次;b. Perform index generation to ensure that each vertex only appears once in the intersection array;

c.获得绘制对象的绘制状态指针,并根据指针获得纹理以及Shader信息;c. Obtain the drawing state pointer of the drawing object, and obtain the texture and Shader information according to the pointer;

d.在全局交叉数组中搜索与该绘制对象具有相同Shader的数组部分,若发现则继续搜索与该绘制对象具有相同纹理状态的数组部分,如发现则将该顶点序列和索引序列分别存储在全局交叉数组和索引数组中,若没有对应纹理的数组,则将该顶点序列和索引序列存储在该Shader对应的最后一个数组序列之后;若没有与相同的Shader,则将该顶点序列和索引序列存储在全局的交叉数组和索引数组之后;d. Search the global intersection array for the array part that has the same Shader as the drawing object, if found, continue to search for the array part that has the same texture state as the drawing object, if found, store the vertex sequence and index sequence in the global respectively In the intersection array and index array, if there is no array corresponding to the texture, the vertex sequence and index sequence will be stored after the last array sequence corresponding to the Shader; if there is no Shader with the same shader, the vertex sequence and index sequence will be stored after the global intersection and index arrays;

(4)在绘制对象中记录其索引在全局索引中的起始点和长度,完成静态优化。(4) Record the starting point and length of its index in the global index in the drawing object, and complete the static optimization.

所述的绘制状态信息以Shader信息排序进行动态优化过程为:The dynamic optimization process of the rendering state information sorted by Shader information is as follows:

(1)初始化绘制数组以便防止绘制对象序列;(1) Initialize the drawing array so as to prevent drawing object sequences;

(2)依次获得每一针的所需的绘制对象;(2) Obtain the required drawing objects of each stitch in turn;

(3)遍历绘制数组搜索相应Shader以及纹理信息的绘制状态(3) Traverse the drawing array to search for the drawing state of the corresponding Shader and texture information

a.若为搜索到相似的Shader,则将该对象放入绘制数组的末端;a. If a similar Shader is found, put the object at the end of the drawing array;

b.若发现相似的Shader而没有相似的纹理,则将该对象放入该Shader对应的数组的相对末端;b. If a similar Shader is found without a similar texture, put the object at the opposite end of the array corresponding to the Shader;

(4)当发现Shader和纹理均相似时开始进行动态排序:(4) When Shader and texture are found to be similar, start dynamic sorting:

a.按照耗时优先级比较最耗时的状态的是否有与该对象相同的,如不相同则插入相同对象的之后;a. According to the time-consuming priority, compare whether the most time-consuming state is the same as the object, and if not, insert the same object after it;

b.若相同则在相同的对象组中继续比较下一个耗时状态,如此往复,直到所有状态比较结束;b. If they are the same, continue to compare the next time-consuming state in the same object group, and so on, until the end of all state comparisons;

c.当最后一个状态比较仍像同,则视为两个绘制对象完全相同,进而顺序排列即可;c. When the last state comparison is still similar, it is considered that the two drawing objects are exactly the same, and then they can be arranged in order;

(5)处理下一个绘制对象,直到所有带绘制对象处理比较完毕。(5) Process the next drawing object until the processing and comparison of all drawing objects are completed.

采用上述基于状态集的Shader三维图形绘制系统,包括下列步骤:Using the above-mentioned Shader three-dimensional graphics rendering system based on the state set includes the following steps:

(1)将绘制对象的模型信息、纹理信息、声音信息以及相应的Shader代码在被调入场景图之前被统一封装和描述在绘制对象的描述接口MaterialsDescription文件中;(1) The model information, texture information, sound information and corresponding Shader code of the drawing object are uniformly encapsulated and described in the description interface MaterialsDescription file of the drawing object before being transferred into the scene graph;

(2)将上述的绘制对象信息通过场景图的数据存储结构中的MaterialLoader和Media Loader分别调入渲染对象中,其中Material Loader负责绘制对象的状态信息调入,Material Loader在将状态信息调入之前,要按照Shader信息排序进行静态优化,并调入渲染对象的状态集中;Media Loader负责读取顶点、纹理、音频以及Shader代码绘制对象本身的几何信息,同时建立全局交叉数组并辅以索引数组,并调入渲染对象的数据集中;(2) The above-mentioned drawing object information is transferred into the rendering object through the MaterialLoader and Media Loader in the data storage structure of the scene graph, among which the Material Loader is responsible for transferring the state information of the drawing object, and before the Material Loader transfers the state information , to perform static optimization according to Shader information sorting, and transfer to the state set of the rendering object; Media Loader is responsible for reading the geometric information of the vertex, texture, audio, and Shader code drawing object itself, and at the same time establishes a global intersection array supplemented by an index array. And call into the data set of the rendering object;

(3)将渲染对象分为状态集和数据集,状态集包括顶点描述VertexDescription和像素描述Pixel Description,在渲染过程中,状态集对绘制对象的状态信息按照Shader信息继续排序进行动态优化,数据集对全局交叉数组和索引数组的更新进行保存;(3) Divide the rendering object into a state set and a data set. The state set includes the vertex description VertexDescription and the pixel description Pixel Description. During the rendering process, the state set dynamically optimizes the state information of the drawing object according to the shader information. The data set Save the update of the global intersection array and index array;

(4)将在渲染对象中渲染后的绘制对象送入绘制引擎进行绘制,绘制引擎由绘制控制和状态控制构成,绘制控制将获得的对象顶点、纹理、音频以及Shader代码的绘制对象本身数据信息分发给OpenGL或硬件代码进行绘制,而绘制对象的状态描述信息则交由状态控制进行绘制状态的改变,绘制控制和状态控制两者配合完成一个绘制对象的绘制过程。(4) Send the drawing object rendered in the rendering object to the drawing engine for drawing. The drawing engine is composed of drawing control and state control. The drawing control will obtain the object vertices, texture, audio and the data information of the drawing object itself in the Shader code Distributed to OpenGL or hardware code for drawing, and the state description information of the drawing object is handed over to the state control to change the drawing state. The drawing control and the state control cooperate to complete the drawing process of a drawing object.

本发明的原理是:一个场景图的生成过程依赖于模型文件和模型读入器,经过模型载入过程生成的场景图数据结构可能存在一些影响图形绘制效率的地方。本发明使场景图数据结构在用于绘制之前,经过一个预处理过程,发现那些影响图形绘制效率的部分,在保证绘制正确地情况下,对场景图数据结构做出调整,提高了绘制效率。The principle of the present invention is: the generation process of a scene graph depends on the model file and the model reader, and the data structure of the scene graph generated through the model loading process may have some places that affect the graphics drawing efficiency. The invention makes the scene graph data structure go through a preprocessing process before being used for drawing, finds those parts that affect the drawing efficiency of graphics, and adjusts the scene graph data structure under the condition of ensuring correct drawing, thereby improving the drawing efficiency.

采用上述绘制引的绘制方法步骤为:The steps of the drawing method using the above-mentioned drawing reference are as follows:

(1)将绘制对象的模型信息、纹理信息、声音信息以及相应的Shader代码在被调入场景图之前被统一封装在绘制对象的描述接口MaterialsDescription文件中,其中包括模型信息、纹理信息、声音信息以及相应得Shader代码;(1) The model information, texture information, sound information and corresponding Shader code of the drawing object are uniformly encapsulated in the description interface MaterialsDescription file of the drawing object before being transferred into the scene graph, including model information, texture information, and sound information And the corresponding Shader code;

(2)将上述的绘制对象信息通过场景图中设置的Material Loader和MediaLoader分别调入渲染对象中,其中Material Loader负责绘制对象的状态信息调入,Material Loader在将状态信息调入之前,要按照Shader信息排序进行静态优化,并调入渲染对象的状态集中;Media Loader负责读取顶点、纹理、音频以及Shader代码绘制对象本身的几何信息,同时建立全局交叉数组并辅以索引数组,存入渲染对象的数据集中;(2) The above-mentioned drawing object information is transferred into the rendering object through the Material Loader and MediaLoader set in the scene graph, among which the Material Loader is responsible for transferring the state information of the drawing object. Before the Material Loader transfers the state information, it must follow the Shader information sorting is statically optimized and transferred to the state set of the rendering object; Media Loader is responsible for reading the geometric information of the vertices, textures, audio, and Shader code drawing objects themselves, and at the same time establishes a global intersection array supplemented by an index array, which is stored in the rendering object's dataset;

(3)将渲染对象分为状态集和数据集,状态集包括顶点描述VertexDescription和像素描述Pixel Description,在渲染过程中,状态集对绘制对象的状态信息按照Shader信息继续排序进行动态优化,数据集对全局交叉数组和索引数组的更新进行保存;(3) Divide the rendering object into a state set and a data set. The state set includes the vertex description VertexDescription and the pixel description Pixel Description. During the rendering process, the state set dynamically optimizes the state information of the drawing object according to the shader information. The data set Save the update of the global intersection array and index array;

(4)将在渲染对象中渲染后的绘制对象送入绘制引擎进行绘制,绘制引擎由绘制控制和状态控制构成,绘制控制将获得的对象顶点、纹理、音频以及Shader代码的绘制对象本身数据信息分发给OpenGL或硬件代码HLSL/CG/GLSL进行绘制,而绘制对象的状态描述信息则交由状态控制进行绘制状态的改变,绘制控制和状态控制两者配合完成一个绘制对象的绘制过程。(4) Send the drawing object rendered in the rendering object to the drawing engine for drawing. The drawing engine is composed of drawing control and state control. The drawing control will obtain the object vertices, texture, audio and the data information of the drawing object itself in the Shader code Distributed to OpenGL or hardware code HLSL/CG/GLSL for drawing, and the state description information of the drawing object is handed over to the state control to change the drawing state. Both the drawing control and the state control cooperate to complete the drawing process of a drawing object.

本发明与现有技术相比的有益效果为:The beneficial effects of the present invention compared with prior art are:

(1)传统的图形系统将绘制对象的模型(几何)、纹理、声音等信息分别进行读取,除人为对应之外,它们之间没有联系。对于一个复杂的绘制对象,如一架飞机,如果能将其几何、纹理、声音甚至绘制状态集合到一起,不仅可以提高完整性以及可扩展性(当一组信息有了明确的内涵,就不难扩展其外延),同时在复杂系统(同时承载上百个绘制对象)中能够更好的加以独立控制(这里的独立控制是指如个例的更改上述信息等操作)。因此,本发明提出绘制对象描述接口,它可以通过xml文件进行定义,接口对模型的几何信息(对应模型文件)、纹理信息(对应纹理贴图文件)、声音信息(对应音频文件)、硬件绘制信息(Shader文件或代码内容)以及绘制所需状态信息(如是否需要使用光照、绘制模式等)进行统一封装和描述,进而可以对文件进行扩充,如增加视频信息,控制信息等。(1) The traditional graphics system reads the model (geometry), texture, sound and other information of the drawn object separately, and there is no connection between them except for artificial correspondence. For a complex drawing object, such as an airplane, if its geometry, texture, sound and even drawing state can be assembled together, it can not only improve the integrity and scalability (when a set of information has a clear connotation, it is not difficult to Extend its extension), and at the same time, it can be better independently controlled in a complex system (carrying hundreds of drawing objects at the same time) (independent control here refers to operations such as changing the above information in individual cases). Therefore, the present invention proposes a drawing object description interface, which can be defined by an xml file, and the interface is to model geometric information (corresponding to model files), texture information (corresponding to texture map files), sound information (corresponding to audio files), hardware drawing information (Shader file or code content) and state information required for drawing (such as whether to use lighting, drawing mode, etc.) are encapsulated and described in a unified way, and then the file can be expanded, such as adding video information, control information, etc.

(2)提供对绘制对象的静-动态结合的状态优化过程,使场景进一步优化,提高了渲染效率,满足了复杂场景的实时显示。(2) Provide a static-dynamic state optimization process for drawing objects, further optimize the scene, improve rendering efficiency, and meet the real-time display of complex scenes.

(3)支持Shader的状态集。将Shader对象融入绘制引擎,并根据状态集的排序特点提供对Shader的排序和可扩展的继承式调用。(3) Support Shader's state set. Integrate the Shader object into the drawing engine, and provide Shader sorting and extensible inheritance calls according to the sorting characteristics of the state set.

(4)将现有技术中的绘制引擎只为绘制控制的结构分为绘制控制和状态控制,即使绘制对象的状态集合被状态管理进行监控和管理,这样做更好的加速绘制过程和状态优化,同时也使绘制效率大大提高。(4) Divide the structure of the drawing engine in the prior art only for drawing control into drawing control and state control, even if the state set of the drawing object is monitored and managed by the state management, this can better accelerate the drawing process and state optimization , but also greatly improve the drawing efficiency.

附图说明 Description of drawings

图1为图形绘制引擎中通常的Shader调用示意图;Figure 1 is a schematic diagram of a common Shader call in a graphics rendering engine;

图2为本发明图形绘制引擎中渲染对象及相关控制数据结构示意图;Fig. 2 is a schematic diagram of rendering objects and related control data structures in the graphics rendering engine of the present invention;

图3为本发明的Materials Description的描述示意图;Fig. 3 is the description sketch map of Materials Description of the present invention;

图4为本发明的Media Loader的结构示意图;Fig. 4 is the structural representation of Media Loader of the present invention;

图5本发明的Material Loader结构示意图;Fig. 5 Material Loader structure schematic diagram of the present invention;

图6为本发明基于Shader信息排序的动态优化过程示意图;Fig. 6 is a schematic diagram of the dynamic optimization process based on Shader information sorting in the present invention;

图7为本发明的场景图中动态优化示例图;Fig. 7 is an example diagram of dynamic optimization in a scene diagram of the present invention;

图8为本发明的Render Engine中状态控制管理示意图;Fig. 8 is a schematic diagram of state control management in the Render Engine of the present invention;

图9为本发明实现图2绘制框架的类图。FIG. 9 is a class diagram for realizing the drawing framework of FIG. 2 in the present invention.

具体实施方式 Detailed ways

如图2所示,本发明的绘制结构分为以下几个部分,它由绘制对象描述接口文件Materials Description、场景图SceneGraph、渲染对象、绘制引擎RenderEngine组成,其中Materials Description通过xml文件进行定义,对绘制对象的模型信息,包括几何信息(对应模型文件)、纹理信息(对应纹理贴图文件)、声音信息(对应音频文件)、硬件绘制信息(Shader文件或代码内容)以及绘制所需状态信息(如是否需要使用光照、绘制模式等)进行统一封装和描述;场景图为描述虚拟场景的树状数据结构,其数据结构由组节点和叶节点组成,将其在内存中的存贮结构分为材质载入器Material Loader和介质载入器MediaLoader两部分,Material Loader负责读取对象整体描述及绘制状态信息,同时对该状态信息以Shader信息排序进行静态优化,并调入渲染对象的状态集中,Media Loader负责读取顶点、纹理、音频以及Shader代码绘制对象本身的几何信息,同时建立全局交叉数组并辅以索引数组,并调入渲染对象的数据集中,Material Loader和Media Loader形成的绘制对象位于场景图的叶节点;渲染对象,分为状态集和数据集,状态集为Material Loader的读取结果,MediaLoader为数据集的读取结果,状态集包括顶点描述Vertex Description和像素描述Pixel Description,在渲染过程中,状态集对绘制对象的状态信息按照Shader信息继续排序进行动态优化,数据集对全局交叉数组和索引数组的更新进行保存;绘制引擎Render Engine由绘制控制和状态控制构成,绘制控制是对渲染对象进行绘制过程中的控制,它根据渲染对象的数据集中的几何信息分发给OpenGL或硬件代码进行绘制,解决进行状态优化后的几何信息,如顶点数据、法向量数据、颜色数据、纹理数据等在何时(不同对象的前后顺序)以何种方式(三角形列表、条带等)送入显示卡进行绘制;状态控制,是对渲染对象进行绘制过程中有关绘制状态的控制,主要解决的是将渲染对象的相关绘制状态(如光照、材质、各种缓冲区等)送入显示卡进行设置,绘制控制和状态控制两者配合完成一个绘制对象的绘制过程。As shown in Figure 2, the drawing structure of the present invention is divided into the following several parts, and it is made up of drawing object description interface file Materials Description, scene graph SceneGraph, rendering object, drawing engine RenderEngine, wherein Materials Description is defined by xml file, to The model information of the drawing object, including geometric information (corresponding to the model file), texture information (corresponding to the texture map file), sound information (corresponding to the audio file), hardware drawing information (Shader file or code content), and drawing required state information (such as Whether it is necessary to use lighting, drawing mode, etc.) for unified packaging and description; the scene graph is a tree-like data structure describing the virtual scene, and its data structure is composed of group nodes and leaf nodes, and its storage structure in memory is divided into material There are two parts: Material Loader and MediaLoader. Material Loader is responsible for reading the overall description of the object and drawing state information. At the same time, the state information is statically optimized by sorting Shader information and transferred to the state set of the rendering object. Media Loader is responsible for reading vertices, textures, audio, and the geometric information of the Shader code drawing object itself. At the same time, it creates a global intersection array supplemented by an index array, and transfers it into the data set of the rendering object. The drawing object formed by Material Loader and Media Loader is located in the scene. The leaf node of the graph; the rendering object is divided into a state set and a data set. The state set is the reading result of the Material Loader, and the MediaLoader is the reading result of the data set. The state set includes the vertex description Vertex Description and the pixel description Pixel Description. During the process, the state set dynamically optimizes the state information of the drawing object according to the Shader information, and the data set saves the update of the global intersection array and index array; the rendering engine Render Engine is composed of rendering control and state control, and the rendering control is for The rendering object controls the drawing process. It distributes the geometric information in the data set of the rendering object to OpenGL or hardware code for drawing, and solves the geometric information after state optimization, such as vertex data, normal vector data, color data, and texture data. When (the order of different objects) and in what way (triangle list, strip, etc.) are sent to the display card for drawing; state control is the control of the drawing state during the drawing process of the rendering object, and the main problem is to solve It is to send the relevant drawing state of the rendering object (such as lighting, material, various buffers, etc.) to the display card for setting, and the drawing control and state control cooperate to complete the drawing process of a drawing object.

如图3所示,本发明的Materials Description描述了绘制对象及其几何、绘制状态信息,并以XML文件的形式进行记录。XML文件形式如下:As shown in Figure 3, the Materials Description of the present invention describes the drawing object and its geometry, drawing state information, and records in the form of an XML file. The XML file format is as follows:

其中,MaterialName记录该绘制对象的名称,以便系统记录并辨认;MaterialRenderState记录绘制所需的绘制状态,提供给状态管理模块使用;MaterialFiles记录了绘制对象的集合信息的文件,包含ModelFile以及TextureFile文件,在多纹理的状态下,TextureFile可以重复出现。Among them, MaterialName records the name of the drawing object so that the system can record and identify it; MaterialRenderState records the drawing state required for drawing and provides it to the state management module; MaterialFiles records the collection information of the drawing object, including ModelFile and TextureFile files, in In the multi-texture state, TextureFile can appear repeatedly.

如图4所示,本发明的Media Loader充分采用了Plug-in的机制,可以随着资源文件类型的扩充不断丰富绘制对象的内容,其工作过程是:获取来自于Materials Description的绘制资源信息,如顶点、纹理和声音等,这些资源实现需要保存在硬盘中,随后Media Loader将根据资源文件名后缀激活Plug-in对象并由该对象完成资源读取,读取后的资源将被保存在绘制对象的数据集合中。As shown in Fig. 4, the Media Loader of the present invention has fully adopted the mechanism of Plug-in, can constantly enrich the content of drawing object along with the expansion of resource file type, its working process is: obtain the drawing resource information from Materials Description, Such as vertices, textures and sounds, etc., these resource implementations need to be saved in the hard disk, and then Media Loader will activate the Plug-in object according to the suffix of the resource file name and complete the resource reading by the object, and the read resource will be saved in the drawing object's data collection.

如图5所示,本发明的Material Loader结构类似于Media Loader,MaterialLoader的信息来源于Materials Description,它记录了绘制对象绘制过程中所需的绘制状态,如光照等,这些信息被Material Loader获取后直接保存到绘制对象的状态集合中并参与后面的状态排序。As shown in Figure 5, the Material Loader structure of the present invention is similar to Media Loader, and the information of Material Loader comes from Materials Description, which records the drawing state required in the drawing process of the drawing object, such as lighting, etc. After the information is obtained by Material Loader It is directly saved to the state collection of the drawing object and participates in the subsequent state sorting.

为了加快绘制过程,本发明采用OpenGL中的交叉数组建立全局交叉数组,并且假设所有绘制对象均包含以上四种坐标(假若缺少则自动补零),将所有绘制对象的几何信息在读入时存入全局的交叉数组可以加速绘制,并辅以索引数组在交叉数组中进行索引。In order to speed up the drawing process, the present invention adopts the intersecting array in OpenGL to set up the global intersecting array, and assumes that all drawing objects include the above four coordinates (if missing, then automatically fills in zeros), the geometric information of all drawing objects is stored when read in Entering the global intersection array can speed up drawing, and it is supplemented by an index array to index in the intersection array.

不难想象,一个复杂的场景包含复杂的对象,对应的绘制状态关系复杂,而绘制过程中绘制状态的复杂严重影响硬件的绘制效率。例如,场景中包含1000架相同的飞机,每架飞机拥有两个绘制状态(如机身是一种纹理状态,而驾驶舱的玻璃是另一种透明的纹理)。理想的绘制顺序是先渲染所有机身,进而渲染所有透明的玻璃。但事与愿违,由于系统是相继的载入飞机,最初形成的渲染序列使得绘制过程为机身、玻璃、机身、玻璃......因此,状态不停切换导致绘制效率极低。所以,本发明提出了对状态信息进行优化的方案,但状态优化过程同样耗费系统时间和空间,一味追求绝对的优化对于整个渲染过程并非有利,因此必须在排序优化时间复杂度和绘制时间复杂度之间平衡,因此,本发明提出的状态优化方法在读入绘制对象时进行静态排序,进而在动态绘制过程中再次基础上进行局部的动态优化排序。It is not difficult to imagine that a complex scene contains complex objects, and the corresponding drawing state relationship is complex, and the complexity of the drawing state during the drawing process seriously affects the drawing efficiency of the hardware. For example, the scene contains 1000 identical planes, and each plane has two draw states (such as the fuselage is a texture state, and the glass of the cockpit is another transparent texture). The ideal drawing order is to render all the fuselage first, and then render all transparent glass. But contrary to expectations, since the system is loaded into the aircraft one after another, the initial rendering sequence makes the drawing process as fuselage, glass, fuselage, glass... Therefore, the rendering efficiency is extremely low due to the continuous switching of states. Therefore, the present invention proposes a solution to optimize the state information, but the state optimization process also consumes system time and space, and blindly pursuing absolute optimization is not beneficial to the entire rendering process, so it is necessary to optimize the time complexity of sorting and rendering. Therefore, the state optimization method proposed by the present invention performs static sorting when reading in the drawing objects, and then performs local dynamic optimization sorting again on the basis of the dynamic drawing process.

Material Loader进行Shader信息排序的静态优化过程为如图6所示:The static optimization process of Shader information sorting by Material Loader is shown in Figure 6:

(1)初始化全局交叉数组,数组结构采用标准库Array模版,每单元内容为OpenGL的枚举型T2_C4_N3_V3结构;(1) Initialize the global intersection array, the array structure adopts the standard library Array template, and the content of each unit is the enumerated T2_C4_N3_V3 structure of OpenGL;

(2)初始化全局索引数组,数组结构采用标准库Array模版,每单元内容为长整形结构;(2) Initialize the global index array, the array structure adopts the standard library Array template, and the content of each unit is a long integer structure;

(3)当有新的绘制对象加入场景图后,分别完成如下操作:(3) When a new drawing object is added to the scene graph, complete the following operations:

a.获得绘制对象的纹理、颜色、法向量、位置数组指针;a. Obtain the texture, color, normal vector, and position array pointer of the drawn object;

b.由于绘制数组顶点可能存在重复,为了节省空间,进行索引生成,保证每一个顶点在交叉数组中只出现一次,用索引描述具体引用顺序,如顶点序列:a,a,b,a,c,d,c,e,索引后的顶点序列为a,b,c,d,e,而索引序列为0,0,1,0,2,3,2,4。b. Since there may be repetitions in drawing array vertices, in order to save space, index generation is performed to ensure that each vertex appears only once in the intersecting array, and the index is used to describe the specific reference order, such as the vertex sequence: a, a, b, a, c , d, c, e, the vertex sequence after the index is a, b, c, d, e, and the index sequence is 0, 0, 1, 0, 2, 3, 2, 4.

c.获得绘制对象的绘制状态指针,并根据指针获得纹理以及Shader信息;c. Obtain the drawing state pointer of the drawing object, and obtain the texture and Shader information according to the pointer;

d.在全局交叉数组中搜索与该绘制对象具有相同Shader的数组部分,若发现则继续搜索与该绘制对象具有相同纹理状态的数组部分,如发现则将该顶点序列和索引序列分别存储在全局交叉数组和索引数组中,若没有对应纹理的数组,则将该顶点序列和索引序列存储在该Shader对应的最后一个数组序列之后;若没有与相同的Shader,则将该顶点序列和索引序列存储在全局的交叉数组和索引数组之后;d. Search the global intersection array for the array part that has the same Shader as the drawing object, if found, continue to search for the array part that has the same texture state as the drawing object, if found, store the vertex sequence and index sequence in the global respectively In the intersection array and index array, if there is no array corresponding to the texture, the vertex sequence and index sequence will be stored after the last array sequence corresponding to the Shader; if there is no Shader with the same shader, the vertex sequence and index sequence will be stored after the global intersection and index arrays;

(4)在绘制对象中记录其索引在全局索引中的起始点和长度,完成静态优化。(4) Record the starting point and length of its index in the global index in the drawing object, and complete the static optimization.

如图1所示,本发明的渲染对象中的状态集的结构采用面对对象的方式实现,其中主要成员时状态数组,记录OpenGL绘制所需的状态,同时数组的存在也保证系统可以对状态进行优化;数据集保存了绘制所需的顶点数组、纹理数组等。As shown in Figure 1, the structure of the state set in the rendering object of the present invention is implemented in an object-oriented manner, wherein the main member is a state array, which records the state required for OpenGL drawing, and the existence of the array also ensures that the system can control the state. Optimized; the dataset saves the vertex arrays, texture arrays, etc. required for drawing.

如图6所示,本发明的渲染对象中状态集的基于Shader信息排序动态优化过程为:As shown in Figure 6, the dynamic optimization process based on Shader information sorting of the state set in the rendering object of the present invention is:

(1)初始化绘制数组以便放置绘制对象序列;(1) Initialize the drawing array to place the drawing object sequence;

(2)依次获得每一针的所需的绘制对象;(2) Obtain the required drawing objects of each stitch in turn;

(3)遍历绘制数组搜索相应Shader以及纹理信息的绘制状态:(3) Traverse the drawing array to search for the drawing state of the corresponding Shader and texture information:

a.若为搜索到相似的Shader,则将该对象放入绘制数组的末端;a. If a similar Shader is found, put the object at the end of the drawing array;

b.若发现相似的Shader而没有相似的纹理,则将该对象放入该Shader对应的数组的相对末端;b. If a similar Shader is found without a similar texture, put the object at the opposite end of the array corresponding to the Shader;

(4)当发现Shader和纹理均相似时开始进行动态排序:(4) When Shader and texture are found to be similar, start dynamic sorting:

a.按照耗时优先级比较最耗时的状态的是否有与该对象相同的,如不相同则插入相同对象的之后;a. According to the time-consuming priority, compare whether the most time-consuming state is the same as the object, and if not, insert the same object after it;

b.若相同则在相同的对象组中继续比较下一个耗时状态,如此往复,直到所有状态比较结束;b. If they are the same, continue to compare the next time-consuming state in the same object group, and so on, until the end of all state comparisons;

c.当最后一个状态比较仍像同,则视为两个绘制对象完全相同,进而顺序排列即可;c. When the last state comparison is still similar, it is considered that the two drawing objects are exactly the same, and then they can be arranged in order;

(5)处理下一个绘制对象,直到所有带绘制对象处理比较完毕;(5) process the next drawing object until all the objects with drawing are processed and compared;

(6)将绘制数组送入绘制引擎进行绘制。(6) Send the drawing array to the drawing engine for drawing.

作为绘制对象主体,顶点的几何、颜色、向量和纹理等坐标信息被保存为数组。为了加快绘制过程,本发明采用OpenGL中的交叉数组对其进行描述,并且假设所有绘制对象均包含以上四种坐标(假若缺少则自动补零)。将所有绘制对象的几何信息在读入时存入全局的交叉数组可以加速绘制,并辅以索引数组在交叉数组中进行索引。As the body of the drawing object, the coordinate information such as geometry, color, vector and texture of the vertex is saved as an array. In order to speed up the drawing process, the present invention adopts the intersecting array in OpenGL to describe it, and assumes that all drawing objects contain the above four coordinates (if they are missing, they will be automatically filled with zeros). Storing the geometric information of all drawing objects into the global intersecting array can speed up the drawing, and the index array is used to index in the intersecting array.

如图8所示,一个绘制对象描述的是虚拟场景中的一个实际物体,而要描述多个实际的物体就需要场景图维护多个绘制对象。根据场景图的树形结构,各个绘制对象之间绘制状态集合元素可以进行聚合-将相似的状态向组节点进行合并,并记录在组节点的状态集中,这样做的好处是在绘制时尽量少的改变状态。图8中a图表示的是当组节点某状态属性(开、关、必开或必关)为开时,那么其子节点的变化形如b图,由于绘制对象A没有设置该状态,那么A继承G的设置,由于B与G状态相同,那么B不变,而C明确指出状态为关,则C状态不继承G。c图表示的是当组节点的属性Attrib为必开AON时,那么如d图所示,A,B同b图,而c图则继承G的属性,变为开。As shown in Figure 8, one drawing object describes an actual object in the virtual scene, but to describe multiple actual objects requires the scene graph to maintain multiple drawing objects. According to the tree structure of the scene graph, the drawing state collection elements between the various drawing objects can be aggregated - the similar states are merged to the group node and recorded in the state set of the group node. change status. Figure a in Figure 8 shows that when a certain state attribute (on, off, must-open or must-close) of a group node is on, then the change of its child nodes is as shown in figure b, since the drawing object A does not set this state, then A inherits the settings of G. Since B and G are in the same state, then B remains unchanged, and C clearly indicates that the state is off, so the state of C does not inherit G. Figure c shows that when the attribute Attrib of the group node is AON, then as shown in Figure d, A and B are the same as Figure b, while Figure c inherits the attribute of G and becomes ON.

如图7所示,本发明的状态控制过程示意图,状态优化过程后,绘制对象之间的状态切换已得到精简,将这些绘制对象形成数组绘制。状态控制室对数组中绘制对象的绘制状态变量进行控制的模块,状态变量名是OpenGL状态机的内容,这些变量的设置有StateHandler进行调用,调用语句就是OpenGL API的内容。As shown in FIG. 7 , a schematic diagram of the state control process of the present invention, after the state optimization process, the state switching between drawing objects has been simplified, and these drawing objects are formed into an array for drawing. The state control room is a module that controls the drawing state variables of the drawing objects in the array. The name of the state variables is the content of the OpenGL state machine. The settings of these variables are called by StateHandler, and the calling statement is the content of the OpenGL API.

绘制物体是所必需指明的,如裁减面状态、Alpha测试状态、多边形模式状态、光源状态等。这些状态与图2中绘制对象的状态变量相对应,它们形成状态集合State Set,这些信息由Material Loader从文件描述中获得,提供给绘制引擎中的State Handler进行优化控制后送入硬件HW。Drawing objects must be specified, such as clipping surface state, Alpha test state, polygon mode state, light source state, etc. These states correspond to the state variables of the drawing object in Figure 2, and they form a state set State Set, which is obtained by the Material Loader from the file description, provided to the State Handler in the drawing engine for optimization control, and then sent to the hardware HW.

此外,对本发明的绘制控制过程:依次获得绘制对象,首先设置绘制状态,然后将顶点、颜色、纹理数组通过OpenGL API送入硬件完成绘制。In addition, for the drawing control process of the present invention: obtain the drawing objects in turn, first set the drawing state, and then send the vertex, color, and texture arrays to the hardware through the OpenGL API to complete the drawing.

如图9所示,为在具体的实现中实现了图2的框架,支持Shader的绘制框架在保存了原有渲染模块的基础上实现了对其的继承和扩充。MaterialSet代表材质信息,是一个广泛的含义,其内涵是一种硬件渲染的方式,包括绘制状态集合、硬件Shader代码集合以及渲染必要的参数集合(如光源参数、纹理参数等),如凹凸贴图就可以被定义为一种MaterialSet,其包含顶点信息,凹凸纹理。lMaterial接口将场景图对MaterialSet的封装进行公开,以导入相关材质编辑器ATI的材质结果;渲染过程Render Pass是Vertex和Pixel程序对象的容器。同时,Material还提供了对于Shader参数ShaderParameters的支持。As shown in Figure 9, in order to implement the framework in Figure 2 in a specific implementation, the rendering framework that supports Shader realizes the inheritance and expansion of the original rendering module on the basis of saving it. MaterialSet represents material information, which is a broad meaning. Its connotation is a hardware rendering method, including a collection of drawing states, a collection of hardware Shader codes, and a collection of necessary parameters for rendering (such as light source parameters, texture parameters, etc.), such as bump maps. Can be defined as a MaterialSet, which contains vertex information, bump texture. The lMaterial interface exposes the encapsulation of the scene graph to the MaterialSet to import the material results of the relevant material editor ATI; the rendering process Render Pass is the container of the Vertex and Pixel program objects. At the same time, Material also provides support for Shader parameters ShaderParameters.

Claims (6)

1. Shader 3 D image drawing system based on state set, by rendered object interface document Materials Description, scene graph SceneGraph, rendering objects are described, drawing engine RenderEngine forms, it is characterized in that:
Described rendered object is described interface document Materials Description and is defined by the xml file, to model information, texture information, acoustic information, tinter Shader file or the code content of rendered object and draw required status information and unify encapsulation and describe;
The internal memory storage structure of described scene graph SceneGraph is divided into material loader MaterialLoader and medium loader Media Loader two parts, material loader Material Loader is responsible for reading rendered object and describes the whole description of object among the interface document Materials Description and draw status information, carry out static optimization to drawing status information with tinter Shader information sorting simultaneously, and call in the state set of rendering objects, medium loader Media Loader is responsible for reading rendered object and describes summit among the interface document Materials Description, texture, the geological information of audio frequency and tinter Shader code rendered object itself, set up overall situation intersection array simultaneously and be aided with array of indexes, and call in the data centralization of rendering objects;
Described rendering objects, be divided into state set and data set, state set comprises that VertexDescription is described on the summit and pixel is described Pixel Description description, in render process, state set carries out dynamic optimization to drawing status information according to tinter Shader information continuation ordering, and data set is to the preservation of upgrading of overall situation intersection array and array of indexes;
Described drawing engine Render Engine constitutes by drawing control and State Control, draws to control rendering objects is carried out control in the drawing process, and it is distributed to OpenGL according to the data centralization geological information of rendering objects or hardware identification code is drawn; State Control is carried out the control of relevant drafting state in the drawing process to rendering objects, draws the drawing process that a rendered object is finished in control and State Control cooperation.
2. the Shader 3 D image drawing system based on state set according to claim 1, it is characterized in that: described drafting status information is carried out static optimization with tinter Shader information sorting, and the process of its static optimization is:
(1) initialization overall situation intersection array, structure of arrays adopts java standard library Array masterplate, and every location contents is the enumeration type T2_C4_N3_V3 structure of OpenGL;
(2) initialization global index array, structure of arrays adopt java standard library Array masterplate, and every location contents is long reshaping structure;
(3) after new rendered object adds scene graph, finish following operation respectively:
A. obtain texture, color, normal vector, the position array pointer of rendered object;
B. carry out index and generate, guarantee that each summit only occurs once in the intersection array;
C. obtain the drafting case pointer of rendered object, and obtain texture and tinter Shader information according to pointer;
D. search has the array part of same colored device Shader with this rendered object in the overall situation is intersected array, if find that then continuing search has the array part of identical texture phase with this rendered object, then this vertex sequence and index sequence are stored in respectively in overall situation intersection array and the array of indexes as finding, if there is not the array of corresponding texture, then this vertex sequence and index sequence are stored in after last array sequence of this tinter Shader correspondence; If not and identical tinter Shader, then this vertex sequence and index sequence are stored in after the intersection array and array of indexes of the overall situation;
(4) starting point and the length of its index of record in global index in rendered object is finished static optimization.
3. the Shader 3 D image drawing system based on state set according to claim 1 is characterized in that: described drafting status information is carried out the dynamic optimization process with tinter Shader information sorting and is:
(1) initialization is drawn array so that prevent the rendered object sequence;
(2) obtain the required rendered object of each pin successively;
(3) traversal is drawn the drafting state that array is searched for corresponding tinter Shader and texture information
If a. search similar tinter Shader, then this object is put into the end of drawing array;
B. do not have similar texture if find similar tinter Shader, then this object is put into the end relatively of the array of this tinter Shader correspondence;
(4) when finding tinter Shader and texture all similar, begin to carry out dynamic order:
A. identical according to whether having of priority ratio consuming time state the most consuming time with this object, as inequality then insert same object after;
B. if the identical then more next state consuming time of continuation in identical group of objects and so forth, relatively finishes up to all states;
C. work as last state more still as same, it is identical then to be considered as two rendered objects, and then series arrangement gets final product;
(5) handle next rendered object, relatively finish up to all band rendered objects processing.
4. adopt the described Shader 3 D image drawing system of claim 1, it is characterized in that comprising the following steps: based on state set
(1) model information, texture information, acoustic information and the corresponding tinter Shader code with rendered object encapsulated and was described in the description interface Materials Description file of rendered object by unified before being called in scene graph;
(2) respectively call in rendering objects by material loader Material Loader in the data store organisation of scene graph and medium loader Media Loader above-mentioned rendered object information, wherein the material loader Material Loader status information of being responsible for rendered object is called in, material loader MaterialLoader is before calling in status information, to carry out static optimization according to tinter Shader information sorting, and call in the state set of rendering objects; Medium loader Media Loader is responsible for reading the geological information of summit, texture, audio frequency and tinter Shader code rendered object itself, sets up overall situation intersection array simultaneously and is aided with array of indexes, and call in the data centralization of rendering objects;
(3) rendering objects is divided into state set and data set, state set comprises that VertexDescription is described on the summit and pixel is described Pixel Description, in render process, state set carries out dynamic optimization to the status information of rendered object according to tinter Shader information continuation ordering, and data set is preserved the renewal of overall situation intersection array and array of indexes;
(4) rendered object after will playing up in rendering objects is sent into drawing engine Render Engine and is drawn, drawing engine Render Engine constitutes by drawing control and State Control, the own data message of rendered object of object summit, texture, audio frequency and tinter Shader code that drafting control will obtain is distributed to OpenGL or hardware identification code is drawn, the context information of rendered object is then transferred to the change that State Control is drawn state, draws the drawing process that a rendered object is finished in control and State Control cooperation.
5. the Shader 3 D image drawing system based on state set according to claim 4, it is characterized in that: described drafting status information is carried out static optimization with tinter Shader information sorting, and the process of its static optimization is:
(1) initialization overall situation intersection array, structure of arrays adopts java standard library Array masterplate, and every location contents is the enumeration type T2_C4_N3_V3 structure of OpenGL;
(2) initialization global index array, structure of arrays adopt java standard library Array masterplate, and every location contents is long reshaping structure;
(3) after new rendered object adds scene graph, finish following operation respectively:
A. obtain texture, color, normal vector, the position array pointer of rendered object;
B. carry out index and generate, guarantee that each summit only occurs once in the intersection array;
C. obtain the drafting case pointer of rendered object, and obtain texture and tinter Shader information according to pointer;
D. search has the array part of same colored device Shader with this rendered object in the overall situation is intersected array, if find that then continuing search has the array part of identical texture phase with this rendered object, then this vertex sequence and index sequence are stored in respectively in overall situation intersection array and the array of indexes as finding, if there is not the array of corresponding texture, then this vertex sequence and index sequence are stored in after last array sequence of this Shader correspondence; If not and identical tinter Shader, then this vertex sequence and index sequence are stored in after the intersection array and array of indexes of the overall situation;
(4) starting point and the length of its index of record in global index in rendered object is finished static optimization.
6. the Shader 3 D image drawing system based on state set according to claim 1 is characterized in that: described drafting status information is carried out the dynamic optimization process with tinter Shader information sorting and is:
(1) initialization is drawn array so that prevent the rendered object sequence;
(2) obtain the required rendered object of each pin successively;
(3) traversal is drawn the drafting state that array is searched for corresponding tinter Shader and texture information;
If a. search similar tinter Shader, then this object is put into the end of drawing array;
B. do not have similar texture if find similar tinter Shader, then this object is put into the end relatively of the array of this tinter Shader correspondence;
(4) when finding tinter Shader and texture all similar, begin to carry out dynamic order:
A. identical according to whether having of priority ratio consuming time state the most consuming time with this object, as inequality then insert same object after;
B. if the identical then more next state consuming time of continuation in identical group of objects and so forth, relatively finishes up to all states;
C. work as last state more still as same, it is identical then to be considered as two rendered objects, and then series arrangement gets final product;
(5) handle next rendered object, relatively finish up to all band rendered objects processing.
CNB2005101262163A 2005-11-28 2005-11-28 A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets Expired - Fee Related CN100388318C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005101262163A CN100388318C (en) 2005-11-28 2005-11-28 A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005101262163A CN100388318C (en) 2005-11-28 2005-11-28 A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets

Publications (2)

Publication Number Publication Date
CN1851753A CN1851753A (en) 2006-10-25
CN100388318C true CN100388318C (en) 2008-05-14

Family

ID=37133232

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005101262163A Expired - Fee Related CN100388318C (en) 2005-11-28 2005-11-28 A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets

Country Status (1)

Country Link
CN (1) CN100388318C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853162A (en) * 2010-06-01 2010-10-06 电子科技大学 An Editable Web Page 3D Geometric Modeling Rendering Method

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100593789C (en) * 2007-07-11 2010-03-10 成都金山互动娱乐科技有限公司 Technology for providing network game anti external hanging image origin by 3D technology
CN101819684B (en) * 2010-04-12 2012-06-20 长春理工大学 Spatial acceleration structure for virtual three-dimensional scene of animated film and creation and update method thereof
US9773343B2 (en) 2010-12-24 2017-09-26 Institute Of Automation, Chinese Academy Of Sciences Method for real-time and realistic rendering of complex scenes on internet
CN102567000B (en) * 2010-12-31 2016-08-17 新奥特(北京)视频技术有限公司 A kind of method and apparatus of the stunt plug-in unit supporting dynamic parameter
CN102867284B (en) * 2011-07-07 2016-10-26 腾讯科技(深圳)有限公司 A kind of graph drawing engine device and its implementation
CN105701854B (en) * 2016-01-06 2018-07-03 网易(杭州)网络有限公司 A kind of 3D rendering intents, device and engine
CN106997610B (en) * 2016-01-26 2020-08-25 阿里巴巴集团控股有限公司 Image rendering method and device and electronic equipment
CN109359224B (en) * 2018-10-19 2020-06-19 珠海金山网络游戏科技有限公司 Material data processing method and device, electronic equipment and storage medium
CN110533755B (en) * 2019-08-30 2021-04-06 腾讯科技(深圳)有限公司 Scene rendering method and related device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1588452A (en) * 2004-08-05 2005-03-02 上海交通大学 Three dimension re-set-up method for two dimension image sequence
CN1691068A (en) * 2004-04-20 2005-11-02 三星电子株式会社 Apparatus and method for reconstructing three-dimensional graphics data

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1691068A (en) * 2004-04-20 2005-11-02 三星电子株式会社 Apparatus and method for reconstructing three-dimensional graphics data
CN1588452A (en) * 2004-08-05 2005-03-02 上海交通大学 Three dimension re-set-up method for two dimension image sequence

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Direct3D中的shader与HLSL. 李学锋.计算机与现代化 2005年第10期. 2005
Direct3D中的shader与HLSL. 李学锋.计算机与现代化 2005年第10期. 2005 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853162A (en) * 2010-06-01 2010-10-06 电子科技大学 An Editable Web Page 3D Geometric Modeling Rendering Method
CN101853162B (en) * 2010-06-01 2013-01-09 电子科技大学 Method for rendering editable webpage three-dimensional (Web3D) geometric modeling

Also Published As

Publication number Publication date
CN1851753A (en) 2006-10-25

Similar Documents

Publication Publication Date Title
US12141908B2 (en) Image rendering method and apparatus, computer device, and storage medium
KR100742419B1 (en) Systems and methods to run shader driven compilation to render assets
US12106424B2 (en) Dedicated ray memory for ray tracing in graphics systems
US7015909B1 (en) Efficient use of user-defined shaders to implement graphics operations
US9087410B2 (en) Rendering graphics data using visibility information
US8253730B1 (en) System and method for construction of data structures for ray tracing using bounding hierarchies
US11282260B2 (en) Bounded volume hierarchy (BVH) tree traversal using spatial division
EP2834792B1 (en) Patched shading in graphics processing
US7098921B2 (en) Method, system and computer program product for efficiently utilizing limited resources in a graphics device
EP1921583A2 (en) Graphics processing apparatus
EP1921584A2 (en) Graphics processing apparatus, graphics library module, and graphics processing method
CN105354872A (en) Rendering engine, implementation method and producing tools for 3D web game
CN105413176A (en) 3D engine system applied to games
Hu et al. Parallel view-dependent level-of-detail control
KR101670958B1 (en) Data processing method and apparatus in heterogeneous multi-core environment
CN100388318C (en) A Shader 3D Graphics Rendering System and Rendering Method Based on State Sets
GB2555929A (en) Task assembly
Pulli New APIs for mobile graphics
CN119075304A (en) Virtual scene rendering method, device, electronic device and storage medium
CN116226969B (en) A method for lightweight data in Unity program production
Christensen et al. RenderMan XPU: A Hybrid CPU+ GPU Renderer for Interactive and Final-frame Rendering
CN115904331A (en) JSON use design method in unity program production
CN116596738A (en) Method for converting Vulkan ray tracing pipeline into computing pipeline
HK40038691A (en) Image rendering method and apparatus, computer device and storage medium
CN118736090A (en) A graphics rendering method and system based on complex scenes

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20080514

Termination date: 20131128