示例#1
0
        public void Draw(IRenderState renderState, ITexture2D depth, float mipmapLevel = 0)
        {
            _geometries[_entity.Type].SetAttribute(_environmentMapProgram.GetResourceLocation(ShaderResourceType.Attribute, "transform"), new[] { _entity.Transform }, true);

            GL.ClearColor(Color.FromArgb(0, 0, 0, 0));
            _outputSurface.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _environmentMapProgram.Activate();
            _environmentMapProgram.ActivateTexture("cubeMap", 0, _cubeFbo.Texture);
            _environmentMapProgram.ActivateTexture("depth", 1, depth);
            _environmentMapProgram.Uniform("camera", _camera);
            Matrix4x4.Invert(_camera.Matrix, out var invert);
            _environmentMapProgram.Uniform("camPos", invert.Translation / invert.M44);
            _environmentMapProgram.Uniform("mipmapLevel", mipmapLevel);

            _geometries[_entity.Type].Draw();

            _environmentMapProgram.DeactivateTexture(0, _cubeFbo.Texture);
            _environmentMapProgram.DeactivateTexture(1, depth);
            _environmentMapProgram.Deactivate();

            _outputSurface.Deactivate();
            GL.ClearColor(Color.FromArgb(0, 0, 0, 1));
        }
        public void ShowTexture(uint texture, Matrix4x4 viewMatrix, Matrix4x4 projectionMatrix)
        {
            cubeProjectionShader.Activate();
            SetSampler(cubeProjectionShader.ProgramID, 0, "equirectangularMap", texture);
            cubeProjectionShader.Uniform("projection", projectionMatrix, true);
            cubeProjectionShader.Uniform("view", viewMatrix, true);

            unitCube.Draw();
            DeactivateTexture(0);
            cubeProjectionShader.Deactivate();
            DeactivateTexture(0);
        }
示例#3
0
        public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, List <Enums.EntityType> disableBackFaceCulling)
        {
            _outputSurface.Activate();
            renderState.Set(new DepthTest(true));
            GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 });
            GL.DrawBuffers(4, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 });

            _deferredProgram.Activate();

            _deferredProgram.Uniform("camera", camera);
            Matrix4x4.Invert(camera.Matrix, out var invert);
            _deferredProgram.Uniform("camPos", invert.Translation / invert.M44);

            foreach (var type in _geometries.Keys)
            {
                if (instanceCounts[type] == 0)
                {
                    continue;
                }

                if (normalMaps.ContainsKey(type))
                {
                    _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]);
                }
                else
                {
                    _deferredProgram.ActivateTexture("normalMap", 1, _defaultMap);
                    _deferredProgram.Uniform("normalMapping", 0f);
                    _deferredProgram.Uniform("paralaxMapping", 0f);
                }

                if (textures.ContainsKey(type))
                {
                    _deferredProgram.ActivateTexture("tex", 0, textures[type]);
                    _deferredProgram.Uniform("textured", 1f);
                }
                else
                {
                    _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray);
                    _deferredProgram.Uniform("textured", 0f);
                }

                renderState.Set(disableBackFaceCulling.Contains(type)
                    ? new BackFaceCulling(false)
                    : new BackFaceCulling(true));

                _geometries[type].Draw(instanceCounts[type]);

                if (textures.ContainsKey(type))
                {
                    _deferredProgram.DeactivateTexture(0, textures[type]);
                }
            }

            renderState.Set(new DepthTest(false));
            renderState.Set(new BackFaceCulling(true));
            _outputSurface.Deactivate();
        }
        private void DrawShadowSurface(IRenderState renderState, Vector3 lightDirection, ITransformation lightCamera, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, List <Enums.EntityType> disableBackFaceCulling)
        {
            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _shadowShader.Activate();

            _depthSurface.Texture.WrapFunction = TextureWrapFunction.ClampToEdge;
            _depthSurface.Texture.Activate();
            _shadowShader.Uniform("lightDirection", lightDirection);
            _shadowShader.Uniform("lightCamera", lightCamera);
            _shadowShader.Uniform("camera", camera);

            GL.Uniform1(_shadowShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDepth"), 0);

            foreach (var type in _geometriesDepth.Keys)
            {
                if (disableBackFaceCulling.Contains(type))
                {
                    renderState.Set(new BackFaceCulling(false));
                }
                _geometriesShadow[type].Draw(instanceCounts[type]);
                renderState.Set(new BackFaceCulling(true));
            }

            _depthSurface.Texture.Deactivate();

            _shadowShader.Deactivate();

            _outputSurface.Deactivate();
        }
示例#5
0
        //Filter FBO2 and Write result in FBO1[0]
        private void ProcessFilterPass(ITexture2D sourceTexture, IRenderSurface fbo)
        {
            int halfKernelX = kernelSizeX / 2;
            int halfKernelY = kernelSizeY / 2;

            fbo.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            shaderSATFilter.Activate();

            int SATSampler = GL.GetUniformLocation(shaderSATFilter.ProgramID, "sourceSampler");

            GL.Uniform1(SATSampler, 0);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID);
            //sourceTexture.Activate();

            shaderSATFilter.Uniform("width", sourceTexture.Width);
            shaderSATFilter.Uniform("height", sourceTexture.Height);
            shaderSATFilter.Uniform("halfKernelX", halfKernelX);
            shaderSATFilter.Uniform("halfKernelY", halfKernelY);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            //sourceTexture.Deactivate();

            shaderSATFilter.Deactivate();

            fbo.Deactivate();
        }
