Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ void Terrain3D::_generate_triangle_pair(PackedVector3Array &p_vertices, PackedVe
///////////////////////////

Terrain3D::Terrain3D() {
LOG(INFO, "Terrain3D v", _version, " - https://github.com/TokisanGames/Terrain3D");
// Process the command line
PackedStringArray args = OS::get_singleton()->get_cmdline_args();
for (int i = args.size() - 1; i >= 0; i--) {
Expand Down
59 changes: 39 additions & 20 deletions src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,21 @@ void Terrain3DMaterial::_update_uniforms(const RID &p_material, const uint32_t p
LOG(EXTREME, "Setting region size in material: ", region_size);
RS->material_set_param(p_material, "_region_size", region_size);
RS->material_set_param(p_material, "_region_texel_size", 1.0f / region_size);

if (p_flags & REGION_ARRAYS) {
RS->material_set_param(p_material, "_height_maps", data->get_height_maps_rid());
RS->material_set_param(p_material, "_control_maps", data->get_control_maps_rid());
RS->material_set_param(p_material, "_color_maps", data->get_color_maps_rid());
LOG(EXTREME, "Height map RID: ", data->get_height_maps_rid());
LOG(EXTREME, "Control map RID: ", data->get_control_maps_rid());
LOG(EXTREME, "Color map RID: ", data->get_color_maps_rid());
if (data->get_region_count() > 0) {
RS->material_set_param(p_material, "_height_maps", data->get_height_maps_rid());
RS->material_set_param(p_material, "_control_maps", data->get_control_maps_rid());
RS->material_set_param(p_material, "_color_maps", data->get_color_maps_rid());
LOG(EXTREME, "Height map RID: ", data->get_height_maps_rid());
LOG(EXTREME, "Control map RID: ", data->get_control_maps_rid());
LOG(EXTREME, "Color map RID: ", data->get_color_maps_rid());
} else {
// Send dummy texture array to stop compatibility error spam
RS->material_set_param(p_material, "_height_maps", _generated_dummy.get_rid());
RS->material_set_param(p_material, "_control_maps", _generated_dummy.get_rid());
RS->material_set_param(p_material, "_color_maps", _generated_dummy.get_rid());
}
}

real_t spacing = _terrain->get_vertex_spacing();
Expand All @@ -651,10 +659,25 @@ void Terrain3DMaterial::_update_uniforms(const RID &p_material, const uint32_t p
return;
}

if (p_flags & TEXTURE_ARRAYS) {
RS->material_set_param(p_material, "_texture_array_albedo", asset_list->get_albedo_array_rid());
RS->material_set_param(p_material, "_texture_array_normal", asset_list->get_normal_array_rid());
if (asset_list->get_generated_array_size() > 0) {
if (p_flags & TEXTURE_ARRAYS) {
RS->material_set_param(p_material, "_texture_array_albedo", asset_list->get_albedo_array_rid());
RS->material_set_param(p_material, "_texture_array_normal", asset_list->get_normal_array_rid());
}
set_show_checkered(false);
LOG(DEBUG, "Texture count >0: ", asset_list->get_generated_array_size(), ", disabling checkered view");
} else {
// Send dummy texture array to stop compatibility error spam
RS->material_set_param(p_material, "_texture_array_albedo", _generated_dummy.get_rid());
RS->material_set_param(p_material, "_texture_array_normal", _generated_dummy.get_rid());

// Enable checkered view if texture_count is 0, disable if not
if (_debug_view_checkered == false) {
set_show_checkered(true);
LOG(DEBUG, "No textures, enabling checkered view");
}
}

RS->material_set_param(p_material, "_texture_color_array", asset_list->get_texture_colors());
RS->material_set_param(p_material, "_texture_normal_depth_array", asset_list->get_texture_normal_depths());
RS->material_set_param(p_material, "_texture_ao_strength_array", asset_list->get_texture_ao_strengths());
Expand All @@ -663,17 +686,6 @@ void Terrain3DMaterial::_update_uniforms(const RID &p_material, const uint32_t p
RS->material_set_param(p_material, "_texture_uv_scale_array", asset_list->get_texture_uv_scales());
RS->material_set_param(p_material, "_texture_detile_array", asset_list->get_texture_detiles());
RS->material_set_param(p_material, "_texture_displacement_array", asset_list->get_texture_displacements());

// Enable checkered view if texture_count is 0, disable if not
if (asset_list->get_generated_array_size() == 0) {
if (_debug_view_checkered == false) {
set_show_checkered(true);
LOG(DEBUG, "No textures, enabling checkered view");
}
} else {
set_show_checkered(false);
LOG(DEBUG, "Texture count >0: ", asset_list->get_generated_array_size(), ", disabling checkered view");
}
}

void Terrain3DMaterial::_set_shader_parameters(const Dictionary &p_dict) {
Expand Down Expand Up @@ -705,6 +717,12 @@ void Terrain3DMaterial::initialize(Terrain3D *p_terrain) {
}
_shader.instantiate();
_buffer_shader.instantiate();
{ // Create dummy texture array to avoid empty sampler2DArrays
Ref<Image> img = Image::create(1, 1, false, Image::FORMAT_RF);
TypedArray<Image> ia = { img };
_generated_dummy.create(ia);
}

update(FULL_REBUILD);
}

Expand All @@ -721,6 +739,7 @@ void Terrain3DMaterial::destroy() {
_shader_code.clear();
_active_params.clear();
_shader_params.clear();
_generated_dummy.clear();
if (_material.is_valid()) {
RS->free_rid(_material);
_material = RID();
Expand Down
1 change: 1 addition & 0 deletions src/terrain_3d_material.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Terrain3DMaterial : public Resource {
Ref<Shader> _buffer_shader_override; // User's shader we copy code from
real_t _displacement_scale = 1.0f;
real_t _displacement_sharpness = 0.5f;
GeneratedTexture _generated_dummy;

// Material Features
WorldBackground _world_background = FLAT;
Expand Down