AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Posted on: August 05, 2013, 07:22:07 AM |
|
|
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
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #1 Posted on: August 05, 2013, 07:36:47 AM |
|
|
My suggestion is to take a look at this example... http://enigma-dev.org/edc/games.php?game=28Provided 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.
|
|
|
TheExDeus
 Joined: Apr 2008
Posts: 1,860
|
 |
Reply #2 Posted on: August 05, 2013, 11:45:10 AM |
|
|
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. QuoteAnd 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.
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #3 Posted on: August 05, 2013, 11:55:38 AM |
|
|
QuoteMaybe 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. QuoteThat 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.
|
|
|
TheExDeus
 Joined: Apr 2008
Posts: 1,860
|
 |
Reply #4 Posted on: August 05, 2013, 12:35:05 PM |
|
|
Quotebut 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
|
|
|
AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Reply #5 Posted on: August 05, 2013, 06:55:45 PM |
|
|
|
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!
|
|
|
TheExDeus
 Joined: Apr 2008
Posts: 1,860
|
 |
Reply #6 Posted on: August 05, 2013, 07:42:52 PM |
|
|
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-lMI 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.
|
|
|
AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Reply #7 Posted on: August 05, 2013, 08:43:56 PM |
|
|
|
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.
|
|
|
AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Reply #8 Posted on: August 06, 2013, 08:11:31 PM |
|
|
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) //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 & toI 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
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #9 Posted on: August 06, 2013, 08:26:04 PM |
|
|
|
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.
|
|
|
AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Reply #10 Posted on: August 06, 2013, 09:46:45 PM |
|
|
When I was writing this question, I kinda knew on the inside that the answer was going to be painfully simple. Thanks 
|
|
|
TheExDeus
 Joined: Apr 2008
Posts: 1,860
|
 |
Reply #11 Posted on: August 06, 2013, 09:47:28 PM |
|
|
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=62That is if you think that will suit better (although its idea is totally different from what you are doing here).
|
|
|
AsherOS
 Joined: Jul 2013
Posts: 19
|
 |
Reply #12 Posted on: August 06, 2013, 09:55:07 PM |
|
|
|
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.
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #13 Posted on: August 07, 2013, 03:06:28 AM |
|
|
Quoted3d_set_projection(x,y,z, x,y,z+1, 0,0,1) Why would you use that? Just use the perspective function....
|
|
|
TheExDeus
 Joined: Apr 2008
Posts: 1,860
|
 |
Reply #14 Posted on: August 07, 2013, 06:31:14 AM |
|
|
QuoteWhy 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).
|
|
|
|