示例#6
0
        private void SumValues(ITexture2D sourceTexture, IShaderProgram program, IRenderSurface fbo)
        {
            int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "sourceSampler");

            fbo.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            program.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Uniform1(SATSampler, 0);

            GL.ActiveTexture(TextureUnit.Texture0);

            GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID);
            program.Uniform("blockLengthX", blockSizeX);
            program.Uniform("blockLengthY", blockSizeX);
            program.Uniform("amountBlockX", amountBlocksX);
            program.Uniform("amountBlockY", amountBlocksX);
            //satFilter.GetFilterTexture().Activate();
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            //satFilter.GetFilterTexture().Deactivate();
            program.Deactivate();

            fbo.Deactivate();
        }
示例#7
0
        private void DrawShadowSurface(Vector3 lightDirection, ITransformation lightCamera, ITexture2D positions, ITexture2D normals)
        {
            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _shadowShader.Activate();

            _depthSurface.Texture.WrapFunction = TextureWrapFunction.ClampToEdge;

            _shadowShader.ActivateTexture("lightDepth", 0, _depthSurface.Texture);
            _shadowShader.ActivateTexture("positions", 1, positions);
            _shadowShader.ActivateTexture("normals", 2, normals);
            _shadowShader.Uniform("lightDirection", lightDirection);
            _shadowShader.Uniform("lightCamera", lightCamera);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            _shadowShader.DeactivateTexture(2, normals);
            _shadowShader.DeactivateTexture(1, positions);
            _shadowShader.DeactivateTexture(0, _depthSurface.Texture);

            _shadowShader.Deactivate();

            _outputSurface.Deactivate();
        }
        uint CreateIntegratedMap(int frameBuffer)
        {
            ErrorCode err = GL.GetError();

            renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE));
            uint integratedMap = (uint)GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, integratedMap);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rg16f, 512, 512, 0, PixelFormat.Rg, PixelType.Float, IntPtr.Zero);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);


            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, integratedMap, 0);

            GL.Viewport(0, 0, 512, 512);
            integrationMapShader.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            integrationMapShader.Deactivate();
            ErrorCode err1 = GL.GetError();

            return(integratedMap);
        }
示例#9
0
 internal void Draw()
 {
     GL.Clear(ClearBufferMask.ColorBufferBit);
     shader.Activate();
     draw();
     shader.Deactivate();
 }
        uint CreateIrradianceMap(int frameBuffer, Matrix4x4 projection, Matrix4x4[] viewMatrices, uint cubeMap)
        {
            DefaultMesh cubeMesh           = Meshes.CreateCubeWithNormals();
            VAO         renderIrradMapCube = VAOLoader.FromMesh(cubeMesh, irradianceMapShader);
            //Create Irradiance Texture
            int fbIrrWidth  = 32;
            int fbIrrHeight = 32;
            int irradMap    = CreateCubeMap(32, 32);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);
            //GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMap, irradMap, 0);
            //Render
            //Irradiance Map
            irradianceMapShader.Activate();
            SetSampler(irradianceMapShader.ProgramID, 0, "environmentMap", cubeMap, TextureTarget.TextureCubeMap);
            irradianceMapShader.Uniform("projection", projection, true);

            GL.Viewport(0, 0, fbIrrWidth, fbIrrHeight);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);
            for (int i = 0; i < 6; i++)
            {
                irradianceMapShader.Uniform("view", viewMatrices[i], true);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0,
                                        TextureTarget.TextureCubeMapPositiveX + i, irradMap, 0);

                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                renderIrradMapCube.Draw();
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            return((uint)irradMap);
        }
        void RenderUIElement(UIElement element)
        {
            renderstate.Set(new DepthTest(true));
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            uiShader.Activate();
            int hasTexture = 0;

            if (element.texture != null)
            {
                element.texture.Activate();
                hasTexture = 1;
            }

            uiShader.Uniform("hasTexture", hasTexture);
            uiShader.Uniform("scale", element.transform.scale);
            uiShader.Uniform("position", element.transform.position);
            uiShader.Uniform("elementColor", element.color);
            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            if (element.texture != null)
            {
                element.texture.Deactivate();
            }
            uiShader.Deactivate();
            GL.Disable(EnableCap.Blend);
        }
 public void ShowTexture2D(uint textureID)
 {
     textureTest.Activate();
     SetSampler(textureTest.ProgramID, 0, "text", currIBLMaps.ibl_BrdfIntegraionMap);
     GL.DrawArrays(PrimitiveType.Quads, 0, 4);
     DeactivateTexture(0);
     textureTest.Deactivate();
 }
