public void ExposureChanged(Slider slider) { // // Unity's tonemapper install image effect to get it working // UnityStandardAssets.CinematicEffects.TonemappingColorGrading tm = mainCamera.gameObject.GetComponent <UnityStandardAssets.CinematicEffects.TonemappingColorGrading> (); UnityStandardAssets.CinematicEffects.TonemappingColorGrading.TonemappingSettings tmSettings = tm.tonemapping; tmSettings.exposure = slider.value; tm.tonemapping = tmSettings; }
void Start() { m_cam = Camera.main; m_sunShafts = m_cam.GetComponent<SunShafts>(); m_bloom = m_cam.GetComponent<Bloom>(); m_motionBlur = m_cam.GetComponent<CameraMotionBlur>(); m_antiAliasing = m_cam.GetComponent<AntiAliasing>(); m_colorGrading = m_cam.GetComponent<TonemappingColorGrading>(); m_defaultGrading = m_colorGrading.colorGrading; GameController.GameOver += OnGameOver; }
public void TogglePostFX() { // // 3rd party effects // UnityStandardAssets.CinematicEffects.TonemappingColorGrading tm = mainCamera.gameObject.GetComponent <UnityStandardAssets.CinematicEffects.TonemappingColorGrading>(); togglepostFXButtonOn.SetActive(!tm.enabled); togglepostFXButtonOff.SetActive(tm.enabled); exposureSlider.interactable = !tm.enabled; tm.enabled = !tm.enabled; UnityStandardAssets.CinematicEffects.Bloom bl = mainCamera.gameObject.GetComponent <UnityStandardAssets.CinematicEffects.Bloom>(); bl.enabled = tm.enabled; }
public static void DrawFilmicCurve(TonemappingColorGrading target) { const int h = 128; const int h1 = h - 1; Rect rect; EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); rect = GUILayoutUtility.GetRect(Mathf.Min(EditorGUIUtility.currentViewWidth - 50f, 512f), h); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); // Background GUI.Box(rect, GUIContent.none); // Curve points int w = Mathf.FloorToInt(rect.width); Vector3[] c = new Vector3[w]; float lutA = TonemappingColorGrading.GetLutA(); TonemappingColorGrading.SimplePolyFunc polyToe; TonemappingColorGrading.SimplePolyFunc polyLinear; TonemappingColorGrading.SimplePolyFunc polyShoulder; var curveData = target.filmicCurve; const float gammaSpace = 2.2f; float x0 = Mathf.Pow(1.0f / 3.0f, gammaSpace); const float shoulderBase = .7f; float x1 = Mathf.Pow(shoulderBase, gammaSpace); float gammaHighY = Mathf.Pow(shoulderBase, 1.0f + (curveData.lutShoulder) * 1.0f); float y1 = Mathf.Pow(gammaHighY, gammaSpace); float t = x0 / x1; float lin = t * y1; float low = lin * (1.0f - curveData.toe * .5f); var y0 = low; float dx = x1 - x0; float dy = y1 - y0; float m = 0.0f; if (dx > 0 && dy > 0) { m = dy / dx; } // Linear section, power is 1, slope is m polyLinear.x0 = x0; polyLinear.y0 = y0; polyLinear.A = m; polyLinear.B = 1.0f; polyLinear.signX = 1.0f; polyLinear.signY = 1.0f; polyLinear.logA = Mathf.Log(m); // Toe polyToe = polyLinear; polyToe.Initialize(x0, y0, m); float linearW = target.GetWhitePoint(); // Shoulder, first think about it "backwards" float offsetX = linearW - x1; float offsetY = 1.0f - y1; polyShoulder = polyLinear; polyShoulder.Initialize(offsetX, offsetY, m); // Flip horizontal polyShoulder.signX = -1.0f; polyShoulder.x0 = -linearW; // Flip vertical polyShoulder.signY = -1.0f; polyShoulder.y0 = 1.0f; float oneOverDim = 1.0f / (1.0f * w - 1.0f); for (int i = 0; i < w; i++) { float src = (i * 1.0f) * oneOverDim; float dst = target.EvalFilmicHelper(src, lutA, polyToe, polyLinear, polyShoulder, x0, x1, linearW); dst = Mathf.LinearToGammaSpace(dst); dst = Mathf.Clamp01(dst); c[i] = new Vector3(rect.x + i, rect.y + (h - dst * h1), 0f); } // Curve drawing Handles.color = EditorGUIUtility.isProSkin ? Color.white : Color.black; Handles.DrawAAPolyLine(2f, c); }
public static void DrawFilmicCurve(TonemappingColorGrading target) { const int h = 128; const int h1 = h - 1; Rect rect; EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); rect = GUILayoutUtility.GetRect(Mathf.Min(EditorGUIUtility.currentViewWidth - 50f, 512f), h); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); // Background GUI.Box(rect, GUIContent.none); // Curve points int w = Mathf.FloorToInt(rect.width); Vector3[] c = new Vector3[w]; float lutA = TonemappingColorGrading.GetLutA(); TonemappingColorGrading.SimplePolyFunc polyToe; TonemappingColorGrading.SimplePolyFunc polyLinear; TonemappingColorGrading.SimplePolyFunc polyShoulder; var curveData = target.filmicCurve; const float gammaSpace = 2.2f; float x0 = Mathf.Pow(1.0f / 3.0f, gammaSpace); const float shoulderBase = .7f; float x1 = Mathf.Pow(shoulderBase, gammaSpace); float gammaHighY = Mathf.Pow(shoulderBase, 1.0f + (curveData.lutShoulder) * 1.0f); float y1 = Mathf.Pow(gammaHighY, gammaSpace); float t = x0 / x1; float lin = t * y1; float low = lin * (1.0f - curveData.toe * .5f); var y0 = low; float dx = x1 - x0; float dy = y1 - y0; float m = 0.0f; if (dx > 0 && dy > 0) m = dy / dx; // Linear section, power is 1, slope is m polyLinear.x0 = x0; polyLinear.y0 = y0; polyLinear.A = m; polyLinear.B = 1.0f; polyLinear.signX = 1.0f; polyLinear.signY = 1.0f; polyLinear.logA = Mathf.Log(m); // Toe polyToe = polyLinear; polyToe.Initialize(x0, y0, m); float linearW = target.GetWhitePoint(); // Shoulder, first think about it "backwards" float offsetX = linearW - x1; float offsetY = 1.0f - y1; polyShoulder = polyLinear; polyShoulder.Initialize(offsetX, offsetY, m); // Flip horizontal polyShoulder.signX = -1.0f; polyShoulder.x0 = -linearW; // Flip vertical polyShoulder.signY = -1.0f; polyShoulder.y0 = 1.0f; float oneOverDim = 1.0f / (1.0f * w - 1.0f); for (int i = 0; i < w; i++) { float src = (i * 1.0f) * oneOverDim; float dst = target.EvalFilmicHelper(src, lutA, polyToe, polyLinear, polyShoulder, x0, x1, linearW); dst = Mathf.LinearToGammaSpace(dst); dst = Mathf.Clamp01(dst); c[i] = new Vector3(rect.x + i, rect.y + (h - dst * h1), 0f); } // Curve drawing Handles.color = EditorGUIUtility.isProSkin ? Color.white : Color.black; Handles.DrawAAPolyLine(2f, c); }