示例#1
0
        public Slider(
            IRenderer renderer,
            string label,
            IParams <float> parameter,
            int element,
            float min,
            float max,
            float displayMin,
            float displayMax,
            IUniformBuffer uniformbuffer
            )
        {
            this.renderer  = renderer;
            this.parameter = parameter;
            this.element   = element;
            Name           = label;

            Style      = Style.Foreground;
            textBuffer = new TextBuffer(Style.Font);
            ninePatch  = new NinePatch(Style.NinePatchStyle);

            Min        = min;
            Max        = max;
            DisplayMin = displayMin;
            DisplayMax = displayMax;

            if (parameter != null)
            {
                CurrentValue = parameter[element];
            }
            Label = label;

            this.uniformBuffer = uniformbuffer;
        }
示例#2
0
 public Material(
     string name,
     IProgram program,
     IUniformBlock uniformBlock
     )
 {
     this.name     = name;
     Program       = program;
     uniformBuffer = UniformBufferFactory.Create(uniformBlock);
     uniformBuffer.Sync();
 }
示例#3
0
 public CameraParameters(IUniformBuffer bufferGL /*, IUniformBuffer bufferRL*/)
 {
     NearFar             = new MultiFloats(CameraUniformBlock.NearFar, new Floats(4, 1), bufferGL /*, bufferRL*/);
     FovXFovYAspect      = new MultiFloats(CameraUniformBlock.FovXFovYAspect, new Floats(4, 1), bufferGL /*, bufferRL*/);
     Viewport            = new MultiFloats(CameraUniformBlock.Viewport, new Floats(4, 1), bufferGL /*, bufferRL*/);
     WorldToClip         = new MultiFloats(CameraUniformBlock.WorldToClip, new Floats(16, 1), bufferGL /*, bufferRL*/);
     ClipToWorld         = new MultiFloats(CameraUniformBlock.ClipToWorld, new Floats(16, 1), bufferGL /*, bufferRL*/);
     ViewToWorld         = new MultiFloats(CameraUniformBlock.ViewToWorld, new Floats(16, 1), bufferGL /*, bufferRL*/);
     WorldToView         = new MultiFloats(CameraUniformBlock.WorldToView, new Floats(16, 1), bufferGL /*, bufferRL*/);
     ViewToClip          = new MultiFloats(CameraUniformBlock.ViewToClip, new Floats(16, 1), bufferGL /*, bufferRL*/);
     ClipToView          = new MultiFloats(CameraUniformBlock.ClipToView, new Floats(16, 1), bufferGL /*, bufferRL*/);
     ViewPositionInWorld = new MultiFloats(CameraUniformBlock.ViewPositionInWorld, new Floats(4, 1), bufferGL /*, bufferRL*/);
 }
示例#4
0
        //public static UniformBufferRL   UniformBufferRL;

        public static void Initialize(
            string blockName,
            int maxLightCount
            )
        {
            UniformBlockGL = new UniformBlockGL(blockName);
            UniformBlockGL.AddInt(spec.Count);
            UniformBlockGL.AddVec4(spec.Exposure);
            UniformBlockGL.AddVec4(spec.Bias);
            UniformBlockGL.AddVec4(spec.AmbientLightColor);
            UniformBlockGL.AddVec4(spec.Color, maxLightCount);
            UniformBlockGL.AddVec4(spec.Direction, maxLightCount);
            UniformBlockGL.AddMat4(spec.WorldToLight, maxLightCount);
            UniformBlockGL.AddMat4(spec.WorldToShadow, maxLightCount);
            UniformBlockGL.Seal();
            var bufferGL = UniformBufferGL = new UniformBufferGL(UniformBlockGL);

#if false
            IUniformBuffer bufferRL = null;
            if (Configuration.useOpenRL)
            {
                UniformBlockRL = new UniformBlockRL(blockName);
                UniformBlockRL.AddInt(spec.Count);
                UniformBlockRL.AddVec4(spec.Exposure);
                UniformBlockRL.AddVec4(spec.Bias);
                UniformBlockRL.AddVec4(spec.AmbientLightColor);
                UniformBlockRL.AddVec4(spec.Color, maxLightCount);
                UniformBlockRL.AddVec4(spec.Direction, maxLightCount);
                UniformBlockRL.AddMat4(spec.WorldToLight, maxLightCount);
                UniformBlockRL.AddMat4(spec.WorldToShadow, maxLightCount);
                UniformBlockRL.Seal();
                UniformBufferRL = new UniformBufferRL(UniformBlockRL);
            }
#endif

            Count             = new MultiInts(spec.Count, new Ints(1, 1), bufferGL /*bufferRL*/);
            Exposure          = new MultiFloats(spec.Exposure, new Floats(4, 1), bufferGL /*bufferRL*/);
            Bias              = new MultiFloats(spec.Bias, new Floats(4, 1), bufferGL /*bufferRL*/);
            AmbientLightColor = new MultiFloats(spec.AmbientLightColor, new Floats(4, 1), bufferGL /*bufferRL*/);
            WorldToLight      = new MultiFloats(spec.WorldToLight, new Floats(16, maxLightCount), bufferGL /*bufferRL*/);
            WorldToShadow     = new MultiFloats(spec.WorldToShadow, new Floats(16, maxLightCount), bufferGL /*bufferRL*/);
            Direction         = new MultiFloats(spec.Direction, new Floats(4, maxLightCount), bufferGL /*bufferRL*/);
            Color             = new MultiFloats(spec.Color, new Floats(4, maxLightCount), bufferGL /*bufferRL*/);
        }