示例#13
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(new DepthTest(true));

            shader = contentLoader.Load <IShaderProgram>("TerrainTessellation.*");
            shader.Activate();

            GL.PatchParameter(PatchParameterInt.PatchVertices, 4);
        }
示例#14
0
        public TessellationExample([Import] IContentLoader contentLoader, [Import] ITime time)
        {
            shader = contentLoader.Load <IShaderProgram>("Tessellation.*");
            shader.Activate();

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PatchParameter(PatchParameterInt.PatchVertices, 4);
            this.time = time;
        }
        void RenderScene(ITexture2D scene)
        {
            sceneShader.Activate();
            scene.Activate();

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);
            scene.Deactivate();
            sceneShader.Deactivate();
        }
        public void Draw(ITexture2D inputTexture)
        {
            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _postProcessShader.Activate();

            inputTexture.Activate();

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            inputTexture.Deactivate();

            _postProcessShader.Deactivate();

            _outputSurface.Deactivate();
        }
示例#17
0
        public MainVisual(IRenderState renderState, IContentLoader contentLoader)
        {
            renderState.Set(new DepthTest(true));

            shader = contentLoader.Load <IShaderProgram>("TerrainTessellation.*");
            shader.Activate();

            //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PatchParameter(PatchParameterInt.PatchVertices, 4);
        }
示例#18
0
        public void Draw(ITransformation camera, ITexture2D materialColor, ITexture2D normals, ITexture2D position, ITexture2D shadowSurface, ITexture2D intensity, List <LightSource> lightSources)
        {
            if (lightSources.Count > _lightArraySizeInShader)
            {
                throw new ArgumentException("A maximum of " + _lightArraySizeInShader + " light sources is possible. See shader 'deferredLighting.glsl' for details.");
            }

            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit);

            _shader.Activate();

            Matrix4x4.Invert(camera.Matrix, out var invert);
            _shader.Uniform("camPos", invert.Translation / invert.M44);
            _shader.Uniform("hemColorTop", new Vector3(0.9f, 0.9f, 1.0f));
            _shader.Uniform("hemColorBottom", new Vector3(41.0f / 255.0f, 49.0f / 255.0f, 51.0f / 255.0f));

            _shader.ActivateTexture("materialColor", 0, materialColor);
            _shader.ActivateTexture("normals", 1, normals);
            _shader.ActivateTexture("position", 2, position);
            _shader.ActivateTexture("shadowSurface", 3, shadowSurface);
            _shader.ActivateTexture("intensity", 4, intensity);

            var bufferObject = LightSourcesToBufferObject(lightSources);
            var loc          = _shader.GetResourceLocation(ShaderResourceType.RWBuffer, "Lights");

            bufferObject.ActivateBind(loc);


            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            _shader.DeactivateTexture(4, intensity);
            _shader.DeactivateTexture(3, shadowSurface);
            _shader.DeactivateTexture(2, position);
            _shader.DeactivateTexture(1, normals);
            _shader.DeactivateTexture(0, materialColor);

            _shader.Deactivate();

            _outputSurface.Deactivate();
        }
 private void Render()
 {
     if (shaderProgram is null)
     {
         return;
     }
     GL.Clear(ClearBufferMask.ColorBufferBit);
     shaderProgram.Activate();
     GL.DrawArrays(PrimitiveType.Quads, 0, 4);
     shaderProgram.Deactivate();
 }
示例#20
0
 private static void Update(IShaderProgram shaderProgram)
 {
     if (shaderProgram is null)
     {
         GL.UseProgram(0);
     }
     else
     {
         shaderProgram.Activate();
     }
 }
