From 6750afe98b8d9982d33c099f0a1a86cce47fdc21 Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Sun, 17 Dec 2023 13:32:23 -0500 Subject: [PATCH] devlook --- deps/vera | 2 +- src/core/sceneRender.cpp | 88 ++++++++++++++++++++++++++++++++++++++-- src/core/sceneRender.h | 7 +++- src/core/tools/text.cpp | 16 +++++++- src/core/tools/text.h | 5 ++- 5 files changed, 109 insertions(+), 9 deletions(-) diff --git a/deps/vera b/deps/vera index 1ffd929c..0e22ddbb 160000 --- a/deps/vera +++ b/deps/vera @@ -1 +1 @@ -Subproject commit 1ffd929cfadf7811fd397b6fd68279f6a0428427 +Subproject commit 0e22ddbb55a8bad38311d63cd1e901afbb1722f3 diff --git a/src/core/sceneRender.cpp b/src/core/sceneRender.cpp index 2f8dffe2..e4db316f 100644 --- a/src/core/sceneRender.cpp +++ b/src/core/sceneRender.cpp @@ -387,6 +387,12 @@ void SceneRender::uniformsInit(Uniforms& _uniforms) { void SceneRender::addDefine(const std::string& _define, const std::string& _value) { m_background_shader.addDefine(_define, _value); m_floor.addDefine(_define, _value); + + for (size_t i = 0; i < m_devlook_spheres.size(); i++) + m_devlook_spheres[i]->getShader()->addDefine(_define, _value); + + for (size_t i = 0; i < m_devlook_billboards.size(); i++) + m_devlook_billboards[i]->getShader()->addDefine(_define, _value); } void SceneRender::delDefine(const std::string& _define) { @@ -418,6 +424,20 @@ void SceneRender::printDefines() { std::cout << "+------------- " << std::endl; m_floor.getShader()->printDefines(); } + + for (size_t i = 0; i < m_devlook_spheres.size(); i++) { + std::cout << "." << std::endl; + std::cout << "| DEVLOOK SPHERE " << i << std::endl; + std::cout << "+------------- " << std::endl; + m_devlook_spheres[i]->getShader()->printDefines(); + } + + for (size_t i = 0; i < m_devlook_billboards.size(); i++) { + std::cout << "." << std::endl; + std::cout << "| DEVLOOK BILLBOARD " << i << std::endl; + std::cout << "+------------- " << std::endl; + m_devlook_billboards[i]->getShader()->printDefines(); + } } bool SceneRender::loadScene(Uniforms& _uniforms) { @@ -431,7 +451,6 @@ bool SceneRender::loadScene(Uniforms& _uniforms) { } m_area = glm::max(0.5f, glm::max(glm::length(bbox.min), glm::length(bbox.max))); - // m_origin.setPosition( -bbox.getCenter() ); // Floor m_floor_height = bbox.min.y; @@ -500,6 +519,11 @@ void SceneRender::setShaders(Uniforms& _uniforms, const std::string& _fragmentSh // Floor bool thereIsFloorDefine = checkFloor(_fragmentShader) || checkFloor(_vertexShader); if (thereIsFloorDefine) { + if (m_floor.getVbo() == nullptr) { + m_floor.setName("FLOOR"); + m_floor.setGeom( vera::planeMesh(1.0f, 1.0f, 2, 2) ); + } + m_floor.setShader(_fragmentShader, _vertexShader); if (m_floor_subd == -1) @@ -522,7 +546,38 @@ void SceneRender::setShaders(Uniforms& _uniforms, const std::string& _fragmentSh } } - return; + int devLookSpheres = countDevLookSpheres(_fragmentShader); + if (devLookSpheres != m_devlook_spheres.size()) { + m_devlook_spheres.clear(); + + for (int i = 0; i < devLookSpheres; i++) { + m_devlook_spheres.push_back( new vera::Model("DEVLOOK_SPHERE_" + vera::toString(i), vera::sphereMesh(24)) ); + + m_devlook_spheres[i]->setShader(_fragmentShader, vera::getDefaultSrc(vera::VERT_DEVLOOK_SPHERE)); + m_devlook_spheres[i]->getShader()->addDefine("DEVLOOK_SPHERE_" + vera::toString(i)); + m_devlook_spheres[i]->getShader()->addDefine("DEVLOOK_Y_OFFSET", 0.8 - i * 0.35); + } + } + else if (devLookSpheres > 0) + for (int i = 0; i < devLookSpheres; i++) + m_devlook_spheres[i]->setShader(_fragmentShader, vera::getDefaultSrc(vera::VERT_DEVLOOK_SPHERE)); + + int devLookBillboards = countDevLookBillboards(_fragmentShader); + if (devLookBillboards != m_devlook_billboards.size()) { + m_devlook_billboards.clear(); + + for (int i = 0; i < devLookBillboards; i++) { + m_devlook_billboards.push_back( new vera::Model("DEVLOOK_BILLBOARD_" + vera::toString(i), vera::planeMesh(1.0f, 1.0f, 2, 2)) ); + + m_devlook_billboards[i]->setShader(_fragmentShader, vera::getDefaultSrc(vera::VERT_DEVLOOK_BILLBOARD)); + m_devlook_billboards[i]->getShader()->addDefine("DEVLOOK_BILLBOARD_" + vera::toString(i)); + m_devlook_billboards[i]->getShader()->addDefine("DEVLOOK_Y_OFFSET", 0.8 - m_devlook_spheres.size() * 0.35 - i * 0.325); + } + } + else if (devLookBillboards > 0) + for (int i = 0; i < devLookBillboards; i++) + m_devlook_billboards[i]->setShader(_fragmentShader, vera::getDefaultSrc(vera::VERT_DEVLOOK_BILLBOARD)); + } void SceneRender::updateBuffers(Uniforms& _uniforms, int _width, int _height) { @@ -585,6 +640,7 @@ void SceneRender::render(Uniforms& _uniforms) { // Update Uniforms and textures variables to the shader _uniforms.feedTo( it->second->getShader() ); + TRACK_END("render:scene:floor") // Pass special uniforms it->second->getShader()->setUniform( "u_modelViewProjectionMatrix", vera::getProjectionViewWorldMatrix() * it->second->getTransformMatrix() ); it->second->getShader()->setUniform( "u_modelMatrix", m_origin.getTransformMatrix() * it->second->getTransformMatrix() ); @@ -597,6 +653,10 @@ void SceneRender::render(Uniforms& _uniforms) { TRACK_END("render:scene:" + it->second->getName() ) } + TRACK_BEGIN("render:scene:devlook") + renderDevLook(_uniforms); + TRACK_END("render:scene:devlook") + if (m_depth_test) glDisable(GL_DEPTH_TEST); @@ -920,7 +980,7 @@ void SceneRender::renderBackground(Uniforms& _uniforms) { } } -void SceneRender::renderFloor(Uniforms& _uniforms, bool _lights) { +void SceneRender::renderFloor(Uniforms& _uniforms) { if (m_floor_subd_target >= 0) { // Floor if (m_floor_subd_target != m_floor_subd) { @@ -933,7 +993,7 @@ void SceneRender::renderFloor(Uniforms& _uniforms, bool _lights) { if (m_floor.getVbo()) { m_floor.getShader()->use(); - _uniforms.feedTo( m_floor.getShader(), _lights ); + _uniforms.feedTo( m_floor.getShader() ); m_floor.getShader()->setUniform("u_modelViewProjectionMatrix", vera::getProjectionViewWorldMatrix() * m_floor.getTransformMatrix() ); m_floor.getShader()->setUniform("u_modelMatrix", m_origin.getTransformMatrix() * m_floor.getTransformMatrix() ); @@ -946,6 +1006,26 @@ void SceneRender::renderFloor(Uniforms& _uniforms, bool _lights) { } } +void SceneRender::renderDevLook(Uniforms& _uniforms) { + for (size_t i = 0; i < m_devlook_spheres.size(); i++) { + if (m_devlook_spheres[i]->getVbo() == nullptr) + continue; + + m_devlook_spheres[i]->getShader()->use(); + _uniforms.feedTo( m_devlook_spheres[i]->getShader() ); + m_devlook_spheres[i]->render(); + } + + for (size_t i = 0; i < m_devlook_billboards.size(); i++) { + if (m_devlook_billboards[i]->getVbo() == nullptr) + continue; + + m_devlook_billboards[i]->getShader()->use(); + _uniforms.feedTo( m_devlook_billboards[i]->getShader() ); + m_devlook_billboards[i]->render(); + } +} + void SceneRender::renderDebug(Uniforms& _uniforms) { glEnable(GL_DEPTH_TEST); vera::blendMode(vera::BLEND_ALPHA); diff --git a/src/core/sceneRender.h b/src/core/sceneRender.h index cb866c96..7fc095d7 100644 --- a/src/core/sceneRender.h +++ b/src/core/sceneRender.h @@ -44,7 +44,8 @@ class SceneRender { void printBuffers(); void render(Uniforms& _uniforms); - void renderFloor(Uniforms& _uniforms, bool _lights = true); + void renderFloor(Uniforms& _uniforms); + void renderDevLook(Uniforms& _uniforms); void renderBackground(Uniforms& _uniforms); void renderDebug(Uniforms& _uniforms); void renderShadowMap(Uniforms& _uniforms); @@ -92,6 +93,10 @@ class SceneRender { int m_floor_subd_target; int m_floor_subd; + // DevLook + std::vector m_devlook_spheres; + std::vector m_devlook_billboards; + // UI Grid std::unique_ptr m_grid_vbo; std::unique_ptr m_axis_vbo; diff --git a/src/core/tools/text.cpp b/src/core/tools/text.cpp index eda63576..34fe5c16 100644 --- a/src/core/tools/text.cpp +++ b/src/core/tools/text.cpp @@ -82,6 +82,8 @@ enum class regex_count_t { Pyramid, Flood, Scene_Buffers, + DevLook_Spheres, + DevLook_Billboards, MAX_KEYWORDS_COUNT_IDS }; using regex_count_string_t = regex_string_t; @@ -90,7 +92,9 @@ const auto valid_count_keyword_ids = std::array values = vera::split(_str, '.'); return "u_" + vera::toLower( vera::toUnderscore( vera::purifyString( values[0] ) ) ); diff --git a/src/core/tools/text.h b/src/core/tools/text.h index dbd6d6dd..9e969c03 100644 --- a/src/core/tools/text.h +++ b/src/core/tools/text.h @@ -24,4 +24,7 @@ bool checkPostprocessing(const std::string& _source); bool checkPositionBuffer(const std::string& _source); bool checkNormalBuffer(const std::string& _source); -int countSceneBuffers(const std::string& _source); \ No newline at end of file +int countSceneBuffers(const std::string& _source); + +int countDevLookBillboards(const std::string& _source); +int countDevLookSpheres(const std::string& _source); \ No newline at end of file