From 741bb027df58fd9f30f4d94cdaf2d6416e11e3ee Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 16 Apr 2024 00:23:43 +0100 Subject: Custom vertex, vertex shader and fragment shader for landmass Handles global position type, colourBias for surface types --- game/terrain.cpp | 22 ++++++++++++++++------ game/terrain.h | 9 ++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'game') diff --git a/game/terrain.cpp b/game/terrain.cpp index c19bd0a..3b16e79 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -15,11 +15,21 @@ #include #include +static constexpr RGB openSurface {-1}; + Terrain::Terrain(std::shared_ptr tm) : geoData {std::move(tm)}, grass {std::make_shared("grass.png")} { generateMeshes(); } +template<> +VertexArrayObject & +VertexArrayObject::addAttribsFor(const GLuint arrayBuffer, const GLuint divisor) +{ + return addAttribs( + arrayBuffer, divisor); +} + void Terrain::generateMeshes() { @@ -32,13 +42,13 @@ Terrain::generateMeshes() [this, &vertexIndex, &vertices](const GeoData::VertexHandle v) { std::for_each(geoData->vf_begin(v), geoData->vf_end(v), [&vertexIndex, v, this, &vertices](const GeoData::FaceHandle f) { - if (const auto vertexIndexRef - = vertexIndex.emplace(std::make_pair(v, geoData->get_surface(f)), 0); + const auto surface = geoData->get_surface(f); + if (const auto vertexIndexRef = vertexIndex.emplace(std::make_pair(v, surface), 0); vertexIndexRef.second) { vertexIndexRef.first->second = vertices.size(); - const auto p = geoData->point(v); - vertices.emplace_back(p, RelativePosition2D(p) / 10000.F, geoData->normal(v)); + vertices.emplace_back(geoData->point(v), geoData->normal(v), + surface ? surface->colorBias : openSurface); } }); }); @@ -49,7 +59,7 @@ Terrain::generateMeshes() return vertexIndex[std::make_pair(v, geoData->get_surface(f))]; }); }); - meshes.create(vertices, indices); + meshes.create>(vertices, indices); } void @@ -68,6 +78,6 @@ Terrain::render(const SceneShader & shader) const void Terrain::shadows(const ShadowMapper & shadowMapper) const { - shadowMapper.fixedPoint.use(); + shadowMapper.landmess.use(); meshes.apply(&Mesh::Draw); } diff --git a/game/terrain.h b/game/terrain.h index 54593fc..d088f89 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -2,6 +2,7 @@ #include "chronology.h" #include "collection.h" +#include "config/types.h" #include "game/worldobject.h" #include #include @@ -20,10 +21,16 @@ public: void tick(TickDuration) override; + struct Vertex { + GlobalPosition3D pos; + Normal3D normal; + RGB colourBias; + }; + private: void generateMeshes(); std::shared_ptr geoData; - Collection meshes; + Collection, false> meshes; std::shared_ptr grass; }; -- cgit v1.2.3