Ejemplo n.º 1
0
        // float sum = 0f;
        void updateUniformBuffers()
        {
            // Vertex shader
            uboVS.projection = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(60.0f),
                ((float)mManager.Width / (float)mManager.Height),
                0.001f, 256.0f
                );
            // uboVS.projection = Matrix4.Identity;
            //uboVS.projection = Matrix4.CreateTranslation(1f,0f,0.5f);

            //var viewMatrix = Matrix4.CreateTranslation( 0f, 0f, mZoom);

            ////uboVS.model = viewMatrix * glm::translate(glm::mat4(), cameraPos);
            //var rotateX = Matrix4.RotateX(rotation.x);
            //var rotateY = Matrix4.RotateY(rotation.y);
            //var rotateZ = Matrix4.RotateZ(rotation.Z);
            ////uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
            ////uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
            ////uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
            //uboVS.model = rotateZ * rotateY * rotateX * viewMatrix;

            uboVS.lodBias = 0.5f;

            uboVS.model = Matrix4.Identity;

            uboVS.viewPos = new Vector3(0f, 0f, mZoom);
            //sum += 0.001f;

            //if (sum > 1f)
            //{
            //    sum = 0;
            //}

            var bufferSize = (uint)Marshal.SizeOf <UniformBufferObject>();

            uniformBufferVS.SetData <UniformBufferObject>(bufferSize, new[] { uboVS }, 0, 1);
        }
Ejemplo n.º 2
0
        void generateQuad()
        {
            // Setup vertices for a single uv-mapped quad made from two triangles
            VertexData[] quadCorners =
            {
                new VertexData
                {
                    pos    = new Vector3(1f, 1f, 0f),
                    uv     = new Vector2(1.0f, 1.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },

                new VertexData
                {
                    pos    = new Vector3(-1.0f, 1.0f, 0f),
                    uv     = new Vector2(0.0f, 1.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },

                new VertexData
                {
                    pos    = new Vector3(-1.0f, -1.0f, 0f),
                    uv     = new Vector2(0.0f, 0.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },


                new VertexData
                {
                    pos    = new Vector3(1.0f, -1.0f, 0f),
                    uv     = new Vector2(1.0f, 0.0f),
                    normal = new Vector3(0.0f, 0.0f, -1.0f)
                },
            };

            // Setup indices
            var indices = new uint[] { 0, 1, 2, 2, 3, 0 };

            indexCount = (uint)indices.Length;

            var device = mManager.Configuration.Device;

            Debug.Assert(device != null);

            // Create buffers
            // For the sake of simplicity we won't stage the vertex data to the gpu memory

            // Vertex buffer
            {
                var bufferSize = (uint)(Marshal.SizeOf <VertexData>() * quadCorners.Length);
                vertexBuffer = new BufferInfo(
                    mManager.Configuration.Partition,
                    MgBufferUsageFlagBits.VERTEX_BUFFER_BIT,
                    MgMemoryPropertyFlagBits.HOST_VISIBLE_BIT | MgMemoryPropertyFlagBits.HOST_COHERENT_BIT,
                    bufferSize);
                vertexBuffer.SetData <VertexData>(bufferSize, quadCorners, 0, quadCorners.Length);
            }


            // Index buffer
            {
                var bufferSize = indexCount * sizeof(uint);
                indexBuffer = new BufferInfo(
                    mManager.Configuration.Partition,
                    MgBufferUsageFlagBits.INDEX_BUFFER_BIT,
                    MgMemoryPropertyFlagBits.HOST_VISIBLE_BIT | MgMemoryPropertyFlagBits.HOST_COHERENT_BIT,
                    bufferSize);
                indexBuffer.SetData(bufferSize, indices, 0, (int)indexCount);
            }
        }