Exemplo n.º 1
0
        static void InitTextures()
        {
            CubeMapTextureID = GLTextureCubeArray.FromDDS(new DDS($"Resources\\CubemapHDR.dds"));

            DiffuseCubeTextureID = GLTextureCube.FromDDS(
                new DDS(new MemoryStream(Resources.CubemapLightmap)),
                new DDS(new MemoryStream(Resources.CubemapLightmapShadow)));

            SpecularCubeTextureID = GLTextureCube.CreateEmptyCubemap(32);

            LightingEngine.LightSettings.InitTextures();

            DepthShadowCascadeTextureID = GLTexture2D.FromBitmap(Resources.white);
            ProjectionTextureID         = GLTexture2D.FromBitmap(Resources.white);
            User1Texture = GLTexture2D.FromBitmap(Resources.white);

            //Adjust mip levels
            CubeMapTextureID.Bind();
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureBaseLevel, 0);
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureMaxLevel, 13);
            CubeMapTextureID.Unbind();

            DiffuseCubeTextureID.Bind();
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(CubeMapTextureID.Target, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(DiffuseCubeTextureID.Target, TextureParameterName.TextureBaseLevel, 0);
            GL.TexParameter(DiffuseCubeTextureID.Target, TextureParameterName.TextureMaxLevel, 2);
            DiffuseCubeTextureID.Unbind();
        }
Exemplo n.º 2
0
        public void GenerateLightmap(GLContext control, EnvironmentGraphics env, string name)
        {
            GLTextureCube output = GLTextureCube.CreateEmptyCubemap(
                32, PixelInternalFormat.Rgb32f, PixelFormat.Rgb, PixelType.Float, 2);

            //Allocate mip data. Need 2 seperate mip levels
            output.Bind();
            output.MinFilter = TextureMinFilter.LinearMipmapLinear;
            output.MagFilter = TextureMagFilter.Linear;
            output.UpdateParameters();
            output.GenerateMipmaps();
            output.Unbind();

            if (Lightmaps.ContainsKey(name))
            {
                Lightmaps[name]?.Dispose();
            }

            if (!Lightmaps.ContainsKey(name))
            {
                Lightmaps.Add(name, output);
            }

            LightmapManager.CreateLightmapTexture(control, this, env, name, output);

            Lightmaps[name] = output;
        }
        public void UpdateProbeLighting(GLContext control)
        {
            return;

            if (!UpdateProbeMap || TurboNXRender.DiffuseLightmapTexture == null /*|| Transform.Position == Vector3.Zero*/)
            {
                return;
            }

            if (DiffuseProbeTexture == null)
            {
                DiffuseProbeTexture = GLTextureCube.CreateEmptyCubemap(
                    32, PixelInternalFormat.Rgb32f, PixelFormat.Rgb, PixelType.Float, 2);

                //Allocate mip data. Need 2 seperate mip levels
                DiffuseProbeTexture.Bind();
                DiffuseProbeTexture.GenerateMipmaps();
                DiffuseProbeTexture.Unbind();
            }


            Transform.Position = new Vector3(ProbeDebugger.Position.X, ProbeDebugger.Position.Y, ProbeDebugger.Position.Z);
            Transform.UpdateMatrix(true);

            var output = LightingEngine.LightSettings.UpdateProbeCubemap(control,
                                                                         DiffuseProbeTexture, new Vector3(
                                                                             ProbeDebugger.Position.X,
                                                                             ProbeDebugger.Position.Y,
                                                                             ProbeDebugger.Position.Z));

            if (output == null)
            {
                return;
            }

            ProbeDebugger.Generated = output.Generated;

            if (output.Generated)
            {
                ProbeDebugger.probeData = output.ProbeData;
            }

            ProbeDebugger.DiffuseProbeTexture = DiffuseProbeTexture;

            // DiffuseProbeTexture.SaveDDS("LIGHT_PROBE.dds");
            //  DiffuseProbeTexture.Save($"LIGHTMAP_PROBE.png");

            ProbeDebugger.ForceUpdate = false;
            UpdateProbeMap            = false;
        }
        //Update all existing cubemap uint objects
        public static void GenerateCubemaps(List <GenericRenderer> targetModels, bool isWiiU)
        {
            var texture = isWiiU ? CubeMapTextureArray : CubeMapTexture;

            if (texture != null)
            {
                texture.Dispose();
            }

            if (isWiiU)
            {
                texture = GLTexture2DArray.CreateUncompressedTexture(CUBEMAP_SIZE, CUBEMAP_SIZE, MAX_LAYER_COUNT * 6, MAX_MIP_LEVEL,
                                                                     PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
            }
            else
            {
                texture = GLTextureCubeArray.CreateEmptyCubemap(CUBEMAP_SIZE, MAX_LAYER_COUNT, MAX_MIP_LEVEL,
                                                                PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
            }

            GLTextureCube cubemapTexture = GLTextureCube.CreateEmptyCubemap(
                CUBEMAP_UPSCALE_SIZE, PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float, 9);

            //Get a list of cubemaps in the scene
            //The lighting engine has cube map objects with the object placement to draw
            var lightingEngine   = LightingEngine.LightSettings;
            var cubemapEnvParams = lightingEngine.Resources.CubeMapFiles.FirstOrDefault().Value;
            var cubeMapUints     = cubemapEnvParams.CubeMapObjects;
            int layer            = 0;

            foreach (var cubeMap in cubeMapUints)
            {
                var cUint = cubeMap.CubeMapUint;
                //Cubemap has no area assigned skip it
                if (cubeMap.CubeMapUint.Name == string.Empty)
                {
                    continue;
                }

                //Setup the camera to render the cube map faces
                CubemapCamera camera = new CubemapCamera(
                    new Vector3(cUint.Position.X, cUint.Position.Y, cUint.Position.Z)
                    * GLContext.PreviewScale, cUint.Near, cUint.Far);

                var context = new GLContext();
                context.Camera = camera;

                GenerateCubemap(context, cubemapTexture, camera, targetModels, MAX_MIP_LEVEL);

                cubemapTexture.Bind();
                cubemapTexture.GenerateMipmaps();
                cubemapTexture.Unbind();

                //HDR encode and output into the array
                CubemapHDREncodeRT.CreateCubemap(cubemapTexture, texture, layer, MAX_MIP_LEVEL, false, true);

                if (SAVE_TO_DISK)
                {
                    cubemapTexture.SaveDDS(cubeMap.Name + "default.dds");
                }

                layer++;
            }

            cubemapTexture.Dispose();

            //Just generate mips to keep things easier
            texture.Bind();
            texture.GenerateMipmaps();
            texture.Unbind();

            if (SAVE_TO_DISK)
            {
                texture.SaveDDS("Cubemap_Array_HDR.dds");
            }

            if (isWiiU)
            {
                CubeMapTextureArray = texture;
            }
            else
            {
                CubeMapTexture = texture;
            }
        }