Exemple #1
0
        public void Render()
        {
            List <Light> lights = Engine.Game.CurrentScene.GetClosestLights(this.gameObject, RenderingPool.MAX_LIGHTS);

            if (lights != null)
            {
                IntUniform lightsCount = Engine.UniformManager.GetUniform <IntUniform>("lightsCount");
                lightsCount.Value = lights.Count;
                lightsCount.Set(this.GetShader());
                for (int i = 0; i < lights.Count; i++)
                {
                    lights[i].Bind(this.GetShader(), i);
                }
            }
            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(this.GetShader());

                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();
        }
Exemple #2
0
        public TerrainShader(IOpenGL33 gl)
        {
            vertexShader = new VertexShader(gl, GetEmbeddedResourceAsString("VertexShader.vs"));
            fragmentShader = new FragmentShader(gl, GetEmbeddedResourceAsString("FragmentShader.fs"));
            var p = new ModGL.ObjectModel.Shaders.Program(gl, vertexShader, fragmentShader);

            p.BindVertexAttributeLocations(PositionNormalTexCoord.Descriptor);
            // Bind output fragment to the specified nme
            gl.BindFragDataLocation(p.Handle, 0, "Color");
            // Compile program and shaders
            p.Compile();
            program = p;
            // Get the uniforms used by the shader program.
            diffuseUniform = p.GetUniform<Vector4fUniform, Vector4f>("DiffuseColor");
            modelViewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ModelViewProjection");
            viewProjection = p.GetUniform<MatrixUniform, Matrix4f>("ViewProjection");
            textureUnitUniform = p.GetUniform<IntUniform, int>("Texture");
        }
Exemple #3
0
 public IntUniformViewModel(IntUniform uniform)
     : base(uniform)
 {
 }
Exemple #4
0
 internal TextureUniform(IntUniform uniform)
 {
     _uniform = uniform;
     _name    = uniform.Name;
 }