Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | momaur |
I have a plane that uses the screen capture demo
https://godotengine.org/asset-library/asset/130
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.
Here is my code (it is the same as the screen capture demo except in a 3D space):
var plane = get_node("../Plane")
get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
# 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).
img.flip_y()
# Create a texture for it.
var tex = ImageTexture.new()
tex.create_from_image(img)
img.save_png("res://tex.png")
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.
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
Calinou | 2021-03-06 23:57
oh sure thing!!
momaur | 2021-03-07 00:58