Draw shadow on terrain

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
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Draw shadow on terrain

Post by suliman »

Hi
Im doing an aircraft game and what some simple shadow on the terrain (to easier see distance when flying close to the ground). I know there are built in shadows, but i use a custom shader for the terrain which i havent done myself so built-in shadows doesnt work right?

Im fine with a dark filled circle as shadow, i dont need real shadows that turn/roll with the actual plane (if its easier to do).

Any ideas?
Thanks
Erik
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: Draw shadow on terrain

Post by Foaly »

Afaik Irrlicht's shadows are independent from the shader. Have you tried it?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Draw shadow on terrain

Post by hendu »

Fake shadows can be done very easily in software: create a sphere, give it a transparent black texture, then scale and move it as needed.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Draw shadow on terrain

Post by suliman »

I will make my own shadows since i need to control position and size myself.
I started experimenting but im a little lost. Is this a good start? It is transparent but brightens everything (obviously) Do i need to create a material or can i just set it to "black"? Preferably it should not be totally opaque (the circular shadow (black color) on the terrain i mean)

Code: Select all

    scene::ISceneNode * sphere = gfx.smgr->addSphereSceneNode(50,20,0,-1,vect3d(1000,200,1000));
    sphere->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Draw shadow on terrain

Post by mongoose7 »

Don't use TRANSPARENT_ADD_COLOR. Maybe TRANSPARENT_VERTEX_ALPHA will work if you don't use a material, but remember to use alpha with the vertex colours (black).
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Draw shadow on terrain

Post by suliman »

Like so? This does not work, its just a solid black. But what do you mean with "use alpha with the vertex colours"? The image file does have an alpha channel.

Code: Select all

    scene::ISceneNode * sphere = gfx.smgr->addSphereSceneNode(50,20,0,-1,vect3d(1000,200,1000));
    sphere->setMaterialTexture(0, gfx.driver->getTexture("gfx/particles/cloud2.png"));
    sphere->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
But even if the texture/material would work, wouldnt the sphere be visible when looking from the side? Halv of the sphere will be sticking out of the ground like a hill... (right now thats how it looks)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Draw shadow on terrain

Post by mongoose7 »

You said "Do i need to create a material or can i just set it to "black"?" so I assumed you were not using a material.

Anyway, does your image file have an alpha channel? If it does, you can use TRANSPARENT_ALPHA_CHANNEL.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Draw shadow on terrain

Post by suliman »

Yes this makes it transparent (if i reduce opacity in photoshop) but concerning my other question: it is still "a hill" sticking up from the terrain (half the sphere). How do i use this as a shadow? Only useful when looking at it from an exact topdown angle... Did i misunderstand something?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Draw shadow on terrain

Post by mongoose7 »

No, that's it. But I thought you were in an aircraft? It now appears you are on the ground looking at the shadow of an aircraft?
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: Draw shadow on terrain

Post by suliman »

Well its an aircraft game yes, but its not a topdown 2D view so i cannot draw spheres and expect them to look like circles all the time. There is a chase-camera (third-person cam) like freelancer or darkstar one or similar games.

But i learned how TRANSPARENT_ALPHA_CHANNEL worked:)

So back to real shadows then:
Are there cheaper built-in shadows than the stencil buffer ones from tutorial 8? I use large open maps with lots of units. Maybe i can just enable shadows for some objects and gain myself to some performance? I might have several "suns" to light the scene properly, can i choose to only cast shadows from some light or is it automatically every light in the scene if i use shadows?

Thanks for all your help!
Erik
Post Reply