Exemple #1
0
        public void Render(ShaderProgram shader, Camera camera)
        {
            int indiceat = 0;

            Matrix4 cameraPerspective = camera.PerspectiveMatrix;
            cameraMatrix.Value = cameraPerspective;
            cameraMatrix.Update(shader);

            cameraPosition.Value = camera.Position;
            cameraPosition.Update(shader);

            numberOfLights.Value = Lights.Count;
            numberOfLights.Update(shader);

            for (int i = 0; i < Lights.Count; i++)
            {
                lightIntensity.Value = Lights[i].Data.Intensity;
                lightIntensity.Update(shader, i);

                lightColor.Value = Lights[i].Data.Color;
                lightColor.Update(shader, i);

                lightPosition.Value = Lights[i].Data.Position;
                lightPosition.Update(shader, i);

                lightAttenuation.Value = Lights[i].Data.Attenuation;
                lightAttenuation.Update(shader, i);

                lightAmbient.Value = Lights[i].Data.Ambient;
                lightAmbient.Update(shader, i);

                lightConeAngle.Value = Lights[i].Data.ConeAngle;
                lightConeAngle.Update(shader, i);

                lightConeDirection.Value = Lights[i].Data.ConeDirection;
                lightConeDirection.Update(shader, i);
            }

            foreach (Volume v in ObjectManager.Instance.Objects)
            {
                IHasMaterial vMat = v as IHasMaterial;
                if (vMat != null)
                {
                    var m = vMat.Material;

                    materialDiffuse.Value = m.DiffuseColor;
                    materialDiffuse.Update(shader);

                    materialDiffuseTexture.Value = m.DiffuseTexture;
                    materialDiffuseTexture.Update(shader);

                    materialSpecular.Value = m.SpecularColor;
                    materialSpecular.Update(shader);

                    materialSpecularExponent.Value = m.SpecularExponent;
                    materialSpecularExponent.Update(shader);
                }

                modelMatrix.Value = v.ModelMatrix;
                modelMatrix.Update(shader);

                GL.DrawElements(BeginMode.Triangles, v.IndiceCount, DrawElementsType.UnsignedInt, indiceat * sizeof(uint));
                indiceat += v.IndiceCount;
            }
        }
Exemple #2
0
        public void Update(ShaderProgram shader, Camera camera, float time)
        {
            foreach (Light l in Lights)
            {
                l.Update(time);
            }

            List<Vector3> vertices = new List<Vector3>();
            List<int> indices = new List<int>();
            List<Vector3> colors = new List<Vector3>();
            List<Vector2> textureCoords = new List<Vector2>();
            List<Vector3> normals = new List<Vector3>();
            int verticesCount = 0;

            foreach (Volume v in Objects)
            {
                v.Update(time);
                v.CalculateModelMatrix();
                v.ViewProjectionMatrix = camera.PerspectiveMatrix;
                v.ModelViewProjectionMatrix = v.ModelMatrix * v.ViewProjectionMatrix;

                vertices.AddRange(v.GetVertices().ToList());
                indices.AddRange(v.GetIndices(verticesCount).ToList());
                colors.AddRange(v.GetColorData().ToList());
                textureCoords.AddRange(v.GetTextureCoords().ToList());
                normals.AddRange(v.GetNormals().ToList());
                verticesCount += v.VerticesCount;
            }

            attributePositions.Value = vertices.ToArray();
            attributePositions.Update(shader);

            attributeColor.Value = colors.ToArray();
            attributeColor.Update(shader);

            attributeNormals.Value = normals.ToArray();
            attributeNormals.Update(shader);

            attributeTextureCoords.Value = textureCoords.ToArray();
            attributeTextureCoords.Update(shader);

            int[] indicesArray = indices.ToArray();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, iboElements);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indicesArray.Length * sizeof(int)), indicesArray, BufferUsageHint.StaticDraw);

            GL.UseProgram(shader.ProgramID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }