Exemple #1
0
        public Entities(GLProgram program, SceneGraph scene)
            : base(program)
        {
            var numPointLights = 0;
            var plights        = new LightingShaders.PointLight[4];

            using (program.Scope())
            {
                foreach (var pointLight in scene.Root.Traverse().OfType <PointLight> ())
                {
                    plights[numPointLights++] = new LightingShaders.PointLight
                    {
                        position             = pointLight.Position,
                        intensity            = pointLight.Intensity,
                        linearAttenuation    = pointLight.LinearAttenuation,
                        quadraticAttenuation = pointLight.QuadraticAttenuation
                    };
                }
                pointLights &= plights;

                var samp = new Sampler2D[4];
                for (int i = 0; i < samp.Length; i++)
                {
                    samp[i] = new Sampler2D(i + 1).LinearFiltering().ClampToEdges(Axes.All);
                }
                samplers   &= samp;
                diffuseMap &= new SamplerCube(5).LinearFiltering().ClampToEdges(Axes.All);

                lighting   = new LightingUniforms(program, scene);
                transforms = new TransformUniforms(program);
                shadows    = new CascadedShadowUniforms(program,
                                                        new Sampler2DArray(0).LinearFiltering().ClampToEdges(Axes.All));
            }
        }
Exemple #2
0
        public static Reaction <Camera> Renderer(SceneGraph sceneGraph)
        {
            _shader = PassThrough;

            return(React.By <Camera> (Render)
                   .Program(_shader));
        }
 public unsafe void SetFloatArray(float[] array, int count, int uniform, GLProgram shaderProgram)
 {
     fixed(float *a = &array[0])
     {
         SetFloatArray((IntPtr)a, count, uniform, shaderProgram);
     }
 }
        /// <summary>
        /// Compile the compute program
        /// </summary>
        /// <param name="codelisting">The code</param>
        /// <param name="constvalues">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="saveable">True if want to save to binary</param>
        /// <param name="completeoutfile">If non null, output the post processed code listing to this file</param>

        public void CompileLink(string codelisting, object[] constvalues = null, bool saveable = false, string completeoutfile = null)
        {
            Program = new GLProgram();
            string ret = Program.Compile(ShaderType.ComputeShader, codelisting, constvalues, completeoutfile);

            System.Diagnostics.Debug.Assert(ret == null, "Compute Shader", ret);
            ret = Program.Link(wantbinary: saveable);
            System.Diagnostics.Debug.Assert(ret == null, "Link", ret);
            GLStatics.Check();
        }
Exemple #5
0
 private Shadows(GLProgram program, bool cascaded)
     : base(program)
 {
     _cascaded = cascaded;
     if (_cascaded)
         csmUniforms = new CascadedShadowUniforms (program);
     else
     {
         shadowUniforms = new ShadowUniforms (program);
     }
 }
Exemple #6
0
 public Materials(GLProgram program)
     : base(program)
 {
     using (program.Scope())
     {
         transforms  = new TransformUniforms(program);
         diffuseMap &= new Sampler2D(0).LinearFiltering();
         normalMap  &= new Sampler2D(1).LinearFiltering();
         heightMap  &= new Sampler2D(2).LinearFiltering();
     }
 }
