Allow the shadow type and map size to be configured in data.
PiperOrigin-RevId: 875179785 Change-Id: I638c8c8c9e45dd58f393684a09f2ab4871911f7a
This commit is contained in:
committed by
Copybara-Service
parent
0c66585e39
commit
abdea379af
@@ -71,6 +71,7 @@ Light::Light(ObjectManager* object_mgr, const Params& params)
|
|||||||
opts.shadowCascades =
|
opts.shadowCascades =
|
||||||
type == filament::LightManager::Type::DIRECTIONAL ? 4 : 1;
|
type == filament::LightManager::Type::DIRECTIONAL ? 4 : 1;
|
||||||
opts.shadowBulbRadius = params.bulbradius;
|
opts.shadowBulbRadius = params.bulbradius;
|
||||||
|
opts.mapSize = params.shadow_map_size;
|
||||||
builder.shadowOptions(opts);
|
builder.shadowOptions(opts);
|
||||||
|
|
||||||
entity_ = utils::EntityManager::get().create();
|
entity_ = utils::EntityManager::get().create();
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ class Light {
|
|||||||
float spot_cone_angle = 180.f;
|
float spot_cone_angle = 180.f;
|
||||||
// The radius of the bulb used for soft shadows.
|
// The radius of the bulb used for soft shadows.
|
||||||
float bulbradius = 0.0f;
|
float bulbradius = 0.0f;
|
||||||
|
// The size of the shadow map.
|
||||||
|
int shadow_map_size = 2048;
|
||||||
// Whether or not the light is a headlight.
|
// Whether or not the light is a headlight.
|
||||||
bool headlight = false;
|
bool headlight = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ T ReadElement(const mjModel* model, const char* name, T default_value = T()) {
|
|||||||
} else if constexpr (std::is_arithmetic_v<T>) {
|
} else if constexpr (std::is_arithmetic_v<T>) {
|
||||||
const mjtNum* ptr = model->numeric_data + model->numeric_adr[id];
|
const mjtNum* ptr = model->numeric_data + model->numeric_adr[id];
|
||||||
return static_cast<T>(*ptr);
|
return static_cast<T>(*ptr);
|
||||||
|
} else if constexpr (std::is_enum_v<T>) {
|
||||||
|
const mjtNum* ptr = model->numeric_data + model->numeric_adr[id];
|
||||||
|
return static_cast<T>(static_cast<int>(*ptr));
|
||||||
} else if constexpr (std::is_same_v<T, filament::math::float2>) {
|
} else if constexpr (std::is_same_v<T, filament::math::float2>) {
|
||||||
const mjtNum* ptr = model->numeric_data + model->numeric_adr[id];
|
const mjtNum* ptr = model->numeric_data + model->numeric_adr[id];
|
||||||
if (model->numeric_size[id] != 2) mju_error("Invalid numeric size.");
|
if (model->numeric_size[id] != 2) mju_error("Invalid numeric size.");
|
||||||
|
|||||||
@@ -132,6 +132,13 @@ SceneView::SceneView(filament::Engine* engine, ObjectManager* object_mgr)
|
|||||||
msaa.enabled = ReadElement(m, "filament.msaa.enabled", true);
|
msaa.enabled = ReadElement(m, "filament.msaa.enabled", true);
|
||||||
views_[kNormalIndex]->setMultiSampleAntiAliasingOptions(msaa);
|
views_[kNormalIndex]->setMultiSampleAntiAliasingOptions(msaa);
|
||||||
|
|
||||||
|
default_shadow_map_size_ = ReadElement(
|
||||||
|
m, "filament.shadows.map_size", default_shadow_map_size_);
|
||||||
|
|
||||||
|
auto shadow_type = views_[kNormalIndex]->getShadowType();
|
||||||
|
shadow_type = ReadElement(m, "filament.shadows.type", shadow_type);
|
||||||
|
views_[kNormalIndex]->setShadowType(shadow_type);
|
||||||
|
|
||||||
// Disable post processing for the depth and segmentation views to preserve
|
// Disable post processing for the depth and segmentation views to preserve
|
||||||
// the values.
|
// the values.
|
||||||
views_[kDepthIndex]->setPostProcessingEnabled(false);
|
views_[kDepthIndex]->setPostProcessingEnabled(false);
|
||||||
@@ -290,9 +297,11 @@ void SceneView::PrepareLights() {
|
|||||||
params.bulbradius = model->light_bulbradius[i];
|
params.bulbradius = model->light_bulbradius[i];
|
||||||
params.range = model->light_range[i];
|
params.range = model->light_range[i];
|
||||||
params.intensity = model->light_intensity[i];
|
params.intensity = model->light_intensity[i];
|
||||||
|
params.shadow_map_size = default_shadow_map_size_;
|
||||||
if (params.type == mjLIGHT_SPOT) {
|
if (params.type == mjLIGHT_SPOT) {
|
||||||
params.spot_cone_angle = model->light_cutoff[i];
|
params.spot_cone_angle = model->light_cutoff[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto light_obj = std::make_unique<Light>(object_mgr_, params);
|
auto light_obj = std::make_unique<Light>(object_mgr_, params);
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
// TODO(b/458045799): Re-enable when lights work on glinux and chromebook.
|
// TODO(b/458045799): Re-enable when lights work on glinux and chromebook.
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class SceneView {
|
|||||||
ColorGradingOptions color_grading_options_;
|
ColorGradingOptions color_grading_options_;
|
||||||
DrawMode active_mode_ = DrawMode::kNumDrawModes;
|
DrawMode active_mode_ = DrawMode::kNumDrawModes;
|
||||||
float aspect_ratio_ = 1.0f;
|
float aspect_ratio_ = 1.0f;
|
||||||
|
int default_shadow_map_size_ = 2048;
|
||||||
float fallback_head_light_intensity_ = 0.f;
|
float fallback_head_light_intensity_ = 0.f;
|
||||||
float fallback_scene_light_intensity_ = 80'000.f;
|
float fallback_scene_light_intensity_ = 80'000.f;
|
||||||
float fallback_environment_light_intensity_ = 5'000.f;
|
float fallback_environment_light_intensity_ = 5'000.f;
|
||||||
|
|||||||
Reference in New Issue
Block a user