Loading weathereffects/graphics/assets/shaders/snow_accumulation.agsl +3 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,9 @@ */ uniform shader foreground; uniform half imageWidth; uniform half snowThickness; uniform half scale; uniform half screenWidth; #include "shaders/simplex2d.agsl" #include "shaders/utils.agsl" Loading @@ -27,7 +28,7 @@ float random(vec2 uv) { vec4 main(float2 fragCoord) { // fragCoord should be already the adjusted UVs to have the expected rect of the image. vec2 uv = fragCoord / imageWidth; vec2 uv = fragCoord * scale / screenWidth; float variation = 0.3 + simplex2d(11. * uv); float distance = variation * snowThickness; Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +32 −18 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils import com.google.android.wallpaper.weathereffects.graphics.utils.MathUtils import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.centerCropMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.extractTranslationMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.getScale import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.postprocessParallaxMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils import java.util.concurrent.Executor Loading @@ -56,10 +57,18 @@ class SnowEffect( private var frameBuffer = FrameBuffer(background.width, background.height) private val frameBufferPaint = Paint().also { it.shader = snowConfig.accumulatedSnowShader } private var matrix: Matrix? = null private var matrix: Matrix = centerCropMatrix( surfaceSize, SizeF(this.foreground.width.toFloat(), this.foreground.height.toFloat()), ) private var scale = getScale(matrix) init { frameBuffer.setRenderEffect(RenderEffect.createBlurEffect(4f, 4f, Shader.TileMode.CLAMP)) frameBuffer.setRenderEffect( RenderEffect.createBlurEffect(4f / scale, 4f / scale, Shader.TileMode.CLAMP) ) updateTextureUniforms() adjustCropping(surfaceSize) prepareColorGrading() Loading @@ -71,9 +80,9 @@ class SnowEffect( } override fun resize(newSurfaceSize: SizeF) { surfaceSize = newSurfaceSize adjustCropping(newSurfaceSize) updateSnowGridSize(newSurfaceSize) surfaceSize = newSurfaceSize } override fun update(deltaMillis: Long, frameTimeNanos: Long) { Loading Loading @@ -108,10 +117,7 @@ class SnowEffect( "intensity", snowConfig.colorGradingIntensity * intensity, ) snowConfig.accumulatedSnowShader.setFloatUniform( "snowThickness", snowConfig.maxAccumulatedSnowThickness * intensity, ) this.intensity = intensity // Regenerate accumulated snow since the uniform changed. generateAccumulatedSnow() } Loading @@ -128,7 +134,19 @@ class SnowEffect( this.background = background this.foreground = foreground ?: background frameBuffer = FrameBuffer(background.width, background.height) matrix = centerCropMatrix( surfaceSize, SizeF(this.foreground.width.toFloat(), this.foreground.height.toFloat()), ) scale = getScale(matrix) frameBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect( RenderEffect.createBlurEffect(4f / scale, 4f / scale, Shader.TileMode.CLAMP) ) } snowConfig.shader.setInputBuffer( "background", BitmapShader(this.background, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), Loading @@ -147,17 +165,11 @@ class SnowEffect( override fun setMatrix(matrix: Matrix) { this.matrix = matrix adjustCropping(surfaceSize) generateAccumulatedSnow() } private fun adjustCropping(surfaceSize: SizeF) { if (matrix == null) { matrix = centerCropMatrix( surfaceSize, SizeF(foreground.width.toFloat(), foreground.height.toFloat()), ) } val postprocessedMatrix = postprocessParallaxMatrix(matrix!!) val postprocessedMatrix = postprocessParallaxMatrix(matrix) val weatherMatrix = extractTranslationMatrix(postprocessedMatrix) snowConfig.shader.setFloatUniform("transformMatrixFgd", postprocessedMatrix) snowConfig.shader.setFloatUniform("transformMatrixBgd", postprocessedMatrix) Loading Loading @@ -198,10 +210,12 @@ class SnowEffect( private fun generateAccumulatedSnow() { val renderingCanvas = frameBuffer.beginDrawing() snowConfig.accumulatedSnowShader.setFloatUniform("scale", scale) snowConfig.accumulatedSnowShader.setFloatUniform( "imageWidth", renderingCanvas.width.toFloat(), "snowThickness", snowConfig.maxAccumulatedSnowThickness * intensity / scale, ) snowConfig.accumulatedSnowShader.setFloatUniform("screenWidth", surfaceSize.width) snowConfig.accumulatedSnowShader.setInputBuffer( "foreground", BitmapShader(foreground, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/utils/MatrixUtils.kt +5 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,9 @@ object MatrixUtils { set(7, matrix[7]) } } fun getScale(matrix: Matrix): Float { matrix.getValues(matrixValues) return matrixValues[0] } } Loading
weathereffects/graphics/assets/shaders/snow_accumulation.agsl +3 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,9 @@ */ uniform shader foreground; uniform half imageWidth; uniform half snowThickness; uniform half scale; uniform half screenWidth; #include "shaders/simplex2d.agsl" #include "shaders/utils.agsl" Loading @@ -27,7 +28,7 @@ float random(vec2 uv) { vec4 main(float2 fragCoord) { // fragCoord should be already the adjusted UVs to have the expected rect of the image. vec2 uv = fragCoord / imageWidth; vec2 uv = fragCoord * scale / screenWidth; float variation = 0.3 + simplex2d(11. * uv); float distance = variation * snowThickness; Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +32 −18 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils import com.google.android.wallpaper.weathereffects.graphics.utils.MathUtils import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.centerCropMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.extractTranslationMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.getScale import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.postprocessParallaxMatrix import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils import java.util.concurrent.Executor Loading @@ -56,10 +57,18 @@ class SnowEffect( private var frameBuffer = FrameBuffer(background.width, background.height) private val frameBufferPaint = Paint().also { it.shader = snowConfig.accumulatedSnowShader } private var matrix: Matrix? = null private var matrix: Matrix = centerCropMatrix( surfaceSize, SizeF(this.foreground.width.toFloat(), this.foreground.height.toFloat()), ) private var scale = getScale(matrix) init { frameBuffer.setRenderEffect(RenderEffect.createBlurEffect(4f, 4f, Shader.TileMode.CLAMP)) frameBuffer.setRenderEffect( RenderEffect.createBlurEffect(4f / scale, 4f / scale, Shader.TileMode.CLAMP) ) updateTextureUniforms() adjustCropping(surfaceSize) prepareColorGrading() Loading @@ -71,9 +80,9 @@ class SnowEffect( } override fun resize(newSurfaceSize: SizeF) { surfaceSize = newSurfaceSize adjustCropping(newSurfaceSize) updateSnowGridSize(newSurfaceSize) surfaceSize = newSurfaceSize } override fun update(deltaMillis: Long, frameTimeNanos: Long) { Loading Loading @@ -108,10 +117,7 @@ class SnowEffect( "intensity", snowConfig.colorGradingIntensity * intensity, ) snowConfig.accumulatedSnowShader.setFloatUniform( "snowThickness", snowConfig.maxAccumulatedSnowThickness * intensity, ) this.intensity = intensity // Regenerate accumulated snow since the uniform changed. generateAccumulatedSnow() } Loading @@ -128,7 +134,19 @@ class SnowEffect( this.background = background this.foreground = foreground ?: background frameBuffer = FrameBuffer(background.width, background.height) matrix = centerCropMatrix( surfaceSize, SizeF(this.foreground.width.toFloat(), this.foreground.height.toFloat()), ) scale = getScale(matrix) frameBuffer = FrameBuffer(background.width, background.height).apply { setRenderEffect( RenderEffect.createBlurEffect(4f / scale, 4f / scale, Shader.TileMode.CLAMP) ) } snowConfig.shader.setInputBuffer( "background", BitmapShader(this.background, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), Loading @@ -147,17 +165,11 @@ class SnowEffect( override fun setMatrix(matrix: Matrix) { this.matrix = matrix adjustCropping(surfaceSize) generateAccumulatedSnow() } private fun adjustCropping(surfaceSize: SizeF) { if (matrix == null) { matrix = centerCropMatrix( surfaceSize, SizeF(foreground.width.toFloat(), foreground.height.toFloat()), ) } val postprocessedMatrix = postprocessParallaxMatrix(matrix!!) val postprocessedMatrix = postprocessParallaxMatrix(matrix) val weatherMatrix = extractTranslationMatrix(postprocessedMatrix) snowConfig.shader.setFloatUniform("transformMatrixFgd", postprocessedMatrix) snowConfig.shader.setFloatUniform("transformMatrixBgd", postprocessedMatrix) Loading Loading @@ -198,10 +210,12 @@ class SnowEffect( private fun generateAccumulatedSnow() { val renderingCanvas = frameBuffer.beginDrawing() snowConfig.accumulatedSnowShader.setFloatUniform("scale", scale) snowConfig.accumulatedSnowShader.setFloatUniform( "imageWidth", renderingCanvas.width.toFloat(), "snowThickness", snowConfig.maxAccumulatedSnowThickness * intensity / scale, ) snowConfig.accumulatedSnowShader.setFloatUniform("screenWidth", surfaceSize.width) snowConfig.accumulatedSnowShader.setInputBuffer( "foreground", BitmapShader(foreground, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR), Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/utils/MatrixUtils.kt +5 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,9 @@ object MatrixUtils { set(7, matrix[7]) } } fun getScale(matrix: Matrix): Float { matrix.getValues(matrixValues) return matrixValues[0] } }