Files
Vibe-HD-2D/engine/include/hd2d/GroundOcclusion.h
Gabrieal Jimmy 2c99305fb0 init
2026-10-02 12:42:00 -05:00

36 lines
1.1 KiB
C++

#pragma once
#include "hd2d/GL.h"
#include <glm/glm.hpp>
#include <vector>
namespace hd2d {
class ModelBatch;
// Baked contact ambient occlusion on the ground under 3D scenery: a dark,
// tight core at a tree trunk / bush / rock base plus a wide, soft canopy
// shadow under tall models. Sampled by terrain, sprite and model shaders, so
// grass tufts and bushes growing at a tree's foot darken too. Rebuild after
// moving instances.
class GroundOcclusion {
public:
GroundOcclusion() = default;
GroundOcclusion(const GroundOcclusion&) = delete;
GroundOcclusion& operator=(const GroundOcclusion&) = delete;
~GroundOcclusion();
// Covers the rectangle [min, max] (world xz). Uses every batch whose
// `groundOcclusion` strength is > 0.
void build(glm::vec2 min, glm::vec2 max, const std::vector<ModelBatch*>& batches, int texelsPerUnit = 8);
GLuint texture() const { return tex_; }
glm::vec4 rect() const { return rect_; } // matches uGroundAO in common.glsl
private:
GLuint tex_ = 0;
glm::vec4 rect_{0.0f};
};
} // namespace hd2d