1 /*
2  * Copyright (C) 2024 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.sun
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.fog.FogEffectConfig
24 import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
25 
26 /** Configuration for a snow effect. */
27 data class SunEffectConfig(
28     /** The main shader of the effect. */
29     val shader: RuntimeShader,
30     /** The color grading shader. */
31     val colorGradingShader: RuntimeShader,
32     /** The main lut (color grading) for the effect. */
33     val lut: Bitmap?,
34     /** Pixel density of the display. Used for dithering. */
35     val pixelDensity: Float,
36     /** The intensity of the color grading. 0: no color grading, 1: color grading in full effect. */
37     @FloatRange(from = 0.0, to = 1.0) val colorGradingIntensity: Float,
38 ) {
39     /**
40      * Constructor for [FogEffectConfig].
41      *
42      * @param assets the application [AssetManager].
43      * @param pixelDensity pixel density of the display.
44      */
45     constructor(
46         assets: AssetManager,
47         pixelDensity: Float,
48     ) : this(
49         shader = GraphicsUtils.loadShader(assets, SHADER_PATH),
50         colorGradingShader = GraphicsUtils.loadShader(assets, COLOR_GRADING_SHADER_PATH),
51         lut = GraphicsUtils.loadTexture(assets, LOOKUP_TABLE_TEXTURE_PATH),
52         pixelDensity,
53         COLOR_GRADING_INTENSITY
54     )
55 
56     companion object {
57         private const val SHADER_PATH = "shaders/sun_effect.agsl"
58         private const val COLOR_GRADING_SHADER_PATH = "shaders/color_grading_lut.agsl"
59         private const val LOOKUP_TABLE_TEXTURE_PATH = "textures/sun_lut.png"
60         private const val COLOR_GRADING_INTENSITY = 0.18f
61     }
62 }
63