Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Mode 7 demo + full source!
Started by rakoonic Oct 15 2013 12:34 AM

23 replies to this topic
graphics 2 mode 7 source
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

rakoonic

[GLOBAL: userInfoPane.html]
rakoonic
  • Pro
  • PipPipPipPipPipPip
  • 500 posts
  • Jedi

After chatting about mode 7 earlier today, I earned myself a short break and used it to knock up this demo. It only really shows the concept, but works well enough that I figured I'd give the source out and let people see how quickly you can knock up code in graphics 2.

 

Note the code is massively un-customisable as a result of me putting in a lot of quick hacks to get everything working ASAP, but it might be of use to someone.

 

Attached File  mode7.jpg   76.84KB   325 downloads

 

What I'm basically doing:

 

1) I load the level and create the sprites.

2) I draw the entire level and place it into a display group.

3) That group gets placed into a snapshot.

4) I rotate the group and snapshot to match the player movement.

5) I invalidate() the snapshot and then distort it to give a perspective effect.

 

The source includes the whole corona set-up, and also the Tiled level so you can have a play yourself.

Attached Files



[TOPIC: post.html]
#2

SegaBoy

[GLOBAL: userInfoPane.html]
SegaBoy
  • Pro
  • PipPipPipPipPipPip
  • 635 posts
  • Jedi

Thanks Rakoonic - you're certainly leading the charge on helping Corona devs utilise the power of Graphics 2.0...



[TOPIC: post.html]
#3

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Enterprise
  • PipPipPipPipPipPip
  • 2,208 posts
  • Jedi

As always... super cool!



[TOPIC: post.html]
#4

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Pro
  • PipPipPipPipPipPip
  • 134 posts
  • Jedi

Thank you very much!



[TOPIC: post.html]
#5

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Pro
  • PipPipPipPipPipPip
  • 285 posts
  • Jedi

awesome! looking forward to digging into this later today :)



[TOPIC: post.html]
#6

jstrahan

[GLOBAL: userInfoPane.html]
jstrahan
  • Pro
  • PipPipPipPipPipPip
  • 1,922 posts
  • Jedi


[TOPIC: post.html]
#7

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Pro
  • PipPipPipPipPipPip
  • 134 posts
  • Jedi

how to add object on the track looking at you? Such as a tree.



[TOPIC: post.html]
#8

walter

[GLOBAL: userInfoPane.html]
walter
  • Corona Staff
  • 641 posts
  • Jedi

Super cool. I played around with adding a filter effect, e.g. pixelate, to the global snapshot.



[TOPIC: post.html]
#9

rakoonic

[GLOBAL: userInfoPane.html]
rakoonic
  • Pro
  • PipPipPipPipPipPip
  • 500 posts
  • Jedi

Just remember if you are applying pixelate to a snapshot, you are likely better off creating a smaller snapshot and just enlarging it onscreen - this way you don't need the over head of the filter, and you actually speed things up as you are asking for lower fill-rate. See my section about pixelate here, about 1/4 of the way down the document: https://docs.google.com/document/d/168-Rp86pioZM-e0QM0GBb2eeBUasXAHPYm-iGu1xjLI/edit?usp=sharing  :)

 

I should point out that if you are distorting the overall snapshot first, then my suggestion likely won't have the intended effect. Just realised that and I will test it out and add it to the above doc to alert people to this!



[TOPIC: post.html]
#10

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Pro
  • PipPipPipPipPipPip
  • 134 posts
  • Jedi

What about my question? How to add objects on the track?(Trees, signs, etc.)



[TOPIC: post.html]
#11

rakoonic

[GLOBAL: userInfoPane.html]
rakoonic
  • Pro
  • PipPipPipPipPipPip
  • 500 posts
  • Jedi

What you'd need to do is come up with a calculation that converts from the 2D coordinates of the Tiled level, via the 3D transform of the snapshot, back into a pair of 2D screen coordinates.

Normally this wouldn't be too tough to achieve, but since I hacked this code together it isn't gonna be really easy.

If I get time next week I'll update the demo to use proper 3D transforms, which would make it easier to calculate.



[TOPIC: post.html]
#12

renato.bugge

[GLOBAL: userInfoPane.html]
renato.bugge
  • Pro
  • PipPipPipPipPipPip
  • 99 posts
  • Jedi

Very nice indeed! Your other demos also look very nice, especially with threes in the car-demo. Are those threes flat 2D or do you model them as textured surfaces?

