Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Hedgehog Arts GPU Mode7 (previously hard-coded Mode7 effect)

Discussion in 'Made With Unity' started by FuzzyQuills, Nov 28, 2015.

?

Who here likes Mode7 in general?

  1. Absolutely loved it back in the day!

    82.6%
  2. Hate it... wish it didn't exist!

    4.3%
  3. ...What's Mode7?

    13.0%
  1. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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.

    Mode7_Unity.PNG
    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:
    https://drive.google.com/file/d/0B2tqYgzg1_lWbnFDWFlaVjFMTGs/view?usp=sharing
    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 :)
     
    Last edited: Jul 25, 2017
    Adam-Bailey, DominoM and artfish like this.
  2. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    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?
     
    Last edited: Jul 21, 2017
  3. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    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?
     
  4. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    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.
     
    Last edited: Jul 24, 2017
  5. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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

    @Metalhawk93

    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... :D
    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
     
    Last edited: Jul 25, 2017
  6. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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.
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Interesting as a programming exercise I guess. .... it's a ... textured plane. :)
     
  8. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    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?
     
    Last edited: Jul 25, 2017
  9. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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. :D

    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)
     
  10. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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)
     
  11. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    Okay I've set my Cameras' Y position to about 10, and it's looking really good. what might you suggest though?

    Example1.jpg
     
  12. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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

    EDIT: Here it is:
    Mode7_Test_1.PNG
     
  13. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    So my map is looking a bit better,(not sure if it's suppose to look like this),

    Example2.jpg

    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?
     
  14. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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
     
  15. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    In terms of how I would like my vehicles to act would be more toward Maio Kart Physics.

    Basically, you have to be able to accelerate forward, stop at will, and make turns. All these for basic movement of both NPCs and the player unit.
     
  16. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    I'm working towards that currently, and so far, the car can turn and accelerate (and slow down when the button is released) but no brakes... yet
     
  17. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    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?
     
  18. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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.
     
  19. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    That's alright, we all have our own things to deal with.

    How well would you say the "Mode 7" scripting might work with a simple parallax scroll script?
     
  20. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    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 :)
     
  21. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    fair enough.
     
  22. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    "Life Update"
    I've had the Mode 7 work put on hold until further notice, at least until proper physics have been conducted for said scripting. In the meantime, I've been brushing on some coding skills for 2D platforming. I'm hoping on combing both racing and platforming for one of my game ideas. For the time being though, I words out to FuzzyQuill's on their work. keep it up chum.
     
  23. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Thanks mate. I know the feeling, there is actually a game project of mine that has been on the backburner for over two years since I stopped any real work.
    School at the time was ramping up, so I had to stop work, and since then, due to the really old cruddy code I wrote, I've also wanted to do a full rewrite of that project. (I'm actually doing a rewrite for a game I released, then pulled, a while back, right now, but that isn't the project I'm talking about)

    About time I redid my sig anyway to include some new/old/rebuilt stuff.
     
  24. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    Update on my prototyping of Mode 7 Style effects in unity. With the new Unity 2017, I''ve been trying to think of ways to incorporate the new Tiled tools when it comes to creating maps for affine transformed backgrounds. Still Was wondering what other ideas people following this thread might have. In any case, work on this project is still on hold for now, but I would like to hear what others have to say about it.
     
  25. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    Hello To anyone still following this forum, Just wanted to make a post to keep it up to date.

    A while back, I happen to have seen a video on Mode 7 posted by the Youtube channel "Retro Game Mechanics Explained". Its the most recent video in a series which explains the technology and coding knowledge behind the SNES. In the video, They talk about how the system utilizes Mode 7 by using Affine Transformations. While Unity itself has no use for such matrices and the like with it implementation of floats, ints, and the like there of, it still might be able to give some insight into how to make code that can produce effects similar to it. The video will be down below to check out. For anyone watching the thread how has any idea how to translate Affine transformation into a simplified C# code, please share your your thoughts. Believe, there are people who'd want to implement such retro-esque effects into their own projects.

     
    FuzzyQuills likes this.
  26. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Guess when I can find the project I did this effect in, I could try my own implementation. I'll have to finish up what I'm currently working on first though before I'm game to do it
     
  27. Metalhawk93

    Metalhawk93

    Joined:
    Jul 13, 2016
    Posts:
    45
    Hey There, This Metalhawk here checking to see if this forum is still Alive and kicking.

    In anycase, there's been a few more uploads on RetroGameMechanics channel, relating to workings of The SNES system. Following up on the video on Mode 7, first up is Lag & Blanking, followed later on by one on DMA & HDMA.

    Heres a link to the playlist for this video series, so that way, it'll keep this forum up to date as best as possible.

    https://www.youtube.com/playlist?list=PLHQ0utQyFw5KCcj1ljIhExH_lvGwfn6GV

    I thought about coming back to this forum because I've gotten back into a game dev groove as of late, and for the game Im making at the moment, I'm want to add some features and mechanics that take advantage of the SNES hardware tricks in a stylish way.

    So if anyone still wants to add anything to this forum, I'd personally be happy for it.