Exemplo n.º 1
0
        /// <summary>
        /// функция коррекции которая принимает делегат и его параметр
        /// </summary>
        /// <param name="bmp">изображение</param>
        /// <param name="corrector">делегат функции (гамма,яркость,контраст и пр.)</param>
        /// <param name="correctorParam">параметр (гамма,яркость,контраст и пр.)</param>
        /// <returns>измененное изображение</returns>
        public static Bitmap Correction(Bitmap img, ColorCorrection corrector, short correctorParam)
        {
            Bitmap bmp = new Bitmap(img);
            // Lock the bitmap's bits.
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;
            // Declare an array to hold the bytes of the bitmap.
            int bytes = Math.Abs(bmpData.Stride) * bmp.Height;

            byte[] rgbValues = new byte[bytes];
            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
            // Set every third value to 255. A 24bpp bitmap will look red.
            for (int counter = 2; counter < rgbValues.Length; counter += 4)
            {
                RGB rgb = corrector.Invoke(rgbValues[counter - 2], rgbValues[counter - 1], rgbValues[counter], correctorParam);
                rgbValues[counter - 2] = rgb.R;
                rgbValues[counter - 1] = rgb.G;
                rgbValues[counter]     = rgb.B;
            }
            // Copy the RGB values back to the bitmap
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
            // Unlock the bits.
            bmp.UnlockBits(bmpData);

            return(bmp);
        }
        public static void Processor()
        {
            Console.Title = "Color Correction Converter";
            Program.Choose(1, "cct", out string[] fileNames);
            if (fileNames.Length < 1)
            {
                return;
            }

            string          filepath, ext;
            ColorCorrection cct;

            foreach (string file in fileNames)
            {
                using (cct = new ColorCorrection())
                {
                    ext      = Path.GetExtension(file);
                    filepath = file.Replace(ext, "");
                    ext      = ext.ToLower();

                    Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
                    if (ext == ".cct")
                    {
                        cct.CCTReader(filepath); cct.TXTWriter(filepath);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the <see cref="_colorCorrectionShader"/> <see cref="ColorCorrection"/> values.
        /// </summary>
        private void UpdateColorCorrection()
        {
            // Interpolate between the color correction settings for the different sun phases
            var correction = ColorCorrection.SinusInterpolate(Universe.LightPhase,
                                                              Universe.ColorCorrectionDawn, Universe.ColorCorrectionNoon, Universe.ColorCorrectionDusk, Universe.ColorCorrectionMidnight, Universe.ColorCorrectionDawn);

            // If the color correction values aren't all at default, activate the shader and transfer the values
            _colorCorrectionShader.Enabled    = (correction != ColorCorrection.Default);
            _colorCorrectionShader.Brightness = correction.Brightness;
            _colorCorrectionShader.Contrast   = correction.Contrast;
            _colorCorrectionShader.Saturation = correction.Saturation;
            _colorCorrectionShader.Hue        = correction.Hue;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YebisPlugin"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public YebisPlugin(string name) : base(name)
        {
            yebis           = new Manager();
            ToneMap         = yebis.Config.ToneMap;
            Glare           = yebis.Config.Glare;
            ColorCorrection = yebis.Config.ColorCorrection;
            Lens            = yebis.Config.Lens;
            DepthOfField    = yebis.Config.DepthOfField;
            HeatShimmer     = yebis.Config.HeatShimmer;
            LightShaft      = yebis.Config.LightShaft;
            PreferredFormat = PixelFormat.R16G16B16A16_Float;

            // Make sure that the Depth Stencil will be created with ShaderResource
            Tags.Set(RenderTargetKeys.RequireDepthStencilShaderResource, true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YebisPlugin"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public YebisPlugin(string name) : base(name)
        {
            yebis = new Manager();
            ToneMap = yebis.Config.ToneMap;
            Glare = yebis.Config.Glare;
            ColorCorrection = yebis.Config.ColorCorrection;
            Lens = yebis.Config.Lens;
            DepthOfField = yebis.Config.DepthOfField;
            HeatShimmer = yebis.Config.HeatShimmer;
            LightShaft = yebis.Config.LightShaft;
            PreferredFormat = PixelFormat.R16G16B16A16_Float;

            // Make sure that the Depth Stencil will be created with ShaderResource
            Tags.Set(RenderTargetKeys.RequireDepthStencilShaderResource, true);
        }
Exemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     foreach (part_ref_list pRL in partObjs)
     {
         if (car_parts.parts_init[(int)pRL.Part] == 0)
         {
             continue;
         }
         for (int i = 0; i < pRL.Refs.Count; i++)
         {
             bool setActive      = my_parts[playerID].val[(int)pRL.Part] > i;
             bool justEnabledNow = !(pRL.Refs[i].activeInHierarchy) && setActive;
             pRL.Refs[i].SetActive(setActive);
             if (justEnabledNow)
             {
                 ColorCorrection.correctColor(pRL.Refs[i].GetComponent <MeshRenderer>(), pickup_player_ids[playerID].val[(int)pRL.Part]);
             }
         }
     }
 }
Exemplo n.º 7
0
            public SystemData(StudioController game)
            {
                // export a dict contains all system status
                //from Studio import Studio
                //studio = Studio.Instance

                bgm = new BGM_s {
                    no = game.studio.bgmCtrl.no, play = game.studio.bgmCtrl.play
                };

                if (game.studio.outsideSoundCtrl.fileName != "")
                {
                    wav = new Wav_s {
                        fileName = game.studio.outsideSoundCtrl.fileName, play = game.studio.outsideSoundCtrl.play, repeat = game.studio.outsideSoundCtrl.repeat == BGMCtrl.Repeat.All
                    };
                }
                else
                {
                    wav = null;
                }

                map = game.studio_scene.mapInfo.no;

                map_pos   = game.studio_scene.mapInfo.ca.pos;
                map_rot   = game.studio_scene.mapInfo.ca.rot;
                map_light = game.studio_scene.mapInfo.light;
                map_opt   = game.studio_scene.mapInfo.option;

                bg_png = game.scene_get_bg_png_orig();

                fm_png = game.scene_get_framefile();

                var cl = game.studio_scene.charaLight;

                char_light = new CharLight_s {
                    rgbDiffuse = cl.color, cameraLightIntensity = cl.intensity, rot_y = cl.rot[0], rot_x = cl.rot[1], cameraLightShadow = cl.shadow
                };

                colorCorrection = System.colorCorrection;

                /* TODO
                 * if (game.isStudioNEO || game.isCharaStudio)
                 * {
                 *  if (extplugins.ExtPlugin.exists("NodesConstraints"))
                 *  {
                 *      if (is_ini_value_true("ExportSys_NodesConstraints"))
                 *      {
                 *          var pl_nodescon = extplugins.NodesConstraints();
                 *          pl_nodescon = pl_nodescon.GetSysSettingsText();
                 *      }
                 *  }
                 * }
                 * if (game.isNEOV2)
                 * {
                 *  if (extplugins.ExtPlugin.exists("DHH_AI4"))
                 *  {
                 *      if (is_ini_value_true("ExportSys_DHH"))
                 *      {
                 *          var pl_dhh = extplugins.DHH_AI();
                 *          pl_dhh = (pl_dhh.getEnable(), pl_dhh.exportGraphSetting());
                 *      }
                 *  }
                 * }
                 */
            }
Exemplo n.º 8
0
        public static void Processor(bool json)
        {
            Console.Title = "Color Correction Converter";
            Program.Choose(1, "cct", out string[] fileNames);
            if (fileNames.Length < 1)
            {
                return;
            }

            bool cc = false;

            foreach (string file in fileNames)
            {
                if (file.EndsWith(".cct"))
                {
                    cc = true; break;
                }
            }

            string choose = "";

            if (cc)
            {
                Console.Clear();
                Program.ConsoleDesign(true);
                Program.ConsoleDesign("          Choose type of format to export:");
                Program.ConsoleDesign(false);
                Program.ConsoleDesign("1. JSON");
                Program.ConsoleDesign("2. TXT");
                Program.ConsoleDesign(false);
                Program.ConsoleDesign(true);
                Console.WriteLine();
                choose = Console.ReadLine().ToUpper();
            }

            string          filepath, ext;
            ColorCorrection cct;

            foreach (string file in fileNames)
            {
                using (cct = new ColorCorrection())
                {
                    filepath = Path.RemoveExtension(file);
                    ext      = Path.GetExtension(file).ToLower();

                    Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
                    if (ext == ".cct")
                    {
                        cct.CCTReader(filepath);
                        if (choose == "2" && !cct.IsX)
                        {
                            cct.TXTWriter(filepath);
                        }
                        else
                        {
                            cct.MsgPackWriter(filepath, json);
                        }
                    }
                    else if (ext == ".json" || ext == ".mp")
                    {
                        cct.MsgPackReader(filepath, json);
                        cct.CCTWriter(filepath);
                    }
                }
            }
        }
Exemplo n.º 9
0
    public void SetColorCorrection(ref ColorCorrection colorCorrection)
    {
        if (s_logstack)
        {
            logger.Log("[INTEROP]SetColorCorrection");
        }
        if (instanceId == InvalidID)
        {
            return;
        }
        // these masks correspond to unmanaged ColorCorrectionParameter enum
        const uint maskBrightness = 0x0001;
        const uint maskContrast   = 0x0002;
        const uint maskSaturation = 0x0004;
        const uint maskGamma      = 0x0008;
        const uint maskHue        = 0x0010;
        const uint maskAlpha      = 0x0020;
        const uint maskTintR      = 0x0040;
        const uint maskTintG      = 0x0080;
        const uint maskTintB      = 0x0100;

        if (colorCorrection.hasBrightness)
        {
            InteropSetColorCorrectionFloat(instanceId, maskBrightness, colorCorrection.hasBrightness, colorCorrection.brightness);
        }

        if (colorCorrection.hasContrast)
        {
            InteropSetColorCorrectionFloat(instanceId, maskContrast, colorCorrection.hasContrast, colorCorrection.contrast);
        }

        if (colorCorrection.hasSaturation)
        {
            InteropSetColorCorrectionFloat(instanceId, maskSaturation, colorCorrection.hasSaturation, colorCorrection.saturation);
        }

        if (colorCorrection.hasGamma)
        {
            InteropSetColorCorrectionFloat(instanceId, maskGamma, colorCorrection.hasGamma, colorCorrection.gamma);
        }

        if (colorCorrection.hasHue)
        {
            InteropSetColorCorrectionFloat(instanceId, maskHue, colorCorrection.hasHue, colorCorrection.hue);
        }

        if (colorCorrection.hasAlpha)
        {
            InteropSetColorCorrectionFloat(instanceId, maskAlpha, colorCorrection.hasAlpha, colorCorrection.alpha);
        }

        if (colorCorrection.hasTintR)
        {
            InteropSetColorCorrectionFloat(instanceId, maskTintR, colorCorrection.hasTintR, colorCorrection.tintR);
        }

        if (colorCorrection.hasTintG)
        {
            InteropSetColorCorrectionFloat(instanceId, maskTintG, colorCorrection.hasTintG, colorCorrection.tintG);
        }

        if (colorCorrection.hasTintB)
        {
            InteropSetColorCorrectionFloat(instanceId, maskTintB, colorCorrection.hasTintB, colorCorrection.tintB);
        }
    }
Exemplo n.º 10
0
        private IEnumerator RefreshHeightmap(ChunkOrientationData chunkOrientation)
        {
            var terrainData = Terrain.terrainData;

            var unsafeOrientationTexture = new AsyncTextureUnsafe <Color32>(chunkOrientation.OrientationTexture);
            var unsafeWeightsTexture     = new AsyncTextureUnsafe <Color32>(chunkOrientation.WeightsTexture);
            var unsafeDuckTexture        = new AsyncTextureUnsafe <Color32>(chunkOrientation.DuckTexture);

            var unsafeFlatlandsNoise = new AsyncTextureUnsafe <Color32>(RenderConfig.FlatlandsElevationNoiseSource);
            var unsafeHillsNoise     = new AsyncTextureUnsafe <Color32>(RenderConfig.HillsElevationNoiseSource);

            Vector3 terrainSize = terrainData.size;

            int mapWidth  = terrainData.heightmapWidth;
            int mapHeight = terrainData.heightmapHeight;

            float[,] heights = terrainData.GetHeights(0, 0, mapWidth, mapHeight);

            float maxTextureNormalX = Width / RenderConfig.ChunkWidth;
            float maxTextureNormalZ = Height / RenderConfig.ChunkHeight;

            float indexToNormalX = 1f / (mapHeight - 1f);
            float indexToNormalZ = 1f / (mapWidth - 1f);

            Vector3 chunkPosition = transform.position;

            var columnTasks = new Task[mapHeight];

            for (int height = 0; height < mapHeight; height++)
            {
                int cachedHeight = height;

                var indexBytes = new byte[2];

                PointOrientationData pointOrientation = new PointOrientationData();

                var columnTask = new Task(() => {
                    for (int width = 0; width < mapWidth; width++)
                    {
                        float terrainNormalX, terrainNormalZ, textureNormalX, textureNormalZ, worldX, worldZ;

                        Color32 orientationColor;
                        Color weightsColor, duckColor;

                        //For some reason, terrainData seems to index its points
                        //as (y, x) rather than the more traditional (x, y), so
                        //we need to sample our texture accordingly
                        terrainNormalX = cachedHeight * indexToNormalX;
                        terrainNormalZ = width * indexToNormalZ;

                        worldX = chunkPosition.x + terrainNormalX * terrainSize.x;
                        worldZ = chunkPosition.z + terrainNormalZ * terrainSize.z;

                        textureNormalX = maxTextureNormalX * terrainNormalX;
                        textureNormalZ = maxTextureNormalZ * terrainNormalZ;

                        orientationColor = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeOrientationTexture));
                        weightsColor     = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeWeightsTexture));
                        duckColor        = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeDuckTexture));

                        PointOrientationLogic.GetOrientationDataFromColors(
                            pointOrientation, indexBytes, orientationColor, weightsColor, duckColor
                            );

                        heights[width, cachedHeight] = HeightLogic.GetHeightForPoint(
                            new Vector2(worldX, worldZ), pointOrientation, unsafeFlatlandsNoise, unsafeHillsNoise
                            );
                    }
                });

                columnTask.Start();

                columnTasks[cachedHeight] = columnTask;
            }

            while (columnTasks.Any(task => !task.IsCompleted))
            {
                yield return(SkipFrame);
            }

            terrainData.SetHeights(0, 0, heights);
        }
