feat(web): wire Blender light cascade controls
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

This commit is contained in:
mes123456
2026-08-30 19:10:24 +08:00
parent 4ce5581bc3
commit ab8d5120b0
40 changed files with 1987 additions and 22 deletions

View File

@@ -5171,6 +5171,10 @@ json scene_ir_from_blend(const ParsedBlend &blend,
{"shadowFilterRadius", read_float(*blend.sdna, element, "shadow_filter_radius").value_or(1.0f)},
{"shadowMaximumResolution", read_float(*blend.sdna, element, "shadow_maximum_resolution").value_or(0.001f)},
{"shadowJitterOverblur", read_float(*blend.sdna, element, "shadow_jitter_overblur").value_or(10.0f)},
{"cascadeMaxDistance", read_float(*blend.sdna, element, "cascade_max_dist").value_or(200.0f)},
{"cascadeExponent", read_float(*blend.sdna, element, "cascade_exponent").value_or(0.8f)},
{"cascadeFade", read_float(*blend.sdna, element, "cascade_fade").value_or(0.1f)},
{"cascadeCount", read_integer(*blend.sdna, element, "cascade_count").value_or(4)},
{"areaSize", read_float(*blend.sdna, element, "area_size").value_or(0.25f)},
{"areaSizeY", read_float(*blend.sdna, element, "area_sizey").value_or(0.25f)},
{"areaSpread", read_float(*blend.sdna, element, "area_spread").value_or(3.14159265f)},

View File

@@ -5515,6 +5515,37 @@ bool web_engine_blend_main_set_light_shadow_controls(WebBlendMainState *state,
return true;
}
bool web_engine_blend_main_set_light_cascade_controls(WebBlendMainState *state,
const char *target_id,
const float max_distance,
const float exponent,
const float fade,
const int count,
std::string &error)
{
if (state == nullptr || state->main == nullptr || target_id == nullptr) {
error = "RENDER_PROPERTY_INVALID: light cascade target is missing";
return false;
}
Light *light = find_light(state->main, target_id);
if (light == nullptr || !ensure_single_user_data(state->main, &light->id, error)) {
if (error.empty()) error = "RENDER_PROPERTY_INVALID: light was not found";
return false;
}
if (!std::isfinite(max_distance) || max_distance < 0.0f || max_distance > 1.0e9f ||
!std::isfinite(exponent) || exponent < 0.0f || exponent > 100.0f ||
!std::isfinite(fade) || fade < 0.0f || fade > 1.0f || count < 1 || count > 4) {
error = "RENDER_PROPERTY_INVALID: light cascade control is outside the bounded range";
return false;
}
light->cascade_max_dist = max_distance;
light->cascade_exponent = exponent;
light->cascade_fade = fade;
light->cascade_count = count;
light->id.recalc |= ID_RECALC_PARAMETERS;
return true;
}
bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
const char *target_id,
const char *properties_json,
@@ -5711,7 +5742,7 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
if (strncmp(target_id, "light:", 6) == 0) {
Light *light = find_light(state->main, target_id);
if (light == nullptr || !ensure_single_user_data(state->main, &light->id, error)) return false;
if (!reject_unknown({"type", "areaShape", "diffuseFactor", "specularFactor", "transmissionFactor", "volumeFactor", "attenuationDistance", "shadowFilterRadius", "shadowMaximumResolution", "shadowJitterOverblur", "color", "energy", "exposure", "temperature", "useTemperature",
if (!reject_unknown({"type", "areaShape", "diffuseFactor", "specularFactor", "transmissionFactor", "volumeFactor", "attenuationDistance", "shadowFilterRadius", "shadowMaximumResolution", "shadowJitterOverblur", "cascadeMaxDistance", "cascadeExponent", "cascadeFade", "cascadeCount", "color", "energy", "exposure", "temperature", "useTemperature",
"castsShadow", "radius", "spotAngle", "spotBlend", "areaSize",
"areaSizeY", "areaSpread", "sunAngle"}))
{
@@ -5764,6 +5795,29 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
if (attenuation < 0.0f || filter_radius < 0.0f || maximum_resolution < 0.0f || jitter_overblur < 0.0f ||
!web_engine_blend_main_set_light_shadow_controls(state, target_id, attenuation, filter_radius, maximum_resolution, jitter_overblur, error)) return false;
}
if (properties.contains("cascadeMaxDistance") || properties.contains("cascadeExponent") || properties.contains("cascadeFade") || properties.contains("cascadeCount")) {
const auto cascade_value = [&](const char *key, const float current) {
if (!properties.contains(key)) return current;
if (!properties[key].is_number()) {
error = std::string("RENDER_PROPERTY_INVALID: ") + key + " must be numeric";
return -1.0f;
}
return properties[key].get<float>();
};
const float max_distance = cascade_value("cascadeMaxDistance", light->cascade_max_dist);
const float exponent = cascade_value("cascadeExponent", light->cascade_exponent);
const float fade = cascade_value("cascadeFade", light->cascade_fade);
int count = light->cascade_count;
if (properties.contains("cascadeCount")) {
if (!properties["cascadeCount"].is_number_integer()) {
error = "RENDER_PROPERTY_INVALID: cascadeCount must be an integer";
return false;
}
count = properties["cascadeCount"].get<int>();
}
if (max_distance < 0.0f || exponent < 0.0f || fade < 0.0f ||
!web_engine_blend_main_set_light_cascade_controls(state, target_id, max_distance, exponent, fade, count, error)) return false;
}
if (!read_color("color", &light->r) ||
!read_float("energy", 0.0f, 1.0e9f, light->energy) ||
!read_float("exposure", -20.0f, 20.0f, light->exposure) ||

View File

@@ -538,6 +538,13 @@ bool web_engine_blend_main_set_light_shadow_controls(WebBlendMainState *state,
float shadow_maximum_resolution,
float shadow_jitter_overblur,
std::string &error);
bool web_engine_blend_main_set_light_cascade_controls(WebBlendMainState *state,
const char *target_id,
float max_distance,
float exponent,
float fade,
int count,
std::string &error);
bool web_engine_blend_main_set_scene_properties(WebBlendMainState *state,
const char *target_id,
const char *properties_json,