コード例 #1
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*/);
        }
コード例 #2
0
        public static void Initialize(string blockName)
        {
            UniformBlockGL = new UniformBlockGL(blockName);
            UniformBlockGL.AddVec4(NearFar);
            UniformBlockGL.AddMat4(ViewToClip);
            UniformBlockGL.AddMat4(WorldToClip);
            UniformBlockGL.AddMat4(WorldToView);
            UniformBlockGL.AddMat4(ViewToWorld);
            UniformBlockGL.AddVec4(Viewport);
            UniformBlockGL.AddVec4(ViewPositionInWorld);
            UniformBlockGL.Seal();

            UniformBlockRL = new UniformBlockRL(blockName);
            UniformBlockRL.AddVec4(FovXFovYAspect);
            UniformBlockRL.AddMat4(ViewToClip);
            UniformBlockRL.AddMat4(WorldToClip);
            UniformBlockRL.AddMat4(WorldToView);
            UniformBlockRL.AddMat4(ViewToWorld);
            UniformBlockRL.AddVec4(Viewport);
            UniformBlockRL.AddVec4(ViewPositionInWorld);
            UniformBlockRL.Seal();
        }
コード例 #3
0
        // \brief Declare uniforms and set Shader replacement strings
        private void InitializeShaderSystem()
        {
            CameraUniformBlock.NearFar             = "near_far";
            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");

            LightsUniforms.spec.Count             = "count";
            LightsUniforms.spec.Exposure          = "exposure";
            LightsUniforms.spec.Bias              = "bias";
            LightsUniforms.spec.AmbientLightColor = "ambient_light_color";
            LightsUniforms.spec.WorldToLight      = "world_to_light_matrix";
            LightsUniforms.spec.WorldToShadow     = "world_to_shadow_matrix";
            LightsUniforms.spec.Direction         = "direction";
            LightsUniforms.spec.Color             = "color";
            LightsUniforms.Initialize("lights", Configuration.maxLightCount);

            System.Text.StringBuilder uniforms = new System.Text.StringBuilder();
            uniforms.Append(CameraUniformBlock.UniformBlockRL.SourceRL);
            uniforms.Append(LightsUniforms.UniformBlockRL.SourceGL);

            modelsUB = new UniformBlockRL("models");
            modelsUB.AddMat4("model_to_world_matrix", Configuration.instanceCount);
            if (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
            {
                modelsUB.AddUInt("id_offset_uint", Configuration.instanceCount);
                ShaderGL3.Replace("#if USE_INTEGER_POLYGON_ID", "#if 1");
            }
            else
            {
                modelsUB.AddVec4("id_offset_vec3", Configuration.instanceCount);
                ShaderGL3.Replace("#if USE_INTEGER_POLYGON_ID", "#if 0");
            }
            modelsUB.Seal();
            uniforms.Append(modelsUB.ToString());

            globalUB = new UniformBlockRL("global");
            globalUB.AddVec4("add_color");
            globalUB.AddFloat("alpha");
            globalUB.Seal();
            uniforms.Append(globalUB.ToString());

            uniforms.Append(LightsUniforms.UniformBlockRL.SourceRL);
            LightsUniforms.UniformBufferRL.Use();

            ShaderGL3.Replace("MAX_LIGHT_COUNT", Configuration.maxLightCount.ToString());

            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();

            LightsUniforms.Exposure.Set(1.0f);
            LightsUniforms.Bias.Set(-0.002f, 0.0f, 0.002f);
            LightsUniforms.AmbientLightColor.Set(0.2f, 0.2f, 0.2f);
            LightsUniforms.UniformBufferRL.Sync();

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

            var nearestClampToEdge = new SamplerRL();

            nearestClampToEdge.MinFilter   = OpenTK.Graphics.OpenGL.TextureMinFilter.Nearest;
            nearestClampToEdge.MagFilter   = OpenTK.Graphics.OpenGL.TextureMagFilter.Nearest;
            nearestClampToEdge.Wrap        = OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToEdge;
            nearestClampToEdge.CompareMode = OpenTK.Graphics.OpenGL.TextureCompareMode.None;

            var bilinearClampToEdge = new SamplerRL();

            bilinearClampToEdge.MinFilter   = OpenTK.Graphics.OpenGL.TextureMinFilter.NearestMipmapLinear;
            bilinearClampToEdge.MagFilter   = OpenTK.Graphics.OpenGL.TextureMagFilter.Linear;
            bilinearClampToEdge.Wrap        = OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToEdge;
            bilinearClampToEdge.CompareMode = OpenTK.Graphics.OpenGL.TextureCompareMode.None;

            Samplers.Global.AddSampler2D("t_font", nearestClampToEdge);
            Samplers.Global.AddSampler2D("t_ninepatch", bilinearClampToEdge).TextureUnitIndex = 1;
            Samplers.Global.AddSampler2D("t_cube", bilinearClampToEdge);
            Samplers.Global.AddSampler2D("t_left", nearestClampToEdge);
            Samplers.Global.AddSampler2D("t_right", nearestClampToEdge).TextureUnitIndex = 1;
            Samplers.Global.AddSampler2D("t_surface_color", bilinearClampToEdge);
            Samplers.Global.AddSampler2D("t_particle", bilinearClampToEdge);
            Samplers.Global.AddSampler2DArray("t_shadowmap_vis", bilinearClampToEdge);
            Samplers.Global.Seal();

            materialUB = new UniformBlockRL("material");
            materialUB.AddVec4("surface_diffuse_reflectance_color");
            materialUB.AddVec4("surface_specular_reflectance_color");
            materialUB.AddFloat("surface_specular_reflectance_exponent");
            materialUB.AddVec2("surface_rim_parameters");
            materialUB.AddVec4("grid_size");
            materialUB.AddFloat("surface_roughness");
            materialUB.AddFloat("surface_isotropy");
            materialUB.AddFloat("contrast").Default   = new Floats(1.0f);
            materialUB.AddFloat("deghost").Default    = new Floats(0.0f);
            materialUB.AddFloat("saturation").Default = new Floats(1.0f);
            materialUB.AddFloat("t");
            materialUB.AddFloat("slider_t");
            materialUB.AddVec4("fill_color");
            materialUB.AddVec4("point_color");
            materialUB.AddFloat("point_z_offset");
            materialUB.AddVec4("line_color");
            materialUB.AddVec2("line_width").Default = new Floats(1.0f, 0.25f); // \todo check how to compute .y
            materialUB.AddFloat("bias_units");
            materialUB.AddFloat("bias_factor");
            materialUB.AddFloat("octaves").Default     = new Floats(4.0f);
            materialUB.AddFloat("offset").Default      = new Floats(0.0f);
            materialUB.AddFloat("frequency").Default   = new Floats(2.2f);
            materialUB.AddFloat("amplitude").Default   = new Floats(0.2f);
            materialUB.AddFloat("lacunarity").Default  = new Floats(3.3f);
            materialUB.AddFloat("persistence").Default = new Floats(0.25f);
            materialUB.Seal();
            uniforms.Append(MaterialUB.ToString());
            uniforms.Append(Samplers.Global.ToString());

            //  Have these last
            ShaderGL3.Replace("UNIFORMS;", uniforms.ToString());
            ShaderGL3.Replace("INSTANCE_COUNT", "50");
        }