Exemplo n.º 1
0
        public void DrawUI(Mesh mesh)
        {
            OpenTK.Mathematics.Matrix4 modelMatrix = Rect.GetModelMatrix();
            Material.SetMatrix("model", modelMatrix);
            Material.SetColor("color", Color);

            GraphicsAPI.UseMeshMaterial(mesh, Material);

            GraphicsAPI.DrawTriangles(mesh.GetIndiceCount());
        }
Exemplo n.º 2
0
        public static RenderCommand DrawGeometry(CameraData camera, Matrix4 cameraTransform)
        {
            return(new RenderCommand("Draw Geometry", (ref RenderContext context) =>
            {
                if (!context.TryGetData(out GeometryRenderData geometryData))
                {
                    return;
                }

                if (!context.TryGetData(out LightsRenderData lightData))
                {
                    return;
                }

                //if (MainDevWindowGL.Window.KeyboardState.IsKeyDown(OpenTK.Windowing.GraphicsLibraryFramework.Keys.I))
                //    yaw += 0.1f;

                //if (MainDevWindowGL.Window.KeyboardState.IsKeyDown(OpenTK.Windowing.GraphicsLibraryFramework.Keys.O))
                //    yaw -= 0.1f;

                //if (MainDevWindowGL.Window.KeyboardState.IsKeyDown(OpenTK.Windowing.GraphicsLibraryFramework.Keys.K))
                //    pitch += 0.1f;

                //if (MainDevWindowGL.Window.KeyboardState.IsKeyDown(OpenTK.Windowing.GraphicsLibraryFramework.Keys.L))
                //    pitch -= 0.1f;

                Ogl.Viewport(0, 0, AppScreen.Resolution.x, AppScreen.Resolution.y);
                Ogl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                Light mainLight = lightData.lights[0];
                Matrix4 projection = camera.CalculateProjection();

                List <MeshRenderGroup> renderGroups = geometryData.GetRenderGroups();
                for (int i = 0; i < renderGroups.Count; i++)
                {
                    MeshRenderGroup renderGroup = renderGroups[i];

                    RenderMesh pair = renderGroup.MeshRender;
                    List <Matrix4> positions = renderGroup.Transforms;

                    pair.mat.SetDepthMap(new DepthTexture(mainLight.Framebuffer.DepthBuffer));
                    GraphicsAPI.UseMeshMaterial(pair.mesh, pair.mat);


                    //Update camera pos for material
                    //TODO: Use 'Uniform buffer objects' to globally share this data
                    pair.mat.SetMatrix("view", cameraTransform);
                    pair.mat.SetMatrix("projection", projection);

                    pair.mat.SetVector3("directionalLight", new Vector3(1, 1, 1));
                    pair.mat.SetVector3("ambientLight", new Vector3(0.5f, 0.5f, 0.5f));
                    pair.mat.SetVector3("directionalDir", LIGHT_FORWARD_NORMALIZED);
                    pair.mat.SetMatrix("lightSpace", LIGHT_VIEW * mainLight.GetProjection());

                    for (int p = 0; p < positions.Count; p++)
                    {
                        pair.mat.SetMatrix("model", positions[p]);

                        GraphicsAPI.DrawTriangles(pair.mesh.GetIndiceCount());
                    }

                    GraphicsAPI.FreeMeshMaterial(pair.mesh, pair.mat);
                }
            }));