示例#21
0
        public void Draw(ITransformation camera, ITexture2D image, ITexture2D depth)
        {
            _outputSurface.Activate();
            GL.ClearColor(Color.FromArgb(0, 0, 0, 0));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _sphereCutProgram.Activate();

            _sphereCutProgram.ActivateTexture("image", 1, image);
            _sphereCutProgram.ActivateTexture("depth", 0, depth);

            _sphereCutProgram.Uniform("camera", camera);
            _sphereGeometry.Draw();

            _sphereCutProgram.DeactivateTexture(1, image);
            _sphereCutProgram.DeactivateTexture(0, depth);

            _sphereCutProgram.Deactivate();

            _outputSurface.Deactivate();
        }
示例#22
0
        public void CreateShadowMapParticle(Camera camera, Camera lightViewCamera, Renderable geometry, Vector3 lightDir, ParticleSystem particleSystem)
        {
            renderState.Set(new DepthTest(true));
            renderState.Set(new FaceCullingModeState(geometry.faceCullingMode));
            if (geometry.hasAlphaMap == 1)
            {
                GL.Enable(EnableCap.Blend);
                //GL.DepthMask(false);
            }
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            shadowMapShaderParticle.Activate();

            satFilter.GetFilterTexture().Activate();
            shadowMapShaderParticle.Uniform("shadowMapExponent", shadowExponent);
            shadowMapShaderParticle.Uniform("camera", camera.GetMatrix());
            shadowMapShaderParticle.Uniform("cameraViewMatrix", camera.GetViewMatrix());
            shadowMapShaderParticle.Uniform("lightCamera", lightViewCamera.GetMatrix());
            shadowMapShaderParticle.Uniform("lightViewMatrix", lightViewCamera.GetViewMatrix());
            shadowMapShaderParticle.Uniform("lightDirection", lightDir);

            shadowMapShaderParticle.Uniform("hasAlphaMap", geometry.hasAlphaMap);

            int normalMap = GL.GetUniformLocation(shadowMapShaderParticle.ProgramID, "normalSampler");

            GL.Uniform1(normalMap, 1);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID);

            int alphaMap = GL.GetUniformLocation(shadowMapShaderParticle.ProgramID, "alphaSampler");

            GL.Uniform1(alphaMap, 2);
            GL.ActiveTexture(TextureUnit.Texture2);
            if (geometry.alphaMap != null)
            {
                GL.BindTexture(TextureTarget.Texture2D, geometry.alphaMap.ID);
            }

            //particleSystem.RegisterParticleData(shadowMapShaderParticle);
            geometry.GetMesh().Draw(particleSystem.NumberOfSpawnedParticles());

            //GL.ActiveTexture(TextureUnit.Texture0);
            //lightViewFBO.Textures[0].Deactivate();
            //satFilter.GetFilterTexture().Deactivate();
            shadowMapShaderParticle.Deactivate();
            //GL.DepthMask(true);
            GL.Disable(EnableCap.Blend);
            renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE));
            renderState.Set(new DepthTest(false));
        }
示例#23
0
        internal void Draw(ITransformation camera, Vector3 cameraPos)
        {
            void SetWorld(ITransformation transform) => shader.Uniform("world", transform);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shader.Activate();
            shader.Uniform(nameof(cameraPos), cameraPos);
            shader.Uniform(nameof(camera), camera);
            model.Draw((float)time.Elapsed.TotalSeconds, SetWorld);
            shader.Deactivate();

            if (time.ElapsedMilliseconds > 5000)
            {
                time.Restart();
            }
        }
