Motivation
Gameplay3D引擎材质系统简描述,一个材质模板文件应该像这样的一个结构
MaterialTemplate
{
Technique0
{
Pass0{}
Pass1{}
}
Technique1
{
Pass0{}
Pass1{}
}
}
Material
- Material类的设计目的是对外接口类,提供Material资源,Technique资源,Pass资源,RenderState资源的加载.
- 多Technique是指一个材质中,应该包含不只一个实现方案。 这样当我们进行材质更替,或者进行高中低端机适配的时候。 就不会那么麻烦。 同时在数据管理上,也显得更为规范.
- Material类包含本材质包含的Technique实例组,以及当前使用的curTechnique实例.
- Technique实例组可以有共同的uniform参数.
- 用Technique实例组index或者Technique id获取相应的Technique.
- 一次drawscene/render,只有current Technique实例会起效.
Technique
- 有时候,我们为了实现一个绘制效果,靠单次绘制是无法实现的。比如描边效果。 这就要求我们单个物体能够在进行绘制的时候,多次提交材质并绘制。
- support different sets of shader + definitions that will be all loaded when a material is loaded.
- You can then change the rendering technique at runtime without having to first load the shaders.
- A technique has one or more passes for supporting multi pass rendering.
- 多少个pass,意味着该Technique材质最终绘制(gldraw)几次,以实现具体材质效果
- 高中低端机适配是一个很重要的特性,因为玩家的机型不可能是一样的。 在需要保证效率的情况下,我们很多时候需要降低物体渲染的复杂度。有两种方案。 一种是通过宏定义,一种是动态切换Technique。
Pass
- This class encapsulates the parameters and logic required to apply a shader to an object to be rendered.
- 继承于RenderState,即包含RenderState
- 持有Effect实例
- 持有VertexAttributeBinding实例
RenderState
- Defines the rendering state of the graphics device.
- Implementing a custom auto binding resolver
- Defines blend constants supported by the blend function.
- Defines the supported depth compare functions.
- Defines culling criteria for front-facing, back-facing and both-side facets.
- Defines the winding of vertices in faces that are considered front facing.
- Defines the supported stencil compare functions.
- Defines the supported stencil operations to perform.
Effect
- An effect essentially wraps an OpenGL program object.
- includes the vertex and fragment shader.
- the map of Uniform name and Uniform location within an effect.
- the map of Attribute location and Attribute Name within an effect.
VertexAttributeBinding
- Defines a binding between the vertex layout of a Mesh and the vertex input attributes of a vertex shader (Effect).