Exemple #7
0
 private Shadows(GLProgram program, bool cascaded) : base(program)
 {
     _cascaded = cascaded;
     if (_cascaded)
     {
         csmUniforms = new CascadedShadowUniforms(program);
     }
     else
     {
         shadowUniforms = new ShadowUniforms(program);
     }
 }
        /// <summary>
        /// Compile and link the pipeline component.
        /// If you specify varyings, you must set up a buffer, and a start action of Gl.BindBuffer(GL.TRANSFORM_FEEDBACK_BUFFER,bufid) AND BeingTransformFeedback.
        /// </summary>
        /// <param name="shadertype">Shader type,Fragment, Vertex etc </param>
        /// <param name="codelisting">The code</param>
        /// <param name="constvalues">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="varyings">List of varyings to report</param>
        /// <param name="varymode">How to write the varying to the buffer</param>
        /// <param name="saveable">True if want to save to binary</param>
        /// <param name="auxname">For reporting purposes on error, name to give to shader </param>
        /// <param name="completeoutfile">If non null, output the post processed code listing to this file</param>
        protected void CompileLink(ShaderType shadertype, string codelisting,
                                   object[] constvalues = null, string[] varyings = null, TransformFeedbackMode varymode = TransformFeedbackMode.InterleavedAttribs,
                                   bool saveable        = false,
                                   string auxname       = "", string completeoutfile = null)
        {
            Program = new GLProgram();
            string ret = Program.Compile(shadertype, codelisting, constvalues, completeoutfile);

            System.Diagnostics.Debug.Assert(ret == null, auxname, ret);
            ret = Program.Link(separable: true, varyings, varymode, saveable);
            System.Diagnostics.Debug.Assert(ret == null, auxname, ret);
        }
Exemple #9
0
        public static Reaction <Camera> Renderer(SceneGraph scene,
                                                 int mapSize, ShadowMapType type, bool cascaded)
        {
            var depthFramebuffer = new Framebuffer(FramebufferTarget.Framebuffer);

            _shadowShader = cascaded ?
                            new GLProgram(
                VertexShaderCascaded(),
                GeometryShaderCascaded(),
                DepthFragmentShader()) :
                            new GLProgram(
                VertexShader(),
                type == ShadowMapType.Depth ? DepthFragmentShader() : VarianceFragmentShader());

            _instance = new Shadows(_shadowShader, cascaded);

            Texture depthTexture;
            var     render = React.By <Camera> (_instance.Render);

            if (type == ShadowMapType.Depth || cascaded)
            {
                depthTexture = cascaded ?
                               new Texture(TextureTarget.Texture2DArray, PixelInternalFormat.DepthComponent16,
                                           mapSize, mapSize, CascadedShadowUniforms.MapCount, PixelFormat.DepthComponent,
                                           PixelType.Float, IntPtr.Zero) :
                               new Texture(TextureTarget.Texture2D, PixelInternalFormat.DepthComponent16,
                                           mapSize, mapSize, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);
                depthFramebuffer.AddTexture(FramebufferAttachment.DepthAttachment, depthTexture);
            }
            else
            {
                depthTexture = new Texture(TextureTarget.Texture2D, PixelInternalFormat.Rg32f,
                                           mapSize, mapSize, PixelFormat.Rg, PixelType.Float, IntPtr.Zero);
                depthFramebuffer.AddTexture(FramebufferAttachment.ColorAttachment0, depthTexture);
                depthFramebuffer.AddRenderbuffer(FramebufferAttachment.DepthAttachment,
                                                 RenderbufferStorage.DepthComponent16, mapSize, mapSize);
                var gaussTexture = new Texture(TextureTarget.Texture2D, PixelInternalFormat.Rg32f,
                                               mapSize / 2, mapSize / 2, PixelFormat.Rg, PixelType.Float, IntPtr.Zero);
                render = render.And(GaussianFilter.Both().MapInput((Camera cam) =>
                                                                   Tuple.Create(depthTexture, gaussTexture)));
            }
            scene.GlobalLighting.ShadowMap = depthTexture;

            return(render
                   .DrawBuffer(type == ShadowMapType.Depth ? DrawBufferMode.None : DrawBufferMode.Front)
                   .DepthTest()
                   .Culling()
                   .Viewport(new Vec2i(mapSize, mapSize))
                   .Program(_shadowShader)
                   .Texture(depthTexture)
                   .Framebuffer(depthFramebuffer));
        }