The reason I ask is that I have been planning a game in which threes and plant modeling would be necessary to get it going. Leaves are always a problem (you kind of end up with too many textures), so it hasn't been possible in Corona.

What is you impression with respect to performance as for zooming in on objects? (E.g. driving towards them). In pre-graphics 2.0 it is very slow, especially for large objects.

Best,
Renato

PS: I used to make 3D games in the old days were 3D->2D transforms were the "normal way". I don't see why you have to go both ways as you could keep all the game mechanics in the 3D universe and only use the 2D transform for showing things on screen?

[TOPIC: post.html]
#13

rakoonic

[GLOBAL: userInfoPane.html]
rakoonic
  • Pro
  • PipPipPipPipPipPip
  • 500 posts
  • Jedi

Zooming large objects isn't much fun (and yes the trees are just a 2D image). I took out most of the overhead banners in the racing demo because up close each one was essentially a full screen or bigger sprite.

Trees get pretty big, but since they are never in the road, they get clipped and culled which helps a great deal.

 

For this demo you'd want to go 2D->3D->2D because the base information isn't in 3D - it is a 2D Tiled map.

So what people would need is a way to take a 2D point in the Tiled level, and end up with a 2D point in screen space (but with a third component - the depth in 3D space so they would know how much to scale the object and how to depth sort).

 

So you'd go:

 

2D->3D (Tiled level position to 3D position on the road in perspective)

3D->2D (The 3D position to screen coordinates)



[TOPIC: post.html]
#14

johannes_lalala

[GLOBAL: userInfoPane.html]
johannes_lalala
  • Starter
  • PipPipPip
  • 44 posts
  • Advanced Member

cool demo, but

I don't get the benefit of emulating 3D in a 2D projection of a real 3D environent, besides retro mode7 coolness.

 

Isn't it more complicated to manage all the perspective transformations instead of using a z-Buffer?



[TOPIC: post.html]
#15

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Pro
  • PipPipPipPipPipPip
  • 720 posts
  • Jedi

cool demo, but

I don't get the benefit of emulating 3D in a 2D projection of a real 3D environent, besides retro mode7 coolness.

 

Isn't it more complicated to manage all the perspective transformations instead of using a z-Buffer?

 

I too am a little confused. Don't get me wrong, it's all very impressive work - but if you've got the technical know-how to do this sort of stuff, then why not just use Unity and not have to worry about making your code super-efficient just to get a half-decent framerate with SNES graphics?



[TOPIC: post.html]
#16

SegaBoy

[GLOBAL: userInfoPane.html]
SegaBoy
  • Pro
  • PipPipPipPipPipPip
  • 635 posts
  • Jedi

Why bother creating 2D games when the biggest selling games are nearly always 3D behemoths? 

 

Firstly there's the sense of a challenge, secondly there's the question of whether 3D actually benefits some genres - I personally prefer old-school SNES Mario Kart to any of the subsequent 3D versions.

 

G2.0 gives us the technology and freedom to do this kind of game, something that just wasn't possible beforehand - so surely that's a good thing? The advent of technology doesn't necessarily deem all games to the dustbin of time - hence the rise in the last few years of retro, pixellated games.

 

There's also the fact that to create semi-decent 3D models is a particularly time-consuming task as well.

 

Perhaps you just need to be an old git like me to appreciate the opportunity to recreate Mode-7 nostalgia?

 

P.S I've just re-found an excellent site on Mode 7 that I remember from a few years back, might be of some use to anybody who's contemplating it:

http://www.coranac.com/tonc/text/mode7.htm



[TOPIC: post.html]
#17

rakoonic

[GLOBAL: userInfoPane.html]
rakoonic
  • Pro
  • PipPipPipPipPipPip
  • 500 posts
  • Jedi

I've said myself repeatedly that in some sense I am doing a disservice to Corona by releasing this stuff.

Corona isn't and isn't ever likely to be a 3D engine.

 

