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

Support for multiple rendertargets #24034

Closed
CptPotato opened this issue Nov 28, 2018 · 13 comments
Closed

Support for multiple rendertargets #24034

CptPotato opened this issue Nov 28, 2018 · 13 comments

Comments

@CptPotato
Copy link
Contributor

As far as I can tell, rendering to multiple rendertargets in a Viewport is not supported at the moment.

I might be the odd one out here but this feature is something I could definitely use, specifically for implementing my own rendering and lighting in 2D. Also, please let me know if I'm wrong and this is already possible.

@Zylann
Copy link
Contributor

Zylann commented Nov 28, 2018

Aren't Viewports themselves usable as rendertargets? In fact it's the only way to achieve that using the API right now, I think limitations were mentionned in past issues

@CptPotato
Copy link
Contributor Author

I thought about this workaround but it would mean that I have to render every rendertarget separately which is something I want to avoid 😕

Ideally, allowing a Viewport to have multiple ViewportTextures would be a nice solution. Though, I'm not sure if this is compatible with how the current renderer works. I may have to resort to writing my own VisualServer implementation.

@starry-abyss
Copy link
Contributor

starry-abyss commented Nov 29, 2018

What is the benefit of that? Like, each render-to-texture is a separate operation, isn't it? No matter if it's from same or different viewport (which can share World with other viewport).
Or am I missing something?

Also, BTW are those multiple ViewportTextures supposed to have the same content? Because instead one can just use the same single texture to read from everywhere (obviously)...

@CptPotato
Copy link
Contributor Author

CptPotato commented Nov 29, 2018

@starry-abyss Multiple Rendertargets (also referred to as "MRT") is a technique which allows you to render your objects to multiple textures simultaneously from the pixel shader. (-> much lower performance impact than rendering multiple times, also easier to set up)

So instead of binding only one rendertarget as output you can bind multiple ones (it should be up to 4 or maybe even higher nowadays). Then all you have to do is write to the different registers from the pixel shader. This way you're not bound by the max. 4 channels RGBA of one texture but instead can output more data to be used later.

This feature has been supported since ancient DirectX 9, it's used by pretty much most engines and I think Godot internally uses it, aswell. I'm sure GLES3 has no issues with it. GLES2 might not support it, though.

Also, BTW are those multiple ViewportTextures supposed to have the same content? Because instead one can just use the same single texture to read from everywhere (obviously)...

Getting multiple textures with the same content is not the aim 😄 (as this would be possible with a simple copy). In my case things like normals, surface color and other material properties are what I want to store in the buffers.

@starry-abyss
Copy link
Contributor

@CptPotato Thanks for explanations! Sounds like sometimes I might want to use (not in Godot project for now though, but for other pixel art 2D game).

@reduz
Copy link
Member

reduz commented Nov 29, 2018

I am planning to implement this in the Vulkan renderer. You will be able to configure extra render targets.
Not sure if this will be project wide or viewport wide, given shaders need to be compiled specifically toi output this.

@CptPotato
Copy link
Contributor Author

Great to hear that something like this is planned. With this I could port my 2D deferred / forward hybrid renderer to Godot 😄

@girng
Copy link

girng commented Nov 30, 2018

you can add another viewport container then just switch between them. if doing a 4 person multiplayer game like diddy kong racing (4 render targets), that is already an edge case imo. several reasons, but not limited to:

  • console
  • AAA production
  • small % of game developers needing 4 render targets is low already
  • can already be done within godot

cool suggestion however. but it's already doable

@CptPotato
Copy link
Contributor Author

@girng I think there's a misunderstanding 😕

Rendering the same scene multiple times from different perspectives is not what I want to do - this is also not what MRT does.

The best way I can explain it is that you just output more data per pixel and store it in multiple buffers. Deferred rendering/shading would be one of the use cases for this. This article about deferred shading might be a bit too technical but illustrates the way it can be used quite well.

@Chaosus
Copy link
Member

Chaosus commented Dec 26, 2018

I am planning to implement this in the Vulkan renderer.

Pushed to 4.0 then

@Chaosus Chaosus added this to the 4.0 milestone Dec 26, 2018
@samdze
Copy link
Contributor

samdze commented Feb 11, 2020

I definitely need this feature, having each shader that can target multiple textures using different rendering strategies, hope it gets added with 4.0 as Juan said.

@samdze
Copy link
Contributor

samdze commented Feb 14, 2020

Oh and furthermore, I also need to be able to render from arbitrary sprites/drawables (not contained in a particular viewport) to a selected buffer/texture to store global data for post-processing, custom depth test, or other things.

A solution could be to allow each Viewport (even the root one) to have an ordered (or named) set of ViewportTextures, which can then be reused by assigning them like any other Resource to slots of sub-Viewports instead of creating new ones (so that objects contained in sub-viewports can also render to the same root ViewportTexture directly)

@reduz what do you think?

@Calinou
Copy link
Member

Calinou commented Mar 12, 2020

Closing in favor of godotengine/godot-proposals#495, as feature proposals are now tracked on the Godot Proposals repository.

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

9 participants