Exemple #10
0
        private TextureFilter(GLProgram program)
        {
            _program = program;
            _uniforms = new TextureUniforms (_program, new Sampler2D (0).LinearFiltering ()
                .ClampToEdges (Axes.X | Axes.Y));

            _framebuffer = new Framebuffer (FramebufferTarget.Framebuffer);

            var rectangle = Quadrilateral<TexturedVertex>.Rectangle (2f, 2f);
            rectangle.ApplyTextureFront (1f, new Vec2 (0f), new Vec2 (1f));
            _vertexBuffer = new VBO<TexturedVertex> (rectangle.Vertices, BufferTarget.ArrayBuffer);
            _indexBuffer = new VBO<int> (rectangle.Indices, BufferTarget.ElementArrayBuffer);
        }
Exemple #11
0
        public static Reaction <Vec2i> Renderer(SceneGraph scene)
        {
            _panelShader = new GLProgram(
                VertexShaders.TransformedTexture <TexturedVertex, PanelFragment, TransformUniforms> (),
                FragmentShaders.TexturedOutput <PanelFragment, TextureUniforms> ());
            _panels = new Panels();
            _scene  = scene;

            return(React.By <Vec2i> (_panels.Render)
                   .Blending()
                   .Culling()
                   .Program(_panelShader));
        }
Exemple #12
0
        private TextureFilter(GLProgram program)
        {
            _program  = program;
            _uniforms = new TextureUniforms(_program, new Sampler2D(0).LinearFiltering()
                                            .ClampToEdges(Axes.X | Axes.Y));

            _framebuffer = new Framebuffer(FramebufferTarget.Framebuffer);

            var rectangle = Quadrilateral <TexturedVertex> .Rectangle(2f, 2f);

            rectangle.ApplyTextureFront(1f, new Vec2(0f), new Vec2(1f));
            _vertexBuffer = new VBO <TexturedVertex> (rectangle.Vertices, BufferTarget.ArrayBuffer);
            _indexBuffer  = new VBO <int> (rectangle.Indices, BufferTarget.ElementArrayBuffer);
        }
Exemple #13
0
        private Terrain(GLProgram program, SceneGraph scene, Vec3 skyCol)
            : base(program)
        {
            transforms = new TransformUniforms(program);
            lighting   = new LightingUniforms(program, scene);
            shadows    = new CascadedShadowUniforms(program,
                                                    new Sampler2DArray(0).LinearFiltering().ClampToEdges(Axes.All));

            using (program.Scope())
            {
                skyColor     &= skyCol;
                sandSampler  &= new Sampler2D(1);
                rockSampler  &= new Sampler2D(2);
                grassSampler &= new Sampler2D(3);
            }
        }
Exemple #14
0
 public LightingUniforms(GLProgram program, SceneGraph scene)
     : base(program)
 {
     using (program.Scope())
     {
         var gl = scene.GlobalLighting;
         if (gl != null)
         {
             globalLighting &= new LightingShaders.GlobalLight()
             {
                 ambientLightIntensity = gl.AmbientLightIntensity,
                 maxintensity          = gl.MaxIntensity,
                 inverseGamma          = 1f / gl.GammaCorrection
             };
         }
     }
 }
Exemple #15
0
        public static Reaction <Camera> Renderer(SceneGraph sceneGraph, CascadedShadowUniforms shadowSource)
        {
            _entityShader = new GLProgram(
                VertexShader(),
                FragmentShader());
            _entities = new Entities(_entityShader, sceneGraph);

            return(React.By <Camera> (cam => _entities.Render(cam, shadowSource))
                   .BindSamplers(new Dictionary <Sampler, Texture> ()
            {
                { !_entities.shadows.csmShadowMap, sceneGraph.GlobalLighting.ShadowMap },
                { !_entities.diffuseMap, sceneGraph.GlobalLighting.DiffuseMap }
            })
                   .DepthTest()
                   .Culling()
                   .Program(_entityShader));
        }