Why did I do these things? Initially technical curiosity, followed by simply realising *some* 3D stuff is possible. Within limitations you can do fast 3D things, and in some cases, easier than in Unity (Retro Racer is an example of something that would be a pain to code in Unity but a breeze here. Dungeoneer is a sort of 'meh' case, because while the scenery itself is really rather easy to do, monsters and their animation will be annoying as they'll use a lot of VRAM.

 

And mode 7? Well, who doesn't have a soft spot for it? For the sake of an evening's coding, I see no harm in it, as long as people don't start wanting too much - I'd never recommend Corona for a full 3D environment naturally.

 

There's also a lot to be said about being comfortable in an environment. Being able to add simple 3D things into an SDK you already know well is certainly no bad thing, and it seems people agree with me.

 

Bottom line: If you can do it in corona and it isn't too complicated, there's no reason *not* to do it. As far as 3D goes, people just need to plan according to what is possible, and be honest about it to avoid running into problems later on when you ask for something beyond the means of Corona.



[TOPIC: post.html]
#18

sharp100

[GLOBAL: userInfoPane.html]
sharp100
  • Pro
  • Pip
  • 8 posts
  • Newbie

@rakoonic,

 

This is great addition to my toolkit.  The more tools in my box the more creative my solutions can be.  I needed a small 3D embellishment for one of my apps and was playing around with ray casting but this is much more simple (and better looking than my current solutions).  Thanks for sharing!

 

Jonathan



[TOPIC: post.html]
#19

hiphopsded

[GLOBAL: userInfoPane.html]
hiphopsded
  • Starter
  • PipPipPip
  • 47 posts
  • Advanced Member

Has anyone figured out how to add objects to the track? such as trees/signs/buildings?

 

I've been playing around with the code for awhile and am having difficulty adding objects to the world, they end up flat on the tiles.

 

Any help would be great!



[TOPIC: post.html]
#20

paulscottrobson

[GLOBAL: userInfoPane.html]
paulscottrobson
  • Pro
  • PipPipPipPipPipPip
  • 389 posts
  • Jedi

I think you'd have to do it differently ; your Mode7 tiles are flat projected, your sprite images are projected using the same positional calculations but are sprites scaled for distance - for simplicity they might look the same from any direction.

 

Did you know ; the first "Mode 7" console was built in the early/mid 1970s, but never released ?



[TOPIC: post.html]
#21

hiphopsded

[GLOBAL: userInfoPane.html]
hiphopsded
  • Starter
  • PipPipPip
  • 47 posts
  • Advanced Member

Do you have an example of how to do that using the Mode7 Demo? I've been trying but have had no luck.

[TOPIC: post.html]
#22

paulscottrobson

[GLOBAL: userInfoPane.html]
paulscottrobson
  • Pro
  • PipPipPipPipPipPip
  • 389 posts
  • Jedi

No, I haven't ever played with it.  

 

The hard bit is figuring out where the bottom middle of each tile is. For simplicity, initially, you would want to put each object in the centre of each tile. This probably is in the Mode 7 code somewhere. Then you have your sprite image - a tree say - arrange this so its anchor point is at the middle bottom and move it to the position on that tile, scaling it by perspective distance based on the 3D coordinate not the mapped 2D one. This might well be extractable from the tiles 2D coordinates, this tile's display size should be scaled the same as the  objects on it pretty much - tiles further away are smaller too. 

 

Visibility of objects could be done using visibility of tiles - if you can see a tile you can see an object on it. Not 100% accurate, but probably good enough.

 

Objects would probably look the same from any direction. If you wanted to have something like (say) cars spinning as on Mario Kart, it would be easier to do this as a sprite that is animated to look that way rather than actually trying to do real 3D calculations. 

 

Have a look at  which is a run through of the 1982 Vectrex game "Dark Tower" or  (the 1983 Sinclair Spectrum game "Death Chase") - these are both examples of fake 3D gaming produced in this sort of fashion. What you want to do is take this approach and put it on top of the Mode7 graphics. Corona would look much better as its a bit more powerful than a Speccy or a Vectrex :)

 

The Mode7 demo is awesome, but there's a degree of practicality in it. If you really want 3D, something more than (say) Mario Kart or Wolfenstein or Knight Lore, but real 3D, Corona is (at present) the wrong tool, for all its many strengths as a 2D tool.



[TOPIC: post.html]
#23

hiphopsded

[GLOBAL: userInfoPane.html]
hiphopsded
  • Starter
  • PipPipPip
  • 47 posts
  • Advanced Member

Those are some good examples!

 

I finally figured it out myself, after playing around with code for hours lol. Now I have the ground plus Objects that give off the appearance of true 3D, and my whole faux 3D world is setup, never thought I would be able to do this with corona!

 

Thanks for the input. 



[TOPIC: post.html]
#24

gazjm

[GLOBAL: userInfoPane.html]
gazjm
  • Pro
  • PipPipPipPipPipPip
  • 140 posts
  • Jedi

Any clues as to how you managed it? Im  trying to do a similar thing, but just can't work out how to convert from 2D - 3D and back

 

Thanks




[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: graphics 2, mode 7, source