diff options
| author | hachem <im@hachem.wtf> | 2026-08-23 22:39:47 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-23 22:39:47 +0200 |
| commit | 90ff03c2fdffc09ddb26bdc7e32c3968a6d274fb (patch) | |
| tree | 2fdb1b6f54c4e380af43c75f1051935587a87faa /src/rendering/black_hole_renderer.cpp | |
| parent | 5ea6c14c0e14bacee766ce1280ab2c71564e05ec (diff) | |
[feat]: wire in scene into the simulation engine
Diffstat (limited to 'src/rendering/black_hole_renderer.cpp')
| -rw-r--r-- | src/rendering/black_hole_renderer.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/rendering/black_hole_renderer.cpp b/src/rendering/black_hole_renderer.cpp index e4bc2a4..5916171 100644 --- a/src/rendering/black_hole_renderer.cpp +++ b/src/rendering/black_hole_renderer.cpp @@ -42,11 +42,9 @@ namespace Donut m_obj_ubo = device.create_buffer(BufferType::Uniform, 800); m_sim_ubo = device.create_buffer(BufferType::Uniform, 16); - // The single "object" is the black hole itself (position 0, radius = r_s). - std::vector<uint8_t> obj(800, 0); - int num_objects = 1; std::memcpy(obj.data() + 0, &num_objects, 4); - float pos_radius[4] = { 0, 0, 0, SagA_rs }; std::memcpy(obj.data() + 16, pos_radius, 16); - float color[4] = { 0, 0, 0, 1 }; std::memcpy(obj.data() + 272, color, 16); + // The hole itself is the hardcoded singularity in the shader; the Objects + // UBO carries the Scene's spheres, refilled each frame in render_geodesic. + std::vector<uint8_t> obj(800, 0); // numObjects = 0 until the first frame m_obj_ubo->update(obj.data(), obj.size()); { @@ -80,7 +78,8 @@ namespace Donut } auto BlackHoleRenderer::render_geodesic(RHI::CommandList& cmd, const GeodesicView& view, - const BlackHoleParams& params, RHI::Texture* cubemap) -> void + const BlackHoleParams& params, + const std::vector<SceneObject>& objects, RHI::Texture* cubemap) -> void { CamUBO cam{}; cam.pos = view.position; cam.right = view.right; cam.up = view.up; cam.fwd = view.forward; @@ -113,6 +112,25 @@ namespace Donut }; m_disk_ubo->update(disk, sizeof(disk)); + // Scene objects → the geodesic's Objects UBO (std140: numObjects@0, + // objPosRadius[i]@16+16i, objColor[i]@272+16i). They render as spheres the + // curved rays intersect, so the hole lenses them. 1 scene unit = 1 r_s. + { + const float k = SagA_rs / SCENE_UNITS_PER_RS; // scene units -> metres + std::vector<uint8_t> objbuf(800, 0); + int n = std::min((int)objects.size(), 16); + std::memcpy(objbuf.data(), &n, 4); + for (int i = 0; i < n; ++i) + { + const SceneObject& o = objects[i]; + float pr[4] = { o.position.x * k, o.position.y * k, o.position.z * k, o.radius * k }; + float col[4] = { o.color.r, o.color.g, o.color.b, 1.0f }; + std::memcpy(objbuf.data() + 16 + 16 * i, pr, 16); + std::memcpy(objbuf.data() + 272 + 16 * i, col, 16); + } + m_obj_ubo->update(objbuf.data(), objbuf.size()); + } + // Progressive resolution: small target while moving, large once settled. RenderTarget* target = view.moving ? m_geo_lo.get() : m_geo_hi.get(); m_last_target = target; |
