global light -> environment; unparent entity with drag&drop
This commit is contained in:
parent
a7aa538c1f
commit
ccbf0e0895
7 changed files with 61 additions and 76 deletions
|
@ -18,7 +18,7 @@ namespace Lumix
|
|||
static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("model_instance");
|
||||
static const ComponentType PHYSICAL_CONTROLLER_TYPE = Reflection::getComponentType("physical_controller");
|
||||
static const ComponentType CAMERA_TYPE = Reflection::getComponentType("camera");
|
||||
static const ComponentType GLOBAL_LIGHT_TYPE = Reflection::getComponentType("global_light");
|
||||
static const ComponentType ENVIRONMENT_TYPE = Reflection::getComponentType("environment");
|
||||
static const ComponentType POINT_LIGHT_TYPE = Reflection::getComponentType("point_light");
|
||||
static const ComponentType TERRAIN_TYPE = Reflection::getComponentType("terrain");
|
||||
|
||||
|
@ -145,7 +145,7 @@ struct EditorIconsImpl final : public EditorIcons
|
|||
icon.type = IconType::CAMERA;
|
||||
break;
|
||||
}
|
||||
if(cmp.type == GLOBAL_LIGHT_TYPE || cmp.type == POINT_LIGHT_TYPE)
|
||||
if(cmp.type == ENVIRONMENT_TYPE || cmp.type == POINT_LIGHT_TYPE)
|
||||
{
|
||||
icon.type = IconType::LIGHT;
|
||||
break;
|
||||
|
|
|
@ -1429,6 +1429,7 @@ public:
|
|||
if (dropped_entity != entity)
|
||||
{
|
||||
m_editor->makeParent(entity, dropped_entity);
|
||||
ImGui::EndDragDropTarget();
|
||||
if (node_open) ImGui::TreePop();
|
||||
return;
|
||||
}
|
||||
|
@ -1520,8 +1521,7 @@ public:
|
|||
ImGui::PopItemWidth();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
// TODO uncomment once it's fixed in imgui
|
||||
/*if (ImGui::BeginDragDropTarget())
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (auto* payload = ImGui::AcceptDragDropPayload("entity"))
|
||||
{
|
||||
|
@ -1529,7 +1529,7 @@ public:
|
|||
m_editor->makeParent(INVALID_ENTITY, dropped_entity);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ static const ComponentType TERRAIN_TYPE = Reflection::getComponentType("terrain"
|
|||
static const ComponentType CAMERA_TYPE = Reflection::getComponentType("camera");
|
||||
static const ComponentType DECAL_TYPE = Reflection::getComponentType("decal");
|
||||
static const ComponentType POINT_LIGHT_TYPE = Reflection::getComponentType("point_light");
|
||||
static const ComponentType GLOBAL_LIGHT_TYPE = Reflection::getComponentType("global_light");
|
||||
static const ComponentType ENVIRONMENT_TYPE = Reflection::getComponentType("environment");
|
||||
static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("model_instance");
|
||||
static const ComponentType TEXT_MESH_TYPE = Reflection::getComponentType("text_mesh");
|
||||
static const ComponentType ENVIRONMENT_PROBE_TYPE = Reflection::getComponentType("environment_probe");
|
||||
|
@ -602,9 +602,9 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
mtx.lookAt({10, 10, 10}, Vec3::ZERO, {0, 1, 0});
|
||||
const EntityRef light_entity = m_tile.universe->createEntity({10, 10, 10}, mtx.getRotation());
|
||||
RenderScene* render_scene = (RenderScene*)m_tile.universe->getScene(MODEL_INSTANCE_TYPE);
|
||||
m_tile.universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
|
||||
render_scene->getGlobalLight(light_entity).m_diffuse_intensity = 1;
|
||||
render_scene->getGlobalLight(light_entity).m_indirect_intensity = 1;
|
||||
m_tile.universe->createComponent(ENVIRONMENT_TYPE, light_entity);
|
||||
render_scene->getEnvironment(light_entity).m_diffuse_intensity = 1;
|
||||
render_scene->getEnvironment(light_entity).m_indirect_intensity = 1;
|
||||
|
||||
m_tile.pipeline->setScene(render_scene);
|
||||
}
|
||||
|
@ -626,9 +626,9 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
|
|||
Matrix mtx;
|
||||
mtx.lookAt({10, 10, 10}, Vec3::ZERO, {0, 1, 0});
|
||||
auto light_entity = m_universe->createEntity({0, 0, 0}, mtx.getRotation());
|
||||
m_universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
|
||||
render_scene->getGlobalLight(light_entity).m_diffuse_intensity = 1;
|
||||
render_scene->getGlobalLight(light_entity).m_indirect_intensity = 1;
|
||||
m_universe->createComponent(ENVIRONMENT_TYPE, light_entity);
|
||||
render_scene->getEnvironment(light_entity).m_diffuse_intensity = 1;
|
||||
render_scene->getEnvironment(light_entity).m_indirect_intensity = 1;
|
||||
|
||||
m_pipeline->setScene(render_scene);
|
||||
}
|
||||
|
@ -2655,7 +2655,7 @@ struct GizmoPlugin final : public WorldEditor::Plugin
|
|||
showPointLightGizmo(cmp);
|
||||
return true;
|
||||
}
|
||||
if (cmp.type == GLOBAL_LIGHT_TYPE)
|
||||
if (cmp.type == ENVIRONMENT_TYPE)
|
||||
{
|
||||
showGlobalLightGizmo(cmp);
|
||||
return true;
|
||||
|
@ -2794,7 +2794,7 @@ struct StudioAppPlugin : StudioApp::IPlugin
|
|||
IAllocator& allocator = m_app.getWorldEditor().getAllocator();
|
||||
|
||||
m_app.registerComponent("camera", "Render/Camera");
|
||||
m_app.registerComponent("global_light", "Render/Global light");
|
||||
m_app.registerComponent("environment", "Render/Environment");
|
||||
|
||||
m_app.registerComponentWithResource(
|
||||
"model_instance", "Render/Mesh", Model::TYPE, *Reflection::getProperty(MODEL_INSTANCE_TYPE, "Source"));
|
||||
|
|
|
@ -499,7 +499,7 @@ struct PipelineImpl final : Pipeline
|
|||
const int shadowmap_width = 1024;
|
||||
|
||||
const Universe& universe = m_scene->getUniverse();
|
||||
const EntityPtr light = m_scene->getActiveGlobalLight();
|
||||
const EntityPtr light = m_scene->getActiveEnvironment();
|
||||
const Vec4 cascades = light.isValid() ? m_scene->getShadowmapCascades((EntityRef)light) : Vec4(3, 10, 60, 150);
|
||||
const Matrix light_mtx = light.isValid() ? universe.getRelativeMatrix((EntityRef)light, m_viewport.pos) : Matrix::IDENTITY;
|
||||
|
||||
|
@ -607,13 +607,13 @@ struct PipelineImpl final : Pipeline
|
|||
global_state.framebuffer_size.x = m_viewport.w;
|
||||
global_state.framebuffer_size.y = m_viewport.h;
|
||||
|
||||
const EntityPtr global_light = m_scene->getActiveGlobalLight();
|
||||
const EntityPtr global_light = m_scene->getActiveEnvironment();
|
||||
if(global_light.isValid()) {
|
||||
EntityRef gl = (EntityRef)global_light;
|
||||
global_state.light_direction = Vec4(m_scene->getUniverse().getRotation(gl).rotate(Vec3(0, 0, -1)), 456);
|
||||
global_state.light_color = m_scene->getGlobalLight(gl).m_diffuse_color;
|
||||
global_state.light_intensity = m_scene->getGlobalLight(gl).m_diffuse_intensity;
|
||||
global_state.light_indirect_intensity = m_scene->getGlobalLight(gl).m_indirect_intensity;
|
||||
global_state.light_color = m_scene->getEnvironment(gl).m_diffuse_color;
|
||||
global_state.light_intensity = m_scene->getEnvironment(gl).m_diffuse_intensity;
|
||||
global_state.light_indirect_intensity = m_scene->getEnvironment(gl).m_indirect_intensity;
|
||||
}
|
||||
|
||||
prepareShadowCameras(global_state);
|
||||
|
|
|
@ -48,7 +48,7 @@ static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("m
|
|||
static const ComponentType DECAL_TYPE = Reflection::getComponentType("decal");
|
||||
static const ComponentType POINT_LIGHT_TYPE = Reflection::getComponentType("point_light");
|
||||
static const ComponentType PARTICLE_EMITTER_TYPE = Reflection::getComponentType("particle_emitter");
|
||||
static const ComponentType GLOBAL_LIGHT_TYPE = Reflection::getComponentType("global_light");
|
||||
static const ComponentType ENVIRONMENT_TYPE = Reflection::getComponentType("environment");
|
||||
static const ComponentType CAMERA_TYPE = Reflection::getComponentType("camera");
|
||||
static const ComponentType TERRAIN_TYPE = Reflection::getComponentType("terrain");
|
||||
static const ComponentType BONE_ATTACHMENT_TYPE = Reflection::getComponentType("bone_attachment");
|
||||
|
@ -629,9 +629,9 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void serializeGlobalLight(ISerializer& serializer, EntityRef entity)
|
||||
void serializeEnvironment(ISerializer& serializer, EntityRef entity)
|
||||
{
|
||||
GlobalLight& light = m_global_lights[entity];
|
||||
Environment& light = m_environments[entity];
|
||||
serializer.write("cascades", light.m_cascades);
|
||||
serializer.write("diffuse_color", light.m_diffuse_color);
|
||||
serializer.write("diffuse_intensity", light.m_diffuse_intensity);
|
||||
|
@ -643,9 +643,9 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void deserializeGlobalLight(IDeserializer& serializer, EntityRef entity, int scene_version)
|
||||
void deserializeEnvironment(IDeserializer& serializer, EntityRef entity, int scene_version)
|
||||
{
|
||||
GlobalLight light;
|
||||
Environment light;
|
||||
light.m_entity = entity;
|
||||
serializer.read(&light.m_cascades);
|
||||
serializer.read(&light.m_diffuse_color);
|
||||
|
@ -655,8 +655,8 @@ public:
|
|||
serializer.read(&light.m_fog_color);
|
||||
serializer.read(&light.m_fog_density);
|
||||
serializer.read(&light.m_fog_height);
|
||||
m_global_lights.insert(entity, light);
|
||||
m_universe.onComponentCreated(light.m_entity, GLOBAL_LIGHT_TYPE, this);
|
||||
m_environments.insert(entity, light);
|
||||
m_universe.onComponentCreated(light.m_entity, ENVIRONMENT_TYPE, this);
|
||||
m_active_global_light_entity = entity;
|
||||
}
|
||||
|
||||
|
@ -1085,8 +1085,8 @@ public:
|
|||
serializer.write(pl);
|
||||
}
|
||||
|
||||
serializer.write((i32)m_global_lights.size());
|
||||
for (const GlobalLight& light : m_global_lights)
|
||||
serializer.write((i32)m_environments.size());
|
||||
for (const Environment& light : m_environments)
|
||||
{
|
||||
serializer.write(light);
|
||||
}
|
||||
|
@ -1385,10 +1385,10 @@ public:
|
|||
|
||||
serializer.read(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
GlobalLight light;
|
||||
Environment light;
|
||||
serializer.read(light);
|
||||
m_global_lights.insert(light.m_entity, light);
|
||||
m_universe.onComponentCreated(light.m_entity, GLOBAL_LIGHT_TYPE, this);
|
||||
m_environments.insert(light.m_entity, light);
|
||||
m_universe.onComponentCreated(light.m_entity, ENVIRONMENT_TYPE, this);
|
||||
}
|
||||
serializer.read(m_active_global_light_entity);
|
||||
}
|
||||
|
@ -1458,15 +1458,15 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void destroyGlobalLight(EntityRef entity)
|
||||
void destroyEnvironment(EntityRef entity)
|
||||
{
|
||||
m_universe.onComponentDestroyed(entity, GLOBAL_LIGHT_TYPE, this);
|
||||
m_universe.onComponentDestroyed(entity, ENVIRONMENT_TYPE, this);
|
||||
|
||||
if ((EntityPtr)entity == m_active_global_light_entity)
|
||||
{
|
||||
m_active_global_light_entity = INVALID_ENTITY;
|
||||
}
|
||||
m_global_lights.erase(entity);
|
||||
m_environments.erase(entity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1625,9 +1625,9 @@ public:
|
|||
}
|
||||
|
||||
|
||||
GlobalLight& getGlobalLight(EntityRef entity) override
|
||||
Environment& getEnvironment(EntityRef entity) override
|
||||
{
|
||||
return m_global_lights[entity];
|
||||
return m_environments[entity];
|
||||
}
|
||||
|
||||
|
||||
|
@ -2864,7 +2864,7 @@ bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, render
|
|||
|
||||
Vec4 getShadowmapCascades(EntityRef entity) override
|
||||
{
|
||||
return m_global_lights[entity].m_cascades;
|
||||
return m_environments[entity].m_cascades;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2876,7 +2876,7 @@ bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, render
|
|||
valid_value.z = maximum(valid_value.y + 0.01f, valid_value.z);
|
||||
valid_value.w = maximum(valid_value.z + 0.01f, valid_value.w);
|
||||
|
||||
m_global_lights[entity].m_cascades = valid_value;
|
||||
m_environments[entity].m_cascades = valid_value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2893,30 +2893,18 @@ bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, render
|
|||
}
|
||||
|
||||
|
||||
void setActiveGlobalLight(EntityRef entity) override
|
||||
void setActiveEnvironment(EntityRef entity) override
|
||||
{
|
||||
m_active_global_light_entity = entity;
|
||||
}
|
||||
|
||||
|
||||
EntityPtr getActiveGlobalLight() override
|
||||
EntityPtr getActiveEnvironment() override
|
||||
{
|
||||
return m_active_global_light_entity;
|
||||
}
|
||||
|
||||
|
||||
EntityRef getPointLightEntity(EntityRef entity) const override
|
||||
{
|
||||
return m_point_lights[entity].entity;
|
||||
}
|
||||
|
||||
|
||||
EntityRef getGlobalLightEntity(EntityRef entity) const override
|
||||
{
|
||||
return m_global_lights[entity].m_entity;
|
||||
}
|
||||
|
||||
|
||||
void reloadEnvironmentProbe(EntityRef entity) override
|
||||
{
|
||||
auto& probe = m_environment_probes[entity];
|
||||
|
@ -3256,9 +3244,9 @@ bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, render
|
|||
IAllocator& getAllocator() override { return m_allocator; }
|
||||
|
||||
|
||||
void createGlobalLight(EntityRef entity)
|
||||
void createEnvironment(EntityRef entity)
|
||||
{
|
||||
GlobalLight light;
|
||||
Environment light;
|
||||
light.m_entity = entity;
|
||||
light.m_diffuse_color.set(1, 1, 1);
|
||||
light.m_diffuse_intensity = 0;
|
||||
|
@ -3269,10 +3257,10 @@ bgfx::TextureHandle& handle = pipeline->getRenderbuffer(framebuffer_name, render
|
|||
light.m_fog_bottom = 0.0f;
|
||||
light.m_fog_height = 10.0f;
|
||||
|
||||
if (m_global_lights.empty()) m_active_global_light_entity = entity;
|
||||
if (m_environments.empty()) m_active_global_light_entity = entity;
|
||||
|
||||
m_global_lights.insert(entity, light);
|
||||
m_universe.onComponentCreated(entity, GLOBAL_LIGHT_TYPE, this);
|
||||
m_environments.insert(entity, light);
|
||||
m_universe.onComponentCreated(entity, ENVIRONMENT_TYPE, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3402,7 +3390,7 @@ private:
|
|||
HashMap<EntityRef, Decal> m_decals;
|
||||
Array<ModelInstance> m_model_instances;
|
||||
Array<MeshSortData> m_mesh_sort_data;
|
||||
HashMap<EntityRef, GlobalLight> m_global_lights;
|
||||
HashMap<EntityRef, Environment> m_environments;
|
||||
HashMap<EntityRef, Camera> m_cameras;
|
||||
EntityPtr m_active_camera;
|
||||
AssociativeArray<EntityRef, TextMesh*> m_text_meshes;
|
||||
|
@ -3444,7 +3432,7 @@ static struct
|
|||
void (RenderSceneImpl::*destroyer)(EntityRef);
|
||||
} COMPONENT_INFOS[] = {
|
||||
COMPONENT_TYPE(MODEL_INSTANCE_TYPE, ModelInstance),
|
||||
COMPONENT_TYPE(GLOBAL_LIGHT_TYPE, GlobalLight),
|
||||
COMPONENT_TYPE(ENVIRONMENT_TYPE, Environment),
|
||||
COMPONENT_TYPE(POINT_LIGHT_TYPE, PointLight),
|
||||
COMPONENT_TYPE(DECAL_TYPE, Decal),
|
||||
COMPONENT_TYPE(CAMERA_TYPE, Camera),
|
||||
|
@ -3471,7 +3459,7 @@ RenderSceneImpl::RenderSceneImpl(Renderer& renderer,
|
|||
, m_text_meshes(m_allocator)
|
||||
, m_terrains(m_allocator)
|
||||
, m_point_lights(m_allocator)
|
||||
, m_global_lights(m_allocator)
|
||||
, m_environments(m_allocator)
|
||||
, m_decals(m_allocator)
|
||||
, m_debug_triangles(m_allocator)
|
||||
, m_debug_lines(m_allocator)
|
||||
|
@ -3532,8 +3520,7 @@ void RenderScene::registerLuaAPI(lua_State* L)
|
|||
REGISTER_FUNCTION(setGlobalLODMultiplier);
|
||||
REGISTER_FUNCTION(getGlobalLODMultiplier);
|
||||
REGISTER_FUNCTION(getCameraViewProjection);
|
||||
REGISTER_FUNCTION(getGlobalLightEntity);
|
||||
REGISTER_FUNCTION(getActiveGlobalLight);
|
||||
REGISTER_FUNCTION(getActiveEnvironment);
|
||||
REGISTER_FUNCTION(getModelInstanceModel);
|
||||
REGISTER_FUNCTION(addDebugCross);
|
||||
REGISTER_FUNCTION(addDebugLine);
|
||||
|
|
|
@ -60,7 +60,7 @@ struct TerrainInfo
|
|||
};
|
||||
|
||||
|
||||
struct GlobalLight
|
||||
struct Environment
|
||||
{
|
||||
Vec3 m_diffuse_color;
|
||||
float m_diffuse_intensity;
|
||||
|
@ -222,8 +222,8 @@ public:
|
|||
|
||||
virtual Pose* lockPose(EntityRef entity) = 0;
|
||||
virtual void unlockPose(EntityRef entity, bool changed) = 0;
|
||||
virtual EntityPtr getActiveGlobalLight() = 0;
|
||||
virtual void setActiveGlobalLight(EntityRef entity) = 0;
|
||||
virtual EntityPtr getActiveEnvironment() = 0;
|
||||
virtual void setActiveEnvironment(EntityRef entity) = 0;
|
||||
virtual Vec4 getShadowmapCascades(EntityRef entity) = 0;
|
||||
virtual void setShadowmapCascades(EntityRef entity, const Vec4& value) = 0;
|
||||
|
||||
|
@ -319,13 +319,11 @@ public:
|
|||
virtual void addGrass(EntityRef entity, int index) = 0;
|
||||
virtual void removeGrass(EntityRef entity, int index) = 0;
|
||||
|
||||
virtual GlobalLight& getGlobalLight(EntityRef entity) = 0;
|
||||
virtual Environment& getEnvironment(EntityRef entity) = 0;
|
||||
virtual PointLight& getPointLight(EntityRef entity) = 0;
|
||||
virtual int getClosestShadowcastingPointLights(const DVec3& reference_pos, int max_count, PointLight* lights) = 0;
|
||||
virtual float getLightRange(EntityRef entity) = 0;
|
||||
virtual void setLightRange(EntityRef entity, float value) = 0;
|
||||
virtual EntityRef getPointLightEntity(EntityRef entity) const = 0;
|
||||
virtual EntityRef getGlobalLightEntity(EntityRef entity) const = 0;
|
||||
|
||||
virtual EnvironmentProbe& getEnvironmentProbe(EntityRef entity) = 0;
|
||||
virtual void enableEnvironmentProbe(EntityRef entity, bool enable) = 0;
|
||||
|
|
|
@ -317,14 +317,14 @@ static void registerProperties(IAllocator& allocator)
|
|||
property("Source", LUMIX_PROP(RenderScene, ModelInstancePath),
|
||||
ResourceAttribute("Mesh (*.msh)", Model::TYPE))
|
||||
),
|
||||
component("global_light",
|
||||
var_property("Color", &RenderScene::getGlobalLight, &GlobalLight::m_diffuse_color, ColorAttribute()),
|
||||
var_property("Intensity", &RenderScene::getGlobalLight, &GlobalLight::m_diffuse_intensity, MinAttribute(0)),
|
||||
var_property("Indirect intensity", &RenderScene::getGlobalLight, &GlobalLight::m_indirect_intensity, MinAttribute(0)),
|
||||
var_property("Fog density", &RenderScene::getGlobalLight, &GlobalLight::m_fog_density, ClampAttribute(0, 1)),
|
||||
var_property("Fog bottom", &RenderScene::getGlobalLight, &GlobalLight::m_fog_bottom),
|
||||
var_property("Fog height", &RenderScene::getGlobalLight, &GlobalLight::m_fog_height, MinAttribute(0)),
|
||||
var_property("Fog color", &RenderScene::getGlobalLight, &GlobalLight::m_fog_color, ColorAttribute()),
|
||||
component("environment",
|
||||
var_property("Color", &RenderScene::getEnvironment, &Environment::m_diffuse_color, ColorAttribute()),
|
||||
var_property("Intensity", &RenderScene::getEnvironment, &Environment::m_diffuse_intensity, MinAttribute(0)),
|
||||
var_property("Indirect intensity", &RenderScene::getEnvironment, &Environment::m_indirect_intensity, MinAttribute(0)),
|
||||
var_property("Fog density", &RenderScene::getEnvironment, &Environment::m_fog_density, ClampAttribute(0, 1)),
|
||||
var_property("Fog bottom", &RenderScene::getEnvironment, &Environment::m_fog_bottom),
|
||||
var_property("Fog height", &RenderScene::getEnvironment, &Environment::m_fog_height, MinAttribute(0)),
|
||||
var_property("Fog color", &RenderScene::getEnvironment, &Environment::m_fog_color, ColorAttribute()),
|
||||
property("Shadow cascades", LUMIX_PROP(RenderScene, ShadowmapCascades))
|
||||
),
|
||||
component("point_light",
|
||||
|
|
Loading…
Reference in a new issue