Dropshadow shader effect

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dart_theg
Posts: 92
Joined: Sun Dec 29, 2024 3:13 am

Dropshadow shader effect

Post by dart_theg »

I'm trying to make a shader that simply applies to an object (like a cylinder) and have that object positioned under say, a character. The intention is to darken anything it intersects under it, but I'm having issues. I've looked up things online about it rendering in like a second pass or something? Am I just messing up the logic for this
CuteAlien
Admin
Posts: 10029
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Dropshadow shader effect

Post by CuteAlien »

One of those things that sound so simple, but can be pretty complicated.

If you just use a shadow object (often called shadow blob) I guess you use some half-transparent dark thing? What are the issues with that? I mean it works badly if the floor is not flat (can stick out or go under). And depending how much above the floor you put it (always has to be bit up to avoid z-flickering) it will go over the feet of the character. And you likely want to scale it when the character jumps.

Fixing the order of rendering can indeed be a bit pain in Irrlicht as it's pretty fixed. So sometimes I do stuff like using 2 scenemanagers to enforce a custom order.


The most common solution these days are probably shadowmaps: You first render all objects in the scene which throw shadows from the direction of the light (so camera is at light position) and write the depth-map to some texture (so using render-target texture). Can use very simple materials - only thing that might matter in that stage is transparency (sometimes you can even ignore that). And when rendering the "real" scene you calculate the shadow position for each pixel in there and then look up in the shadowmap if the position is in the shadows or not (bit math involved, look it up). Works relatively well, thought you can get a bit of a blocky pattern around the border of objects as there is no perfect lookup (as shadowmap doesn't fit your render scene perfectly, so ... lots of workarounds and hacks to reduce errors for that).


Maybe another solution is possible iwth stencil shadows (I've not done that yet myself, this is all theory):
1. draw shadow into stencil buffer (IVideoDriver::drawStencilShadowVolume)
2. color stuff marked in stencil buffer (IVideoDriver::drawStencilShadow or SceneManager::requestDrawShadowPassStencilShadow)

Sadly drawStencilShadowVolume only allows passing triangles (instead of allowing to pass meshes as usual). So maybe do first test with some simple sphere or so. Can create a triangle-selector for the sphere-node then you get triangles you can use for this. Flatten them by scaling y by 0 or so. Slow solution, but just for first test it should be fine (later you'll likely want to write your own shadow-nodes). Problem is again you want to draw it after floors but before drawing characters. Likely have to split your scene in 2 as Irrlicht doesn't have a renderstage in between solids otherwise.
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
dart_theg
Posts: 92
Joined: Sun Dec 29, 2024 3:13 am

Re: Dropshadow shader effect

Post by dart_theg »

I wanted to achieve the top to bottom shadow for say a platformer character. It’s not coming from an actual light source. It’s say a mesh that makes things dark inside of it. (Specially Super Mario 64 DS, those drop shadows)
Noiecity
Posts: 393
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Dropshadow shader effect

Post by Noiecity »

For that shadow to affect other objects, you'll need at least some spotlight-style lighting, but you might not actually need the lighting itself. So, if you just want the shadow, you'll need spotlight-style shadow maps. There are currently shaders available for this on xeffects
Irrlicht is love, Irrlicht is life, long live to Irrlicht
dart_theg
Posts: 92
Joined: Sun Dec 29, 2024 3:13 am

Re: Dropshadow shader effect

Post by dart_theg »

I feel like there must be a simpler solution… so many older games have these under shadows…
CuteAlien
Admin
Posts: 10029
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Dropshadow shader effect

Post by CuteAlien »

The simpler solution are likely the stencil buffers I mentioned. Thought you still didn't tell us what the issues with the blob shadow solution had been.
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
dart_theg
Posts: 92
Joined: Sun Dec 29, 2024 3:13 am

Re: Dropshadow shader effect

Post by dart_theg »

I’ll toy with stencil buffers then. The blob shadow looks ugly, especially when it’s on the edge of a platform.
Noiecity
Posts: 393
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Dropshadow shader effect

Post by Noiecity »

Old games used geometry directly for moving shadows, such as animated characters, and for static objects, they applied the shadows directly to the texture. You can use Blender or irredIt to bake the shadows into the texture. Now, to ensure that the object intersecting the shadow is obscured, you have two simple options if you don’t want to resort to re-rendering the scene from the light source: you can use collisions based on the cast shadow. The first option is to shade all triangles that partially or completely collide with that shadow; you can use aabbox3d for that in Irrlicht. Alternatively, you can use aabbox3d to completely obscure the 3D model that collides with it—that was another technique used in older games....
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Post Reply