diff --git a/src/pp/pp.c b/src/pp/pp.c index c9c67797..bd37578e 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -2854,14 +2854,14 @@ void P_StepFrame(P_Frame *frame) // insert a path from the bullet's base to its starting position before // its actual firing path { - // Firer origin -> weapon base path + // Firer origin -> weapon chamber path BulletPath *path = PushStruct(scratch.arena, BulletPath); SllQueuePush(first_bullet_path, last_bullet_path, path); path->start = bullet->bullet_base0; path->end = bullet->bullet_base1; } { - // Weapon base -> bullet start path + // Weapon chamber -> bullet start path BulletPath *path = PushStruct(scratch.arena, BulletPath); SllQueuePush(first_bullet_path, last_bullet_path, path); path->start = bullet->bullet_base1; @@ -2928,7 +2928,7 @@ void P_StepFrame(P_Frame *frame) } if (!P_IsEntKeyNil(victim_key)) { - // No need to check future paths if this path hit + // No need to check subsequent paths if this path hit break; } } @@ -2944,11 +2944,19 @@ void P_StepFrame(P_Frame *frame) bullet->hit_entry_normal = victim_raycast.normal; // bullet->bullet_end = bullet->hit_entry; bullet->exists = 0; + if (victim->is_guy) + { + bullet->hit_material = P_MaterialKind_Flesh; + } + else + { + bullet->hit_material = P_MaterialKind_Wall; + } } + // TODO: Remove this if (!P_IsEntNil(victim)) { - // TODO: Remove this victim->health -= 0.25; } diff --git a/src/pp/pp.h b/src/pp/pp.h index 5d4f8079..e6bb8ee8 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -126,7 +126,7 @@ Struct(P_Ent) i64 last_fire_ns; b32 has_weapon; - //- Bullet + //- Bullet / hit P_EntKey bullet_firer; b32 is_bullet; @@ -138,6 +138,7 @@ Struct(P_Ent) b32 has_hit; Vec2 hit_entry; Vec2 hit_entry_normal; + P_MaterialKind hit_material; //- Player / Guy diff --git a/src/pp/pp_shared.cgh b/src/pp/pp_shared.cgh index 9cf5e9ab..6443efaf 100644 --- a/src/pp/pp_shared.cgh +++ b/src/pp/pp_shared.cgh @@ -11,6 +11,15 @@ #define P_TilesCount (P_TilesPitch * P_TilesPitch) #define P_CellsCount (P_CellsPitch * P_TilesPitch) +//////////////////////////////////////////////////////////// +//~ Material types + +Enum(P_MaterialKind) +{ + P_MaterialKind_Wall, + P_MaterialKind_Flesh, +}; + //////////////////////////////////////////////////////////// //~ Tile types @@ -21,7 +30,7 @@ X(Carpet) \ /* -------------------- */ -//- Tiles kinds +//- Tile kinds Enum(P_TileKind) { #define X(name, ...) P_TileKind_##name, diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index a4e10c72..22743106 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -2146,9 +2146,6 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: Not like this - - - for (P_Ent *bullet = P_FirstEnt(local_frame); !P_IsEntNil(bullet); bullet = P_NextEnt(bullet)) { if (bullet->is_bullet) @@ -2222,103 +2219,14 @@ void V_TickForever(WaveLaneCtx *lane) } V_PushParticles(emitter); } - - } } - - - // { - // PERSIST Vec2 start = {5, 5}; - // PERSIST Vec2 end = {3, -20}; - - - // b32 skip = 1; - // if (frame->held_buttons[Button_G]) - // { - // end = frame->world_cursor; - // if (!prev_frame->held_buttons[Button_G]) - // { - // start = end; - // } - // skip = 0; - // } - - // Vec2 vel = SubVec2(end, start); - - - // f32 trail_len = Vec2Len(SubVec2(end, start)); - // // f32 particles_count = MaxF32(trail_len * 10000, 1); - // // f32 particles_count = MaxF32(trail_len * 512, 1); - // // f32 particles_count = MaxF32(trail_len * 64, 1); - // f32 particles_count = MaxF32(trail_len * 32, 1); - - - // f32 angle = AngleFromVec2(PerpVec2(SubVec2(end, start))); - // // f32 angle = AngleFromVec2(NegVec2(SubVec2(end, start))); - - // V_Emitter *emitter = V_PushEmitter(particles_count); - - // // emitter->flags |= V_ParticleFlag_StainOnPrune; - // // emitter->flags |= V_ParticleFlag_StainTrail; - - // // emitter->lifetime = 1; - // // emitter->lifetime_spread = 2; - - // emitter->lifetime = 0.25; - // emitter->lifetime_spread = emitter->lifetime * 2; - - // emitter->angle = angle; - // // emitter->angle_spread = Tau / 4; - // emitter->angle_spread = Tau / 4; - - // emitter->start = start; - // emitter->end = end; - - // // emitter->color_lin = LinearFromSrgb(VEC4(0, 1, 0, 1)); - - // // emitter->color_lin = LinearFromSrgb(VEC4(0.8, 0.8, 0.8, 0.25)); - // emitter->color_lin = LinearFromSrgb(VEC4(0.8, 0.6, 0.2, 1)); - // // emitter->color_spread = LinearFromSrgb(VEC4(0, 0, 0, 0.2)); - - // emitter->speed = 0; - // emitter->speed_spread = 1; - - // // emitter->speed = 1; - // // emitter->speed_spread = 1; - - // // emitter->velocity_falloff = 1; - // // emitter->velocity_falloff_spread = 0; - - // start = end; - // end = AddVec2(end, vel); - // } - - - - - - - - - - - - - - - - - - - - ////////////////////////////// - //- Push test blood particles + //- Push test impact particles // TODO: Not like this @@ -2330,8 +2238,7 @@ void V_TickForever(WaveLaneCtx *lane) { if (bullet->is_bullet && bullet->has_hit) { - // Vec2 bullet_start = bullet->start; - // Vec2 bullet_end = bullet->end; + P_MaterialKind material = bullet->hit_material; Vec2 hit_entry = bullet->hit_entry; Vec2 hit_entry_normal = bullet->hit_entry_normal; @@ -2339,54 +2246,137 @@ void V_TickForever(WaveLaneCtx *lane) V_DrawLine(bullet->bullet_start, bullet->bullet_end, Color_Cyan); - V_ParticleFlag flags = 0; - flags |= V_ParticleFlag_PruneWhenStill; - flags |= V_ParticleFlag_StainOnPrune; - if (TweakBool("Emitter stain trail", 1)) + ////////////////////////////// + //- Wall particles + + if (material != P_MaterialKind_Flesh) { - flags |= V_ParticleFlag_StainTrail; - } - // f32 count = TweakFloat("Emitter count", 50, 0, 10000); - f32 count = TweakFloat("Emitter count", 20, 1, 1000); - f32 speed = TweakFloat("Emitter speed", 20, 0, 100); - f32 falloff = TweakFloat("Emitter falloff", 50, 0, 100); - f32 angle_spread = TweakFloat("Emitter angle spread", 0.1, 0, 1) * Tau; + //- Wall debris + { + V_Emitter emitter = Zi; + { + emitter.flags |= V_ParticleFlag_PruneWhenStill; + emitter.flags |= V_ParticleFlag_StainOnPrune; - V_Emitter emitter = Zi; + emitter.count = 4; + + emitter.start = hit_entry; + emitter.end = emitter.start; + + emitter.color_lin = LinearFromSrgb(VEC4(0.3, 0.25, 0.0, 1)); + // emitter.color_spread = VEC4(0.1, 0.1, 0.1, 0); + + emitter.speed = 2; + // emitter.speed_spread = emitter.speed * 2; + emitter.speed_spread = emitter.speed * 2; + + emitter.velocity_falloff = 5; + emitter.velocity_falloff_spread = emitter.velocity_falloff_spread * 1.5; + + Vec2 dir = hit_entry_normal; + + emitter.angle = AngleFromVec2(dir); + emitter.angle_spread = Tau * 0.5; + + // emitter.lifetime = 0.25; + // emitter.lifetime = 0.05; + // emitter.lifetime = 0.04; + emitter.lifetime_spread = emitter.lifetime * 2; + } + V_PushParticles(emitter); + } + + //- Wall dust + { + V_Emitter emitter = Zi; + { + // emitter.flags |= V_ParticleFlag_PruneWhenStill; + + emitter.count = 32; + + emitter.start = hit_entry; + emitter.end = emitter.start; + + emitter.color_lin = LinearFromSrgb(VEC4(0.5, 0.5, 0.5, 0.75)); + + emitter.speed = 4; + // emitter.speed_spread = emitter.speed * 2; + emitter.speed_spread = emitter.speed * 2; + + emitter.velocity_falloff = 12; + emitter.velocity_falloff_spread = emitter.velocity_falloff_spread * 1.5; + + Vec2 dir = hit_entry_normal; + + emitter.angle = AngleFromVec2(dir); + emitter.angle_spread = Tau * 0.1; + + emitter.lifetime = 1; + // emitter.lifetime = 0.05; + // emitter.lifetime = 0.04; + emitter.lifetime_spread = emitter.lifetime * 2; + } + V_PushParticles(emitter); + } + } + + ////////////////////////////// + //- Blood particles + + if (material == P_MaterialKind_Flesh) { - emitter.count = count; - emitter.flags = flags; + // Vec2 bullet_start = bullet->start; + // Vec2 bullet_end = bullet->end; - // Vec2 dir = hit_entry_normal; - Vec2 dir = NormVec2(NegVec2(bullet_vel)); + V_ParticleFlag flags = 0; + flags |= V_ParticleFlag_PruneWhenStill; + flags |= V_ParticleFlag_StainOnPrune; + if (TweakBool("Emitter stain trail", 1)) + { + flags |= V_ParticleFlag_StainTrail; + } + // f32 count = TweakFloat("Emitter count", 50, 0, 10000); + f32 count = TweakFloat("Emitter count", 20, 1, 1000); + f32 speed = TweakFloat("Emitter speed", 20, 0, 100); + f32 falloff = TweakFloat("Emitter falloff", 50, 0, 100); + f32 angle_spread = TweakFloat("Emitter angle spread", 0.1, 0, 1) * Tau; - emitter.start = hit_entry; - emitter.end = emitter.start; + V_Emitter emitter = Zi; + { + emitter.count = count; + emitter.flags = flags; - emitter.speed = speed; - emitter.speed_spread = speed * 2; + // Vec2 dir = hit_entry_normal; + Vec2 dir = NormVec2(NegVec2(bullet_vel)); - emitter.velocity_falloff = falloff; - emitter.velocity_falloff_spread = falloff * 1.5; + emitter.start = hit_entry; + emitter.end = emitter.start; - emitter.angle = AngleFromVec2(dir); - // emitter.angle_spread = Tau / 4; - emitter.angle_spread = angle_spread; - // emitter.angle_spread = Tau / 32; + emitter.speed = speed; + emitter.speed_spread = speed * 2; - // emitter.color_lin = LinearFromSrgb(VEC4(0.5, 0.1, 0.1, 1)); - emitter.color_lin = LinearFromSrgb(VEC4(0.5, 0.1, 0.1, 0.5)); + emitter.velocity_falloff = falloff; + emitter.velocity_falloff_spread = falloff * 1.5; - // emitter.color_spread = VEC4(0.1, 0, 0, 0); - emitter.color_spread = VEC4(0.1, 0, 0, 0.5); + emitter.angle = AngleFromVec2(dir); + // emitter.angle_spread = Tau / 4; + emitter.angle_spread = angle_spread; + // emitter.angle_spread = Tau / 32; - // emitter.color = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1)); + // emitter.color_lin = LinearFromSrgb(VEC4(0.5, 0.1, 0.1, 1)); + emitter.color_lin = LinearFromSrgb(VEC4(0.5, 0.1, 0.1, 0.5)); - // emitter.angle_spread = 1; - // emitter.angle_spread = 0.5; - // emitter.angle_spread = Tau; + // emitter.color_spread = VEC4(0.1, 0, 0, 0); + emitter.color_spread = VEC4(0.1, 0, 0, 0.5); + + // emitter.color = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1)); + + // emitter.angle_spread = 1; + // emitter.angle_spread = 0.5; + // emitter.angle_spread = Tau; + } + V_PushParticles(emitter); } - V_PushParticles(emitter); // V_DrawPoint(victim_raycast.p, Color_Green); // V_DrawLine(victim_raycast.p, AddVec2(victim_raycast.p, MulVec2(victim_raycast.normal, 0.5)), Color_White); diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index bf9cc4e1..220e3fda 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -498,6 +498,7 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) // TODO: Remove this Vec4 particle_color = cells.Load(cell_pos); + particle_color.rgb *= particle_color.a; ////////////////////////////// //- Compose world