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

Global illumination doesn't update when force drawing a SubViewport if main viewport is disabled #97658

Open
ydeltastar opened this issue Sep 30, 2024 · 2 comments

Comments

@ydeltastar
Copy link
Contributor

ydeltastar commented Sep 30, 2024

Tested versions

  • 4.4.dev
  • 4.3.1.rc

System information

Godot v4.4.dev (e3213aa) - Windows 11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 31.0.15.4633)

Issue description

SDFGI takes some frames to converge the global illumination (setting rendering/global_illumination/sdfgi/frames_to_converge).
However, when force drawing a SubViewport like the below example, global illumination doesn't update if the main viewport is disabled.

func _render_subviewport(subviewport: SubViewport, iterations: int = 30,  disable_main = true) -> Image:
	var scene_tree = Engine.get_main_loop() as SceneTree
	var root_viewport = scene_tree.root.get_viewport_rid()
	if disable_main:
		# Disable main viewport so it doesn't redrawn
		RenderingServer.viewport_set_active(root_viewport, false)
	
 	# Render SubViewport
	for i in iterations:
		await RenderingServer.frame_pre_draw
		RenderingServer.viewport_set_update_mode(render.get_viewport_rid(), RenderingServer.VIEWPORT_UPDATE_ONCE)
		RenderingServer.force_draw(true, 1.0 / iterations)
		await RenderingServer.frame_post_draw

	if disable_main:
		# Enable main viewport again
		RenderingServer.viewport_set_active(root_viewport, true)
		await RenderingServer.frame_post_draw # image data doesn't updates correctly without this..

	return subviewport.get_texture().get_image()

Left: expected. Right: result of multiple force_draw(), lighting didn't iterate and it always looks like the first iteration.

image

It only updates correclty when the main viewport is enabled during force_draw().

image

But it slows down rendering since force_draw() draws all active viewports although I don't need the main viewport.

Steps to reproduce

  • Open the MRP. It contains the test project of the images above.
  • Run the project. The left is a realtime SubViewport. The right creates a SubViewport dynamically, force draw multiple times and shows a TextureRect with the resulting image.
  • Toggle "Disable main viewport".
  • Rendering only looks correct when the main viewport is enabled.

Minimal reproduction project (MRP)

sdfgi-update.zip

@ydeltastar ydeltastar changed the title Global illumination doesn't updated when force drawing SubViewport Global illumination doesn't update when force drawing a SubViewport Sep 30, 2024
@ydeltastar ydeltastar changed the title Global illumination doesn't update when force drawing a SubViewport Global illumination doesn't update when force drawing a SubViewport if main viewport is disabled Sep 30, 2024
@Deltt
Copy link

Deltt commented Oct 3, 2024

I was about to post this, glad someone else did already. Any potential workarounds that don't slow down rendering time?

@Calinou
Copy link
Member

Calinou commented Oct 3, 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

3 participants