public override void Draw(float time)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            Lamp.Shader.Use();
            _diffuseMap.Bind(0);
            Lamp.Shader.SetInt("material.diffuse", 0);
            _specularMap.Bind(1);
            Lamp.Shader.SetInt("material.specular", 1);

            Lamp.Shader.SetMatrix4("model", Matrix4.Identity);
            Lamp.Shader.SetMatrix4("view", Camera.View);
            Lamp.Shader.SetMatrix4("projection", Camera.Projection);
            Lamp.Shader.SetVector3("light.position", Lamp.Position);
            Lamp.Shader.SetVector3("light.ambient", new Vector3(0.2f));
            Lamp.Shader.SetVector3("light.diffuse", new Vector3(.5f));
            Lamp.Shader.SetVector3("light.specular", new Vector3(1.0f));
            Lamp.Shader.SetVector3("viewPos", Camera.Position);

            Lamp.Bind();

            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            _modelShader.Use();
            var lampMatrix = Matrix4.Identity;

            lampMatrix *= Matrix4.CreateScale(0.2f);
            lampMatrix *= Matrix4.CreateTranslation(Lamp.Position);

            _modelShader.SetMatrix4("model", lampMatrix);
            _modelShader.SetMatrix4("view", Camera.View);
            _modelShader.SetMatrix4("projection", Camera.Projection);
            _modelVao.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            base.Draw(time);
        }
Example #2
0
        public override void Draw(float time)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            _time += goBack ? -time : time;

            Lamp.Shader.Use();
            Lamp.Shader.SetMatrix4("model", Matrix4.Identity);
            Lamp.Shader.SetMatrix4("view", Camera.View);
            Lamp.Shader.SetMatrix4("projection", Camera.Projection);
            Lamp.Shader.SetVector3("objectColor", Lamp.Position);
            Lamp.Shader.SetVector3("lightColor", new Vector3(_time));
            Lamp.Shader.SetFloat("time", _time);
            Lamp.Shader.SetVector3("viewPos", Camera.Position);
            Lamp.Shader.SetVector3("lightPos", Lamp.Position);
            Lamp.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            _modelShader.Use();
            var lampMatrix = Matrix4.Identity;

            lampMatrix *= Matrix4.CreateScale(0.5f);
            lampMatrix *= Matrix4.CreateTranslation(Lamp.Position) * Matrix4.CreateRotationY((Lamp.Position * _time).X);

            _modelShader.SetMatrix4("model", lampMatrix);
            _modelShader.SetMatrix4("view", Camera.View);
            _modelShader.SetMatrix4("projection", Camera.Projection);
            _modelVao.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            if (_time >= 360.0f || _time < 0.0f)
            {
                goBack = !goBack;
            }
            base.Draw(time);
        }
Example #3
0
        public void Render()
        {
            Light light = Engine.Game.CurrentScene.GetClosestLight(this.gameObject);

            if (light != null)
            {
                light.Bind();
            }
            foreach (Mesh mesh in this.Model.Meshes)
            {
                Matrix4 transformMatrix = this.gameObject.Transform.GetLocalToWorldMatrix();
                if (mesh.LocalMatrix != Matrix4.Identity)
                {
                    transformMatrix = mesh.LocalMatrix * transformMatrix;
                }
                Matrix3Uniform normalMatrixUniform = Engine.UniformManager.GetUniform <Matrix3Uniform>("normalMatrix");
                normalMatrixUniform.Matrix = Matrix3.Transpose(new Matrix3(transformMatrix.Inverted()));
                normalMatrixUniform.Set(Engine.RenderingPool.PhongShaderProgram);

                foreach (Mesh.Primitive primitive in mesh.Primitives)
                {
                    // Bind vertex buffer and array objects
                    this.vertexBuffers[primitive.GUID].Bind();
                    this.vertexArrays[primitive.GUID].Bind();

                    // Upload vertices to GPU and draw them
                    this.vertexBuffers[primitive.GUID].BufferData();

                    // Bind primitive Material
                    Model.Materials[primitive.MaterialModelId].Bind(this.GetShader());

                    if (primitive.Indices.Count == 0)
                    {
                        this.vertexBuffers[primitive.GUID].Draw();
                    }
                    else
                    {
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.glBufferIds[primitive.GUID]);
                        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(primitive.Indices.Count * sizeof(ushort)), primitive.Indices.ToArray(), BufferUsageHint.DynamicDraw);
                        GL.DrawElements(PrimitiveType.Triangles, primitive.Indices.Count, DrawElementsType.UnsignedShort, (IntPtr)0);
                    }
                }
            }

            this.UpdateAllVertexBuffers();
        }
Example #4
0
        public override void Draw(float time)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            var   lightColor = new Vector3();
            float dTime      = DateTime.UtcNow.Second + DateTime.Now.Millisecond / 1000f;

            lightColor.X = MathF.Sin(dTime * 2.0f);
            lightColor.Y = MathF.Sin(dTime * 0.7f);
            lightColor.Z = MathF.Sin(dTime * 1.3f);

            var ambientColor = lightColor * new Vector3(0.2f);
            var diffuseColor = lightColor * new Vector3(0.5f);

            Lamp.Shader.Use();
            Lamp.Shader.SetMatrix4("model", Matrix4.Identity);
            Lamp.Shader.SetMatrix4("view", Camera.View);
            Lamp.Shader.SetMatrix4("projection", Camera.Projection);
            Lamp.Shader.SetVector3("light.ambient", ambientColor);
            Lamp.Shader.SetVector3("light.diffuse", diffuseColor);
            Lamp.Shader.SetVector3("viewPos", Camera.Position);
            Lamp.Shader.SetVector3("light.position", Lamp.Position);
            Lamp.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            _modelShader.Use();
            var lampMatrix = Matrix4.Identity;

            lampMatrix *= Matrix4.CreateScale(0.2f);
            lampMatrix *= Matrix4.CreateTranslation(Lamp.Position);

            _modelShader.SetMatrix4("model", lampMatrix);
            _modelShader.SetMatrix4("view", Camera.View);
            _modelShader.SetMatrix4("projection", Camera.Projection);
            _modelVao.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            base.Draw(time);
        }