Exemplo n.º 11
0
        private IEnumerator RefreshAlphamap(ChunkOrientationData orientationData)
        {
            var terrainData = Terrain.terrainData;

            var unsafeOrientationTexture = new AsyncTextureUnsafe <Color32>(orientationData.OrientationTexture);
            var unsafeWeightsTexture     = new AsyncTextureUnsafe <Color32>(orientationData.WeightsTexture);
            var unsafeDuckTexture        = new AsyncTextureUnsafe <Color32>(orientationData.DuckTexture);

            Vector3 terrainSize = terrainData.size;

            int mapWidth  = terrainData.alphamapWidth;
            int mapHeight = terrainData.alphamapHeight;

            int alphamapLength = RenderConfig.MapTextures.Count();

            float[,,] alphaMaps = terrainData.GetAlphamaps(0, 0, mapWidth, mapHeight);

            float maxTextureNormalX = Width / RenderConfig.ChunkWidth;
            float maxTextureNormalZ = Height / RenderConfig.ChunkHeight;

            float indexToNormalX = 1f / (mapHeight - 1f);
            float indexToNormalZ = 1f / (mapWidth - 1f);

            Vector3 chunkPosition = transform.position;

            var columnTasks = new Task[mapHeight];

            for (int height = 0; height < mapHeight; height++)
            {
                int cachedHeight = height;

                var indexBytes = new byte[2];

                PointOrientationData pointOrientation = new PointOrientationData();

                float[] returnMap       = new float[RenderConfig.MapTextures.Count()];
                float[] intermediateMap = new float[RenderConfig.MapTextures.Count()];

                var columnTask = new Task(() => {
                    for (int width = 0; width < mapWidth; width++)
                    {
                        float terrainNormalX, terrainNormalZ, textureNormalX, textureNormalZ, worldX, worldZ;

                        Color32 orientationColor;
                        Color weightsColor, duckColor;

                        //For some reason, terrainData seems to index its points
                        //as (y, x) rather than the more traditional (x, y), so
                        //we need to sample our texture accordingly
                        terrainNormalX = cachedHeight * indexToNormalX;
                        terrainNormalZ = width * indexToNormalZ;

                        worldX = chunkPosition.x + terrainNormalX * terrainSize.x;
                        worldZ = chunkPosition.z + terrainNormalZ * terrainSize.z;

                        textureNormalX = maxTextureNormalX * terrainNormalX;
                        textureNormalZ = maxTextureNormalZ * terrainNormalZ;

                        orientationColor = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeOrientationTexture));
                        weightsColor     = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeWeightsTexture));
                        duckColor        = ColorCorrection.ARGB_To_RGBA(RawTextureSampler.SamplePoint(textureNormalX, textureNormalZ, unsafeDuckTexture));

                        PointOrientationLogic.GetOrientationDataFromColors(
                            pointOrientation, indexBytes, orientationColor, weightsColor, duckColor
                            );

                        AlphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, pointOrientation);

                        for (int alphaIndex = 0; alphaIndex < alphamapLength; alphaIndex++)
                        {
                            alphaMaps[width, cachedHeight, alphaIndex] = returnMap[alphaIndex];
                        }
                    }
                });

                columnTask.Start();

                columnTasks[cachedHeight] = columnTask;
            }

            while (columnTasks.Any(task => !task.IsCompleted))
            {
                yield return(SkipFrame);
            }

            terrainData.SetAlphamaps(0, 0, alphaMaps);
        }
