correct LOD in the shadowmap
This commit is contained in:
parent
e34ac28892
commit
e495a30d0c
4 changed files with 16 additions and 13 deletions
|
@ -1129,7 +1129,7 @@ void TerrainEditor::paintEntities(const Lumix::RayCastModelHit& hit)
|
|||
2 * m_terrain_brush_size,
|
||||
-m_terrain_brush_size,
|
||||
m_terrain_brush_size);
|
||||
auto& meshes = scene->getRenderableInfos(frustum);
|
||||
auto& meshes = scene->getRenderableInfos(frustum, frustum.getPosition());
|
||||
|
||||
float w, h;
|
||||
scene->getTerrainSize(m_component.index, &w, &h);
|
||||
|
|
|
@ -1310,7 +1310,7 @@ struct PipelineImpl : public Pipeline
|
|||
SHADOW_CAM_FAR);
|
||||
m_current_render_views = &m_view_idx;
|
||||
m_current_render_view_count = 1;
|
||||
renderAll(shadow_camera_frustum, false);
|
||||
renderAll(shadow_camera_frustum, false, camera_matrix.getTranslation());
|
||||
m_is_rendering_in_shadowmap = false;
|
||||
}
|
||||
|
||||
|
@ -1724,7 +1724,7 @@ struct PipelineImpl : public Pipeline
|
|||
}
|
||||
|
||||
|
||||
void renderAll(const Frustum& frustum, bool render_grass)
|
||||
void renderAll(const Frustum& frustum, bool render_grass, const Vec3& lod_ref_point)
|
||||
{
|
||||
PROFILE_FUNCTION();
|
||||
|
||||
|
@ -1733,7 +1733,7 @@ struct PipelineImpl : public Pipeline
|
|||
m_tmp_grasses.clear();
|
||||
m_tmp_terrains.clear();
|
||||
|
||||
auto& meshes = m_scene->getRenderableInfos(frustum);
|
||||
auto& meshes = m_scene->getRenderableInfos(frustum, lod_ref_point);
|
||||
Entity camera_entity = m_scene->getCameraEntity(m_applied_camera);
|
||||
Vec3 camera_pos = m_scene->getUniverse().getPosition(camera_entity);
|
||||
LIFOAllocator& frame_allocator = m_renderer.getFrameAllocator();
|
||||
|
@ -2547,7 +2547,7 @@ int renderModels(lua_State* L)
|
|||
|
||||
pipeline->m_current_render_views = views;
|
||||
pipeline->m_current_render_view_count = len;
|
||||
pipeline->renderAll(pipeline->m_camera_frustum, true);
|
||||
pipeline->renderAll(pipeline->m_camera_frustum, true, pipeline->m_camera_frustum.getPosition());
|
||||
pipeline->m_current_render_views = &pipeline->m_view_idx;
|
||||
pipeline->m_current_render_view_count = 1;
|
||||
return 0;
|
||||
|
|
|
@ -1949,7 +1949,9 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void fillTemporaryInfos(const CullingSystem::Results& results, const Frustum& frustum)
|
||||
void fillTemporaryInfos(const CullingSystem::Results& results,
|
||||
const Frustum& frustum,
|
||||
const Vec3& lod_ref_point)
|
||||
{
|
||||
PROFILE_FUNCTION();
|
||||
m_jobs.clear();
|
||||
|
@ -1969,11 +1971,11 @@ public:
|
|||
if (results[subresult_index].empty()) continue;
|
||||
|
||||
MTJD::Job* job = MTJD::makeJob(m_engine.getMTJDManager(),
|
||||
[&subinfos, this, &results, subresult_index, &frustum]()
|
||||
[&subinfos, this, &results, subresult_index, &frustum, lod_ref_point]()
|
||||
{
|
||||
PROFILE_BLOCK("Temporary Info Job");
|
||||
PROFILE_INT("Renderable count", results[subresult_index].size());
|
||||
Vec3 frustum_position = frustum.getPosition();
|
||||
Vec3 ref_point = lod_ref_point;
|
||||
const int* LUMIX_RESTRICT raw_subresults = &results[subresult_index][0];
|
||||
Renderable* LUMIX_RESTRICT renderables = &m_renderables[0];
|
||||
for (int i = 0, c = results[subresult_index].size(); i < c; ++i)
|
||||
|
@ -1981,8 +1983,7 @@ public:
|
|||
Renderable* LUMIX_RESTRICT renderable = &renderables[raw_subresults[i]];
|
||||
Model* LUMIX_RESTRICT model = renderable->model;
|
||||
float squared_distance =
|
||||
(renderable->matrix.getTranslation() - frustum_position)
|
||||
.squaredLength();
|
||||
(renderable->matrix.getTranslation() - ref_point).squaredLength();
|
||||
|
||||
LODMeshIndices lod = model->getLODMeshIndices(squared_distance);
|
||||
for (int j = lod.from, c = lod.to; j <= c; ++j)
|
||||
|
@ -2163,7 +2164,8 @@ public:
|
|||
}
|
||||
|
||||
|
||||
Array<Array<RenderableMesh>>& getRenderableInfos(const Frustum& frustum) override
|
||||
Array<Array<RenderableMesh>>& getRenderableInfos(const Frustum& frustum,
|
||||
const Vec3& lod_ref_point) override
|
||||
{
|
||||
PROFILE_FUNCTION();
|
||||
|
||||
|
@ -2171,7 +2173,7 @@ public:
|
|||
const CullingSystem::Results* results = cull(frustum);
|
||||
if (!results) return m_temporary_infos;
|
||||
|
||||
fillTemporaryInfos(*results, frustum);
|
||||
fillTemporaryInfos(*results, frustum, lod_ref_point);
|
||||
return m_temporary_infos;
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,8 @@ public:
|
|||
virtual int getRenderableMaterialsCount(ComponentIndex cmp) = 0;
|
||||
virtual void setRenderableLayer(ComponentIndex cmp, const int32& layer) = 0;
|
||||
virtual void setRenderablePath(ComponentIndex cmp, const Path& path) = 0;
|
||||
virtual Array<Array<RenderableMesh>>& getRenderableInfos(const Frustum& frustum) = 0;
|
||||
virtual Array<Array<RenderableMesh>>& getRenderableInfos(const Frustum& frustum,
|
||||
const Vec3& lod_ref_point) = 0;
|
||||
virtual void getRenderableEntities(const Frustum& frustum, Array<Entity>& entities) = 0;
|
||||
virtual Entity getRenderableEntity(ComponentIndex cmp) = 0;
|
||||
virtual ComponentIndex getFirstRenderable() = 0;
|
||||
|
|
Loading…
Reference in a new issue