diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets/shaders/common/frag.glsl | 3 | ||||
| -rw-r--r-- | src/audio.rs | 2 | ||||
| -rw-r--r-- | src/context.rs | 31 | ||||
| -rw-r--r-- | src/state.rs | 12 |
4 files changed, 40 insertions, 8 deletions
diff --git a/src/assets/shaders/common/frag.glsl b/src/assets/shaders/common/frag.glsl index a3123fd..26d63fa 100644 --- a/src/assets/shaders/common/frag.glsl +++ b/src/assets/shaders/common/frag.glsl @@ -86,7 +86,8 @@ vec3 point_light(vec3 normal, const int idx) { vec3 reflect_dir = reflect(-normalize(light_vector), normalize(normal.xyz)); float specular = pow(max(dot(view_dir, reflect_dir), 0.0), 32.0); vec3 specular_light = 0.5 * specular * color; - return (directional_light + specular_light) * attenuation; + // return (directional_light + specular_light) * attenuation; + return directional_light * attenuation; } vec3 point_light_billboard(const int idx) { diff --git a/src/audio.rs b/src/audio.rs index dd89a67..2b190de 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -74,9 +74,7 @@ impl Assets { } pub fn play_sfx(&mut self, name: &str) { - log::info!("sfx: {}", name); if let Some(a) = self.audio.get(name) { - log::info!("actually playing"); a.play(&self.ctx, None); } } diff --git a/src/context.rs b/src/context.rs index db6a2a7..db402a8 100644 --- a/src/context.rs +++ b/src/context.rs @@ -61,8 +61,7 @@ impl Context { gl.enable(glow::STENCIL_TEST); - // gl.enable(glow::CULL_FACE); - // gl.cull_face(glow::FRONT); + gl.cull_face(glow::BACK); } let emptyvao = unsafe { @@ -71,7 +70,6 @@ impl Context { unsafe { js_track_resized_setup(); } - Self { window, gl, @@ -154,4 +152,31 @@ impl Context { self.gl.draw_arrays(glow::TRIANGLE_STRIP, 0, 4); } } + + pub fn reset_blend(&self) { + unsafe { + self.gl.blend_func(glow::SRC_ALPHA, glow::ONE_MINUS_SRC_ALPHA); + } + } + + pub fn inverse_blend(&self) { + unsafe { + self.gl.blend_func( + glow::ONE_MINUS_DST_COLOR, + glow::ZERO, + ); + } + } + + pub fn enable_culling(&self) { + unsafe { + self.gl.enable(glow::CULL_FACE); + } + } + + pub fn disable_culling(&self) { + unsafe { + self.gl.disable(glow::CULL_FACE); + } + } } diff --git a/src/state.rs b/src/state.rs index 7170a84..86b60bf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -172,7 +172,7 @@ impl State { ) } - pub fn bind_3d(&mut self, ctx: &context::Context, shader: &shader::Shader) { + pub fn bind_3d_helper(&mut self, ctx: &context::Context, shader: &shader::Shader, plc: usize) { shader.bind(ctx); shader.set_mat4(ctx, "projection", &self.projection); shader.set_mat4(ctx, "view", &self.view()); @@ -188,11 +188,19 @@ impl State { ctx, "light_dir", &self.lighting.2.normalize(), ); - let plc = self.point_lights.len().min(5); shader.set_i32( ctx, &format!("light_count"), plc as _, ); + } + + pub fn bind_3d_no_point_lights(&mut self, ctx: &context::Context, shader: &shader::Shader) { + self.bind_3d_helper(ctx, shader, 0); + } + + pub fn bind_3d(&mut self, ctx: &context::Context, shader: &shader::Shader) { + let plc = self.point_lights.len().min(5); + self.bind_3d_helper(ctx, shader, plc); if plc > 0 { let lpos: Vec<_> = self.point_lights.iter().take(plc).map(|l| l.pos).collect(); shader.set_vec3_array( |
