void SetPreset(Presets preset, DeluxeTonemapper tonemapper)
 {
     if (preset == Presets.LDR_Neutral)
     {
         Set(tonemapper, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f);
     }
     else if (preset == Presets.LDR_Contrasted1)
     {
         Set(tonemapper, 0.518f, 0.1f, 0.0f, 0.54f, 1.0f);
     }
     else if (preset == Presets.LDR_Contrasted2)
     {
         Set(tonemapper, 0.5f, 0.1f, 0.0f, 0.5f, 1.0f);
     }
     else if (preset == Presets.LDR_Soft)
     {
         Set(tonemapper, -0.2f, 0.2f, 0.0f, 0.4f, 1.0f);
     }
     else if (preset == Presets.HDR_Neutral)
     {
         Set(tonemapper, 0.0f, 0.5f, 0.0f, 0.0f, 4.0f);
     }
     else if (preset == Presets.HDR_Soft)
     {
         Set(tonemapper, 0.127f, 0.3f, 0.0f, 0.833f, 4.0f);
     }
     else if (preset == Presets.HDR_Contrasted1)
     {
         Set(tonemapper, 0.402f, 0.04f, 0.0f, 0.9f, 4.0f);
     }
     else if (preset == Presets.HDR_Contrasted2)
     {
         Set(tonemapper, 0.385f, 0.12f, 0.0f, 0.883f, 4.0f);
     }
 }
 void Set(DeluxeTonemapper dt, float t, float c, float b, float s, float w)
 {
     dt.m_MainCurve.m_ToeStrength      = t;
     dt.m_MainCurve.m_CrossOverPoint   = c;
     dt.m_MainCurve.m_BlackPoint       = b;
     dt.m_MainCurve.m_ShoulderStrength = s;
     dt.m_MainCurve.m_WhitePoint       = w;
     dt.UpdateCoefficients();
 }
    public override void OnInspectorGUI()
    {
        DeluxeTonemapper dt = (DeluxeTonemapper)target;

        Undo.RecordObject(dt, "Deluxe Tonemapper");

        if (m_Logo != null)
        {
            Rect rect = GUILayoutUtility.GetRect(m_Logo.width, m_Logo.height);
            //GUI.DrawTexture(rect, m_Background);
            GUI.DrawTexture(rect, m_Logo, ScaleMode.ScaleToFit);
        }

        EditorGUILayout.LabelField("Filmic Curve", EditorStyles.boldLabel);
        dt.m_MainCurve.OnGUI(dt.m_Mode);

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Curve Settings", EditorStyles.boldLabel);

        Presets preset = (Presets)EditorGUILayout.EnumPopup("Presets", Presets.ChoosePreset);

        if (preset != Presets.ChoosePreset)
        {
            SetPreset(preset, dt);
        }

        dt.m_Mode = (DeluxeTonemapper.Mode)EditorGUILayout.EnumPopup("Mode", dt.m_Mode);

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Color Correction", EditorStyles.boldLabel);
        dt.m_Tint = EditorGUILayout.ColorField("Tint", dt.m_Tint);


        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Beispiel #4
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        this.CreateMaterials();
        if (this.m_Logic == null)
        {
            this.m_Logic = new DeluxeEyeAdaptationLogic();
        }
        DeluxeTonemapper component = base.GetComponent <DeluxeTonemapper>();

        if (component != null)
        {
            this.m_Logic.m_Range = component.m_MainCurve.m_WhitePoint;
        }
        RenderTexture temporary  = RenderTexture.GetTemporary(source.width / 2, source.height / 2, 0, source.format);
        RenderTexture temporary2 = RenderTexture.GetTemporary(temporary.width / 2, temporary.height / 2, 0, source.format);

        if (this.m_BrightnessMaterial == null)
        {
            Graphics.Blit(source, destination);
            return;
        }
        this.m_BrightnessMaterial.SetTexture("_UpTex", source);
        source.filterMode = FilterMode.Bilinear;
        this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)source.width * 0.5f, 1f / (float)source.height * 0.5f));
        Graphics.Blit(source, temporary, this.m_BrightnessMaterial, 1);
        this.m_BrightnessMaterial.SetTexture("_UpTex", temporary);
        temporary.filterMode = FilterMode.Bilinear;
        this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)temporary.width * 0.5f, 1f / (float)temporary.height * 0.5f));
        Graphics.Blit(temporary, temporary2, this.m_BrightnessMaterial, 1);
        source.filterMode = FilterMode.Point;
        if (this.m_LowResolution)
        {
            RenderTexture temporary3 = RenderTexture.GetTemporary(temporary2.width / 2, temporary2.height / 2, 0, source.format);
            this.m_BrightnessMaterial.SetTexture("_UpTex", temporary2);
            temporary2.filterMode = FilterMode.Bilinear;
            this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)temporary2.width * 0.5f, 1f / (float)temporary2.height * 0.5f));
            Graphics.Blit(temporary2, temporary3, this.m_BrightnessMaterial, 1);
            this.m_HistogramMaterial.SetTexture("_FrameTex", temporary3);
            this.m_Logic.ComputeExposure(temporary3.width, temporary3.height, this.m_HistogramMaterial);
            RenderTexture.ReleaseTemporary(temporary3);
        }
        else
        {
            this.m_HistogramMaterial.SetTexture("_FrameTex", temporary2);
            this.m_Logic.ComputeExposure(temporary2.width, temporary2.height, this.m_HistogramMaterial);
        }
        RenderTexture.ReleaseTemporary(temporary);
        RenderTexture.ReleaseTemporary(temporary2);
        this.m_BrightnessMaterial.SetFloat("_BrightnessMultiplier", this.m_Logic.m_BrightnessMultiplier);
        this.m_BrightnessMaterial.SetTexture("_BrightnessTex", this.m_Logic.m_BrightnessRT);
        this.m_BrightnessMaterial.SetTexture("_ColorTex", source);
        if (this.m_ShowHistogram)
        {
            RenderTexture temporary4 = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);
            Graphics.Blit(source, temporary4, this.m_BrightnessMaterial, 0);
            this.m_BrightnessMaterial.SetTexture("_Histogram", this.m_Logic.m_HistogramList[0]);
            this.m_BrightnessMaterial.SetTexture("_ColorTex", temporary4);
            this.m_BrightnessMaterial.SetFloat("_LuminanceRange", this.m_Logic.m_Range);
            this.m_BrightnessMaterial.SetVector("_HistogramCoefs", this.m_Logic.m_HistCoefs);
            this.m_BrightnessMaterial.SetVector("_MinMax", new Vector4(0.01f, this.m_HistogramSize, 0.01f, this.m_HistogramSize));
            this.m_BrightnessMaterial.SetFloat("_TotalPixelNumber", (float)(this.m_Logic.m_CurrentWidth * this.m_Logic.m_CurrentHeight));
            Graphics.Blit(temporary4, destination, this.m_BrightnessMaterial, 2);
            RenderTexture.ReleaseTemporary(temporary4);
        }
        else
        {
            Graphics.Blit(source, destination, this.m_BrightnessMaterial, 0);
        }
    }
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        this.CreateMaterials();
        this.VerifyAndUpdateShaderVariations(false);
        if (this.m_Logic == null)
        {
            this.m_Logic = new DeluxeEyeAdaptationLogic();
        }
        DeluxeTonemapper component  = base.GetComponent <DeluxeTonemapper>();
        RenderTexture    temporary  = RenderTexture.GetTemporary(source.width / 2, source.height / 2, 0, source.format);
        RenderTexture    temporary2 = RenderTexture.GetTemporary(temporary.width / 2, temporary.height / 2, 0, source.format);

        if (this.m_BrightnessMaterial == null)
        {
            Graphics.Blit(source, destination);
            return;
        }
        this.m_BrightnessMaterial.SetTexture("_UpTex", source);
        source.filterMode = FilterMode.Bilinear;
        this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)source.width * 0.5f, 1f / (float)source.height * 0.5f));
        Graphics.Blit(source, temporary, this.m_BrightnessMaterial, 1);
        this.m_BrightnessMaterial.SetTexture("_UpTex", temporary);
        temporary.filterMode = FilterMode.Bilinear;
        this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)temporary.width * 0.5f, 1f / (float)temporary.height * 0.5f));
        Graphics.Blit(temporary, temporary2, this.m_BrightnessMaterial, 1);
        source.filterMode = FilterMode.Point;
        if (this.m_LowResolution)
        {
            RenderTexture temporary3 = RenderTexture.GetTemporary(temporary2.width / 2, temporary2.height / 2, 0, source.format);
            this.m_BrightnessMaterial.SetTexture("_UpTex", temporary2);
            temporary2.filterMode = FilterMode.Bilinear;
            this.m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1f / (float)temporary2.width * 0.5f, 1f / (float)temporary2.height * 0.5f));
            Graphics.Blit(temporary2, temporary3, this.m_BrightnessMaterial, 1);
            this.m_HistogramMaterial.SetTexture("_FrameTex", temporary3);
            this.m_Logic.ComputeExposure(temporary3.width, temporary3.height, this.m_HistogramMaterial);
            RenderTexture.ReleaseTemporary(temporary3);
        }
        else
        {
            this.m_HistogramMaterial.SetTexture("_FrameTex", temporary2);
            this.m_Logic.ComputeExposure(temporary2.width, temporary2.height, this.m_HistogramMaterial);
        }
        RenderTexture.ReleaseTemporary(temporary);
        RenderTexture.ReleaseTemporary(temporary2);
        if (!Application.isPlaying)
        {
            RenderTexture active = RenderTexture.active;
            RenderTexture.active = this.m_Logic.m_BrightnessRT;
            GL.Clear(false, true, Color.white);
            RenderTexture.active = active;
        }
        this.m_BrightnessMaterial.SetFloat("_ExposureOffset", this.m_Logic.m_ExposureOffset);
        this.m_BrightnessMaterial.SetFloat("_BrightnessMultiplier", this.m_Logic.m_BrightnessMultiplier);
        this.m_BrightnessMaterial.SetTexture("_BrightnessTex", this.m_Logic.m_BrightnessRT);
        this.m_BrightnessMaterial.SetTexture("_ColorTex", source);
        if (this.RenderDebugInfos)
        {
            this.m_BrightnessMaterial.SetFloat("_VisualizeExposure", (!this.m_ShowExposure) ? 0f : 1f);
            this.m_BrightnessMaterial.SetFloat("_VisualizeHistogram", (!this.m_ShowHistogram) ? 0f : 1f);
            this.m_BrightnessMaterial.SetVector("_MinMaxSpeedDt", this.m_Logic.MinMaxSpeedDT);
            this.m_BrightnessMaterial.SetTexture("_Histogram", this.m_Logic.m_HistogramList[0]);
            this.m_BrightnessMaterial.SetTexture("_ColorTex", source);
            this.m_BrightnessMaterial.SetFloat("_LuminanceRange", this.m_Logic.m_Range);
            this.m_BrightnessMaterial.SetVector("_HistogramCoefs", this.m_Logic.m_HistCoefs);
            this.m_BrightnessMaterial.SetVector("_MinMax", new Vector4(0.01f, this.m_HistogramSize * 0.75f, 0.01f, this.m_HistogramSize * 0.5f));
            this.m_BrightnessMaterial.SetFloat("_TotalPixelNumber", (float)(this.m_Logic.m_CurrentWidth * this.m_Logic.m_CurrentHeight));
            Graphics.Blit(source, destination, this.m_BrightnessMaterial, 2);
            return;
        }
        Graphics.Blit(source, destination, this.m_BrightnessMaterial, 0);
    }
