What is the best way in 2013 to make decent dynamic shadows?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Keziolio
Posts: 9
Joined: Sat Aug 10, 2013 12:09 pm

What is the best way in 2013 to make decent dynamic shadows?

Post by Keziolio »

hello there, this is my first post, i need some information, i need a shadowing system for my project but the built-in shadows are very slow and glitchy as you know.
I searched a lot and i found a dumpload of stuff, the most part of it was broken links or very very old stuff working with very old irrlicht versions, i'm asking you what is the best method today to make decent shadow (maybe shadow maps) in a game, what do you use?
I've read that to achieve it i need to make shaders, i have no idea how to do it, i work with opengl (in linux) and i've seen that i have to do it in GLSL (am i right?), i know absolutely nothing about it, i have a very good knowledge about c and c++ and 3d graphics in general but i never did such a thing. how much time do i need to learn that stuff and make my shadows and shaders?

I tried xeffects but for some reason it dont work, i can't see any shadow or effects from it, it does not work with irrlicht 1.8 or it's my fault?

hope you can tell me something, i'm very confused at the moment, best regards
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: What is the best way in 2013 to make decent dynamic shad

Post by CuteAlien »

Shader programming itself is not that hard to learn if you already know c coding. It's basically c-code with just a few special rules for passing the parameters between application and shaders and between vertex- and pixelshader (pixelshader = fragment shaders in opengl). You can ignore geometry shaders for now.

Shaders are a material. In Irrlicht you can pass a base material when creating shader-materials to get the usual setup for that (which is mainly to decide in which render-stage it will be called).

Passing parameters to shaders is also made easy in Irrlicht. Checkout example 10.Shaders. Basically you derive from a callback class called IShaderConstantSetCallBack which you set once when creating a shader material. And that has a function OnSetConstants which is then called each frame before the shader renders. And in that function you can pass your custom parameters to the shader with services->setVertexShaderConstant (or setPixelShaderConstant for the pixel shader).

If you take then a look at the example shaders coming with Irrlicht, for example opengl.vert for the vertex shader, you will see those parameters which were passed with services->setVertexShaderConstant again at the top of that program with the keyword "uniform" in front of them. That's all that's needed to pass parameters from application to shader - now you can just use those values you have passed in OnSetConstants in the shader.

The shaders have a few special-types for easier 3d programming like mat4 and vec3 etc - but I think if you are familiar with 3d coding they probably make some sense without even have to look at the shader documentation.

And well - then it's basically that your vertex shaders runs once for each vertex you have given the card (they run in parallel, that's why it's rather fast). And your pixel shaders runs for each pixel once (again pixel shaders run parallel, but after the vertex shaders as they get parameters from the results of those).

The rest is c-code and some special rules for passing parameters between pixel and vertex-shader (you have to look that up, I only know the HLSL part for that, I think in GLSL they have just special fixed names for that. And yes - that means you can only pass a fixed number of parameters between vertex and pixelshader). And you have to learn the tricks like how to access for example neighbor pixels in a pixel-shader (you can learn those by looking at a few similar shaders - you will find lots and lots of them on the web). One major trick that's often useful for shadows, and I think XEffects is also using it, is that you render a scene to a texture instead of on the screen (with IVideoDriver::setRenderTarget in Irrlicht). And then you work further by putting that texture on a quad (2 triangles) which fills the whole screen. And then run shaders working with that quad and the textures on in. You can also pass stuff like the z-buffer that way in textures for further processing.

The rest is math... can't help you much with deciding on which shadow algorithm to use and how to implement it. I still have that part in front of me myself :-) (I used shaders only for some other things so far). Google around which shadows look nice, take a look at the shader implementations you find for those.

One more thing - if you want good shadows you will really need shaders. The build-in shadows working with the fixed-function pipeline can work for some situations, but it will never get you to shadows which are as good as people expect by now in games. And you have to understand a little how they work to really work with them - so it's probably not that much easier than just learning to code with shaders anyway.

