I want to render G-buffers on screen - how should I possibly best approach it in Defold?
I want to be able to draw albedo, normal, depth textures to render targets and then use them for postprocessing.
How should I change materials on models (it’s 3D) to draw whole scene to one render target that will show whole scene as albedo/normal/depth textures?
I guess MRT introduced to Defold some time ago comes to help here, is it right?
Ok, I managed to find the example of deffered lighting by @jhonny.goransson
It allowed me to correctly display them separately, I basically needed to indeed use MRT and replace gl_FragColor
with gl_FragData[0]
etc
I started reading this one yesterday.
https://learnopengl.com/Advanced-Lighting/Deferred-Shading
I did one many years ago in Blitz3d And I have a couple of examples that kinda do some of the things you need. I also have a deferred rendering system with compositors and such for Defold, but its not pretty. Will post it if you want a look.
Heres roughly how I tackled it:
I render a few things together in a single pass with a single shader type to a RT. I used RGBA in the past and split up the values into sections I needed. Like my PBR shader, usually a full pass for albedo. If color contribution is really one of your main focusses - loss of color during compositing can be a bit nasty.
I then put ao + Metallic + Roughness into a single texture - this is much like how I combine them in my blender exporter These are essentially grey scales for metallic and roughness, and I give ao 16 bit (B and A).
Then you can do some lighting passes and combine lit + shadow + emissive - this can be handy if you want.
These three shader passes can give you the majority of what you need, then I use compositor shaders to combine them. So, for instance with alpha objects you might need an extra albedo or even add a transparency component to one of the passes, but composit it at a different stage.
So, something like:
albedo + aoMetRough → temp + transp → temp + lighting ->temp + post effects (bloom, etc).
Note: post effects are interesting, because sometimes its good to put them onto specific outputs (like lighting) and then you might not need a post render pass.
This is all multi-pass approach of years gone by
Deferred Renderer - geez its still around!
One of my personal favourite reads on Deferred approaches was the one by Guerilla Games on how they did KillZone. Back in the day… it was kinda cutting edge… and is very much a more classic GBuffer technique which I think is where you are more interested (than multipass).
Deferred Rendering in Killzone 2 - Guerrilla Games
My example used a render target with multiple outputs, its the standard approach afaik:
You can also pack multiple 8-bit outputs into a float texture, which is slightly lossy but works as well.
You did use Blitz3D? It was somehow my first “game engine” or a rendering tool, I don’t know for sure, I was a kid not knowing what I was doing, but I was making simple “games” in it
Hehe. yeah loved it. Used it on the Amiga in the early 90’s… on the Amy you could do inline assembly and copper instructions (gpu)… was very very cool fun