您的位置:首页 > 其它

Behind the 3D scenes - part2

2016-03-31 17:56 127 查看
渲染管道:从加载到渲染的整个过程。

模型是由多个节点构成,而节点石油节点node-parts构成,node-part包含了meshpart (形状)和 materialpart(颜色等信息),

ModelLoader modelLoader = new G3dModelLoader(new JsonReader());//UBJsonReader for g3db格式
ModelData modelData = modelLoader.loadModelData(Gdx.files.internal("data/invaderscene.g3dj"));// g3dj格式的文件
model = new Model(modelData, new TextureProvider.FileTextureProvider());


灵活修改材料的颜色属性:
private void doneLoading() {
Material blockMaterial = model.getNode("block1").parts.get(0).material;
ColorAttribute colorAttribute = (ColorAttribute)blockMaterial.get(ColorAttribute.Diffuse);
colorAttribute.color.set(Color.YELLOW);
for (int i = 0; i < model.nodes.size; i++) {
...
}
}

Material blockMaterial = model.getMaterial("block_default1");
blockMaterial.set(ColorAttribute.createDiffuse(Color.YELLOW));
for (int i = 0; i < model.nodes.size; i++) {
...
}

ModelBatch doesn't actually render them. Instead it sorts them so they are rendered in the most optimal order and then passes them
to the renderable's shader.Note that if no shader is provided (or the provided shader is not suitable), the ModelBatch will create
a Shader for us. It does that by asking a ShaderProvider for
the required shader. 
 For
OpenGL ES 2.0 it will encapsulate a ShaderProgram and set uniforms and attributes according to the specified Renderable.

真正负责渲染的是 Shader

To summarize:
ModelInstance contains a copy of the nodes and materials of a Model. But it only references the resources of the Model like the meshes and textures. A ModelInstance creates Renderable
instances for each NodePart it contains.
Renderable is the smallest renderable part, which is passed through the rendering pipeline.
ModelBatch gathers a Shader for each Renderable and sorts the renderables to make sure they are rendered in an optimal order.
Shader is responsible for actual rendering a Renderable. Most commonly an application uses multiple shaders, where each shader is dedicated to a single ShaderProgram (GLSL program). RenderContext is
used to keep track of the OpenGL context, like which texture is currently bound.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: