// #define V_ParticlesCap Kibi(128) // #define V_ParticlesCap Mebi(1) #define V_ParticlesCap Mebi(2) // #define V_ParticlesCap Mebi(16) //////////////////////////////////////////////////////////// //~ Constant types Enum(V_GpuFlag) { V_GpuFlag_None = 0, }; G_DeclConstant(V_GpuFlag, V_GpuConst_Flags, 0); G_DeclConstant(G_StructuredBufferRef, V_GpuConst_Frame, 1); G_DeclConstant(G_Texture3DRef, V_GpuConst_NoiseTex, 2); G_DeclConstant(i32, V_GpuConst_MipsCount, 3); G_DeclConstant(i32, V_GpuConst_MipIdx, 4); //////////////////////////////////////////////////////////// //~ Particle types #define V_ParticleSimBasis 0xb49f2d9e406873b9ull #define V_ParticleColorBasis 0x569aa8341ecc0ea3ull #define V_ParticleCellBasis 0xf60c0cff344b0c5dull #define V_ParticleStainBasis 0x3c64e8226d98d376ull Enum(V_ParticleFlag) { V_ParticleFlag_None = 0, V_ParticleFlag_StainWhenPruned = (1 << 1), V_ParticleFlag_NoReflect = (1 << 2), V_ParticleFlag_OnlyCollideWithWalls = (1 << 3), V_ParticleFlag_GasBlend = (1 << 4), }; Enum(V_ParticleLayer) { V_ParticleLayer_Ground, V_ParticleLayer_Mid, V_ParticleLayer_Air, V_ParticleLayer_COUNT }; // NOTE: Higher particle enum values take priority over lower ones #define V_ParticlesXList(X) \ X( \ /* Name */ None, \ /* Flags */ V_ParticleFlag_None, \ /* Layer */ V_ParticleLayer_Ground, \ /* Stain rate, pen chance */ 30, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(0, 0, 0, 0), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ \ /* Ground particles */ \ X( \ /* Name */ BloodTrail, \ /* Flags */ V_ParticleFlag_NoReflect | V_ParticleFlag_StainWhenPruned, \ /* Layer */ V_ParticleLayer_Ground, \ /* Stain rate, pen chance */ 100, 0.25, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.5, \ /* Base color */ VEC4(0.6, 0.1, 0.1, 0.05), \ /* Dry color factor */ VEC4(0.4, 0.4, 0.4, 1) \ ) \ X( \ /* Name */ BloodDebris, \ /* Flags */ V_ParticleFlag_StainWhenPruned, \ /* Layer */ V_ParticleLayer_Mid, \ /* Stain rate, pen chance */ 30, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(0.5, 0.1, 0.1, 0.8), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Debris, \ /* Flags */ V_ParticleFlag_StainWhenPruned, \ /* Layer */ V_ParticleLayer_Mid, \ /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(0.4, 0.3, 0.2, 1), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Fire, \ /* Flags */ V_ParticleFlag_StainWhenPruned, \ /* Layer */ V_ParticleLayer_Mid, \ /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.1, \ /* Base color */ VEC4(2, 0.5, 0, 1), \ /* Dry color factor */ VEC4(0.2, 0.1, 0.0, 1) \ ) \ \ /* Air particles */ \ X( \ /* Name */ BulletTrail, \ /* Flags */ V_ParticleFlag_OnlyCollideWithWalls | V_ParticleFlag_GasBlend, \ /* Layer */ V_ParticleLayer_Mid, \ /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ 0.075, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(0.8, 0.6, 0.2, 0.25), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ X( \ /* Name */ Smoke, \ /* Flags */ V_ParticleFlag_OnlyCollideWithWalls | V_ParticleFlag_GasBlend, \ /* Layer */ V_ParticleLayer_Air, \ /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(0.25, 0.25, 0.25, 0.75), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ \ /* Test particles */ \ X( \ /* Name */ Test, \ /* Flags */ V_ParticleFlag_None, \ /* Layer */ V_ParticleLayer_Mid, \ /* Stain rate, pen chance */ 0, 0, \ /* Lifetime */ Inf, \ /* Prune speed threshold */ 0.01, \ /* Base color */ VEC4(1, 1, 0, 1), \ /* Dry color factor */ VEC4(1, 1, 1, 1) \ ) \ /* ----------------------------------------------------------------------------------------------------------------------------------- */ Enum(V_ParticleKind) { #define X(name, ...) V_ParticleKind_##name, V_ParticlesXList(X) #undef X V_ParticleKind_COUNT, }; Struct(V_Emitter) { V_ParticleKind kind; u32 first_particle_seq; u32 count; Rng2 pos; Rng speed; Rng angle; }; // TODO: Pack this efficiently Struct(V_Particle) { i32 kind; // If >= 0, then this maps to V_ParticleKind. Otherwise it represent a particle to be initialized using emitter at index [abs(kind) - 1] u32 origin_occluder; u32 prev_occluder; // TODO: Remove this f32 life; f32 stain_accum; u32 cells_count; Vec2 pos; Vec2 velocity; }; Struct(V_ParticleDesc) { V_ParticleKind kind; V_ParticleFlag flags; V_ParticleLayer layer; f32 stain_rate; f32 pen_rate; f32 lifetime; f32 prune_speed_threshold; Vec4 base_color; Vec4 dry_factor; }; #if IsCpu Struct(V_EmitterNode) { V_EmitterNode *next; V_Emitter emitter; }; #endif //////////////////////////////////////////////////////////// //~ Quad types Enum(V_QuadFlag) { V_QuadFlag_None = 0, }; Struct(V_Quad) { V_QuadFlag flags; u32 occluder_id; Affine quad_uv_to_world_af; G_Texture2DRef tex; Rng2 tex_slice_uv; }; //////////////////////////////////////////////////////////// //~ Debug vert types Struct(V_DVert) { Vec2 pos; Vec4 color_lin; }; //////////////////////////////////////////////////////////// //~ State types Struct(V_TileDesc) { G_Texture2DRef tex; Rng2 tex_slice_uv; }; Enum(V_SelectionMode) { V_SelectionMode_Tile, }; Enum(V_EditMode) { V_EditMode_Tile, V_EditMode_Prefab, }; Struct(V_Affines) { // World <-> screen (raw) Affine world_to_screen_raw; Affine screen_to_world_raw; // World <-> screen Affine world_to_screen; Affine screen_to_world; // World <-> shade Affine world_to_shade; Affine shade_to_world; // Shade <-> screen Affine shade_to_screen; Affine screen_to_shade; // World <-> cell Affine world_to_cell; Affine cell_to_world; // World <-> tile Affine world_to_tile; Affine tile_to_world; }; Struct(V_SharedFrame) { //- Time i64 tick; i64 time_ns; i64 dt_ns; f32 dt; //- Modes // TODO: Move to shader-constant flags b32 tiles_dirty; b32 should_clear_particles; b32 should_tone_map; b32 is_looking; b32 is_moving; b32 is_editing; b32 ui_debug; b32 show_console; b32 is_selecting; b32 is_panning; b32 has_mouse_focus; b32 has_keyboard_focus; //- Editor state V_EditMode edit_mode; V_SelectionMode selection_mode; P_TileKind equipped_tile; P_PrefabKind equipped_prefab; Vec2 world_selection_start; Vec2 edit_camera_pos; f32 edit_camera_zoom; //- Camera i32 zooms; f32 camera_lerp_rate; Vec2 camera_pos; f32 camera_zoom; //- Dims Vec2 screen_dims; Vec2 shade_dims; //- Affines V_Affines af; //- Cursor Vec2 screen_cursor; Vec2 shade_cursor; Vec2 world_cursor; Rng2 screen_selection; Rng2 shade_selection; Rng2 world_selection; //- Crosshair Vec2 world_guy_origin; Vec2 world_crosshair_base; Vec2 world_crosshair; Vec2 screen_crosshair; Vec2 shade_crosshair; //- Control Vec2 move; Vec2 look; f32 fire_held; f32 fire_presses; f32 roll_presses; //- Gpu data G_SamplerStateRef basic_samplers[G_BasicSamplerKind_COUNT]; V_TileDesc tile_descs[P_TileKind_COUNT]; G_Texture2DRef tiles; f32 backdrop_parallax; G_Texture2DRef backdrop_src; G_Texture2DRef backdrop_mips[G_MaxMips]; G_Texture2DRef screen; G_Texture2DRef shade; G_Texture2DRef albedo; G_Texture2DRef bloom_mips[G_MaxMips]; u32 emitters_count; G_StructuredBufferRef emitters; G_StructuredBufferRef particles; G_Texture2DRef stains; G_Texture2DRef dry_stains; G_Texture2DRef drynesses; G_Texture2DRef occluders; G_Texture2DRef particle_cells[V_ParticleLayer_COUNT]; G_Texture2DRef particle_densities[V_ParticleLayer_COUNT]; G_StructuredBufferRef dverts; G_StructuredBufferRef quads; }; //////////////////////////////////////////////////////////// //~ Helpers V_ParticleDesc V_DescFromParticleKind(V_ParticleKind kind);