Does anyone know how to do a performant water refraction shader? Examples? #22643
Unanswered
l-monninger
asked this question in
Q&A
Replies: 1 comment
-
|
I was able to do a stylized one here: ramate-io/maybraid#34 FPS on my M3 Pro chip drops as low as 30 at sharp refraction angles and when texture is full screen. use bevy::{
prelude::*, reflect::TypePath, render::render_resource::AsBindGroup, shader::ShaderRef,
};
#[derive(Asset, TypePath, AsBindGroup, Clone)]
pub struct RefractionWater {
/// Overall water tint + "how much water color overrides refracted scene"
/// (alpha is used as opacity in the shader)
#[uniform(0)]
pub water_color: LinearRgba,
/// Shallow water tint (beach / clear water)
#[uniform(1)]
pub shallow_color: LinearRgba,
/// Deep water tint (ocean / lake depths)
#[uniform(2)]
pub deep_color: LinearRgba,
/// UV distortion strength (refraction amount)
/// keep small for performance
#[uniform(3)]
pub distortion_strength: f32,
/// Depth scale in view-space units (bigger = stays shallow longer)
/// Higher is smoother
#[uniform(4)]
pub depth_scale: f32,
/// Fade out distortion near the camera to avoid shimmer/jitter
/// (0 disables fading, 1 is typical)
#[uniform(5)]
pub close_fade_strength: f32,
}
impl Default for RefractionWater {
fn default() -> Self {
Self {
water_color: LinearRgba::new(0.05, 0.35, 0.45, 0.35),
shallow_color: LinearRgba::new(0.15, 0.55, 0.60, 1.0),
deep_color: LinearRgba::new(0.02, 0.08, 0.18, 1.0),
distortion_strength: 0.006, // keep small for performance
depth_scale: 10.0, // higher is smoother
close_fade_strength: 1.0,
}
}
}
impl Material for RefractionWater {
fn fragment_shader() -> ShaderRef {
"shaders/refraction_water.wgsl".into()
}
fn reads_view_transmission_texture(&self) -> bool {
true
}
fn enable_prepass() -> bool {
false
}
fn enable_shadows() -> bool {
false
}
}Credits to @MatrixDev and #22623 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been playing around with some water shader concepts. However, anytime I add any kind of alpha, full screen renders of the material drop the frame rate hard. It seems I would need to pull into a more manual second pass, which I'm planning to give a try soon. But, any suggestions? Examples?
Beta Was this translation helpful? Give feedback.
All reactions