public void Draw(ShaderController shader) { if (!IsVisible) return; var useTextures = Vector3.Zero; var useTexture = ProgramCore.MainForm.ctrlRenderControl.UseTexture; GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, Material.TransparentTexture); shader.UpdateUniform("u_TransparentMap", 1); useTextures.Y = Material.TransparentTexture; //shader.UpdateUniform("u_UseTransparent", (float)Material.TransparentTexture); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, Material.Texture); shader.UpdateUniform("u_Texture", 0); if (useTexture) // заказ старичка. что типа проги не отрабатывают текстуры (которые 3д печать) и надо со всего убрать { shader.UpdateUniform("u_Color", Material.DiffuseColor); useTextures.X = Material.Texture; } //shader.UpdateUniform("u_UseTexture", useTexture ? (float)Material.Texture : 0); shader.UpdateUniform("u_UseTexture", useTextures); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.ColorArray); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.VertexPointer(3, VertexPointerType.Float, Vertex.Stride, new IntPtr(0)); GL.NormalPointer(NormalPointerType.Float, Vertex.Stride, new IntPtr(Vector3.SizeInBytes)); GL.TexCoordPointer(2, TexCoordPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes)); GL.ColorPointer(4, ColorPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes + Vector2.SizeInBytes)); GL.DrawRangeElements(PrimitiveType.Triangles, 0, NumIndices, NumIndices, DrawElementsType.UnsignedInt, new IntPtr(0)); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.ColorArray); }
private bool DrawToTexture(ShaderController shader, int oldTextureId, int textureId) { //GL.BindTexture(TextureTarget.Texture2D, oldTextureId); DrawQuad(ProgramCore.Project.FaceColor.X, ProgramCore.Project.FaceColor.Y, ProgramCore.Project.FaceColor.Z, 1f); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); shader.Begin(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, HeadTextureId); shader.UpdateUniform("u_Texture", 0); shader.UpdateUniform("u_BlendStartDepth", -0.5f); shader.UpdateUniform("u_BlendDepth", 4f); headMeshesController.RenderMesh.DrawToTexture(headMeshesController.RenderMesh.Parts.Where(p => p.Texture == textureId)); shader.End(); GL.Disable(EnableCap.Blend); return true; }
public bool DrawToBrushTexture(ShaderController shader, int oldTextureId, int textureId) { GL.BindTexture(TextureTarget.Texture2D, oldTextureId); DrawQuad(1f, 1f, 1f, 1f); shader.Begin(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, oldTextureId); shader.UpdateUniform("u_Texture", 0); shader.UpdateUniform("u_World", Matrix4.Identity); shader.UpdateUniform("u_BrushColor", brushTool.Color); shader.UpdateUniform("u_SphereCenter", brushTool.SphereCenter); shader.UpdateUniform("u_SphereRadius", brushTool.Radius); headMeshesController.RenderMesh.DrawToTexture(headMeshesController.RenderMesh.Parts.Where(p => p.Texture == textureId)); shader.End(); return true; }
private void DrawMeshes(IEnumerable<BaseRenderMesh> meshes, ref ShaderController shader, bool transparent) { foreach (var mesh in meshes) { if (mesh.Material.IsTransparent != transparent) continue; var worldMatrix = mesh.Transform;//Если мы в режиме просмотра морфинга, то делаем это if (InStageMode) { var position = new Vector3(worldMatrix[3, 0], worldMatrix[3, 1], worldMatrix[3, 2]); worldMatrix[3, 0] = 0.0f; worldMatrix[3, 1] = 0.0f; worldMatrix[3, 2] = 0.0f; worldMatrix *= Matrix4.CreateScale(headMeshesController.RenderMesh.RealScale); worldMatrix[3, 0] = position.X * headMeshesController.RenderMesh.RealScale; worldMatrix[3, 1] = position.Y * headMeshesController.RenderMesh.RealScale; worldMatrix[3, 2] = position.Z * headMeshesController.RenderMesh.RealScale; } shader.UpdateUniform("u_World", worldMatrix); shader.UpdateUniform("u_WorldView", worldMatrix * camera.ViewMatrix); shader.UpdateUniform("u_ViewProjection", camera.ViewMatrix * camera.ProjectMatrix); mesh.Draw(shader); } }