Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Render to several render textures in one draw ?  (Read 885 times)

0 Members and 1 Guest are viewing this topic.

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Render to several render textures in one draw ?
« on: December 10, 2022, 04:22:51 pm »
Hi, I'm still working on my Jabos project, currently on the rendering part to add lighting effects :
https://youtu.be/AzQpn7Ow65M?start=186

At this point I'm drawing each frame bit by bit. Each kind of element to draw is a Vertex Array using UV coords to manage normals, drawn with its own shader to manage lights:
  • stars
  • atmosphere
  • ocean background (necessary to mask the stars)
  • ship parts
  • ocean foreground (applied with a multiply blend mode)
  • planet ground

I feel this is suboptimal as code managing lighting is duplicated in each shader and I'm facing few limitations for example in how light affects ocean. I'm thinking about switching to using a few render textures:
  • base material colors
  • normals
  • environment kind (water, air, void)
And in one last step mix everything using a list of lights. Though I'm worried about the performance impact of drawing everything to 2 or 3 render textures each frame.

Is there a way to draw to several render textures in one shader call? Is that a standard way of doing things?
« Last Edit: December 11, 2022, 11:56:44 am by Tyrendel »

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Render to several render textures in one draw ?
« Reply #1 on: December 11, 2022, 11:54:41 am »
Ok so I found the terms for what I was looking for, and the answer to my questions.

I was talking about Multiple Render Targets, it is a standard way of doing things, it isn't currently possible in SFML.

-> Any plan of having it added in the future?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Render to several render textures in one draw ?
« Reply #2 on: December 12, 2022, 10:57:57 am »
SFML doesn't really support that.

There aren't currently any plans to add that.
I've not done anything like that, so my statements might be completely wrong, but looks like this is mostly a optimization. Unsure if this has a big impact on performance for 2D games.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Render to several render textures in one draw ?
« Reply #3 on: December 14, 2022, 01:07:19 pm »
Thanks for your answer. I think I'll still try this without the MRT in the future!

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Render to several render textures in one draw ?
« Reply #4 on: December 14, 2022, 02:25:46 pm »
I did make an SFML-compatible(ish) MRT some time ago, which you can check out here:

https://github.com/fallahn/xygine/blob/legacy/xygine/include/xygine/MultiRenderTexture.hpp

I say 'ish' it breaks compatibility with the version of OpenGL SFML uses, so while it works on Windows using a compatibility context it won't work on macOS (and I think linux was spotty too, but it's been a while and I don't recall for sure  ;D)

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Render to several render textures in one draw ?
« Reply #5 on: December 14, 2022, 03:25:52 pm »
Thanks, I'll have a look out of curiosity but I'm developping on OsX and Windows + using the Rust-SFML binding and I'm not confident at all to try and modify the library + binding  ;)