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

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

Merge changes Ic39209e1,I8f432c63

* changes:
  renderengine: avoid divide-by-zero in shaders
  renderengine: clamp XYZ to [0.0, 1.0] in shaders
parents 8e8fb4aa e01fc2c7
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {

                            // scale [0.0, maxInLumi] to [0.0, maxOutLumi]
                            if (maxInLumi <= maxOutLumi) {
                                nits *= maxOutLumi / maxInLumi;
                                return color * (maxOutLumi / maxInLumi);
                            } else {
                                // three control points
                                const float x0 = 10.0;
@@ -337,7 +337,7 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
                                if (nits < x0) {
                                    // scale [0.0, x0] to [0.0, y0] linearly
                                    float slope = y0 / x0;
                                    nits *= slope;
                                    return color * slope;
                                } else if (nits < x1) {
                                    // scale [x0, x1] to [y0, y1] linearly
                                    float slope = (y1 - y0) / (x1 - x0);
@@ -355,7 +355,8 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
                                }
                            }

                            return color * (nits / max(1e-6, color.y));
                            // color.y is greater than x0 and is thus non-zero
                            return color * (nits / color.y);
                        }
                    )__SHADER__";
                    break;
@@ -386,7 +387,7 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
                    if (nits <= x0) {
                        // scale [0.0, x0] to [0.0, y0] linearly
                        const float slope = y0 / x0;
                        nits *= slope;
                        return color * slope;
                    } else if (nits <= x1) {
                        // scale [x0, x1] to [y0, y1] using a curve
                        float t = (nits - x0) / (x1 - x0);
@@ -401,7 +402,8 @@ void ProgramCache::generateToneMappingProcess(Formatter& fs, const Key& needs) {
                        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));
                    // color.y is greater than x0 and is thus non-zero
                    return color * (nits / color.y);
                }
            )__SHADER__";
            break;
@@ -574,7 +576,7 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) {
            fs << "uniform mat4 inputTransformMatrix;";
            fs << R"__SHADER__(
                highp vec3 InputTransform(const highp vec3 color) {
                    return vec3(inputTransformMatrix * vec4(color, 1.0));
                    return clamp(vec3(inputTransformMatrix * vec4(color, 1.0)), 0.0, 1.0);
                }
            )__SHADER__";
        } else {