add setBloom method

This commit is contained in:
Nick Fisher
2023-08-24 09:36:30 +08:00
parent 482666da31
commit e1edb6299a
6 changed files with 29 additions and 4 deletions

View File

@@ -53,6 +53,7 @@ namespace polyvox {
~FilamentViewer();
void setToneMapping(ToneMapping toneMapping);
void setBloom(float strength);
void loadSkybox(const char* const skyboxUri);
void removeSkybox();

View File

@@ -15,6 +15,7 @@ void set_background_image(const void* const viewer, const char *path);
void set_background_image_position(const void* const viewer, float x, float y, bool clamp);
void set_background_color(const void* const viewer, const float r, const float g, const float b, const float a);
void set_tone_mapping(const void* const viewer, int toneMapping);
void set_bloom(const void* const viewer, float strength);
void load_skybox(const void* const viewer, const char *skyboxPath);
void load_ibl(const void* const viewer, const char *iblPath, float intensity);
void remove_skybox(const void* const viewer);

View File

@@ -138,10 +138,7 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
setToneMapping(ToneMapping::ACES);
decltype(_view->getBloomOptions()) opts;
opts.enabled = true;
opts.strength = 0.6f;
_view->setBloomOptions(opts);
setBloom(0.6f);
_view->setScene(_scene);
_view->setCamera(_mainCamera);
@@ -238,6 +235,13 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
_scene->addEntity(imageEntity);
}
void FilamentViewer::setBloom(float strength) {
decltype(_view->getBloomOptions()) opts;
opts.enabled = true;
opts.strength = strength;
_view->setBloomOptions(opts);
}
void FilamentViewer::setToneMapping(ToneMapping toneMapping) {
ToneMapper* tm;

View File

@@ -52,6 +52,11 @@ extern "C" {
((FilamentViewer*)viewer)->setToneMapping((ToneMapping)toneMapping);
}
FLUTTER_PLUGIN_EXPORT void set_bloom(const void* const viewer, float strength) {
Log("Setting bloom to %f", strength);
((FilamentViewer*)viewer)->setBloom(strength);
}
FLUTTER_PLUGIN_EXPORT void load_skybox(const void* const viewer, const char* skyboxPath) {
((FilamentViewer*)viewer)->loadSkybox(skyboxPath);
}

View File

@@ -366,6 +366,12 @@ class FilamentController {
}
}
void setBloom(double bloom) async {
if (!await _channel.invokeMethod("setBloom", bloom)) {
throw Exception("Failed to set bloom");
}
}
void setCameraFocalLength(double focalLength) async {
await _channel.invokeMethod("setCameraFocalLength", focalLength);
}

View File

@@ -703,6 +703,12 @@ static FlMethodResponse* _set_tone_mapping(PolyvoxFilamentPlugin* self, FlMethod
return FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(true)));
}
static FlMethodResponse* _set_bloom(PolyvoxFilamentPlugin* self, FlMethodCall* method_call) {
FlValue* args = fl_method_call_get_args(method_call);
set_bloom(self->viewer, fl_value_get_float(args));
return FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(true)));
}
// Called when a method call is received from Flutter.
static void polyvox_filament_plugin_handle_method_call(
PolyvoxFilamentPlugin* self,
@@ -722,6 +728,8 @@ static void polyvox_filament_plugin_handle_method_call(
response = _get_asset_manager(self, method_call);
} else if(strcmp(method, "setToneMapping") == 0) {
response = _set_tone_mapping(self, method_call);
} else if(strcmp(method, "setBloom") == 0) {
response = _set_bloom(self, method_call);
} else if(strcmp(method, "resize") == 0) {
response = _resize(self, method_call);
} else if(strcmp(method, "getContext") == 0) {