(3D) Setting albedo_texture from an imported image makes the lighting looks incorrect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By momaur

I have a plane that uses the screen capture demo


I take a picture of the viewport and set the material to it.

However, once the new picture is set, the lighting looks off. Is there another setting I am needed to use? Or I may be using the wrong method.

changing image

Here is my code (it is the same as the screen capture demo except in a 3D space):

	var plane = get_node("../Plane")
	# Wait until the frame has finished before getting the texture.
	yield(VisualServer, "frame_post_draw")

	# Retrieve the captured image.
	var img = get_viewport().get_texture().get_data()

	# Flip it on the y-axis (because it's flipped).

	# Create a texture for it.
	var tex = ImageTexture.new()

	plane.get_node("mesh").get_surface_material(0).albedo_texture = tex

One thing I noticed is that if I drag and drop an image into the Texture of the Spatial Material from within the inspector while the game is running, it works properly. The lighting looks fine.

So I suspect maybe it’s a loading issue or I need to set the albedo_color to something else. I played around with it and found that the default albedo_color is (1,1,1,1). I think maybe I need to manually set it, but I haven’t yet found a good value.

EDIT: I found the problem. I set this flag and the color is true to the viewport screenshot.

enter image description here

i’m not sure how to delete this but you can reject/delete the question

You should post the answer to your own question as an answer (then accept it as the best answer), rather than edit your first post. This makes it clearer that the question has a solution :slight_smile:

Calinou | 2021-03-06 23:57

oh sure thing!!

momaur | 2021-03-07 00:58

:bust_in_silhouette: Reply From: momaur

I found the flag to set. It is a Flag in SpatialMaterial called flags_albedo_tex_force_srgb.
The screenshot will appear as it does on the viewport is this is set on the material of the mesh.

enter image description here