For those retro nuts out there, I decided to do the unthinkable in this day and age… and hard-code “mode7” (aka. a well-known special effect that uses affine transformations) in screen space. I initially did it on the CPU, but I then moved it to a shader. Works well enough that I decided to showcase it.
NOTE: This image is quite old, I may be uploading a better one soon.
And I’ve decided on something even crazier; I’m releasing the source! Below is a download link:
For those using my original version, delete it and download this one, It has more polish and is better tested.
This should work in any version of Unity 5.x and on any platform supporting Shader Model 2.0/GLES2/OpenGL
If there is any issues, please let me know here!
Any example sprite/BG assets are (C) Hedgehog Arts 2015-2017. All rights reserved. additional licensing info in README.txt in the zip
2017 update: Thanks to @Metalhawk93 for bumping this! I am about to upload a new version. I’ll include some basic documentation as well for you retro lovers out there, as well as a basic sprite rotation script. Updated the package, enjoy
Finally, I’ve been trying to find a way to emulate the feel of the old SNES racing games for my own project for so long! I’m going to try it out and see how it works out well. Thanks a million man, this is great!
“EDIT”
alrighty, I’ve writen down the code for the shader and the script to apply to my camera. any pointers on how I should set up my scene?
Alright, things are good, but I’m having a problem with my shader now. I’m using version 5.2.3f and my compiler says that subscript ‘w’ is invalid. any idea what this might mean?
Okay, now I have both my shader and my script working pretty well, thogu I am curious about some things. For starters, the setting I place for my Quads’ Texture doesn’t get applied to my camera, specifically my Horizon. Any ideas what I might be experiencing? Plus in regards to moving across the texture, movement on the y axis is inverted with the texture. when moving forward, the texture moves backwards, and likewise when moving back, it pushes forward.
Man, I made this ages ago. Anyway, I do have an improved version around somewhere, give me 30mins and I’ll have it uploaded.
As for the inverted Y movement, are you going underneath the plane by any chance? I had an issue like that when I first made this, it’s a bug in the shader calculation
EDIT: I can also pack in my texture-sheet based “Mario Kart 64 sprite” script if you like, that allows one to make pre-rendered content that changes when you view it at angles.
EDIT2: I also wonder, how this thread woke up two years later…
Eh, worth necroing IMO, it’s time I updated this
EDIT3: The new version I am uploading also restricts local X and Z rotation on the camera, mostly because of limitations with my algorithm
B U M P
Post updated, enjoy making SNES style games
Feel free to ask for feature requests, but being as I don’t work on stuff much these days, it may take a while before I have a feature implemented.
Thanks Man, I really appreciate it. So as for how I had my scene set, it was like this. I had a quad parented to my camera, and while my quad had aa material which used the old Mode7 shader, my camera had the Mode7 script attached. Now both my camera and Quad were parallel to each other in both the X & Y axis but where 20 units apart on the Z. Now when the camera move forward, the quad moved along with it. Yet while both the camera & quad move forward on the y axis, the texture goes in the opposite direction it’s mean’t to go.
I’m going to try out the improved versions of the Mode 7 code, see how well they’ll do better, but I can’t help but wonder what was going on with the old set up I had. It might just be a computer problem, So I might check it out.
“EDIT”
So Far I’ve done the basic set up, but I’m having a problem with how the texture is projected. no matter how I set up the texture, whether it’s as a sprite or a texture, it just comes out as a solid color?
That sounds like the total scale is set wrong, try 0.019
Also, make sure your camera isn’t 0 on the Y axis… of which is equivalent of being flat on the ground.
EDIT: A screenshot of the problem would help too, it could also be because of an undocumented feature I have in there (pseudo-fog)
Pretty much! Except it’s missing a proper transform for pitch. (aka; adding a pitch transform warps in odd ways at the moment)
It also doesn’t clip with sprites, making it a little more authentic (technically, a textured quad could do this as well, but that would have been too easy)
Also, at all mods; does this still warrant being in the Made with Unity section?
When this was posted, it was still called Showcase, but I’m not sure what goes where now.
(Damn it’s been a while since I actively did stuff here)
Well, one thing I forgot to mention is that it looks best with aniso turned up or mip maps off on your map texture. That’s the reason for that weird distance blurring.
Also, there is a backdrop slot on the material itself, give it a go if you have a background ready
Otherwise, looking good!
Might as well put up something I was working on (with this set of scripts) a while back to show a higher detail example
So my map is looking a bit better,(not sure if it’s suppose to look like this),
And I’ve set up my scene in terms of visuals. There is some things I am curious about.
What sort of player script do you use to move the sprite across the course it’s on, like how you might move forward and make turns and such in F-ZERO/Super Mario Kart? would this script be compatible with other visual effects akin to what also appeared on the SNES, like scrolling backgrounds and so forth?
I actually have a small “physics engine” in Dev for that, although it’s mostly suited to racing type games only. It works by checking an array of pixels that correspond to the “floor” and looks for marked holes when applying gravity. I use an Alpha8 format texture as a reference, as that way, you can do anything you want with the image texture and use the alpha 8 as a collision mask.
Oh and best of all is that this entire process is really CPU light, no PhysX/Rigidbodies required.
For actual car physics, it depends on the game, I just have some code for moving forwards using an acceleration factor + turning physics. (aka. slight sideways skidding the faster you go)
For the mode7 script itself, it has no involvement in calculation whatsoever (well, except maybe for generating the bitfield for the physics, hence the size restrictions) any scrolling/turning is controlled by the camera movement itself (the mode7 script transaltes this movement into shader values)
I am yet to figure out what to do for car to car collisions, I’ll post here my findings when I get to it
Sweet, That sounds awesome dude, looking forward to see what you come up with. What about that “physics engine” you mentioned before? how is that working out for you?
Well, other than car collisions, (and perhaps “jump pads” to simulate ramps) it’s functional.
The cars stay on track until a hole in the mode7 layer is found, where the car then falls through.
I haven’t tested mobile yet (need to figure out AI to auto-drive round the track) but the lack of PhysX should make it very performant there, since it doesn’t have to do very much math at all.
Also, sorry for the late reply, I don’t check the forums that often anymore.
Parallax? As in a background? Keep in mind that the mode7 script does it’s own background scrolling, for a parallax scrolling effect, it should be easy enough to add a second background texture and have it scroll 2x speed for a parallax effect…
…unless you don’t know Cg/HLSL of course. In that case, I can add that feature in if you like