/// <summary> /// Renderiza la malla, si esta habilitada /// </summary> public void render() { if (!enabled) { return; } Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformaciones updateMeshTransform(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Activar AlphaBlending si corresponde activateAlphaBlend(); //Cargar matrices para el shader setShaderMatrix(); //Renderizar segun el tipo de render de la malla effect.Technique = this.technique; int numPasses = effect.Begin(0); switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas texturesManager.clear(0); texturesManager.clear(1); //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(0); effect.EndPass(); } break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Dibujar cada subset con su DiffuseMap correspondiente for (int i = 0; i < diffuseMaps.Length; i++) { //Setear textura en shader texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]); //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(i); effect.EndPass(); } } break; case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Cargar lightmap texturesManager.shaderSet(effect, "texLightMap", lightMap); //Dibujar cada subset con su Material y su DiffuseMap correspondiente for (int i = 0; i < diffuseMaps.Length; i++) { //Setear textura en shader texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]); //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(i); effect.EndPass(); } } break; } //Finalizar shader effect.End(); //Desactivar alphaBlend resetAlphaBlend(); }
/// <summary> /// Renderiza la malla, si esta habilitada /// </summary> public void render() { if (!enabled) { return; } Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformaciones updateMeshTransform(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Activar AlphaBlending si corresponde activateAlphaBlend(); //Renderizar segun el tipo de render de la malla switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas y materiales texturesManager.clear(0); texturesManager.clear(1); device.Material = TgcD3dDevice.DEFAULT_MATERIAL; //Dibujar mesh d3dMesh.DrawSubset(0); break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); d3dMesh.DrawSubset(i); } break; case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: //Cargar Lightmap texturesManager.set(1, lightMap); device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.Current); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); //Aplicar operacion para Lightmap device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); device.SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.Diffuse); d3dMesh.DrawSubset(i); } break; } //Desactivar alphaBlend resetAlphaBlend(); }