Skip to content

Commit 285b896

Browse files
committed
small shader tweak
1 parent d6ab664 commit 285b896

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

crates/web/src/utility/webgl/constants.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ pub const VERTEX_SHADER_2: &str = r#"
2828

2929
pub const FRAGMENT_SHADER_1: &str = r#"
3030
precision mediump float;
31+
32+
uniform vec2 u_resolution;
3133
varying float v_density;
3234
3335
void main() {
34-
gl_FragColor = vec4(v_density * v_density, v_density * 0.0, v_density * 1.0, 1.0);
36+
vec2 uv = gl_FragCoord.xy / u_resolution;
37+
gl_FragColor = vec4(v_density * uv.x, v_density * uv.y, v_density, 1.0);
3538
}
3639
"#;
3740

crates/web/src/utility/webgl/functions.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ pub fn initialise_webgl(canvas: &web_sys::HtmlCanvasElement, nw: f32, nh: f32) -
279279
.get_uniform_location(&rtc_program, "u_imageProjection")
280280
.unwrap();
281281

282+
let resolution_uniform_location = context
283+
.get_uniform_location(&rtt_program, "u_resolution")
284+
.unwrap();
285+
282286
let position_buffer = context.create_buffer().unwrap();
283287

284288
let density_buffer = context.create_buffer().unwrap();
@@ -304,6 +308,11 @@ pub fn initialise_webgl(canvas: &web_sys::HtmlCanvasElement, nw: f32, nh: f32) -
304308
&texture_position_projection_matrix,
305309
);
306310

311+
context.uniform2fv_with_f32_array(
312+
Some(&resolution_uniform_location),
313+
&vec![nw as f32, nh as f32],
314+
);
315+
307316
context.use_program(Some(&rtc_program));
308317

309318
#[rustfmt::skip]

0 commit comments

Comments
 (0)