Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary> Initialize control and setup GL settings </summary>
        public void Initialize()
        {
            loaded = true;
            PlayAnimation = false;
            pickingController = new PickingController(camera);

            idleShader = new ShaderController("idle.vs", "idle.fs");
            idleShader.SetUniformLocation("u_UseTexture");
            idleShader.SetUniformLocation("u_Color");
            idleShader.SetUniformLocation("u_Texture");
            idleShader.SetUniformLocation("u_BrushMap");
            idleShader.SetUniformLocation("u_TransparentMap");
            idleShader.SetUniformLocation("u_World");
            idleShader.SetUniformLocation("u_WorldView");
            idleShader.SetUniformLocation("u_ViewProjection");
            idleShader.SetUniformLocation("u_LightDirection");

            blendShader = new ShaderController(ProgramCore.PluginMode ? "blendingPl.vs" : "blending.vs", "blending.fs");
            blendShader.SetUniformLocation("u_Texture");
            blendShader.SetUniformLocation("u_BlendStartDepth");
            blendShader.SetUniformLocation("u_BlendDepth");

            brushShader = new ShaderController("brush.vs", "brush.fs");
            brushShader.SetUniformLocation("u_Texture");
            brushShader.SetUniformLocation("u_World");
            brushShader.SetUniformLocation("u_BrushColor");
            brushShader.SetUniformLocation("u_SphereCenter");
            brushShader.SetUniformLocation("u_SphereRadius");

            SetupViewport(glControl);

            windowInfo = Utilities.CreateWindowsWindowInfo(renderPanel.Handle);
            graphicsContext = new GraphicsContext(GraphicsMode.Default, windowInfo);
            renderPanel.Resize += (sender, args) => graphicsContext.Update(windowInfo);
            glControl.Context.MakeCurrent(glControl.WindowInfo);

            InitializeProfileSprites();
            InitializeCustomBaseSprites();
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        public Bitmap RenderToTexture(int oldTextureId, int textureId, int textureWidth, int textureHeight, ShaderController shader,
            Func<ShaderController, int, int, bool> renderFunc, bool useAlpha = false)
        {
            graphicsContext.MakeCurrent(windowInfo);
            renderPanel.Size = new Size(textureWidth, textureHeight);
            GL.Viewport(0, 0, textureWidth, textureHeight);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Enable(EnableCap.Texture2D);
            GL.DepthMask(false);

            renderFunc(shader, oldTextureId, textureId);

            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();

            var result = GrabScreenshot(String.Empty, textureWidth, textureHeight, useAlpha);
            glControl.Context.MakeCurrent(glControl.WindowInfo);
            SetupViewport(glControl);
            return result;
        }