Exemple #16
0
        /// <summary>
        /// Compile and link the pipeline component.
        /// If you specify varyings, you must set up a buffer, and a start action of Gl.BindBuffer(GL.TRANSFORM_FEEDBACK_BUFFER,bufid) AND BeingTransformFeedback.
        /// </summary>
        /// <param name="vertex">The code for this shader type, or null</param>
        /// <param name="tcs">The code for this shader type, or null</param>
        /// <param name="tes">The code for this shader type, or null</param>
        /// <param name="geo">The code for this shader type, or null</param>
        /// <param name="frag">The code for this shader type, or null</param>
        /// <param name="vertexconstvars">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="tcsconstvars">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="tesconstvars">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="geoconstvars">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="fragconstvars">List of constant values to use. Set of {name,value} pairs</param>
        /// <param name="varyings">List of varyings to report</param>
        /// <param name="varymode">How to write the varying to the buffer</param>
        /// <param name="saveable">True if want to save to binary</param>

        public void CompileLink(string vertex            = null, string tcs = null, string tes = null, string geo = null, string frag = null,
                                object[] vertexconstvars = null, object[] tcsconstvars          = null, object[] tesconstvars = null, object[] geoconstvars = null, object[] fragconstvars = null,
                                string[] varyings        = null, TransformFeedbackMode varymode = TransformFeedbackMode.InterleavedAttribs, bool saveable = false
                                )
        {
            Program = new GLProgram();

            string ret;

            if (vertex != null)
            {
                ret = Program.Compile(ShaderType.VertexShader, vertex, vertexconstvars);
                System.Diagnostics.Debug.Assert(ret == null, "Vertex Shader", ret);
            }

            if (tcs != null)
            {
                ret = Program.Compile(ShaderType.TessControlShader, tcs, tcsconstvars);
                System.Diagnostics.Debug.Assert(ret == null, "Tesselation Control Shader", ret);
            }

            if (tes != null)
            {
                ret = Program.Compile(ShaderType.TessEvaluationShader, tes, tesconstvars);
                System.Diagnostics.Debug.Assert(ret == null, "Tesselation Evaluation Shader", ret);
            }

            if (geo != null)
            {
                ret = Program.Compile(ShaderType.GeometryShader, geo, geoconstvars);
                System.Diagnostics.Debug.Assert(ret == null, "Geometry shader", ret);
            }

            if (frag != null)
            {
                ret = Program.Compile(ShaderType.FragmentShader, frag, fragconstvars);
                System.Diagnostics.Debug.Assert(ret == null, "Fragment Shader", ret);
            }


            ret = Program.Link(false, varyings, varymode, saveable);
            System.Diagnostics.Debug.Assert(ret == null, "Link", ret);

            GLStatics.Check();
        }
Exemple #17
0
        public static Filter Renderer(GLProgram program)
        {
            var filter = new TextureFilter (program);

            return React.By<Tuple<Texture, Texture>> (t =>
                filter._program.DrawElements (PrimitiveType.Triangles, filter._vertexBuffer,
                    filter._indexBuffer))
                .BindSamplers (t => new Dictionary<Sampler, Texture> ()
                {
                    { (!filter._uniforms.textureMap), t.Item1 }
                })
                .Viewport (t => t.Item2.Size)
                .Culling ()
                .Program (program)
                .Texture (t => t.Item1)
                .FramebufferTexture (t => Tuple.Create (filter._framebuffer,
                    FramebufferAttachment.ColorAttachment0, t.Item2));
        }
Exemple #18
0
        public static Filter Renderer(GLProgram program)
        {
            var filter = new TextureFilter(program);

            return(React.By <Tuple <Texture, Texture> > (t =>
                                                         filter._program.DrawElements(PrimitiveType.Triangles, filter._vertexBuffer,
                                                                                      filter._indexBuffer))
                   .BindSamplers(t => new Dictionary <Sampler, Texture> ()
            {
                { (!filter._uniforms.textureMap), t.Item1 }
            })
                   .Viewport(t => t.Item2.Size)
                   .Culling()
                   .Program(program)
                   .Texture(t => t.Item1)
                   .FramebufferTexture(t => Tuple.Create(filter._framebuffer,
                                                         FramebufferAttachment.ColorAttachment0, t.Item2)));
        }
