power_play/src/pp/pp_vis/pp_vis_shared.cgh

250 lines
4.2 KiB
C

// #define V_ParticlesCap Kibi(128)
// #define V_ParticlesCap Mebi(1)
#define V_ParticlesCap Mebi(2)
// #define V_ParticlesCap Mebi(16)
////////////////////////////////////////////////////////////
//~ State types
G_DeclConstant(G_StructuredBufferRef, V_ShaderConst_Frame, 0);
G_DeclConstant(G_Texture3DRef, V_ShaderConst_NoiseTex, 1);
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
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 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;
//- Gpu data
G_SamplerStateRef pt_clamp_sampler;
G_SamplerStateRef pt_wrap_sampler;
V_TileDesc tile_descs[P_TileKind_COUNT];
G_Texture2DRef tiles;
G_Texture2DRef screen_ro;
G_Texture2DRef shade_ro;
G_RWTexture2DRef shade_rw;
G_Texture2DRef albedo_ro;
G_RWTexture2DRef albedo_rw;
u32 emitters_count;
G_StructuredBufferRef emitters;
G_RWStructuredBufferRef particles;
G_RWTexture2DRef cells;
G_RWTexture2DRef stains;
G_RWTexture2DRef drynesses;
G_StructuredBufferRef dverts;
G_StructuredBufferRef quads;
};
////////////////////////////////////////////////////////////
//~ Particle types
Enum(V_ParticleFlag)
{
V_ParticleFlag_None = 0,
V_ParticleFlag_PruneWhenStill = (1 << 0),
V_ParticleFlag_StainOnPrune = (1 << 1),
V_ParticleFlag_StainTrail = (1 << 2),
};
Struct(V_Emitter)
{
V_ParticleFlag flags;
u32 first_particle_seq;
u32 count;
Vec2 start;
Vec2 end;
f32 lifetime;
f32 lifetime_spread;
f32 speed;
f32 speed_spread;
f32 angle;
f32 angle_spread;
f32 velocity_falloff;
f32 velocity_falloff_spread;
Vec4 color_lin;
Vec4 color_spread;
};
// TODO: Pack this efficiently
Struct(V_Particle)
{
u32 emitter_init_num; // if != 0, then initialize using emitter at index [emitter_init_num - 1]
u32 seq;
V_ParticleFlag flags;
Vec2 pos;
Vec2 velocity;
f32 exists;
f32 lifetime;
f32 velocity_falloff;
Vec4 color;
};
#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;
Affine quad_uv_to_screen_af;
G_Texture2DRef tex;
Rng2 tex_slice_uv;
};
////////////////////////////////////////////////////////////
//~ Debug vert types
Struct(V_DVert)
{
Vec2 pos;
Vec4 color_lin;
};
////////////////////////////////////////////////////////////
//~ Helpers
#define V_ThreadGroupSizeFromBufferSize(buffer_size) VEC3I32((((buffer_size) + 63) / 64), 1, 1)
#define V_ThreadGroupSizeFromTexSize(tex_size) VEC3I32(((tex_size).x + 7) / 8, ((tex_size).y + 7) / 8, 1)