コード例 #1
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            Texture texture = RgbmHelper.ConvertHdrTextureToRgbmOnlyRgb(new Texture("CubeTextures\\Desert-15_XXLResize"), 17);
            var     stream  = new FileStream("Desert-15_XXLResizeRGB.jpg", FileMode.OpenOrCreate);

            texture.Resource.SaveAsJpeg(stream, texture.Width, texture.Height);
            texture = RgbmHelper.ConvertHdrTextureToRgbmOnlyM(new Texture("CubeTextures\\Desert-15_XXLResize"), 17);
            stream  = new FileStream("Desert-15_XXLResizeM.jpg", FileMode.OpenOrCreate);
            texture.Resource.SaveAsJpeg(stream, texture.Width, texture.Height);
        } // Load
コード例 #2
0
        } // GetWeightedAverageLightInputFromSphere

        private static SphericalHarmonicL2 ExtractSphericalHarmonicForCubeFace(Matrix faceTransform, Color[] colorDataRgb, int faceSize, bool isRgbm, float rgbmMaxRange)
        {
            SphericalHarmonicL2 sh = new SphericalHarmonicL2();

            // For each pixel in the face, generate it's SH contribution.
            // Treat each pixel in the cube as a light source, which gets added to the SH.
            // This is used to generate an indirect lighting SH for the scene.

            float directionStep = 2.0f / (faceSize - 1.0f);
            int   pixelIndex    = 0;

            float dirY = 1.0f;

            for (int y = 0; y < faceSize; y++)
            {
                SphericalHarmonicL2 lineSh = new SphericalHarmonicL2();
                float dirX = -1.0f;

                for (int x = 0; x < faceSize; x++)
                {
                    // The direction to the pixel in the cube.
                    Vector3 direction = new Vector3(dirX, dirY, 1);
                    Vector3.TransformNormal(ref direction, ref faceTransform, out direction);

                    // Length of the direction vector.
                    float length = direction.Length();
                    // Approximate area of the pixel (pixels close to the cube edges appear smaller when projected).
                    float weight = 1.0f / length;

                    direction.Normalize();

                    Vector3 rgbFloat;
                    if (isRgbm)
                    {
                        Color rgbm = colorDataRgb[pixelIndex++];
                        rgbFloat = RgbmHelper.RgbmGammaToFloatLinear(rgbm, rgbmMaxRange);
                    }
                    else
                    {
                        Color rgb = colorDataRgb[pixelIndex++];
                        rgbFloat = new Vector3(GammaLinearSpaceHelper.GammaToLinear(rgb).X, GammaLinearSpaceHelper.GammaToLinear(rgb).Y, GammaLinearSpaceHelper.GammaToLinear(rgb).Z);
                    }

                    //Add it to the SH
                    lineSh.AddLight(rgbFloat, direction, weight);

                    dirX += directionStep;
                }

                // Average the SH.
                if (lineSh.weighting > 0)
                {
                    lineSh *= 1 / lineSh.weighting;
                }

                // Add the line to the full SH
                // (SH is generated line by line to ease problems with floating point accuracy loss)
                sh += lineSh;

                dirY -= directionStep;
            }

            // Average the SH.
            if (sh.weighting > 0)
            {
                sh *= 1 / sh.weighting;
            }

            return(sh);
        } // ExtractSphericalHarmonicForCubeFace