Beispiel #6
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        CreateMaterials();

        if (m_Logic == null)
        {
            m_Logic = new DeluxeEyeAdaptationLogic();
        }

        DeluxeTonemapper tonemapper = GetComponent <DeluxeTonemapper>();

        if (tonemapper != null)
        {
            m_Logic.m_Range = tonemapper.m_MainCurve.m_WhitePoint;
        }


        RenderTexture ds0 = RenderTexture.GetTemporary(source.width / 2, source.height / 2, 0, source.format);
        RenderTexture ds1 = RenderTexture.GetTemporary(ds0.width / 2, ds0.height / 2, 0, source.format);

        if (m_BrightnessMaterial == null)
        {
            Graphics.Blit(source, destination);
            return;
        }

        m_BrightnessMaterial.SetTexture("_UpTex", source);
        source.filterMode = FilterMode.Bilinear;
        m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1.0f / source.width * 0.5f, 1.0f / source.height * 0.5f));
        Graphics.Blit(source, ds0, m_BrightnessMaterial, 1);

        m_BrightnessMaterial.SetTexture("_UpTex", ds0);
        ds0.filterMode = FilterMode.Bilinear;
        m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1.0f / ds0.width * 0.5f, 1.0f / ds0.height * 0.5f));
        Graphics.Blit(ds0, ds1, m_BrightnessMaterial, 1);

        source.filterMode = FilterMode.Point;
        if (m_LowResolution)
        {
            RenderTexture ds2 = RenderTexture.GetTemporary(ds1.width / 2, ds1.height / 2, 0, source.format);
            m_BrightnessMaterial.SetTexture("_UpTex", ds1);
            ds1.filterMode = FilterMode.Bilinear;
            m_BrightnessMaterial.SetVector("_PixelSize", new Vector4(1.0f / ds1.width * 0.5f, 1.0f / ds1.height * 0.5f));
            Graphics.Blit(ds1, ds2, m_BrightnessMaterial, 1);

            m_HistogramMaterial.SetTexture("_FrameTex", ds2);
            m_Logic.ComputeExposure(ds2.width, ds2.height, m_HistogramMaterial);


            RenderTexture.ReleaseTemporary(ds2);
        }
        else
        {
            m_HistogramMaterial.SetTexture("_FrameTex", ds1);
            m_Logic.ComputeExposure(ds1.width, ds1.height, m_HistogramMaterial);
        }

        RenderTexture.ReleaseTemporary(ds0);
        RenderTexture.ReleaseTemporary(ds1);

        m_BrightnessMaterial.SetFloat("_BrightnessMultiplier", m_Logic.m_BrightnessMultiplier);
        m_BrightnessMaterial.SetTexture("_BrightnessTex", m_Logic.m_BrightnessRT);
        m_BrightnessMaterial.SetTexture("_ColorTex", source);

        if (m_ShowHistogram)
        {
            RenderTexture tmp = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);
            Graphics.Blit(source, tmp, m_BrightnessMaterial, 0);

            m_BrightnessMaterial.SetTexture("_Histogram", m_Logic.m_HistogramList[0]);
            m_BrightnessMaterial.SetTexture("_ColorTex", tmp);
            m_BrightnessMaterial.SetFloat("_LuminanceRange", m_Logic.m_Range);
            m_BrightnessMaterial.SetVector("_HistogramCoefs", m_Logic.m_HistCoefs);
            m_BrightnessMaterial.SetVector("_MinMax", new Vector4(0.01f, m_HistogramSize, 0.01f, m_HistogramSize));
            m_BrightnessMaterial.SetFloat("_TotalPixelNumber", m_Logic.m_CurrentWidth * m_Logic.m_CurrentHeight);
            Graphics.Blit(tmp, destination, m_BrightnessMaterial, 2);

            RenderTexture.ReleaseTemporary(tmp);
        }
        else
        {
            Graphics.Blit(source, destination, m_BrightnessMaterial, 0);
        }
    }