Skip to content

Commit

Permalink
Expose settng custom uniforms via script, and rename stored param dic…
Browse files Browse the repository at this point in the history
…tionary to cache
  • Loading branch information
TokisanGames committed Oct 18, 2023
1 parent 6aba3c7 commit d36ee4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,19 @@ void Terrain3DMaterial::set_shader_override(const Ref<Shader> &p_shader) {
_update_shader();
}

void Terrain3DMaterial::set_shader_params(const Dictionary &p_dict) {
void Terrain3DMaterial::set_shader_param(const StringName &p_name, const Variant &p_value) {
LOG(INFO, "Setting shader parameter: ", p_name);
_set(p_name, p_value);
}

Variant Terrain3DMaterial::get_shader_param(const StringName &p_name) const {
LOG(INFO, "Setting shader parameter: ", p_name);
Variant value;
_get(p_name, value);
return value;
}

void Terrain3DMaterial::set_shader_param_cache(const Dictionary &p_dict) {
LOG(INFO, "Setting param cache dictionary: ", p_dict.size());
_shader_params = p_dict;
}
Expand Down Expand Up @@ -603,8 +615,10 @@ void Terrain3DMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shader_override", "shader"), &Terrain3DMaterial::set_shader_override);
ClassDB::bind_method(D_METHOD("get_shader_override"), &Terrain3DMaterial::get_shader_override);

ClassDB::bind_method(D_METHOD("set_shader_params", "dict"), &Terrain3DMaterial::set_shader_params);
ClassDB::bind_method(D_METHOD("get_shader_params"), &Terrain3DMaterial::get_shader_params);
ClassDB::bind_method(D_METHOD("set_shader_param", "name", "value"), &Terrain3DMaterial::set_shader_param);
ClassDB::bind_method(D_METHOD("get_shader_param", "name"), &Terrain3DMaterial::get_shader_param);
ClassDB::bind_method(D_METHOD("set_shader_param_cache", "dict"), &Terrain3DMaterial::set_shader_param_cache);
ClassDB::bind_method(D_METHOD("get_shader_param_cache"), &Terrain3DMaterial::get_shader_param_cache);

ClassDB::bind_method(D_METHOD("set_region_size"), &Terrain3DMaterial::set_region_size);
ClassDB::bind_method(D_METHOD("get_region_size"), &Terrain3DMaterial::get_region_size);
Expand Down Expand Up @@ -638,7 +652,7 @@ void Terrain3DMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shader_override_enabled", PROPERTY_HINT_NONE), "enable_shader_override", "is_shader_override_enabled");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shader_override", PROPERTY_HINT_RESOURCE_TYPE, "Shader"), "set_shader_override", "get_shader_override");

ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "shader_params", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_shader_params", "get_shader_params");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "shader_params", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_shader_param_cache", "get_shader_param_cache");

ADD_GROUP("Debug Views", "show_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_checkered", PROPERTY_HINT_NONE), "set_show_checkered", "get_show_checkered");
Expand Down
6 changes: 4 additions & 2 deletions src/terrain_3d_material.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ class Terrain3DMaterial : public Resource {
void set_shader_override(const Ref<Shader> &p_shader);
Ref<Shader> get_shader_override() const { return _shader_override; }

void set_shader_params(const Dictionary &p_dict);
Dictionary get_shader_params() const { return _shader_params; }
void set_shader_param(const StringName &p_name, const Variant &p_value);
Variant get_shader_param(const StringName &p_name) const;
void set_shader_param_cache(const Dictionary &p_dict);
Dictionary get_shader_param_cache() const { return _shader_params; }

void set_region_size(int p_size);
int get_region_size() const { return _region_size; }
Expand Down

0 comments on commit d36ee4f

Please sign in to comment.