Exemplo n.º 12
0
    private void UpdatePostProcess()
    {
        foreach (Camera cam in Camera.allCameras)
        {
            SMAA                   defAntiAlias = cam.GetComponent <SMAA>();
            Bloom                  b            = cam.GetComponent <Bloom>();
            BloomAndFlares         baf          = cam.GetComponent <BloomAndFlares>();
            ContrastEnhance        ce           = cam.GetComponent <ContrastEnhance>();
            MotionBlur             mb           = cam.GetComponent <MotionBlur>();
            WeaponDepthOfField     wdof         = cam.GetComponent <WeaponDepthOfField>();
            SunShafts              ss           = cam.GetComponent <SunShafts>();
            AmplifyOcclusionEffect ao           = cam.GetComponent <AmplifyOcclusionEffect>();
            ColorCorrection        ccc          = cam.GetComponent <ColorCorrection>();

            if (defAntiAlias)
            {
                defAntiAlias.enabled = (antiAliasing == 1);
            }

            if (wdof)
            {
                wdof.enabled = (wDepthOfField == 1);
            }

            bool bloomBool = (bloom == 1);
            if (baf)
            {
                baf.enabled = bloomBool;
            }
            if (b)
            {
                b.enabled = bloomBool;
            }

            if (ss)
            {
                ss.enabled = (sunShafts == 1);
            }
            if (mb)
            {
                mb.enabled = (motionBlur == 1);
            }

            bool ssaoBool = (SSAO == 1);
            if (ao)
            {
                ao.enabled = ssaoBool;
            }

            bool ccBool = (colorCorrection == 1);
            if (ccc)
            {
                ccc.enabled = ccBool;
            }
            if (ce)
            {
                ce.enabled = ccBool;
            }
        }

        lastPP      = Time.unscaledTime;
        cameraCount = Camera.allCameras.Length;
    }