Skip to content

Commit

Permalink
devlook
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo committed Dec 17, 2023
1 parent db3def8 commit 6750afe
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deps/vera
88 changes: 84 additions & 4 deletions src/core/sceneRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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() );
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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() );
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/core/sceneRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,6 +93,10 @@ class SceneRender {
int m_floor_subd_target;
int m_floor_subd;

// DevLook
std::vector<vera::Model*> m_devlook_spheres;
std::vector<vera::Model*> m_devlook_billboards;

// UI Grid
std::unique_ptr<vera::Vbo> m_grid_vbo;
std::unique_ptr<vera::Vbo> m_axis_vbo;
Expand Down
16 changes: 14 additions & 2 deletions src/core/tools/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<regex_count_t>;
Expand All @@ -90,7 +92,9 @@ const auto valid_count_keyword_ids = std::array<regex_count_string_t, +(regex_co
{regex_count_t::Double_Buffers, "DOUBLE_BUFFER"},
{regex_count_t::Pyramid, "PYRAMID"},
{regex_count_t::Flood, "FLOOD"},
{regex_count_t::Scene_Buffers, "SCENE_BUFFER"}
{regex_count_t::Scene_Buffers, "SCENE_BUFFER"},
{regex_count_t::DevLook_Spheres, "DEVLOOK_SPHERE"},
{regex_count_t::DevLook_Billboards, "DEVLOOK_BILLBOARD"}
}};

struct is_not_duplicate_number_predicate {
Expand Down Expand Up @@ -216,11 +220,19 @@ bool checkFloodAlgorithm(const std::string& _source) {
return generic_search_check(_source, regex_check_t::Flood_Algorithm);
}


int countSceneBuffers(const std::string& _source) {
return generic_search_count(_source, regex_count_t::Scene_Buffers);
}


int countDevLookSpheres(const std::string& _source) {
return generic_search_count(_source, regex_count_t::DevLook_Spheres);
}

int countDevLookBillboards(const std::string& _source) {
return generic_search_count(_source, regex_count_t::DevLook_Billboards);
}

std::string getUniformName(const std::string& _str) {
std::vector<std::string> values = vera::split(_str, '.');
return "u_" + vera::toLower( vera::toUnderscore( vera::purifyString( values[0] ) ) );
Expand Down
5 changes: 4 additions & 1 deletion src/core/tools/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
int countSceneBuffers(const std::string& _source);

int countDevLookBillboards(const std::string& _source);
int countDevLookSpheres(const std::string& _source);

0 comments on commit 6750afe

Please sign in to comment.