Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightmaps look washed out in GLES3 unless Hdr As Srgb is enabled in the lightmap EXR's import settings #53388

Open
Calinou opened this issue Oct 4, 2021 · 6 comments

Comments

@Calinou
Copy link
Member

Calinou commented Oct 4, 2021

Godot version

3.3.4.stable, 3.4.beta (69b2f1d)

System information

Fedora 34, GeForce GTX 1080 (NVIDIA 470.57.02)

Issue description

While working on #52918, I noticed that lightmaps look washed out in GLES3 unless Hdr As Srgb is enabled in the lightmap EXR's import settings. Enabling this import setting makes the colors correct, but the resulting lightmap becomes too dark compared to the real-time rendering.

This may not be something we can fix due to GLES3 working with a HDR pipeline and linear light. In this case, we should document it in the Baked Lightmaps documentation and in the class reference.

Steps to reproduce

Fully baked lights (with no bounces) on the left, real-time lights (with no baked GI) on the right:

GLES3

gles3_attenuation_old

GLES3 (Hdr As Srgb enabled on the lightmap EXR)

Lightmap looks identical to GLES2.

gles3_attenuation_old_hdr_as_srgb

GLES2

gles2_attenuation_old

Minimal reproduction project

test_light_attenuation_lightmap_3.x.zip

@Dadaskis
Copy link

Dadaskis commented Jun 8, 2023

Thanks for sharing this info! By the way, when working with lightmaps on v3.5.2., i noticed that my lightmaps tend to be way too desaturated in comparison to real-time lights. Should i do a separate issue for this?

@Calinou
Copy link
Member Author

Calinou commented Jun 8, 2023

Thanks for sharing this info! By the way, when working with lightmaps on v3.5.2., i noticed that my lightmaps tend to be way too desaturated in comparison to real-time lights. Should i do a separate issue for this?

Are you using GLES3 or GLES2? Can you upload a minimal reproduction project? Did you try playing with the import options as mentioned in OP?

@Dadaskis
Copy link

Dadaskis commented Jun 8, 2023

Thanks for sharing this info! By the way, when working with lightmaps on v3.5.2., i noticed that my lightmaps tend to be way too desaturated in comparison to real-time lights. Should i do a separate issue for this?

Are you using GLES3 or GLES2? Can you upload a minimal reproduction project? Did you try playing with the import options as mentioned in OP?

So, answering these...

Are you using GLES3 or GLES2?

GLES3

Can you upload a minimal reproduction project?

I think i can, it can be tricky though because i'm experiencing it in a game project that uses a lot of custom editor tools

Did you try playing with the import options as mentioned in OP?

Yes! It fixed problem with lights in one of my interiors, they looked like they were clamped as i disabled HDR, but after changing the importing setting for EXR, it fixed that and now it looks like actual HDR render. However, all the lights are slightly desaturated so i'm thinking about writing a script to load EXR and edit all the layers to make them more saturated

Edit: Fixing quotes

@Dadaskis
Copy link

Dadaskis commented Jun 8, 2023

Update: Now it looks normal. For some reason, after rebaking, SRGB has been disabled in importing settings, and setting it back fixes desaturation. Sorry for missing that. Now i wonder if i can change importing settings in code ._.

@Dadaskis
Copy link

Dadaskis commented Jun 8, 2023

func reimport_lightmap():
	var import_path = "path/to/lightmap_folder/lightmap.exr.import"
	
	var file = File.new()
	
	file.open(import_path, File.READ)
	var text = file.get_as_text()
	file.close()

	text = text.replace("compress/mode=0", "compress/mode=1")
	text = text.replace("flags/srgb=false", "flags/srgb=1")
	
	file.open(import_path, File.WRITE)
	file.store_string(text)
	file.close()
	
	var img_path = "path/to/lightmap_folder/lightmap.exr"
	var img = load(img_path) as TextureLayered
	
	var bc: Control
	for c in get_tree().root.get_node('EditorNode').get_children():
		if c.is_class('EditorInterface'):
			c.edit_resource(img)
			c.inspect_object(self)
			bc = c.get_base_control()
			break
	if bc:
		# super duper big hack
		# Taken from https://ask.godotengine.org/26987/texture-importing-settings-from-gdscript-default-setting
		var import = bc.find_node('Import', true, false)
		if import:
			import._reimport()

It is possible in a dirty, hacky way. So if anyone else has a problem with lightmapping and is willing to fix it using tool scripts, here is a way. Of course it is unrecommended for using and can be incompatible with future updates, but currently, at 3.5.2., it does the job well

Edit: Fixing code tags

@Dadaskis
Copy link

Dadaskis commented Mar 6, 2024

And here i am, once again. I still had an issue with lightmaps being washed out or looking different from real-time analog, so i decided to implement color adjustment for lightmaps. I hope someone will find it helpful:

export(float) var adjust_brightness = 1.0
export(float) var adjust_contrast = 1.0
export(float) var adjust_saturation = 2.0

func set_adjust_update(value: bool, force_resaving = false):
	if value == false:
		return

	var res_path = "path/to/your.exr"
	
	var image = Image.new()
	image.load(res_path)
	image.lock()
	for x in range(image.get_width()):
		for y in range(image.get_height()):
			var color = image.get_pixel(x, y)
			
			color = lerp(Color(0.0, 0.0, 0.0), color, adjust_brightness)
			color = lerp(Color(0.5, 0.5, 0.5), color, adjust_contrast)
			var vec = Vector3(color.r, color.g, color.b)
			var vec_sat = Vector3.ONE.dot(vec) * 0.33333
			vec = lerp(
				Vector3(vec_sat, vec_sat, vec_sat), 
				vec, 
				adjust_saturation
			)
			color.r = vec.x
			color.g = vec.y
			color.b = vec.z
			
			image.set_pixel(x, y, color)
	image.unlock()
	image.save_exr(res_path)
	reimport_lightmap()

What i would like to point out is that in my project, all lightmaps, for some reason, are desaturated by half. So that is the reason why adjust_saturation is equal to 2.0 by default as it is providing the most accurate result. I have no clue why does it work this way, but just wanted to say it here

@lawnjelly lawnjelly modified the milestones: 3.5, 3.x Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants