Loading weathereffects/graphics/assets/shaders/snow_accumulation.agsl +8 −6 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ */ uniform shader foreground; uniform float2 imageSize; uniform half intensity; uniform half imageWidth; uniform half snowThickness; #include "shaders/simplex2d.agsl" #include "shaders/utils.agsl" Loading @@ -27,17 +27,19 @@ float random(vec2 uv) { vec4 main(float2 fragCoord) { // fragCoord should be already the adjusted UVs to have the expected rect of the image. float variation = 0.5 + 0.5 * simplex2d(25. * fragCoord / imageSize.xx); float distance = 8. * variation * intensity; vec2 uv = fragCoord / imageWidth; float variation = 0.3 + simplex2d(11. * uv); float distance = 20. * variation * snowThickness; float aN = foreground.eval(fragCoord + vec2(0., distance)).a; float aS = foreground.eval(fragCoord + vec2(0., -distance)).a; float dY = (aN - aS) * 0.5; dY = max(dY, 0.0); float accumulatedSnow = smoothstep(0.1, 1.8, sqrt(dY * dY) * 5.0); float accumulatedSnow = smoothstep(0.1, 1.8, dY * 5.0); vec4 color = vec4(0., 0., 0., 1.); color.r = accumulatedSnow; color.g = random(fragCoord / imageSize.xx); color.g = random(uv); color.b = variation; return color; } weathereffects/graphics/assets/shaders/snow_effect.agsl +5 −5 Original line number Diff line number Diff line Loading @@ -32,9 +32,9 @@ uniform float2 screenSize; /* Constants that can be modified. */ // Snow tint. const vec4 snowColor = vec4(vec3(0.9), 1.); const vec3 snowColor = vec3(0.9); // Glass tint. const vec4 glassTint = vec4(vec3(0.8), 1.); // gray const vec3 glassTint = vec3(0.8); // gray // snow opacity (how visible it is). const float snowOpacity = 1.4; Loading @@ -54,7 +54,7 @@ vec4 main(float2 fragCoord) { // Add some slight tint to the frosted glass. // Get color of the background texture. color.rgb = mix(colorBackground.rgb, glassTint.rgb, frostedGlassIntensity); color.rgb = mix(colorBackground.rgb, glassTint, frostedGlassIntensity); for (half i = 9.; i > 2.; i--) { // Generate snow behind the subject. // Normalized layer index. Loading @@ -66,7 +66,7 @@ vec4 main(float2 fragCoord) { /* Grid size = */ vec2(mix(3.0, 6.0, idx), mix(1.0, 3.0, idx)), /* layer number = */ i); color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask); color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask); } // Add the foreground. Any effect from here will be in front of the subject. Loading @@ -87,7 +87,7 @@ vec4 main(float2 fragCoord) { /* Grid size = */ vec2(i + 1., 1.4), /* layer number = */ i); color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask); color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask); } /* Debug snow */ Loading weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +3 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ class SnowEffect( "intensity", snowConfig.colorGradingIntensity * intensity ) snowConfig.accumulatedSnowShader.setFloatUniform("intensity", intensity) snowConfig.accumulatedSnowShader.setFloatUniform("snowThickness", intensity) // Regenerate accumulated snow since the uniform changed. generateAccumulatedSnow() Loading Loading @@ -166,9 +166,8 @@ class SnowEffect( private fun generateAccumulatedSnow() { val renderingCanvas = frameBuffer.beginDrawing() snowConfig.accumulatedSnowShader.setFloatUniform( "imageSize", renderingCanvas.width.toFloat(), renderingCanvas.height.toFloat() "imageWidth", renderingCanvas.width.toFloat() ) snowConfig.accumulatedSnowShader.setInputBuffer( "foreground", Loading Loading
weathereffects/graphics/assets/shaders/snow_accumulation.agsl +8 −6 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ */ uniform shader foreground; uniform float2 imageSize; uniform half intensity; uniform half imageWidth; uniform half snowThickness; #include "shaders/simplex2d.agsl" #include "shaders/utils.agsl" Loading @@ -27,17 +27,19 @@ float random(vec2 uv) { vec4 main(float2 fragCoord) { // fragCoord should be already the adjusted UVs to have the expected rect of the image. float variation = 0.5 + 0.5 * simplex2d(25. * fragCoord / imageSize.xx); float distance = 8. * variation * intensity; vec2 uv = fragCoord / imageWidth; float variation = 0.3 + simplex2d(11. * uv); float distance = 20. * variation * snowThickness; float aN = foreground.eval(fragCoord + vec2(0., distance)).a; float aS = foreground.eval(fragCoord + vec2(0., -distance)).a; float dY = (aN - aS) * 0.5; dY = max(dY, 0.0); float accumulatedSnow = smoothstep(0.1, 1.8, sqrt(dY * dY) * 5.0); float accumulatedSnow = smoothstep(0.1, 1.8, dY * 5.0); vec4 color = vec4(0., 0., 0., 1.); color.r = accumulatedSnow; color.g = random(fragCoord / imageSize.xx); color.g = random(uv); color.b = variation; return color; }
weathereffects/graphics/assets/shaders/snow_effect.agsl +5 −5 Original line number Diff line number Diff line Loading @@ -32,9 +32,9 @@ uniform float2 screenSize; /* Constants that can be modified. */ // Snow tint. const vec4 snowColor = vec4(vec3(0.9), 1.); const vec3 snowColor = vec3(0.9); // Glass tint. const vec4 glassTint = vec4(vec3(0.8), 1.); // gray const vec3 glassTint = vec3(0.8); // gray // snow opacity (how visible it is). const float snowOpacity = 1.4; Loading @@ -54,7 +54,7 @@ vec4 main(float2 fragCoord) { // Add some slight tint to the frosted glass. // Get color of the background texture. color.rgb = mix(colorBackground.rgb, glassTint.rgb, frostedGlassIntensity); color.rgb = mix(colorBackground.rgb, glassTint, frostedGlassIntensity); for (half i = 9.; i > 2.; i--) { // Generate snow behind the subject. // Normalized layer index. Loading @@ -66,7 +66,7 @@ vec4 main(float2 fragCoord) { /* Grid size = */ vec2(mix(3.0, 6.0, idx), mix(1.0, 3.0, idx)), /* layer number = */ i); color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask); color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask); } // Add the foreground. Any effect from here will be in front of the subject. Loading @@ -87,7 +87,7 @@ vec4 main(float2 fragCoord) { /* Grid size = */ vec2(i + 1., 1.4), /* layer number = */ i); color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask); color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask); } /* Debug snow */ Loading
weathereffects/graphics/src/main/java/com/google/android/wallpaper/weathereffects/graphics/snow/SnowEffect.kt +3 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,7 @@ class SnowEffect( "intensity", snowConfig.colorGradingIntensity * intensity ) snowConfig.accumulatedSnowShader.setFloatUniform("intensity", intensity) snowConfig.accumulatedSnowShader.setFloatUniform("snowThickness", intensity) // Regenerate accumulated snow since the uniform changed. generateAccumulatedSnow() Loading Loading @@ -166,9 +166,8 @@ class SnowEffect( private fun generateAccumulatedSnow() { val renderingCanvas = frameBuffer.beginDrawing() snowConfig.accumulatedSnowShader.setFloatUniform( "imageSize", renderingCanvas.width.toFloat(), renderingCanvas.height.toFloat() "imageWidth", renderingCanvas.width.toFloat() ) snowConfig.accumulatedSnowShader.setInputBuffer( "foreground", Loading