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

Commit 73ccc8a7 authored by Yein Jo's avatar Yein Jo
Browse files

Fix initial visual artifacts in rain effect.

The buffers have garbage value when initialized. Initialize the shader
input with black to avoid initial visual artifact.

Bug: 337347778
Test: Visual inspect
Flag: EXEMPT bugfix
Change-Id: I27447d084a191940d1436a28c668f940c4d7a853
parent 1ca2971f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,5 +32,6 @@ vec4 main(float2 fragCoord) {
    half outline = smoothstep(0.1, 1.8, dY * 5.0);

    // Return the results in the R channel.
    return vec4(outline, 0., 0., 0.);
    // Also return alpha 1 avoid visual artifacts when it is used standalone.
    return vec4(outline, 0., 0., 1.);
}
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.google.android.wallpaper.weathereffects.graphics.rain

import android.graphics.BitmapShader
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RenderEffect
import android.graphics.Shader
@@ -26,6 +27,7 @@ import com.google.android.wallpaper.weathereffects.graphics.FrameBuffer
import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect
import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.ImageCrop
import com.google.android.wallpaper.weathereffects.graphics.utils.SolidColorShader
import java.util.concurrent.Executor
import kotlin.random.Random

@@ -177,6 +179,8 @@ class RainEffect(
    }

    private fun prepareColorGrading() {
        // Initialize the buffer with black, so that we don't ever draw garbage buffer.
        rainConfig.glassRainShader.setInputShader("texture", SolidColorShader(Color.BLACK))
        rainConfig.colorGradingShader.setInputShader("texture", rainConfig.glassRainShader)
        rainConfig.lut?.let {
            rainConfig.colorGradingShader.setInputShader(
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.wallpaper.weathereffects.graphics.utils

import android.graphics.RuntimeShader

/** Simply renders a solid color. */
class SolidColorShader(color: Int) : RuntimeShader(SHADER) {
    // language=AGSL
    private companion object {
        private const val SHADER =
            """
                layout(color) uniform vec4 in_color;
                vec4 main(vec2 p) {
                    return in_color;
                }
            """
    }

    init {
        setColorUniform("in_color", color)
    }
}