Exemple #19
0
        public static Reaction <Camera> Renderer(Texture diffuseMap, Texture normalMap, Texture heightMap)
        {
            _materialShader = new GLProgram(
                VertexShader(),
                FragmentShader());
            _materials = new Materials(_materialShader);

            return(React.By <Camera> (_materials.Render)
                   .BindSamplers(new Dictionary <Sampler, Texture> ()
            {
                { !_materials.diffuseMap, diffuseMap },
                { !_materials.normalMap, normalMap },
                { !_materials.heightMap, heightMap }
            })
                   .DepthTest()
                   .Culling()
                   .Program(_materialShader));
        }
Exemple #20
0
        void Init()
        {
            Console.WriteLine(GL.GetString(StringName.Renderer));
            Console.WriteLine(GL.GetString(StringName.Version));

            AssetLoader.Init();
            RenderCore.Create();
            GameLoop                   = new GameLoop(this);
            EditorLoop                 = new GameLoop(this);
            DisplayRT                  = new RenderTexture();
            FullscreenQuadProgram      = ShaderUtils.CreateFromResource("RasterDraw.Shaders.SimpleVert.glsl", "RasterDraw.Shaders.SimpleFrag.glsl");
            PhysicsEngine              = new PhysicsManager();
            EditorManager              = new EditorManager(ClientSize);
            EditorManager.GameGameLoop = GameLoop;
            GameObject editorManager = new GameObject("Editor Manager");

            editorManager.AddScript(EditorManager);
            EditorManager.Enabled = false;
            EditorLoop.Add(editorManager);
        }
Exemple #21
0
        public static Reaction <Camera> Renderer(SceneGraph sceneGraph, Vec3 skyCol,
                                                 CascadedShadowUniforms shadowSource)
        {
            _terrainShader = new GLProgram(VertexShader(), FragmentShader());
            _terrain       = new Terrain(_terrainShader, sceneGraph, skyCol);
            var sandTexture  = LoadTexture("Sand");
            var rockTexture  = LoadTexture("Rock");
            var grassTexture = LoadTexture("Grass");

            return(React.By((Camera cam) => _terrain.Render(cam, shadowSource))
                   .BindSamplers(new Dictionary <Sampler, Texture> ()
            {
                { !_terrain.shadows.csmShadowMap, sceneGraph.GlobalLighting.ShadowMap },
                { !_terrain.sandSampler, sandTexture },
                { !_terrain.rockSampler, rockTexture },
                { !_terrain.grassSampler, grassTexture }
            })
                   .DepthTest()
                   .Culling()
                   .Program(_terrainShader));
        }
Exemple #22
0
        public static Reaction<Camera> Renderer(SceneGraph sceneGraph, Vec3 skyColor)
        {
            _skyboxShader = new GLProgram (VertexShader (), FragmentShader ());
            _skybox = new Skybox (_skyboxShader);
            _skyColor = skyColor;
            var cube = Extrusion.Cube<PositionalVertex> (_cubeSize, _cubeSize, _cubeSize).Center ();
            _vertices = new VBO<PositionalVertex> (cube.Vertices, BufferTarget.ArrayBuffer);
            _indices = new VBO<int> (cube.Indices, BufferTarget.ElementArrayBuffer);
            var environmentMap = Texture.CubeMapFromFiles (
                _paths.Map (s => string.Format (@"Textures/{0}.bmp", s)), 0)
                .LinearFiltering ().ClampToEdges (Axes.All);
            sceneGraph.GlobalLighting.DiffuseMap = environmentMap;

            return React.By<Camera> (_skybox.Render)
                .BindSamplers (new Dictionary<Sampler, Texture> ()
                {
                    { !_skybox.cubeMap, environmentMap }
                })
                .Culling (CullFaceMode.Front)
                .Program (_skyboxShader);
        }
