Exemplo n.º 1
0
        internal static void ReadMaterial(MaterialConfiguration material, string fileName)
        {
            foreach (var line in File.ReadAllLines(fileName))
            {
                var values = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length < 2)
                {
                    continue;
                }

                var uniformName = values[0];
                if (uniformName == "newmtl" || uniformName.StartsWith("#"))
                {
                    continue;
                }
                if (uniformName.StartsWith("map_"))
                {
                    var textureBinding = new TextureBindingConfiguration();
                    textureBinding.Name        = uniformName;
                    textureBinding.TextureName = Path.GetFileNameWithoutExtension(values[1]);
                    textureBinding.TextureSlot = TextureUnit.Texture0 + material.BufferBindings.Count;
                    material.BufferBindings.Add(textureBinding);
                }
                else
                {
                    UniformConfiguration uniform;
                    var uniformValues = ParseValues(values);
                    switch (uniformValues.Length)
                    {
                    case 1: uniform = new FloatUniform {
                            Value = uniformValues[0]
                    }; break;

                    case 2: uniform = new Vec2Uniform {
                            Value = new Vector2(uniformValues[0], uniformValues[1])
                    }; break;

                    case 3: uniform = new Vec3Uniform {
                            Value = new Vector3(uniformValues[0], uniformValues[1], uniformValues[2])
                    }; break;

                    case 4: uniform = new Vec4Uniform {
                            Value = new Vector4(uniformValues[0], uniformValues[1], uniformValues[2], uniformValues[3])
                    }; break;

                    default: throw new InvalidOperationException("Unsupported number of values in the configuration of uniform " + uniformName + ".");
                    }
                    uniform.Name = uniformName;
                    material.ShaderUniforms.Add(uniform);
                }
            }
        }
Exemplo n.º 2
0
        public void Render(ITransformation camera, Vector3 cameraPosition)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            var cameraUniform    = new TransformUniform(nameof(camera), camera);
            var cameraPosUniform = new Vec3Uniform(nameof(cameraPosition), cameraPosition);

            foreach (var visual in visuals)
            {
                visual.SetUniform(cameraPosUniform);                 //TODO: only per shader needed
                visual.SetUniform(cameraUniform);
                visual.Draw();
            }
        }
Exemplo n.º 3
0
 public static void Set(this ShaderProgram @this, Vec3Uniform uniform, Vector3 vector)
 => Gl.ProgramUniform3(@this.Handle, uniform.Location, vector.X, vector.Y, vector.Z);