示例#24
0
        public void PointLightPass(Matrix4x4 cameraMatrix, Vector3 cameraPosition, Vector3 cameraDirection)
        {
            pointLightFBO.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            renderState.Set(new DepthTest(false));
            renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE));
            renderState.Set(BlendStates.Additive);
            pointLightShader.Activate();

            int position = GL.GetUniformLocation(pointLightShader.ProgramID, "positionSampler");
            int albedo   = GL.GetUniformLocation(pointLightShader.ProgramID, "albedoSampler");
            int normal   = GL.GetUniformLocation(pointLightShader.ProgramID, "normalSampler");

            GL.Uniform1(position, 1);
            GL.Uniform1(albedo, 2);
            GL.Uniform1(normal, 3);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[0].ID);
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[1].ID);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID);


            pointLightShader.Uniform("camera", cameraMatrix);
            pointLightShader.Uniform("cameraPosition", cameraPosition);
            pointLightShader.Uniform("camDir", cameraDirection);
            GL.ActiveTexture(TextureUnit.Texture0);
            pointLightFBO.Textures[0].Activate();

            DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[1];

            drawBuffers[0] = DrawBuffersEnum.ColorAttachment0;
            GL.DrawBuffers(1, drawBuffers);

            pointLightSphere.Draw(pointLightAmount);

            GL.ActiveTexture(TextureUnit.Texture0);
            pointLightFBO.Textures[0].Deactivate();

            pointLightShader.Deactivate();
            renderState.Set(BlendStates.Opaque);
            renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE));
            renderState.Set(new DepthTest(false));
            pointLightFBO.Deactivate();
        }
        uint CreatePrefilteredMap(int frameBuffer, Matrix4x4 projection, Matrix4x4[] viewMatrices, uint cubeMap)
        {
            DefaultMesh cubeMesh            = Meshes.CreateCubeWithNormals();
            VAO         renderPrefilterCube = VAOLoader.FromMesh(cubeMesh, prefilterMapShader);
            int         texResX             = 128;
            int         texResY             = 128;

            int prefiltMap = CreateCubeMap(texResX, texResY);

            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);


            prefilterMapShader.Activate();

            SetSampler(prefilterMapShader.ProgramID, 0, "environmentMap", cubeMap, TextureTarget.TextureCubeMap);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);


            prefilterMapShader.Uniform("projection", projection, true);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);
            int maxMipLvl = 5;

            for (int i = 0; i < maxMipLvl; i++)
            {
                float mipWidth  = texResX * (float)Math.Pow(0.5, i);
                float mipHeight = texResY * (float)Math.Pow(0.5, i);
                GL.Viewport(0, 0, (int)mipWidth, (int)mipHeight);

                float roughness = (float)i / (float)(maxMipLvl - 1.0);
                prefilterMapShader.Uniform("roughness", roughness);
                for (int j = 0; j < 6; j++)
                {
                    prefilterMapShader.Uniform("view", viewMatrices[j], true);
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0,
                                            TextureTarget.TextureCubeMapPositiveX + j, prefiltMap, i);

                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    renderPrefilterCube.Draw();
                }
            }
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            return((uint)prefiltMap);
        }
        protected void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader)
        {
            surface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit);

            shader.Activate();

            inputTexture.Activate();

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            inputTexture.Deactivate();

            shader.Deactivate();

            surface.Deactivate();
        }
示例#27
0
 private void WpfOpenGLControl_GlRender(object sender, EventArgs e)
 {
     if (!glControl.ValidOpenGLContext)
     {
         return;
     }
     CheckShaderReload();
     shader.Activate();
     //set all changed uniforms
     foreach (var setter in uniformSetters.Values)
     {
         setter.Invoke();
     }
     uniformSetters.Clear();
     //draw quad
     GL.DrawArrays(PrimitiveType.Quads, 0, 4);
     shader.Deactivate();
 }
示例#28
0
        public void CreateMaps(float time)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            mapFBO.Activate();

            waterMapShader.Activate();
            waterMapShader.Uniform("time", time);
            waterMapShader.Uniform("numberOfWaves", numberOfWaves);
            int buffer = waterMapShader.GetResourceLocation(ShaderResourceType.RWBuffer, "WavesBuffer");

            waveBuffer.ActivateBind(buffer);

            //Activate Textures of FBO
            int textAmount = mapFBO.Textures.Count; //Number of Texture Channels of FBO

            for (int i = 0; i < textAmount; i++)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + i);
                mapFBO.Textures[i].Activate();
            }

            DrawBuffersEnum[] buffers = new DrawBuffersEnum[textAmount];
            for (int i = 0; i < textAmount; i++)
            {
                buffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
            }

            GL.DrawBuffers(textAmount, buffers);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            waveBuffer.Deactivate();

            for (int i = textAmount - 1; i >= 0; i--)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + i);
                mapFBO.Textures[i].Deactivate();
            }

            waterMapShader.Deactivate();

            mapFBO.Deactivate();
        }
示例#29
0
        private new void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader)
        {
            surface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit);

            shader.Activate();
            shader.Uniform("Size", _blurKernelSize);

            inputTexture.Activate();

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            inputTexture.Deactivate();

            shader.Deactivate();

            surface.Deactivate();
        }
示例#30
0
        public void Draw(ITexture2D texOne, ITexture2D texTwo, float factor = 1)
        {
            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _addProgram.Activate();
            _addProgram.ActivateTexture("image1", 0, texOne);
            _addProgram.ActivateTexture("image2", 1, texTwo);
            _addProgram.Uniform("factor", factor);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            _addProgram.DeactivateTexture(1, texTwo);
            _addProgram.DeactivateTexture(0, texOne);

            _addProgram.Deactivate();

            _outputSurface.Deactivate();
        }