public static void ConvertColourGradingViaLUT(PostProcessProfile ppp,
                                                  ColorGradingModel oldColorGradingSettings, PostProcessingProfile oldPPP)
    {
        var materialFactory = new MaterialFactory();

        var uberShader = materialFactory.Get("Hidden/Post FX/Uber Shader");

        uberShader.shaderKeywords = new string[0];

        var cgc = new ColorGradingComponent();

        cgc.Init(new PostProcessingContext
        {
            materialFactory = materialFactory
        }, oldColorGradingSettings);

        cgc.context.profile = oldPPP;

        cgc.Prepare(uberShader);

        var cg = ppp.AddSettings <ColorGrading>();

        cg.gradingMode.value         = GradingMode.LowDefinitionRange;
        cg.gradingMode.overrideState = true;

        var lut = cgc.model.bakedLut;

        /*
         * var textureFormat = TextureFormat.RGBAHalf;
         * if (!SystemInfo.SupportsTextureFormat(textureFormat))
         *  textureFormat = TextureFormat.ARGB32;
         *
         * var lutAsT2D = lut.GrabTexture(dontUseCopyTexture: true, format: textureFormat).GetPixels();
         *
         * for (int i = 0; i < lutAsT2D.Length; i++)
         * {
         *  lutAsT2D[i] = lutAsT2D[i].gamma;
         * }
         *
         * var newLut = new Texture2D(lut.width, lut.height, textureFormat, false, true);
         * newLut.SetPixels(lutAsT2D);
         * newLut.Apply(true, false);
         */

        cg.ldrLut.value = lut;//newLut;//TextureCompositor.GPUDegamma(newLut, null, true);

        cg.ldrLut.overrideState = true;

        cg.ldrLutContribution.value         = 1.0f;
        cg.ldrLutContribution.overrideState = true;

        var exposure = ppp.AddSettings <AutoExposure>();

        exposure.eyeAdaptation.value         = EyeAdaptation.Fixed;
        exposure.eyeAdaptation.overrideState = true;
        exposure.keyValue.value         = 1.0f;
        exposure.keyValue.overrideState = true;
    }
Beispiel #2
0
        void OnPreCull()
        {
            // All the per-frame initialization logic has to be done in OnPreCull instead of Update
            // because [ImageEffectAllowedInSceneView] doesn't trigger Update events...

            m_Camera = GetComponent <Camera>();

            if (profile == null || m_Camera == null)
            {
                return;
            }

#if UNITY_EDITOR
            // Track the scene view camera to disable some effects we don't want to see in the
            // scene view
            // Currently disabled effects :
            //  - Temporal Antialiasing
            //  - Depth of Field
            //  - Motion blur
            m_RenderingInSceneView = UnityEditor.SceneView.currentDrawingSceneView != null &&
                                     UnityEditor.SceneView.currentDrawingSceneView.camera == m_Camera;
#endif

            // Prepare context
            var context = m_Context.Reset();
            context.profile = profile;
            context.renderTextureFactory = m_RenderTextureFactory;
            context.materialFactory      = m_MaterialFactory;
            context.camera = m_Camera;

            // Prepare components
            m_DebugViews.Init(context, profile.debugViews);
            m_AmbientOcclusion.Init(context, profile.ambientOcclusion);
            m_ScreenSpaceReflection.Init(context, profile.screenSpaceReflection);
            m_FogComponent.Init(context, profile.fog);
            m_MotionBlur.Init(context, profile.motionBlur);
            m_Taa.Init(context, profile.antialiasing);
            m_EyeAdaptation.Init(context, profile.eyeAdaptation);
            m_DepthOfField.Init(context, profile.depthOfField);
            m_Bloom.Init(context, profile.bloom);
            m_ChromaticAberration.Init(context, profile.chromaticAberration);
            m_ColorGrading.Init(context, profile.colorGrading);
            m_UserLut.Init(context, profile.userLut);
            m_Grain.Init(context, profile.grain);
            m_Vignette.Init(context, profile.vignette);
            m_Dithering.Init(context, profile.dithering);
            m_Fxaa.Init(context, profile.antialiasing);

            // Handles profile change and 'enable' state observers
            if (m_PreviousProfile != profile)
            {
                DisableComponents();
                m_PreviousProfile = profile;
            }

            CheckObservers();

            // Find out which camera flags are needed before rendering begins
            // Note that motion vectors will only be available one frame after being enabled
            var flags = context.camera.depthTextureMode;
            foreach (var component in m_Components)
            {
                if (component.active)
                {
                    flags |= component.GetCameraFlags();
                }
            }

            context.camera.depthTextureMode = flags;

            // Temporal antialiasing jittering, needs to happen before culling
            if (!m_RenderingInSceneView && m_Taa.active && !profile.debugViews.willInterrupt)
            {
                m_Taa.SetProjectionMatrix(jitteredMatrixFunc);
            }
        }