Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca175ee1 authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge "[RenderEngine] Add inverse tone mapper." into pi-dev

parents 31419e7a 9a1b6556
Loading
Loading
Loading
Loading
+38 −3
Original line number Original line Diff line number Diff line
@@ -345,11 +345,46 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
            }
            }
            break;
            break;
        default:
        default:
            // TODO(73825729) We need to revert the tone mapping in
            // inverse tone map; the output luminance can be up to maxOutLumi.
            // hardware composer properly.
            fs << R"__SHADER__(
            fs << R"__SHADER__(
                highp vec3 ToneMap(highp vec3 color) {
                highp vec3 ToneMap(highp vec3 color) {
                    return color;
                    const float maxOutLumi = 3000.0;

                    const float x0 = 5.0;
                    const float y0 = 2.5;
                    float x1 = displayMaxLuminance * 0.7;
                    float y1 = maxOutLumi * 0.15;
                    float x2 = displayMaxLuminance * 0.9;
                    float y2 = maxOutLumi * 0.45;
                    float x3 = displayMaxLuminance;
                    float y3 = maxOutLumi;

                    float c1 = y1 / 3.0;
                    float c2 = y2 / 2.0;
                    float c3 = y3 / 1.5;

                    float nits = color.y;

                    float scale;
                    if (nits <= x0) {
                        // scale [0.0, x0] to [0.0, y0] linearly
                        const float slope = y0 / x0;
                        nits *= slope;
                    } else if (nits <= x1) {
                        // scale [x0, x1] to [y0, y1] using a curve
                        float t = (nits - x0) / (x1 - x0);
                        nits = (1.0 - t) * (1.0 - t) * y0 + 2.0 * (1.0 - t) * t * c1 + t * t * y1;
                    } else if (nits <= x2) {
                        // scale [x1, x2] to [y1, y2] using a curve
                        float t = (nits - x1) / (x2 - x1);
                        nits = (1.0 - t) * (1.0 - t) * y1 + 2.0 * (1.0 - t) * t * c2 + t * t * y2;
                    } else {
                        // scale [x2, x3] to [y2, y3] using a curve
                        float t = (nits - x2) / (x3 - x2);
                        nits = (1.0 - t) * (1.0 - t) * y2 + 2.0 * (1.0 - t) * t * c3 + t * t * y3;
                    }

                    return color * (nits / max(1e-6, color.y));
                }
                }
            )__SHADER__";
            )__SHADER__";
            break;
            break;