Exemple #23
0
        public static Reaction <Camera> Renderer(SceneGraph sceneGraph, Vec3 skyColor)
        {
            _skyboxShader = new GLProgram(VertexShader(), FragmentShader());
            _skybox       = new Skybox(_skyboxShader);
            _skyColor     = skyColor;
            var cube = Extrusion.Cube <PositionalVertex> (_cubeSize, _cubeSize, _cubeSize).Center();

            _vertices = new VBO <PositionalVertex> (cube.Vertices, BufferTarget.ArrayBuffer);
            _indices  = new VBO <int> (cube.Indices, BufferTarget.ElementArrayBuffer);
            var environmentMap = Texture.CubeMapFromFiles(
                _paths.Map(s => string.Format(@"Textures/{0}.bmp", s)), 0)
                                 .LinearFiltering().ClampToEdges(Axes.All);

            sceneGraph.GlobalLighting.DiffuseMap = environmentMap;

            return(React.By <Camera> (_skybox.Render)
                   .BindSamplers(new Dictionary <Sampler, Texture> ()
            {
                { !_skybox.cubeMap, environmentMap }
            })
                   .Culling(CullFaceMode.Front)
                   .Program(_skyboxShader));
        }
Exemple #24
0
 private Skybox(GLProgram program) : base(program)
 {
     using (program.Scope())
         cubeMap &= new SamplerCube(0).LinearFiltering().ClampToEdges(Axes.All);
 }
Exemple #25
0
 public ShadowUniforms(GLProgram program)
     : base(program)
 {
 }
 /// <summary> Load the binary into the shader </summary>
 public void Load(byte[] bin, BinaryFormat binformat)
 {
     Program = new GLProgram(bin, binformat);
 }
Exemple #27
0
 public TextureUniforms(GLProgram program, Sampler2D sampler) : base(program)
 {
     using (program.Scope())
         textureMap &= sampler;
 }
Exemple #28
0
 public CascadedShadowUniforms(GLProgram program) : base(program)
 {
 }
Exemple #29
0
 public ShadowUniforms(GLProgram program) : base(program)
 {
 }
Exemple #30
0
 public CascadedShadowUniforms(GLProgram program)
     : base(program)
 {
 }
Exemple #31
0
 public Materials(GLProgram program)
     : base(program)
 {
     using (program.Scope ())
     {
         transforms = new TransformUniforms (program);
         diffuseMap &= new Sampler2D (0).LinearFiltering ().ClampToEdges (Axes.All);
         normalMap &= new Sampler2D (1).LinearFiltering ().ClampToEdges (Axes.All);
     }
 }
Exemple #32
0
 private MaterialPanels(GLProgram program)
     : base(program)
 {
     Texture   = new TextureUniforms(_panelShader, new Sampler2D(0).NearestColor());
     Transform = new TransformUniforms(_panelShader);
 }
Exemple #33
0
 public static Reaction <T> Program <T> (this Reaction <T> render, GLProgram program)
 {
     return(render.Program(i => program));
 }
Exemple #34
0
 public ShadowUniforms(GLProgram program, Sampler2D sampler)
     : base(program)
 {
     using (program.Scope ())
         shadowMap &= sampler;
 }
Exemple #35
0
 public LightingUniforms(GLProgram program, SceneGraph scene)
     : base(program)
 {
     using (program.Scope ())
     {
         var gl = scene.GlobalLighting;
         if (gl != null)
         {
             globalLighting &= new LightingShaders.GlobalLight ()
             {
                 ambientLightIntensity = gl.AmbientLightIntensity,
                 maxintensity = gl.MaxIntensity,
                 inverseGamma = 1f / gl.GammaCorrection
             };
         }
     }
 }
Exemple #36
0
 private Skybox(GLProgram program)
     : base(program)
 {
     using (program.Scope ())
         cubeMap &= new SamplerCube (0).LinearFiltering ().ClampToEdges (Axes.All);
 }
