Use a dedicated grass mesh

This commit is contained in:
Vsevolod Kremianskii 2021-03-19 13:15:03 +07:00
parent 08fc51f3aa
commit cdd4c09536
3 changed files with 24 additions and 23 deletions

View file

@ -26,7 +26,7 @@ namespace reone {
namespace render {
// Quad
// Quads
static const vector<float> g_quadVertices {
0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
@ -63,11 +63,25 @@ static const vector<float> g_quadNDCVertices {
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f
};
static const vector<float> g_billboardVertices = {
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f
};
static const vector<float> g_grassVertices = {
-0.5f, 0.0f, 0.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 1.0f, 0.0f, 1.0f, 1.0f,
-0.5f, 1.0f, 0.0f, 0.0f, 1.0f
};
static const vector<uint16_t> g_quadIndices = { 0, 1, 2, 2, 3, 0 };
static const Mesh::VertexOffsets g_quadOffsets = { 0, -1, 3 * sizeof(float), -1, -1, -1, -1, -1, 5 * sizeof(float) };
// END Quad
// END Quads
// Cube
@ -95,23 +109,6 @@ static const Mesh::VertexOffsets g_cubeOffsets = { 0, -1, -1, -1, -1, -1, -1, -1
// END Cube
// Billboard
static const vector<float> g_billboardVertices = {
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f
};
static const vector<uint16_t> g_billboardIndices = {
0, 1, 2, 2, 3, 0
};
static Mesh::VertexOffsets g_billboardOffsets = { 0, -1, 3 * sizeof(float), -1, -1, -1, -1, -1, 5 * sizeof(float) };
// END Billboard
// Cubemap
static const vector<float> g_cubemapVertices {
@ -262,9 +259,10 @@ void Meshes::init() {
_quadFlipY = getMesh(4, g_quadFlipYVertices, g_quadIndices, g_quadOffsets);
_quadFlipXY = getMesh(4, g_quadFlipXYVertices, g_quadIndices, g_quadOffsets);
_quadNDC = getMesh(4, g_quadNDCVertices, g_quadIndices, g_quadOffsets);
_billboard = getMesh(4, g_billboardVertices, g_quadIndices, g_quadOffsets);
_grass = getMesh(4, g_grassVertices, g_quadIndices, g_quadOffsets);
_cube = getMesh(8, g_cubeVertices, g_cubeIndices, g_cubeOffsets);
_sphere = getSphereMesh();
_billboard = getMesh(4, g_billboardVertices, g_billboardIndices, g_billboardOffsets);
_cubemap = getMesh(24, g_cubemapVertices, g_cubemapIndices, g_cubemapOffsets);
_aabb = getMesh(8, g_aabbVertices, g_aabbIndices, g_aabbOffsets, Mesh::DrawMode::Lines);
@ -283,8 +281,9 @@ void Meshes::deinit() {
_quadFlipY.reset();
_quadFlipXY.reset();
_quadNDC.reset();
_cube.reset();
_billboard.reset();
_grass.reset();
_cube.reset();
_cubemap.reset();
_aabb.reset();

View file

@ -45,6 +45,7 @@ public:
std::shared_ptr<Mesh> getQuadFlipXY() const { return _quadFlipXY; }
std::shared_ptr<Mesh> getQuadNDC() const { return _quadNDC; }
std::shared_ptr<Mesh> getBillboard() const { return _billboard; }
std::shared_ptr<Mesh> getGrass() const { return _grass; }
std::shared_ptr<Mesh> getCube() const { return _cube; }
std::shared_ptr<Mesh> getSphere() const { return _sphere; }
std::shared_ptr<Mesh> getCubemap() const { return _cubemap; }
@ -58,9 +59,10 @@ private:
std::shared_ptr<Mesh> _quadFlipY;
std::shared_ptr<Mesh> _quadFlipXY;
std::shared_ptr<Mesh> _quadNDC;
std::shared_ptr<Mesh> _billboard;
std::shared_ptr<Mesh> _grass;
std::shared_ptr<Mesh> _cube;
std::shared_ptr<Mesh> _sphere;
std::shared_ptr<Mesh> _billboard;
std::shared_ptr<Mesh> _cubemap;
std::shared_ptr<Mesh> _aabb;
};

View file

@ -66,7 +66,7 @@ void GrassSceneNode::drawClusters(const vector<GrassCluster> &clusters) {
}
Shaders::instance().activate(ShaderProgram::GrassGrass, uniforms);
Meshes::instance().getQuadFlipY()->drawInstanced(numClusters);
Meshes::instance().getGrass()->drawInstanced(numClusters);
}
} // namespace scene