1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.android.wallpaper.weathereffects.graphics.rain 18 19 import android.content.res.AssetManager 20 import android.graphics.Bitmap 21 import android.graphics.RuntimeShader 22 import androidx.annotation.FloatRange 23 import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils 24 25 /** Configuration for a rain effect. */ 26 data class RainEffectConfig( 27 /** The first layer of the shader, rain showering in the environment. */ 28 val rainShowerShader: RuntimeShader, 29 /** The final layer of the shader, which adds color grading. */ 30 val colorGradingShader: RuntimeShader, 31 /** Shader that evaluates the outline based on the alpha value. */ 32 val outlineShader: RuntimeShader, 33 /** The main lut (color grading) for the effect. */ 34 val lut: Bitmap?, 35 /** Pixel density of the display. Used for dithering. */ 36 val pixelDensity: Float, 37 /** The intensity of the color grading. 0: no color grading, 1: color grading in full effect. */ 38 @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float, 39 ) { 40 /** 41 * Constructor for [RainEffectConfig]. 42 * 43 * @param assets asset manager, 44 * @param pixelDensity pixel density of the display. 45 */ 46 constructor( 47 assets: AssetManager, 48 pixelDensity: Float, 49 ) : this( 50 rainShowerShader = GraphicsUtils.loadShader(assets, RAIN_SHOWER_LAYER_SHADER_PATH), 51 colorGradingShader = GraphicsUtils.loadShader(assets, COLOR_GRADING_SHADER_PATH), 52 outlineShader = GraphicsUtils.loadShader(assets, OUTLINE_SHADER_PATH), 53 lut = GraphicsUtils.loadTexture(assets, LOOKUP_TABLE_TEXTURE_PATH), 54 pixelDensity, 55 COLOR_GRADING_INTENSITY, 56 ) 57 58 private companion object { 59 private const val RAIN_SHOWER_LAYER_SHADER_PATH = "shaders/rain_shower_layer.agsl" 60 private const val COLOR_GRADING_SHADER_PATH = "shaders/color_grading_lut.agsl" 61 private const val OUTLINE_SHADER_PATH = "shaders/outline.agsl" 62 private const val LOOKUP_TABLE_TEXTURE_PATH = "textures/rain_lut.png" 63 private const val COLOR_GRADING_INTENSITY = 0.3f 64 } 65 } 66