New Dustbin Shaders

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

New Dustbin Shaders

Post by Brainsaw »

Hello,

I have been fiddling around with creating a framework for future games (still work in progress, I hope I can show it off later this year), but I have now enhanced the shaders I use for MarbleGP and wanted to share it.

Image

The shader now creates two shadows, one detailed which is close to the camera, and one rough for the object further away (there is one spot in the test scene where you can see that quite well). The shader does also support transparent shadows as seen in the image.
I render two sets of shadow maps (details / rough) with three maps each, i.e. six textures are used for rendering the shadow:
  1. a depth map for the solid shadow
  2. a depth map for the transparent shadow
  3. a color map for the colors of the transparent shadows
There is still one glitch in my test application: if I load a new test scene the main camera turns orthographic, and at the moment I don't know why.

You can download my test application from https://forumdata.dustbin-online.de/DustbinShaders.zip
The project is available on https://sourceforge.net/projects/dustbinshader/

The project for the application is for Visual Studio 2026, and it needs some tweaking before it compiles (like path to the libs... / for the framework I'm going to switch to CMake), it uses Irrlicht trunk from a few months ago.

I hope you like it

Edit: some information on the left side menu for the test application / screenshot
  • on top you have a dropdown where you can load test scenes. All except the default need to be updated though as three textures are used for the road, but now the shader needs 6 textures
  • next is a button to load the selected scene. Note that the camera issue I mentioned above will show
  • then you have a combobox which allows you to select the mode used (shadows with transparent shadow colors, shadows with single color transparent shadows, only solid shadows, off)
  • below that you see another combobox which allows setting the quality of the shadows ("Top": 16384x16384, "High": 8192x8192, "HiMid": 4096x4096, "LoMid": 2048x2048, "Low": 1024x1024, "Poor": 512x512). I am quite happy with "LoMid" on my 4k display
  • The "(un)lock Framerate" button let's you see how good the shaders perform. I have 200+ FPS on my Asus Rog Ally X with the "LoMid" settings
  • The next combobox allows you to see the textures of the shadow maps
  • Then there is a button which saves the currently selected RTT. Note that later saves will overwrite previous
  • The "Show Shadow Map" button gives you a large view of the current shadow map
  • last but not least you can see the current framerate (again)
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: New Dustbin Shaders

Post by Brainsaw »

I have made some little updates: first I simplified the code of the RTT generation, and I added an input field to the test application which allows modifying the light direction while the app runs. The download package
Image
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
Noiecity
Posts: 398
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: New Dustbin Shaders

Post by Noiecity »

thanks for sharing
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 10042
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: New Dustbin Shaders

Post by CuteAlien »

Thanks, the shadows look good. I don't think the camera is orthographic after loading the roads still get smaller in the back. Looks either like very wide fov or maybe some messed up viewport.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: New Dustbin Shaders

Post by Brainsaw »

Thanks for the hint, I'll debug into it when I have time to

Today I had an idea to improve things: I have started coding a version which uses render target textures with the color format 32Bits for Alpha, Red, Green and Blue each. If things work as I assume I can endode all necessary data into a single teture instead of three: Red for the distance to the non-transparent shadow, Green for the distance to the transparent shadow and Blue for the color of the transparent shadow. This way I could also use three levels of shadows, because at the moment if you move the camera far outside the test scene you see that in the distance the shadow disappears. I'll write another post here if I get it working ;)
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: New Dustbin Shaders

Post by Brainsaw »

A new version of my shaders is available on https://forumdata.dustbin-online.de/DustbinShaders.zip. I didn't manage to implement the idea with the 32 Bit shaders so I chose another route: I just render all necessary data into a single RTT:

Image
  • the upper half of the image is the depthmap for the solid shadows
  • the lower left part is the depth map for the transparent shadows
  • the lower right part is the transparent color information
I also added a 3rd level so that (at least in the demo) the complete viewport does now have shadows. I still have some ideas for improvement. I'd like to fix the shadow map viewport directly to the viewing camera, and to distort the shadow map depending on the shadow's camera.

At the moment I'm thinking about the first point, for this I would need my orthogonal camera to be limited to the view frustum of the current camera, but this is above my math skills (use 4 points which must be inside the visible area), but I'll play around a little with this idea.

But first I'll add a whole lot of comments to the new code, because if I stop working on it and touch the code in half a year I'll be completely riddled by what I tried to achieve :wink:

Here is a new screenshot (though it looks almost as the first one):
Image
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
CuteAlien
Admin
Posts: 10042
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: New Dustbin Shaders

Post by CuteAlien »

I sometimes use multi-texture render targets. Yeah... more memory. Thought those also have their troubles, especially in Irrlicht which doesn't allow masking per texture so far (so mixing fixed function materials with shaders is nearly impossible for that case as fixed function materials always writes same data to all textures).
Also one depth-map is usually already in the rendertarget (didn't check your specific case). Thought maybe not in the format you want (so lookup of that one usually involves some function which converts the values into linear distance or so)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: New Dustbin Shaders

Post by Brainsaw »

I searched a little but couldn't find that depthmap. I also have a problem in one of the test scenes ("loop_double") where it seems that no Z-Buffer check is done when rendering the depth for transparent shadows:

Image

The break in the red shadow comes from the other red rectangle below. It seems I'm doing something quite wrong
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
Brainsaw
Posts: 1252
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: New Dustbin Shaders

Post by Brainsaw »

I managed to fix the problem above:

Image

The issue still visible with the stripe of darker red was expected, the colors of the transparent materials are rendered to a single viewport, so if multiple materials overlap from the perspective of the light they will always be added, I don't really see an option to fix this, but it's ok for me

The second image shows another track, it looks OK in MarbleGP, but with the detailes shadowing it really looks cool imho:
Image
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
CuteAlien
Admin
Posts: 10042
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: New Dustbin Shaders

Post by CuteAlien »

Hm, do you still have an older version? With Irrlicht trunk rendertargets have functions to set/get the depthmap. Don't remember how Irrlicht 1.8 did it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply