From 9f8c8a52079d37a6c804c357147adff97a4f4f61 Mon Sep 17 00:00:00 2001 From: EIntemporel Date: Mon, 14 Nov 2022 23:22:58 +0100 Subject: [PATCH] Render new sphere light Add more param to WorldRender, for handling light editor option --- src/noggit/MapView.cpp | 7 ++- src/noggit/rendering/WorldRender.cpp | 52 +++++++++++++++---- src/noggit/rendering/WorldRender.hpp | 4 ++ .../ui/tools/PresetEditor/ModelView.cpp | 3 ++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index 01815706..f439add8 100755 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -1429,7 +1429,6 @@ void MapView::setupAssistMenu() } ); - auto cur_adt_import_menu(assist_menu->addMenu("Import")); @@ -3872,6 +3871,8 @@ void MapView::tick (float dt) _world->time += this->mTimespeed * dt; _world->animtime += dt * 1000.0f; + lightEditor->UpdateWorldTime(); + if (_draw_model_animations.get()) { _world->update_models_emitters(dt); @@ -4217,6 +4218,7 @@ glm::mat4x4 MapView::model_view() const return _camera.look_at_matrix(); } } + glm::mat4x4 MapView::projection() const { float far_z = _settings->value("farZ", 2048).toFloat(); @@ -4321,6 +4323,9 @@ void MapView::draw_map() , _cursorType , radius , _left_sec_toolbar->showUnpaintableChunk() + , _left_sec_toolbar->drawOnlyInsideSphereLight() + , _left_sec_toolbar->drawWireframeSphereLight() + , _left_sec_toolbar->getAlphaSphereLight() , inner_radius , ref_pos , angle diff --git a/src/noggit/rendering/WorldRender.cpp b/src/noggit/rendering/WorldRender.cpp index 236accef..02c160ed 100755 --- a/src/noggit/rendering/WorldRender.cpp +++ b/src/noggit/rendering/WorldRender.cpp @@ -30,6 +30,9 @@ void WorldRender::draw (glm::mat4x4 const& model_view , CursorType cursor_type , float brush_radius , bool show_unpaintable_chunks + , bool draw_only_inside_light_sphere + , bool draw_wireframe_light_sphere + , float alpha_light_sphere , float inner_radius_ratio , glm::vec3 const& ref_pos , float angle @@ -918,16 +921,46 @@ void WorldRender::draw (glm::mat4x4 const& model_view } } - /* - skies->drawLightingSphereHandles(model_view - , projection - , camera_pos - , frustum - , culldistance - , false); + if (terrainMode == editing_mode::light) + { + Sky* CurrentSky = skies()->findClosestSkyByDistance(camera_pos); + if (!CurrentSky) + return; - */ + int CurrentSkyID = CurrentSky->Id; + + const int MAX_TIME_VALUE = 2880; + const int CurrenTime = static_cast(_world->time) % MAX_TIME_VALUE; + glCullFace(GL_FRONT); + for (Sky& sky : skies()->skies) + { + if (CurrentSkyID > 1 && draw_only_inside_light_sphere) + break; + + if (CurrentSkyID == sky.Id) + continue; + + if (glm::distance(sky.pos, camera_pos) <= _cull_distance) // TODO: frustum cull here + { + glm::vec4 diffuse = { sky.colorFor(LIGHT_GLOBAL_DIFFUSE, CurrenTime), 1.f }; + glm::vec4 ambient = { sky.colorFor(LIGHT_GLOBAL_AMBIENT, CurrenTime), 1.f }; + + _sphere_render.draw(mvp, sky.pos, ambient, sky.r1, 32, 18, alpha_light_sphere, false, draw_wireframe_light_sphere); + _sphere_render.draw(mvp, sky.pos, diffuse, sky.r2, 32, 18, alpha_light_sphere, false, draw_wireframe_light_sphere); + } + } + + glCullFace(GL_BACK); + if (CurrentSky && draw_only_inside_light_sphere) + { + glm::vec4 diffuse = { CurrentSky->colorFor(LIGHT_GLOBAL_DIFFUSE, CurrenTime), 1.f }; + glm::vec4 ambient = { CurrentSky->colorFor(LIGHT_GLOBAL_AMBIENT, CurrenTime), 1.f }; + + _sphere_render.draw(mvp, CurrentSky->pos, ambient, CurrentSky->r1, 32, 18, alpha_light_sphere, false, draw_wireframe_light_sphere); + _sphere_render.draw(mvp, CurrentSky->pos, diffuse, CurrentSky->r2, 32, 18, alpha_light_sphere, false, draw_wireframe_light_sphere); + } + } } void WorldRender::upload() @@ -1156,6 +1189,7 @@ void WorldRender::unload() _cursor_render.unload(); _sphere_render.unload(); _square_render.unload(); + _cylinder_render.unload(); _horizon_render.reset(); _liquid_texture_manager.unload(); @@ -1508,7 +1542,7 @@ void WorldRender::drawMinimap ( MapTile *tile } draw(model_view, projection, glm::vec3(), 0, glm::vec4(), - CursorType::NONE, 0.f, false, 0.f, glm::vec3(), 0.f, 0.f, false, false, false, editing_mode::minimap, camera_pos, true, false, true, settings->draw_wmo, settings->draw_water, false, settings->draw_m2, false, false, true, settings, false, eTerrainType::eTerrainType_Linear, 0, display_mode::in_3D, false, true); + CursorType::NONE, 0.f, false, false, false, 0.3f, 0.f, glm::vec3(), 0.f, 0.f, false, false, false, editing_mode::minimap, camera_pos, true, false, true, settings->draw_wmo, settings->draw_water, false, settings->draw_m2, false, false, true, settings, false, eTerrainType::eTerrainType_Linear, 0, display_mode::in_3D, false, true); if (unload) diff --git a/src/noggit/rendering/WorldRender.hpp b/src/noggit/rendering/WorldRender.hpp index 70b9f823..383f6707 100755 --- a/src/noggit/rendering/WorldRender.hpp +++ b/src/noggit/rendering/WorldRender.hpp @@ -40,6 +40,9 @@ namespace Noggit::Rendering , CursorType cursor_type , float brush_radius , bool show_unpaintable_chunks + , bool draw_only_inside_light_sphere + , bool draw_wireframe_light_sphere + , float alpha_light_sphere , float inner_radius_ratio , glm::vec3 const& ref_pos , float angle @@ -125,6 +128,7 @@ namespace Noggit::Rendering Noggit::CursorRender _cursor_render; Noggit::Rendering::Primitives::Sphere _sphere_render; Noggit::Rendering::Primitives::Square _square_render; + Noggit::Rendering::Primitives::Cylinder _cylinder_render; // buffers OpenGL::Scoped::deferred_upload_buffers<8> _buffers; diff --git a/src/noggit/ui/tools/PresetEditor/ModelView.cpp b/src/noggit/ui/tools/PresetEditor/ModelView.cpp index d8a609b1..1ac39645 100755 --- a/src/noggit/ui/tools/PresetEditor/ModelView.cpp +++ b/src/noggit/ui/tools/PresetEditor/ModelView.cpp @@ -38,6 +38,9 @@ void ModelViewer::paintGL() , CursorType::CIRCLE , 0.f , false + , false + , false + , 0.3f , 0.f , glm::vec3(0.f, 0.f, 0.f) , 0.f