Bevy makes it easy to try different material and lighting settings. I played with those settings, but getting the look I wanted was trickier than I expected. I think I could get closer by tuning them further. This time, I also wanted to try writing my own shaders, so I used WGSL to adjust the ground lighting and the lake surface.
In the forest, I liked how bright the grass looked in sunlight. Once I stepped into the shade, though, I wanted the ground to have a softer color. Turning up the ground material's base color makes the grass in sunlight brighter too.
At the lake, I wanted the sand to show through right at the shore, with blue water already visible a little farther out. The original implementation drew the surface with Bevy's standard material. My Rust code set the color and transparency from the water depth. Both used the same blend weight, so moving the point where the water turned blue also changed where the lakebed became harder to see.
I compared the ground lighting at the forest edge and farther inside. In each row, I kept the framing fixed and switched the lighting. The branch shadows in the foreground of the bottom row fall in the same places. The standard lighting gives a sharper separation between sunlight and shade. With the custom shader, the color of the shaded ground looks a little softer. I like that look better.
At first the left image looked more vivid to me. So I took the original images for the lower row and measured matching patches of sunlit and shaded ground in the foreground.
| Sample | Lightness (left, Bevy PBR) | Lightness (right, custom WGSL) | Chroma (left, Bevy PBR) | Chroma (right, custom WGSL) |
|---|---|---|---|---|
| Sunlight | 65.1 | 64.0 | 24.2 | 31.2 |
| Shade | 19.2 | 32.1 | 9.1 | 18.6 |
These are medians from 32 × 32 pixel patches in the original PNGs. Lightness is CIELAB L*, and color intensity is measured as chroma C*.
The sunlit patch was about as light in both images. The shaded patch got lighter, narrowing the gap. What surprised me was that the measured patch in shade also had higher chroma on the right, even though the image on the left initially looked more vivid to me.
The comparison switches the ground lighting model as a whole. Where the custom model fully takes over, Bevy's standard PBR specular term drops out of the final color.
Bevy already lets me change the color and strength of ambient light, and camera color grading can adjust saturation and contrast in the shadows. Here I used WGSL to change the light reaching the nearby ground. I'd also like to try changing the color of that light with the time of day. Bevy 0.19.1 ambient light · Color grading for shadows, midtones, and highlights
I also switched the water rendering with the same framing at the lakeshore. I kept the blue farther out close to the original and adjusted how much of the lakebed shows through near shore.
Bevy still handles the camera and generates the shadow maps. The WGSL I added computes the light on the ground and the lake color and opacity as a function of depth.
The light that remains in the shade
I wanted to decide how much light, and what color of light, reaches the nearby ground once direct sunlight is blocked. I also wanted the slope of the ground to affect the balance between blue sky light and warmer bounced light.
Bevy records the depth of trees and other objects as seen from the sun in a shadow map. When shading the ground, we can sample that map to see how much direct light reaches each point, including where sunlight gets through gaps in the branches.
I could tune the ground's base color and roughness with the standard material. I wanted separate control over the color and strength of the light in shade, so I reused Bevy's shadow data and set the lighting in WGSL. Bevy's StandardMaterial
Bevy's fetch_directional_shadow gives me a visibility factor for the sun, around zero in full shade and one in direct sunlight. I multiply the direct-light term by that factor. Here's the lighting function in forest_floor_light.wgsl.
fn forest_floor_fill(normal_y: f32) -> vec3<f32> { let sky_fraction = clamp(0.5 + 0.5 * normal_y, 0.0, 1.0); return mix(vec3<f32>(0.34, 0.26, 0.18), vec3<f32>(0.36, 0.44, 0.54), sky_fraction); } fn forest_floor_light(albedo: vec3<f32>, normal: vec3<f32>, to_sun: vec3<f32>, sun_rgb: vec3<f32>, sun_visibility: f32) -> vec3<f32> { let incidence = max(dot(normal, to_sun), 0.0); let sunlight = sun_rgb * vec3<f32>(1.06, 0.98, 0.84) * incidence * clamp(sun_visibility, 0.0, 1.0); return albedo * (forest_floor_fill(normal.y) + sunlight); } When visibility is zero, forest_floor_fill(normal.y) still contributes to the ground color. Upward-facing surfaces pick up more blue sky light, while sloping surfaces get a warmer tint. The fill mixes fixed colors, while camera exposure scales the direct-light term. The code that reads lights and shadows from Bevy lives outside this function. Another engine could reuse the same function by supplying the sun direction, color, and visibility.
In ground_blend.wgsl, I take the larger of the X and Z offsets from the player and blend back to standard PBR over the 40–64 m band. After combining the lighting, I pass the result to Bevy for fog and color processing.
var lit = apply_pbr_lighting(pbr); if forest_light_enabled != 0u { let delta = abs(p.xz - focus_and_time.xy); let weight = 1.0 - smoothstep(40.0, 64.0, max(delta.x, delta.y)); if weight > 0.0 { lit = vec4<f32>(mix(lit.rgb, scene_forest_floor_light(pbr), weight), lit.a); } } out.color = main_pass_post_lighting_processing(pbr, lit); Controlling lake color and transparency separately
The original water used a white base color in Bevy's StandardMaterial. With AlphaMode::Blend, the vertex color's alpha controls how the water blends with the background. In Rust, water_color used the depth at each water-mesh vertex to find a weight t and blend the shallow-water and deep-water RGBA values. The blend reaches the deep-water value at 1.2 m.
let t = (depth.max(0.) / 1.2).clamp(0., 1.); let t = t * t * (3. - 2. * t); // Use the same weight for all four RGBA components. std::array::from_fn(|i| shallow[i] + (deep[i] - shallow[i]) * t) A smaller value than 1.2 brings the blue in at a shallower depth. Alpha uses the same t, so the lakebed also gets harder to see sooner. I could split the weights in the Rust code to tune color and transparency separately.
The original code calculated color and transparency at the mesh vertices, and the GPU interpolated those values between them. In the WGSL version, the vertices carry water depth. The GPU interpolates depth first, and the fragment shader uses that value to calculate color and opacity.
I use MaterialExtension to specify the vertex and fragment shaders. Bevy still blends the result with the background using AlphaMode::Blend. Bevy's MaterialExtension
fn lake_depth_color(depth_m: f32) -> vec4<f32> { let depth = max(depth_m, 0.0); let opacity = 0.97 * (1.0 - exp(-2.6 * depth)); let deep_fraction = 1.0 - exp(-1.7 * depth); let tint = mix(vec3<f32>(0.12, 0.43, 0.59), vec3<f32>(0.067, 0.245, 0.48), deep_fraction); return vec4<f32>(tint, opacity); } 2.6 controls how quickly the surface becomes opaque, and 1.7 controls how quickly the color changes. At 1 m the function returns an opacity of about 0.90. Where this result goes straight into alpha blending, about 10% of the background color contributes to the result. The screenshot above shows the version after I adjusted the tint and transparency.
The diagram compares the midpoint of a shallow stretch that goes from 0.1 m to 1.1 m deep. Both sides use the same water color and the same opacity formula from the shader above so we can see what changes with the order of operations.
With the original order, I evaluate the formula at both ends, getting about 22% and 91%, and interpolate to about 57%. With the WGSL order, I put the interpolated depth of 0.6 m into the formula and get about 77%. The lakebed is harder to see at that same point.
The ripples add brightness based on position on the lake and elapsed time. The current code also uses a weight to blend back into the original rendering where the lake meets the river.
let ripple = lake_ripple_light(in.world_position.xz - basin.xy, globals.time); let surface = vec4<f32>(water.rgb + vec3<f32>(0.060, 0.082, 0.098) * ripple, water.a); color = mix(color, surface, weight); The ripple changes water.rgb while keeping water.a intact, so I can adjust the strength of the ripple separately from the water's transparency. Alpha blending scales the water color contribution, including the ripple, so the ripples are more subtle in shallower, more transparent water.
What I noticed by switching between the two
In my first attempt at the lake, the sandy color went too far out and made the shoreline harder to pick out. Seeing both versions together helped me put my finger on what I wanted. I wanted to see the bottom right at the shore and see blue water when I looked a little farther out.
In the forest, I liked the softer color on the ground as I moved from sunlight into shade. Writing these shaders let me adjust the light that remains in the shade and the way the lake turns blue as it gets deeper, then see how those choices look as I move through the map.
Next I'd like to dig into what the GPU is doing and see where I can reduce the work while keeping the look.




