Ejemplo n.º 1
0
 private void EnvLight()
 {
     EnvLightShader.Use();
     EnvLightFramebuffer.Use();
     SetUniformsShared();
     EnableAdditiveBlending();
     GL.CullFace(CullFaceMode.Front);
     GL.Enable(EnableCap.TextureCubeMapSeamless);
     for (int i = 0; i < CubeMaps.Count; i++)
     {
         if (i == Game.World.CurrentlyRenderedCubeMap)
         {
             continue;
         }
         Matrix4 mat = Matrix4.CreateScale(CubeMaps[i].FalloffScale) * Matrix4.CreateTranslation(CubeMaps[i].FalloffScale > 99999.0f ? Camera.MainDisplayCamera.GetPosition() : CubeMaps[i].Position);
         CubeMaps[i].Texture.Use(TextureUnit.Texture23);
         EnvLightShader.SetUniform("ModelMatrix", mat);
         EnvLightShader.SetUniform("MapPosition", CubeMaps[i].FalloffScale > 99999.0f ? Camera.MainDisplayCamera.GetPosition() : CubeMaps[i].Position);
         EnvLightShader.SetUniform("CubeCutOff", CubeMaps[i].FalloffScale);
         CubeMapSphere.Draw();
     }
     GL.CullFace(CullFaceMode.Back);
     DisableBlending();
     Game.CheckErrors("Environment light pass");
 }
Ejemplo n.º 2
0
        public Renderer(int initialWidth, int initialHeight, int samples)
        {
            GlareTexture = new Texture(Media.Get("glaretex.png"));

            Voxelizer = new Voxel3dTextureWriter(256, 256, 256, new Vector3(22, 22, 22), new Vector3(0, 8, 0));

            CubeMapSphere = new Object3dInfo(Object3dManager.LoadFromObjSingle(Media.Get("cubemapsphere.obj")).Vertices);

            var cubeMapTexDefault = new CubeMapTexture(Media.Get("posx.jpg"), Media.Get("posy.jpg"), Media.Get("posz.jpg"),
                                                       Media.Get("negx.jpg"), Media.Get("negy.jpg"), Media.Get("negz.jpg"));

            CubeMaps.Add(new CubeMapInfo()
            {
                Texture      = cubeMapTexDefault,
                FalloffScale = 99999999.0f,
                Position     = Vector3.Zero
            });

            Width  = initialWidth;
            Height = initialHeight;


            Samples = samples;

            CreateBuffers();

            HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl");
            HDRShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                HDRShader.SetGlobal("USE_MSAA", "");
            }

            VXGIShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "VXGI.fragment.glsl");
            VXGIShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                VXGIShader.SetGlobal("USE_MSAA", "");
            }

            AmbientOcclusionShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "AmbientOcclusion.fragment.glsl");
            AmbientOcclusionShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                AmbientOcclusionShader.SetGlobal("USE_MSAA", "");
            }

            FogShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Fog.fragment.glsl");
            FogShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                FogShader.SetGlobal("USE_MSAA", "");
            }

            DeferredShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "Deferred.fragment.glsl");
            DeferredShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                DeferredShader.SetGlobal("USE_MSAA", "");
            }

            EnvLightShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "EnvironmentLight.fragment.glsl");
            EnvLightShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                EnvLightShader.SetGlobal("USE_MSAA", "");
            }

            CombinerShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Combiner.fragment.glsl");
            CombinerShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerShader.SetGlobal("USE_MSAA", "");
            }

            CombinerSecondShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "CombinerSecond.fragment.glsl");
            CombinerSecondShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerSecondShader.SetGlobal("USE_MSAA", "");
            }

            MotionBlurShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "MotionBlur.fragment.glsl");
            MotionBlurShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                MotionBlurShader.SetGlobal("USE_MSAA", "");
            }

            BloomShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Bloom.fragment.glsl");

            PostProcessingMesh          = new Object3dInfo(VertexInfo.FromFloatArray(postProcessingPlaneVertices));
            PostProcessingMesh.DrawMode = PrimitiveType.TriangleStrip;
        }