the lua commands you are using only work on 'old' shading env objects.
Does your level have a 'new' shading env entity?
(one that has components etc?)
If so, then these lua commands don't work on it.
(which imo is kinda of a bug on our end, but that is still being debated)
I'm going to dump a bunch of lua code here to show you how to set the properties for the 'new' shading env entity.
This is pretty sucky and hopefully we will provide a nicer interface for this in the future (or just make the old lua calls work with the new entity)
-- Cached Engine Modules
local Application = stingray.Application
local Keyboard = stingray.Keyboard
local Vector3 = stingray.Vector3
local Quaternion = stingray.Quaternion
local World = stingray.World
local Unit = stingray.Unit
local Window = stingray.Window
local World = stingray.World
local Level = stingray.Level
local EntityManager = stingray.EntityManager
Game = Game or {}
local Game = Game
local shading_env_entity = nil
local exposure_component = nil
function gather_shading_env_params()
-- this tries to find shading environment variables from the shading env entity
-- in the future, there may be better API to handle this, but for now we loop all entities.
local data_component_manager = EntityManager.data_component(Game.world)
local all_entity_handles = World.entities(Game.world)
for _, entity_handle in ipairs(all_entity_handles) do
local all_data_component_handles = {data_component_manager:instances(entity_handle)} -- Returns values on stack, so wrap in {} to get array.
for _, data_component_handle in ipairs(all_data_component_handles) do
-- Missing properties return nil, so this is "safe".
local shading_environment_mapping_resource_name = data_component_manager:get_property(entity_handle, data_component_handle, {"shading_environment_mapping"})
if shading_environment_mapping_resource_name == "core/stingray_renderer/shading_environment_components/exposure" then
if (shading_env_entity == nil) then
shading_env_entity = entity_handle
end
exposure_component = data_component_handle;
end
end
end
end
function update_shading_env_entity()
-- Arrays are immutable - must replace whole array, not a component.
-- Thus, colors, vectors and ranges are set using whole arrays.
-- Refer to "core/stingray_renderer/shading_environment_components/fog.component" for available properties.
--local fog_rgb_linear = {1.0, 0.5, 0.0}
--local fog_alpha = 1.0
--local fog_depth_range = {20, 150}
--data_component_manager:set_property(entity_handle, data_component_handle, {"fog_color", "rgb"}, fog_rgb_linear)
--data_component_manager:set_property(entity_handle, data_component_handle, {"fog_color", "alpha"}, fog_alpha)
--data_component_manager:set_property(entity_handle, data_component_handle, {"fog_depth_range"}, fog_depth_range)
if (shading_env_entity ~= nil) then
local data_component_manager = EntityManager.data_component(Game.world)
if (exposure_component ~= nil) then
local exposure_val = 0.2
data_component_manager:set_property(shading_env_entity, exposure_component, {"exposure"}, exposure_val)
end
end
end
function init()
if LEVEL_EDITOR_TEST and not LEVEL_EDITOR_TEST_READY then
print("Waiting for test level initialization...")
return
end
Game.world = Application.new_world()
Game.viewport = Application.create_viewport(Game.world, "default")
local level = World.load_level(Game.world, "content/levels/empty")
Level.spawn_background(level)
Level.trigger_level_loaded(level)
stingray.Window.set_clip_cursor(true)
stingray.Window.set_mouse_focus(true)
stingray.Window.set_show_cursor(true)
-- even though we have a entitiy shading env in our levels, we still need the 'old' shading environment to pass to render_world in render()
-- values set in the shading env entity will automatically override the values in the old shading env.
-- so to get values to change in your level, you need to update them in the entity
if Level.has_data(level, "shading_environment") then
print("level has shading env")
World.set_shading_environment(Game.world, Game.shading_environment, Level.get_data(level, "shading_environment"))
else
Game.shading_environment = World.create_shading_environment(Game.world, "core/stingray_renderer/environments/midday/midday")
end
Game.camera_unit = World.spawn_unit(Game.world, "core/units/camera")
gather_shading_env_params()
--Game.model_unit = stingray.World.unit_by_name(Game.world, "some_model");
--model_position = stingray.Unit.local_position(Game.model_unit, 1);
end
function update(dt)
if LEVEL_EDITOR_TEST and not LEVEL_EDITOR_TEST_READY then return end
update_shading_env_entity()
Game.world:update(dt)
end
function render()
if LEVEL_EDITOR_TEST and not LEVEL_EDITOR_TEST_READY then return end
local camera = Unit.camera(Game.camera_unit, "camera")
Application.render_world(Game.world, camera, Game.viewport, Game.shading_environment)
end