From c8938fe29132a11126013ed1b010c3092f5645e4 Mon Sep 17 00:00:00 2001 From: Matt Kosarek Date: Wed, 8 Jul 2026 09:07:55 -0400 Subject: feature: improved summer scene --- themes/src/summer/water_model.h | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 themes/src/summer/water_model.h (limited to 'themes/src/summer/water_model.h') diff --git a/themes/src/summer/water_model.h b/themes/src/summer/water_model.h new file mode 100644 index 0000000..a99f91d --- /dev/null +++ b/themes/src/summer/water_model.h @@ -0,0 +1,70 @@ +#ifndef WATER_MODEL_H +#define WATER_MODEL_H + +#include "../mathlib.h" +#include "../shader.h" +#include "../types.h" + +struct WebglContext; + +/// A water mesh is a 3D plane in the simulation world. +/// +/// The mesh reflects the sun above it and refracts whatever is +/// below its surface. It owns its own shader, geometry buffers, +/// and perspective camera, so it is fully standalone. +/// +/// The mesh can be rendered and updated. +class WaterModel { +public: + WaterModel(Vector3 position, Vector3 size); + ~WaterModel(); + + /// Compile the water shader, build the grid mesh, and set up the camera. + void load(WebglContext* context); + void update(f32 dtSeconds); + void render(); + void unload(); + + /// Direction pointing toward the sun (normalized internally) and its color, + /// used to fake the surface reflection. + void setSun(Vector3 direction, Vector4 color); + +private: + Vector3 position; + Vector3 size; + + WebglContext* context = nullptr; + Shader shader = 0; + u32 vao = 0; + u32 vbo = 0; + u32 ebo = 0; + i32 numIndices = 0; + f32 elapsedTime = 0.f; + + Mat4x4 projection; + Mat4x4 view; + Mat4x4 model; + + Vector3 cameraPos; + Vector3 sunDir; + Vector3 sunColor; + + static const i32 RES = 200; + + struct { + i32 position = -1; + } attributes; + + struct { + i32 projection = -1; + i32 view = -1; + i32 model = -1; + i32 time = -1; + i32 amplitude = -1; + i32 cameraPos = -1; + i32 sunDir = -1; + i32 sunColor = -1; + } uniforms; +}; + +#endif // WATER_MODEL_H -- cgit v1.2.1