示例#5
0
        private int modelCount;                         //  How many models in scene

        protected override void OnLoad(System.EventArgs e)
        {
            //  Check GL features
            RenderStack.Graphics.Configuration.Initialize();
            if (RenderStack.Graphics.Configuration.glslVersion < 150)
            {
                throw new System.PlatformNotSupportedException("You need at least GL 3.2");
            }

            AttributeMappings.Global.Add(0, "_position", VertexUsage.Position, 0, 3);
            AttributeMappings.Global.Add(1, "_normal", VertexUsage.Normal, 0, 3);

            //  Build uniform blocks
            {
                System.Text.StringBuilder uniforms = new System.Text.StringBuilder();
                CameraUniformBlock.NearFar             = "near_far";
                CameraUniformBlock.FovXFovYAspect      = "fovx_fovy_aspect";
                CameraUniformBlock.ViewToClip          = "view_to_clip_matrix";
                CameraUniformBlock.ClipToView          = "view_to_clip_matrix";
                CameraUniformBlock.WorldToClip         = "world_to_clip_matrix";
                CameraUniformBlock.ClipToWorld         = "clip_to_world_matrix";
                CameraUniformBlock.WorldToView         = "world_to_view_matrix";
                CameraUniformBlock.ViewToWorld         = "view_to_world_matrix";
                CameraUniformBlock.Viewport            = "viewport";
                CameraUniformBlock.ViewPositionInWorld = "view_position_in_world";
                CameraUniformBlock.Initialize("camera");
                uniforms.Append(CameraUniformBlock.UniformBlockGL.SourceGL);

                ModelsUB = new UniformBlockGL("models");
                ModelsUB.AddMat4("model_to_world_matrix", maxInstanceCount);
                ModelsUB.Seal();
                uniforms.Append(ModelsUB.SourceGL);

                GlobalUB = new UniformBlockGL("global");
                GlobalUB.AddVec4("add_color");
                GlobalUB.AddFloat("alpha");
                GlobalUB.Seal();
                uniforms.Append(GlobalUB.SourceGL);

                MaterialUB = new UniformBlockGL("material");
                MaterialUB.AddVec4("surface_diffuse_reflectance_color");
                MaterialUB.AddVec4("surface_specular_reflectance_color");
                MaterialUB.AddFloat("surface_roughness");
                MaterialUB.Seal();
                uniforms.Append(MaterialUB.SourceGL);

                LightsUB = new UniformBlockGL("lights");
                LightsUB.AddVec4("exposure");
                LightsUB.AddVec4("color", lightCount);
                LightsUB.AddVec4("ambient_light_color");
                LightsUB.AddVec4("direction", lightCount);
                LightsUB.AddMat4("world_to_shadow_matrix", lightCount);
                LightsUB.Seal();
                uniforms.Append(LightsUB.SourceGL);

                ShaderGL3.Replace("UNIFORMS;", uniforms.ToString());
            }

            //  Models
            List <Vector2> positions = UniformPoissonDiskSampler.SampleCircle(Vector2.Zero, poissonRadius, poissonMinDistance);

            modelCount = positions.Count;
            System.Diagnostics.Debug.WriteLine("Model count: " + modelCount);
            modelFrame = new Frame[modelCount];
            for (int i = 0; i < modelCount; ++i)
            {
                modelFrame[i] = new Frame();
                modelFrame[i].LocalToParent.Set(
                    Matrix4.CreateTranslation(positions[i].X, positions[i].Y, -40.0f)
                    );
            }

            //  Setup geometry and mesh
            Geometry geometry = new Sphere(radius, 20, 8);

            //Matrix4 translate = Matrix4.CreateTranslation(0.0f, 0.0f, -4.0f);
            //geometry.Transform(translate);
            mesh = new GeometryMesh(geometry, NormalStyle.PointNormals).GetMesh;
            //  \todo Get rid of this
            //mesh.VertexBufferRange.Buffer.VertexFormat.Seal(AttributeMappings.Global);

            //  This is where we collect models transformations
            models = UniformBufferFactory.Create(ModelsUB);

            global = UniformBufferFactory.Create(GlobalUB);
            global.Floats("alpha").Set(1.0f);
            global.Floats("add_color").Set(0.0f, 0.0f, 0.4f);
            global.Sync();

            //  Setup lights
            lights = UniformBufferFactory.Create(LightsUB);
            lights.Floats("exposure").Set(1.0f);
            lights.Floats("ambient_light_color").Set(1.0f, 1.0f, 1.0f);
            for (int i = 0; i < lightCount; ++i)
            {
                lights.Floats("direction").SetI(i, 0.0f, 1.0f, 0.0f);
                lights.Floats("color").SetI(i, 1.0f, 1.0f, 1.0f, 1.0f / (float)lightCount);
            }
            lights.Sync();

            global.Use();
            models.Use();
            lights.Use();

            //  Setup viewport and camera
            viewport = new Viewport(base.Width, base.Height);
            camera   = new Camera();
            camera.Projection.Near = 0.1f;
            camera.Projection.Far  = 300.0f;
            camera.Frame.LocalToParent.Set(
                Matrix4.CreateLookAt(
                    new Vector3(0.0f, 0.0f, 4.0f),      //  camera location
                    new Vector3(0.0f, 0.0f, 0.0f),      //  aim point
                    new Vector3(0.0f, 1.0f, 0.0f)       //  up vector
                    )
                );

            camera.Projection.FovYRadians    = RenderStack.Math.Conversions.DegreesToRadians(60.0f);
            camera.Projection.ProjectionType = ProjectionType.PerspectiveVertical;
            camera.UniformBufferGL.Use();

            //  Setup shader program
            program = (IProgram) new ProgramGL3(vs, fs);

            //  Setup material
            for (int i = 0; i < Materials.Length; ++i)
            {
                var   material = UniformBufferFactory.Create(MaterialUB);
                float h = (float)(i) / (float)(Materials.Length - 1);
                float r, g, b;
                Conversions.HSVtoRGB(360.0f * h, 1.0f, 1.0f, out r, out g, out b);
                float diffuse   = 0.2f;
                float specular  = 0.8f;
                float roughness = 0.1f;
                material.Floats("surface_diffuse_reflectance_color").Set(diffuse * r, diffuse * g, diffuse * b);
                material.Floats("surface_specular_reflectance_color").Set(specular * r, specular * r, specular * r);
                material.Floats("surface_roughness").Set(roughness);
                material.Sync();
                Materials[i] = material;
            }

            //  Update scene. There is no animation in this scene
            //  so we only need to do it once.
            camera.Frame.UpdateHierarchical(serial);
            foreach (var frame in modelFrame)
            {
                frame.UpdateHierarchical(serial);
            }

            //  Setup initial GL state
            {
                //  Since we only use one program, we don't need to touch this after.
                camera.UpdateFrame();
                camera.UpdateViewport(viewport);
                camera.UniformBufferGL.Sync();

                //  Bind program
                program.Use(0);

                GL.Enable(EnableCap.DepthTest);
                GL.Enable(EnableCap.CullFace);

                float gammaHalf = (float)Math.Pow(0.5, 1.0 / 2.2);
                GL.ClearColor(gammaHalf, gammaHalf, gammaHalf, 1.0f);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                SwapBuffers();

                Visible = true;

                //  Since we only use one mesh, we don't need to change this after
                SetupAttributeBindings();

                //  The mesh has not yet been uploaded to GL, do it now
                IBufferRange vertexBufferRange = mesh.VertexBufferRange;
                IBufferRange indexBufferRange  = mesh.IndexBufferRange(MeshMode.PolygonFill);
                if (vertexBufferRange.NeedsUploadGL)
                {
                    vertexBufferRange.UpdateGL();
                }
                if (indexBufferRange.NeedsUploadGL)
                {
                    indexBufferRange.UpdateGL();
                }
            }

            Resize += new EventHandler <EventArgs>(Application_Resize);
            Unload += new EventHandler <EventArgs>(Application_Unload);
        }
示例#6
0
 public Parameter(string name, Floats @default, IUniformBuffer bufferGL, IUniformBuffer bufferRL)
 {
     ValueGL = (bufferGL != null) && bufferGL.Contains(name) ? bufferGL.Floats(name) : @default;
     ValueRL = (bufferRL != null) && bufferRL.Contains(name) ? bufferRL.Floats(name) : @default;
 }