From dbc620aa032493ec187bc9ca6014ef2091da30ca Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 25 Apr 2021 18:15:45 -0400 Subject: [PATCH] Big fancy shaders --- assets/shaders/pixel.fs | 4 ++-- src/logic/ingame/mod.rs | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/assets/shaders/pixel.fs b/assets/shaders/pixel.fs index 1af2679..de265bd 100644 --- a/assets/shaders/pixel.fs +++ b/assets/shaders/pixel.fs @@ -31,8 +31,8 @@ void main() vec2 baseUV = fragTexCoord; // Use a wave function to translate the pixel UV - float X = baseUV.x*5.+time; - float Y = baseUV.y*5.+time; + float X = baseUV.x*0.5+time; + float Y = baseUV.y*0.5+time; baseUV.y += cos(X+Y)*0.01*cos(Y); baseUV.x += sin(X-Y)*0.01*sin(Y); diff --git a/src/logic/ingame/mod.rs b/src/logic/ingame/mod.rs index 77b855a..1dbb09c 100644 --- a/src/logic/ingame/mod.rs +++ b/src/logic/ingame/mod.rs @@ -65,7 +65,12 @@ impl InGameScreen { width: game_core.resources.background_back.width as f32, height: game_core.resources.background_back.height as f32, }, - Rectangle::new(0.0,0.0, (game_core.resources.background_back.width * 2) as f32, (game_core.resources.background_back.height * 2) as f32), + Rectangle::new( + 0.0, + 0.0, + (game_core.resources.background_back.width * 2) as f32, + (game_core.resources.background_back.height * 2) as f32, + ), Vector2 { x: 0.0, y: 0.0 }, 0.0, Color::WHITE, @@ -78,7 +83,12 @@ impl InGameScreen { width: game_core.resources.background_front.width as f32, height: game_core.resources.background_front.height as f32, }, - Rectangle::new(0.0 ,0.0, (game_core.resources.background_front.width * 2) as f32,(game_core.resources.background_front.height * 2) as f32), + Rectangle::new( + 0.0, + 0.0, + (game_core.resources.background_front.width * 2) as f32, + (game_core.resources.background_front.height * 2) as f32, + ), Vector2 { x: 0.0, y: 0.0 }, 0.0, Color::WHITE, @@ -251,13 +261,22 @@ impl Screen for InGameScreen { } } + // Update the shader's internal time + unsafe { + let time_var_location = raylib::ffi::GetShaderLocation( + *game_core.resources.pixel_shader, + rstr!("time").as_ptr(), + ); + game_core.resources.pixel_shader.set_shader_value(time_var_location, draw_handle.get_time() as f32); + } + // Render the 2D context via the ripple shader { let mut shader_context = draw_handle.begin_shader_mode(&game_core.resources.pixel_shader); // Blit the texture - shader_context.draw_texture_rec( + shader_context.draw_texture_pro( &game_core.resources.shader_texture, Rectangle { x: 0.0, @@ -265,7 +284,14 @@ impl Screen for InGameScreen { width: game_core.resources.shader_texture.width() as f32, height: (game_core.resources.shader_texture.height() as f32) * -1.0, }, + Rectangle { + x: -10.0, + y: -10.0, + width: win_width as f32 + 20.0, + height: win_height as f32 + 20.0 + }, Vector2::zero(), + 0.0, Color::WHITE, ); }