Post subject: Recreating Mode 7 effects
NESAtlas
He/Him
Player (56)
Joined: 7/4/2010
Posts: 114
Location: Gales Ferry, CT
Would it be possible to recreate Mode 7 effects by piping X/Y/Z values through a LUA script to affect an image like this: http://vgmaps.com/Atlas/SuperNES/SuperMarioKart-MushroomCup-MarioCircuit1.png I'm sure you can guess where I'm going with this ;)
Player (79)
Joined: 8/5/2007
Posts: 865
Wikipedia says that this is Mode 7's transformation principle: That's very simple to implement in Lua. The hard part (for me, at least) would be fetching the pixels from the source image. Now, you used a track from Mario Kart as your "example" image, which is a little bit harder to replicate, since it would require some perspective effects, which Wikipedia states goes a bit beyond what Mode 7 alone can do. I still think it wouldn't be so bad, but I would need to sit down and give it some careful thought. I'm intrigued by the idea, but I'm very busy at the moment and probably will remain so through the month (though I tend to get a lot of work done on side projects when I'm putting off bigger work). Also, I will never forgive you for causing Phil Hartman's death. Edit: Since I'm guessing you want this for one of the Atlas encodings, I'm a little confused as to how you plan on using it. Are you sure you don't wish to undo the Mode 7 transformations? After all, the analogous video for Mario Kart would impose the top-down view on the karters' positions. If that's your goal, I would instead recommend building the encode from the ground up: First, get all karters' x, y, and z positions and orientations every frame and have them output to some text file. Then have a script draw the karters on the map you've provided (I assume a program like Adobe Aftereffects can do this). Finish off the encode by syncing the video with the run's audio.
NESAtlas
He/Him
Player (56)
Joined: 7/4/2010
Posts: 114
Location: Gales Ferry, CT
I was hoping we could somehow orient the map in 3D space like it's already shown in-game. I would overlay the players afterwards with a simple avi dump of whatever layer is needed. Here's a really rough pic of what I mean:
Player (79)
Joined: 8/5/2007
Posts: 865
Do you have access to a Lua function that inputs a bitmap (or other image format) and outputs an array with indices x, y, and RGB? If so, what is the array's format? Are x and y read from left to right and top to bottom respectively? (Just to be clear, I'm still not yet committed to writing this script, but having access to a function like that would make my life much easier.) Edit: Also, you should crop the map and move it to one of the corners when it comes time to do the real thing. Edit 2: A quick search reveals that all three of addresses 7E0052, 7E005E, and 7E008C are correlated with one of the camera's coordinates. (I believe that their previous addresses are involved as well because they seem to be the least significant byte.) Would it be possible to freeze one or all of these to a position a fixed distance from the karter, effectively expanding the field of view? Why do everything in Lua when we can take advantage of the SNES's direct ability to use Mode 7? Edit 3: Try cheating in values for 7E0052 or 7E005E (or best of all, both simultaneously). The position of the camera isn't fixed like I'd hoped, but the results are hilarious. Fixing the value for 7E008C doesn't seem to have an effect but if it is indeed the less significant byte in a word, then it might not be noticeable. I tried fixing 7E008B and 7E008D to no noticeable effect. Anyway, the fact that altering 7E0052 and 7E005E both affect the camera gives me hope that this can be done entirely within the SNES. Once we find the position addresses, all you would need is a small Lua script to extrapolate back the position of the camera.
NESAtlas
He/Him
Player (56)
Joined: 7/4/2010
Posts: 114
Location: Gales Ferry, CT
I think I found what you're looking for, but I'm not sure how to test it:
img:get_pixel(x, y)

Gives the color of the pixel at the given (x,y) coordinates. The origin - (0,0) is at the top left.

Return an instance of imlib2.color matching the color at the given coordinates.
Found it here. Also, there's no rush on figuring this out as I can wait many months if it means some time in the future we'll have a cool new tool to use. I'll help out the best I can, but I have 0 experience with Lua. And feel free to go down whatever path you think would would be best as I'm willing to play around with anything including just a top-down view of the map!
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
Each line, the game feeds Mode 7 matrix values to the PPU via the HDMA channels. Channel 1 sets matrix parameter A Channel 2 sets matrix parameter B Channel 3 sets matrix parameter C Channel 4 sets matrix parameter D Channel 5 sets BGMODE: Mode 0 on line 0, Mode 7 on line 24, Mode 0 on line 112, Mode 7 on line 115 Channel 6 sets Main Screen layers (turns off layers 2-4 during the Mode 7 lines; useless because they wouldn't get rendered anyway) Channel 7 sets window coordinates (probably for the transparent digits) I'm not sure you'll need that though when you can get the camera position...
Editor
Joined: 3/10/2010
Posts: 899
Location: Sweden
The game is basically changing the transformation matrix each hblank. So to emulate the effect you need to do the same, change the matrix for each row of the image.