Hope that helps a little.
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
Keziolio
Posts: 9
Joined: Sat Aug 10, 2013 12:09 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by Keziolio »

Ok, I'll try to learn shader programming then. will follow your tips.

Thank you for your time
dialNforNinja
Posts: 26
Joined: Wed Oct 10, 2012 1:28 am

Re: What is the best way in 2013 to make decent dynamic shad

Post by dialNforNinja »

I'm a far noobier noob than the OP, I admit, but why is this a reinvent the wheel situation? Can a shadows GSLS or HLSL shader not be just applied to whatever scene and objects you feed it? Every time the question comes up, the replies are "here's some tips and examples as you learn to write shaders," not "here's something that'll work, but you should learn shaders anyway to tweak it for your specific needs." My question is, why is that so?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by mongoose7 »

You cannot do shadow-mapping with one shader and a single pass, you have to have a framework.
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: What is the best way in 2013 to make decent dynamic shad

Post by lumirion »

Another option would be to borrow from a decal system like this one http://irrlicht.sourceforge.net/forum/v ... =6&t=44968. Then generate a shadow decal roughly based on shape of the object casting the shadow. Use a line made from light source coordinate and object coordinate to calculate shadow trajectory and length. Then apply the decal.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by robmar »

Trying to setup Xeffects to try the shadows, but get this error under VS2010, and don´t know why as my calls are all the same type in both Irrlicht LIB and Xeffects:-

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

What did I miss?
Last edited by robmar on Sun Sep 08, 2013 1:27 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: What is the best way in 2013 to make decent dynamic shad

Post by CuteAlien »

@dialNforNinja: You are certainly right. The simply answer is no-one did it yet. We had hoped to get XEffects stuff into Irrlicht when we added BlindSide to the team. But then he finished studying, got a job, etc - all good things. But unfortunately it means he didn't find time for Irrlicht anymore so we still have no easier way to give you shadows. Basically unless someone else with sufficient programming knowledge to work on an engine shows up and works on this all we can do is refer to XEffects and tell people to learn about shaders. It's just one of the problems of OpenSource - you don't get some stuff until you find good people who do work on that seriously. Maybe one of us get's to it at some point - I hope 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
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by mongoose7 »

I don't think it is appropriate to add XEffects to Irrlicht. It is not true shadow mapping.

With shadow mapping, the amount of light falling on a surface is calculated for each light and summed over all the lights.

XEffects uses "normal" lighting, either lights or no lighting, and subtracts the shadows from the light falling on a surface.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: What is the best way in 2013 to make decent dynamic shad

Post by CuteAlien »

mongoose7: The problem is that right now it's as dialNforNinja said - anyone asking about modern shadows all we can do is to tell them to learn about shaders. Meaning pretty much every working shader shadow solution would already be an improvement.
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
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by robmar »

Great, I´m happy to give it a try and see if I can patch Xeffects in... just need to get it to compile! :)
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by robmar »

Compiled and working well. Not sure it even needs to he integrated though.
Keziolio
Posts: 9
Joined: Sat Aug 10, 2013 12:09 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by Keziolio »

for me xeffects don't work
it compiles well, using codeblocks with mingw (windows 8 ) or gcc (linux mint 15 (ubuntu/debian based)) (both 64 bit and opengl, irrlicht 1.8 ), it compiles but don't work, i can't see any shadows or water.

am i doing something wrong? i just add all the xeffects files and headers to the project, using the source of an example it compiles without errors, but it dont work.
i placed the /shaders directory in bin/Debug (i start the executable from that folder)
when i open a precompiled example it works

any idea?
Last edited by Keziolio on Wed Sep 11, 2013 2:18 pm, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: What is the best way in 2013 to make decent dynamic shad

Post by mongoose7 »

You need a change in XEffects for it to work with 1.8. The precompiled version was compiled against 1.7.
Post Reply