Compare commits

...

3 commits
main ... shader

Author SHA1 Message Date
Fredi
e6222d82ee Using alpha value 2024-07-07 17:28:52 +02:00
Fredi
686b31e41d Merge branch 'main' into shader 2024-07-07 17:22:33 +02:00
Fredi
ffeb6524ce activating shader 2024-07-07 17:20:24 +02:00
5 changed files with 52 additions and 15 deletions

View file

@ -0,0 +1,7 @@
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let global_coord: vec3<f32> = in.world_position;
let tex = textureSample(t_diffuse, s_diffuse, in.tex_coords);
var final_color: vec4<f32> = tex * in.color;
return vec4(global_coord, final_color.a);
}

View file

@ -50,18 +50,19 @@ impl HouseState {
}
}
pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) {
pub fn draw(state: &crate::State, _ctx: &mut comfy::EngineContext<'_>) {
let Some(house) = state.house() else {
error!("How can I render a house when I'm not in one?!?");
return;
};
//Draw House
house
.rooms
.get(house.current_room_id)
.unwrap()
.draw(house.human_layer, house.player.can_see_metal(0.1));
house.rooms.get(house.current_room_id).unwrap().draw(
house.human_layer,
house.player.can_see_metal(0.1),
house.player.get_position(),
_ctx
);
//Draw Grid
//state.house.grid.draw();

View file

@ -32,6 +32,9 @@ impl Player {
}
}
pub fn get_position(&self) -> Vec2 {
self.position
}
pub fn draw(&self) {
draw_circle(self.position, 0.5, RED, 0);
}

View file

@ -1,8 +1,7 @@
use super::{furniture::Furniture, grid::Grid};
use crate::game;
use comfy::{
draw_rect, draw_rect_outline, draw_sprite, error, random_i32, vec2, EngineContext,
HashSet, Index, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE
create_reloadable_sprite_shader, draw_rect, draw_rect_outline, draw_sprite, error, hashmap, random_i32, set_uniform_f32, use_default_shader, use_shader, vec2, EngineContext, HashSet, Index, RandomRange as _, ReloadableShaderSource, UniformDef, Vec2, GREEN, PURPLE, RED, WHITE
};
use indexmap::IndexSet;
@ -285,7 +284,8 @@ impl Room {
}
},
RoomType::LivingRoom => {
_ => {
//RoomType::LivingRoom => {
let has_couch = match u8::gen_range(0, 2) {
0 => false,
1 => true,
@ -319,9 +319,8 @@ impl Room {
z: 0
});
}
},
_ => {}
}
//_ => {}
}
furnitures
@ -377,7 +376,13 @@ impl Room {
Grid::new(nodes, connections)
}
pub fn draw(&self, human_layer: bool, magnet_layer: bool) {
pub fn draw(
&self,
human_layer: bool,
magnet_layer: bool,
position: Vec2,
_ctx: &mut comfy::EngineContext<'_>
) {
let (width, height) = self.size;
draw_rect(
@ -418,7 +423,27 @@ impl Room {
}
}
if magnet_layer {
if true {
let magnet_shader_id = Some(
create_reloadable_sprite_shader(
&mut _ctx.renderer.shaders.borrow_mut(),
"magnet-shader",
ReloadableShaderSource {
static_source: include_str!("magnet-shader.wgsl").to_string(),
path: "src/activities/house/magnet-shader.wgsl".to_string()
},
hashmap! {
// "px".to_string() => UniformDef::F32(None),
// "py".to_string() => UniformDef::F32(None),
}
)
.unwrap()
).unwrap();
use_shader(magnet_shader_id);
// set_uniform_f32("px", position.x);
// set_uniform_f32("py", position.y);
if let Some(texture) = tile.f.get_magnet_texture_handle() {
draw_sprite(
texture,
@ -428,6 +453,7 @@ impl Room {
tile.size * SCALE
);
}
use_default_shader();
}
if tile.f.is_on() {

View file

@ -157,7 +157,7 @@ pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
state.ghost.charge = state.ghost.charge.max(0.0);
}
pub fn draw(state: &State, engine: &EngineContext<'_>) {
pub fn draw(state: &State, engine: &mut EngineContext<'_>) {
match state.activity {
Activity::House(_) => house::draw(state, engine),
Activity::Overworld => overworld::draw(state, engine)