Skip to content

Commit 64dc3e4

Browse files
committed
Store/paint colormap in srgb, convert to linear in shader, instead of store/paint linear. Upgrade older maps
1 parent 4fc9b4c commit 64dc3e4

7 files changed

Lines changed: 25 additions & 8 deletions

File tree

project/addons/terrain_3d/editor/components/tool_settings.gd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ func add_setting(p_type: SettingType, p_name: StringName, value: Variant, parent
271271
func get_setting(p_setting: String) -> Variant:
272272
var object: Object = settings[p_setting]
273273
var value: Variant
274-
275274
if object is Range:
276275
value = object.get_value()
277276
elif object is DoubleSlider:
@@ -283,8 +282,7 @@ func get_setting(p_setting: String) -> Variant:
283282
elif object is CheckBox:
284283
value = object.is_pressed()
285284
elif object is ColorPickerButton:
286-
value = object.color.srgb_to_linear()
287-
285+
value = object.color
288286
return value
289287

290288

project/addons/terrain_3d/editor/components/ui.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func update_decal() -> void:
213213
_:
214214
decal.modulate = Color.WHITE
215215
Terrain3DEditor.COLOR:
216-
decal.modulate = brush_data["color"]
216+
decal.modulate = brush_data["color"].srgb_to_linear()*.5
217217
Terrain3DEditor.ROUGHNESS:
218218
decal.modulate = COLOR_ROUGHNESS
219219
_:
@@ -224,7 +224,6 @@ func update_decal() -> void:
224224
decal_timer.start()
225225

226226

227-
228227
func set_decal_rotation(rot: float) -> void:
229228
decal.rotation.y = rot
230229

project/addons/terrain_3d/tools/importer.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func start_import(value: bool) -> void:
6767
material.show_checkered = false
6868
material.show_colormap = true
6969
storage.import_images(imported_images, import_position, import_offset, import_scale)
70+
print("Import finished")
7071

7172

7273
@export_group("Export File")

src/shaders/main.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uniform int _region_map[256];
1111
uniform vec2 _region_offsets[256];
1212
uniform sampler2DArray _height_maps : filter_linear_mipmap, repeat_disable;
1313
uniform sampler2DArray _control_maps : filter_linear_mipmap, repeat_disable;
14-
uniform sampler2DArray _color_maps : filter_linear_mipmap, repeat_disable;
14+
uniform sampler2DArray _color_maps : source_color, filter_linear, repeat_disable;
1515

1616
uniform sampler2DArray _texture_array_albedo : source_color, filter_linear_mipmap_anisotropic, repeat_enable;
1717
uniform sampler2DArray _texture_array_normal : hint_normal, filter_linear_mipmap_anisotropic, repeat_enable;

src/terrain_3d_material.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ void Terrain3DMaterial::_update_regions(const Array &p_args) {
180180
}
181181
RS->material_set_param(_material, "_region_map", _region_map);
182182
RS->material_set_param(_material, "_region_map_size", Terrain3DStorage::REGION_MAP_SIZE);
183+
RS->material_set_param(_material, "_region_uv_limit", Terrain3DStorage::REGION_MAP_SIZE / 2);
183184
if (Terrain3D::_debug_level >= DEBUG) {
184185
LOG(DEBUG, "Region map");
185186
for (int i = 0; i < _region_map.size(); i++) {

src/terrain_3d_storage.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,25 @@ void Terrain3DStorage::set_control_maps(const TypedArray<Image> &p_maps) {
377377

378378
void Terrain3DStorage::set_color_maps(const TypedArray<Image> &p_maps) {
379379
LOG(INFO, "Setting color maps: ", p_maps.size());
380-
_color_maps = sanitize_maps(TYPE_COLOR, p_maps);
380+
381+
TypedArray<Image> maps = p_maps;
382+
// DEPRECATED 0.8.4 Remove 0.9
383+
// Convert colormap from linear <0.8.4 to srgb 0.8.41
384+
if (_version < CURRENT_VERSION && maps.size() > 0) {
385+
LOG(WARN, "Color maps are being converted from linear to srgb. Upgrading: ", vformat("%.2f", _version), "->", vformat("%.2f", CURRENT_VERSION));
386+
for (int i = 0; i < maps.size(); i++) {
387+
Ref<Image> img = maps[i];
388+
for (int x = 0; x < img->get_width(); x++) {
389+
for (int y = 0; y < img->get_height(); y++) {
390+
Color c = img->get_pixel(x, y);
391+
img->set_pixel(x, y, c.linear_to_srgb());
392+
}
393+
}
394+
maps[i] = img;
395+
}
396+
_version = CURRENT_VERSION; // Prevent running again on focus
397+
}
398+
_color_maps = sanitize_maps(TYPE_COLOR, maps);
381399
force_update_maps(TYPE_COLOR);
382400
}
383401

src/terrain_3d_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Terrain3DStorage : public Resource {
2020

2121
// Constants & Definitions
2222

23-
static inline const real_t CURRENT_VERSION = 0.84;
23+
static inline const real_t CURRENT_VERSION = 0.841;
2424
static inline const int REGION_MAP_SIZE = 16;
2525
static inline const Vector2i REGION_MAP_VSIZE = Vector2i(REGION_MAP_SIZE, REGION_MAP_SIZE);
2626

0 commit comments

Comments
 (0)