Pages: 1 2 »
  Print  
Author Topic: Need Help Creating 2D Shadow Casting (e.g. Teleglitch)  (Read 16908 times)
Offline (Unknown gender) AsherOS
Posted on: August 05, 2013, 02:22:07 am
Member
Joined: Jul 2013
Posts: 19

View Profile
Hello, as the title says, I am trying to create a shadow casting effect much like that of Teleglitch for my stealth game.


(Teleglitch)

I was able to get something working in Game Maker Studio, but it was rather glitchy. Once I moved to Enigma, I tried to remake the system from scratch, but I didn't get anywhere alone. I'm just wondering if anyone can point me the right way on making this. I realize the Teleglitch creators use 3D shapes to make the shadows, but if a 2D system is simpler (my game is 2D), that's great.

Cheers,
Asher
Logged
Offline (Male) Goombert
Reply #1 Posted on: August 05, 2013, 02:36:47 am

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2991

View Profile
My suggestion is to take a look at this example...
http://enigma-dev.org/edc/games.php?game=28
Provided it has not been broken recently XD

And whatever the hell you are making, it looks cool. The right way to do it though is using shaders, which are not quite completed yet.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #2 Posted on: August 05, 2013, 06:45:10 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
There are many ways to draw shadows. Like using surfaces (geargod style), polar coordinates (xot's style) and others. The thing about Teleglitch is that it actually created shadows just by extending the geometry upwards. So no need for any real computation, it just a model which creates that effect. Like in this animation:
So it shouldn't be hard to replicate. Now some things could be broken in ENIGMA (surfaces specifically) and I am trying to fix them, so I won't be able to create an example for you. Maybe Robert can as he likes 3D stuff. The negative side is that only one "light" can be in the scene. In teleglitch there was no lights at all and it just symbolized visibility, so it worked there quite well. If you really want a shadow casting by multiple color and blended lights, then other techniques must be used.

Quote
And whatever the hell you are making, it looks cool. The right way to do it though is using shaders, which are not quite completed yet.
That screenshot is from a quite popular rogue style game Teleglitch. And there is rarely a "right way" to do anything. If you can get the same performance otherwise (like in this case just using geometry), then it is the right way as well.
Logged
Offline (Male) Goombert
Reply #3 Posted on: August 05, 2013, 06:55:38 am

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2991

View Profile
Quote
Maybe Robert can as he likes 3D stuff.
Sure, if he doesn't want it for lighting and just occlusion like in his screen, but if he needs perpixel lighting like in your animation, I need hold off and do some other things and then shaders.

Quote
That screenshot is from a quite popular rogue style game Teleglitch. And there is rarely a "right way" to do anything. If you can get the same performance otherwise (like in this case just using geometry), then it is the right way as well.
Agreed, but if you want it like you say for lighting, that still requires a perpixel fragment shader unless you want to bump up the geometry.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #4 Posted on: August 05, 2013, 07:35:05 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
but if he needs perpixel lighting like in your animation,
That animation actually just shows the occlusion and no per-pixel lighting. You just draw walls as tall black rectangles and you will get what he showed in the screenshot. If you add a blended circle at ground level, then you will get what is in the animation. In the animation there are also 3D walls which are lower, if they are used the probably surfaces are needed. No shaders or anything though. Most 2D shadow effects can be made just by using surfaces and blend modes. That is how this is made: http://www.youtube.com/watch?v=6KvjEiur0eY
Logged
Offline (Unknown gender) AsherOS
Reply #5 Posted on: August 05, 2013, 01:55:45 pm
Member
Joined: Jul 2013
Posts: 19

View Profile
Thanks for the replies.

@Robert B Colton
That example is a lot like what I had in my Game Maker project. It got the job done. I'll see how the performance of this goes with my game.

@TheExDeus
There seems to be more advantages with the 3D technique. In Teleglitch this is an interesting effect where the shadow casting geometry shifts around a bit. I think it's due to a dynamic effect they add to the player being near it, and also that the geometry is raised , so the perspective makes it move in relation to the player ever so slightly.

I'll try both techniques. I may ask more questions on this thread down the line about the 3D technique though.

Thanks again!
Logged
Offline (Unknown gender) TheExDeus
Reply #6 Posted on: August 05, 2013, 02:42:52 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
The guy who created the lightning engine posted in EDC actually created a new which is a lot easier to use and allows colored lights. Here is a video: http://www.youtube.com/watch?v=MaDPr2Z1-lM
I will upload it to EDC when I fix up GL3. I will commit a fix for GL1 and GL3 so the example works without changes (though the variable_exists() will be removed).

And the 3D was cool. It did shift around a little, but it is not a lightning engine or a shadow engine. That means you will have only one caster. If it suits your needs, then anything more complex might not be needed.
Logged
Offline (Unknown gender) AsherOS
Reply #7 Posted on: August 05, 2013, 03:43:56 pm
Member
Joined: Jul 2013
Posts: 19

View Profile
My GM project lighting was based on that version. Didn't know it was the same person.

I started dabbling with the 3D elements. So far I only created a cube and all the setup before hand, but it doesn't look like the final goal will be too complicated to reach.
Logged
Offline (Unknown gender) AsherOS
Reply #8 Posted on: August 06, 2013, 03:11:31 pm
Member
Joined: Jul 2013
Posts: 19

View Profile
I've been able to create cameras, objects, etc. in 3D, however I need help figuring something out.

The camera direction commands don't entirely make sense to me, but I know I need to to point along the z-axis, in order to see the 2D room.
This is the example code I'm using (from http://enigma-dev.org/forums/index.php?topic=1169.0)
Code: [Select]
//DRAW WHAT CAMERA SEES

xf=x;       //x to look from
yf=y;       //y to look from
zf=z;    //z to look from

xt=xf+cos(degtorad(direction));         //x to look to (with direction)
yt=yf-sin(degtorad(direction));         //y to look to (with direction)
zt=zf-sin(degtorad(zdirection));     //z to look to (with z direction)

d3d_set_projection(xf,yf,zf,    xt,yt,zt,   0,0,1);     //look from & to
I know this code points the camera along the x-axis, looking east in the room editor. Could someone explain how I would need to change this for what I need?

I hope this isn't too much trouble.

Cheers,
Asher
Logged
Offline (Male) Goombert
Reply #9 Posted on: August 06, 2013, 03:26:04 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2991

View Profile
Ohhh no you silly goose, you don't need those projection commands for what you are doing, just use d3d_set_projection_perspective, it will give a 2D view except have a 3D FOV.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) AsherOS
Reply #10 Posted on: August 06, 2013, 04:46:45 pm
Member
Joined: Jul 2013
Posts: 19

View Profile
When I was writing this question, I kinda knew on the inside that the answer was going to be painfully simple.

Thanks :D
Logged
Offline (Unknown gender) TheExDeus
Reply #11 Posted on: August 06, 2013, 04:47:28 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
And didn't that code work? It should be as simple as d3d_set_projection(x,y,z, x,y,z+1,   0,0,1) or something like it.
Also, I uploaded a working version of the easy to use light and shadow engine here: http://enigma-dev.org/edc/games.php?game=62
That is if you think that will suit better (although its idea is totally different from what you are doing here).
Logged
Offline (Unknown gender) AsherOS
Reply #12 Posted on: August 06, 2013, 04:55:07 pm
Member
Joined: Jul 2013
Posts: 19

View Profile
It worked, but I got confused with the direction commands. I'm still experimenting, so I'm not sure which one I will ultimately choose. I'll definitely give that light engine a go after I get a reasonable demo done with the 3D technique.
Logged
Offline (Male) Goombert
Reply #13 Posted on: August 06, 2013, 10:06:28 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2991

View Profile
Quote
d3d_set_projection(x,y,z, x,y,z+1,   0,0,1)
Why would you use that? Just use the perspective function....
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #14 Posted on: August 07, 2013, 01:31:14 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
Quote
Why would you use that? Just use the perspective function....
Because a person has to know how those functions worked. I am surprised his code didn't do what he wanted, as at first glance it was correct (maybe some cos or sin was wrong).
Logged
Pages: 1 2 »
  Print