Exemple #37
0
        public static Reaction<Camera> Renderer(Texture diffuseMap, Texture normalMap)
        {
            _materialShader = new GLProgram (
                VertexShader (),
                FragmentShader ());
            _materials = new Materials (_materialShader);

            return React.By<Camera> (_materials.Render)
                .BindSamplers (new Dictionary<Sampler, Texture> ()
                {
                    { !_materials.diffuseMap, diffuseMap },
                    { !_materials.normalMap, normalMap }
                })
                .DepthTest ()
                .Culling ()
                .Program (_materialShader);
        }
Exemple #38
0
 public CascadedShadowUniforms(GLProgram program, Sampler2DArray sampler)
     : base(program)
 {
     using (program.Scope ())
         csmShadowMap &= sampler;
 }
Exemple #39
0
 public ShadowUniforms(GLProgram program, Sampler2D sampler) : base(program)
 {
     using (program.Scope())
         shadowMap &= sampler;
 }
Exemple #40
0
        public static Reaction<Camera> Renderer(SceneGraph scene,
			int mapSize, ShadowMapType type, bool cascaded)
        {
            var depthFramebuffer = new Framebuffer (FramebufferTarget.Framebuffer);
            _shadowShader = cascaded ?
                new GLProgram (
                    VertexShaderCascaded (),
                    GeometryShaderCascaded (),
                    DepthFragmentShader ()) :
                new GLProgram (
                    VertexShader (),
                    type == ShadowMapType.Depth ? DepthFragmentShader () : VarianceFragmentShader ());

            _instance = new Shadows (_shadowShader, cascaded);

            Texture depthTexture;
            var render =React.By<Camera> (_instance.Render);
            if (type == ShadowMapType.Depth || cascaded)
            {
                depthTexture = cascaded ?
                    new Texture (TextureTarget.Texture2DArray, PixelInternalFormat.DepthComponent16,
                        mapSize, mapSize, CascadedShadowUniforms.MapCount, PixelFormat.DepthComponent,
                        PixelType.Float, IntPtr.Zero) :
                    new Texture (TextureTarget.Texture2D, PixelInternalFormat.DepthComponent16,
                        mapSize, mapSize, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);
                depthFramebuffer.AddTexture (FramebufferAttachment.DepthAttachment, depthTexture);
            }
            else
            {
                depthTexture = new Texture (TextureTarget.Texture2D, PixelInternalFormat.Rg32f,
                    mapSize, mapSize, PixelFormat.Rg, PixelType.Float, IntPtr.Zero);
                depthFramebuffer.AddTexture (FramebufferAttachment.ColorAttachment0, depthTexture);
                depthFramebuffer.AddRenderbuffer (FramebufferAttachment.DepthAttachment,
                    RenderbufferStorage.DepthComponent16, mapSize, mapSize);
                var gaussTexture = new Texture (TextureTarget.Texture2D, PixelInternalFormat.Rg32f,
                    mapSize / 2, mapSize / 2, PixelFormat.Rg, PixelType.Float, IntPtr.Zero);
                render = render.And (GaussianFilter.Both ().MapInput ((Camera cam) =>
                    Tuple.Create (depthTexture, gaussTexture)));
            }
            scene.GlobalLighting.ShadowMap = depthTexture;

            return render
                .DrawBuffer (type == ShadowMapType.Depth ? DrawBufferMode.None : DrawBufferMode.Front)
                .DepthTest ()
                .Culling ()
                .Viewport (new Vec2i (mapSize, mapSize))
                .Program (_shadowShader)
                .Texture (depthTexture)
                .Framebuffer (depthFramebuffer);
        }
Exemple #41
0
 public CascadedShadowUniforms(GLProgram program, Sampler2DArray sampler) : base(program)
 {
     using (program.Scope())
         csmShadowMap &= sampler;
 }
Exemple #42
0
 public TransformUniforms(GLProgram program) : base(program)
 {
 }