[MZ][MV] Ultra Mode 7

Started by Blizzard, April 15, 2018, 08:23:32 am

Previous topic - Next topic

Blizzard

April 15, 2018, 08:23:32 am Last Edit: May 26, 2024, 04:34:20 am by Blizzard
Ultra Mode 7
Authors: Blizzard
Version: 2.2.0
Type: Environment Add-on
Key Term: Environment Add-on

Introduction

Ultra Mode 7 simulates the Mode 7 rendering mode from the SNES by using 3D rendering (hence the "Ultra"). Sprites are scaled appropriately and use additional code to determine whether they are visible, because of cut-off distance. The view of a Mode 7 map is defined by the following parameters:

  • camera distance
  • camera Y position
  • field of view
  • pitch rotation angle
  • yaw rotation angle
  • maximum Z coordinate

This work is licensed under BSD License 2.0:
Quote from: undefinedCopyright (c) Boris "Blizzard" Mikić
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1.  Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

2.  Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

3.  Neither the name of the copyright holder nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

You may use this script for both non-commercial and commercial products without limitations as long as you fulfill the conditions presented by the above license. The "complete" way to give credit is to include the license somewhere in your product (e.g. in the credits screen), but a "simple" way is also acceptable. The "simple" way to give credit is as follows:
Quote from: undefinedUltra Mode 7 licensed under BSD License 2.0, Copyright (c) Boris "Blizzard" Mikić

Alternatively, if your font doesn't support diacritic characters, you may use this variant:
Quote from: undefinedUltra Mode 7 licensed under BSD License 2.0, Copyright (c) Boris "Blizzard" Mikic

In general other similar variants are allowed as long as it is clear who the creator is (e.g. "Ultra Mode 7 created by Blizzard" is acceptable). But if possible, prefer to use one of the two variants listed above.

If you fail to give credit and/or claim that this work was created by you, this may result in legal action and/or payment of damages even though this work is free of charge to use normally.


Features

  • render map in 3D
  • control rendering with various parameters and even change them on the fly
  • supports white fading of horizon
  • supports auto-scaling for sprites depending on distance from camera
  • high performance
  • easy to use

v1.1.0
  • added animation function for parameters
  • renamed RENDER_PIXELATED option to TILEMAP_PIXELATED
  • added CHARACTERS_PIXELATED option
  • fixed issue with floating characters
  • fixed issue with normal maps not working anymore
  • added some code to prevent compatibility issues with some map scripts

v1.2.0
  • fixed FPS drop problem while moving

v1.2.1
  • fixed save data issue

v1.2.2
  • fixed a syntax error that was caused by code cleanup

v1.2.3
  • added parallax distance parameter in maps for parallax movement with yaw and pitch
  • renamed "Camera" functions to "CameraDistance"
  • fixed bug with parallax scrolling on non-Mode 7 maps
  • fixed bug with shaking the screen
  • removed FOV limit and implemented orthogonal projection with FOV of 0°

v1.2.4
  • fixed accidental removal of animateCameraDistance function

v1.3.0
  • implemented map looping functionality
  • added workaround for PIXI bug where a lag spike would occur about every 10 seconds
  • fixed issue where sprite direction didn't display properly at certain yaw angles
  • fixed issue where movement controls didn't adjust to yaw angle
  • added CHARACTERS_ADJUST_SPRITE_DIRECTION option
  • fixed coordinate offset when using yaw angle

v1.3.1
  • fixed a crash with event testing

v1.3.2
  • added coordinate rounding for X and Y coordinates
  • improved code that handles sprite visibility when outside of the view frustum
  • removed some leftover debug prints

v1.3.3
  • fixed issue with event visibility on map borders when using looping maps

v1.3.4
  • added compatibility code for KhasUltraLighting
  • added compatibility instructions for Terrax Plugins - Lighting system

v1.3.5
  • corrected some minor positioning and scaling calculation errors
  • improved compatibility code for KhasUltraLighting

v1.3.6
  • added experimental compatibility for BattleLighting plugin

v1.3.8
  • added script call to enable/disable pixelated rendering during runtime
  • reduced WEBGL_MAX_VERTICES to reduce possibility of glitched rendering

v1.4.0
  • added new license
  • added usage and crediting instructions

v1.4.1
  • added compatibility with Yanfly's Grid-Free Doodads
  • added compatibility with MOG's Character Motion

v1.4.2
  • added new parameter FADE_Z_COLOR
  • added option to setup custom fade colors for specific maps
  • added option to change fade color at any time

v1.4.3
  • changed NEAR_CLIP_Z from constant to plugin parameter

v1.4.4
  • added compatibility with Thomas Edison MV
  • fixed issue with fixed-coordinate parallax not working

v1.4.5
  • added compatibility with Quasi Simple Shadows

v1.4.6
  • added compatibility for newer pixi-tilemap versions

v1.5.0
  • added map parameters for map borders

v1.5.1
  • added color fade begin to map parameters
  • added color fade end to map parameters

v1.5.2
  • added camera Y position

v1.5.3
  • improved compatibility code for KhasUltraLighting

v1.5.4
  • fixed bug with screen-to-map calculations when using orthogonal projection

v1.6.0
  • implemented improved scaling of sprites on map which doesn't get messed up by near and far clipping planes
  • changed some of the default parameters to accommodate the fixed scaling issues
  • added LEGACY_SCALING parameter for backwards compatibility

v1.6.1
  • improved code that handles sprite positioning in looped maps

v1.6.2
  • attempted fix in Yanfly's Grid-Free Doodads for sprite positioning in looped maps

v1.6.3
  • refactored positioning in looped maps
  • fixed sprite positioning in looped maps for Yanfly's Grid-Free Doodads
  • added CHARACTERS_USE_FADE_Z option
  • removed some left-over debug code

v1.6.4
  • fixed a const assignment errors

v1.6.5
  • updated some instructions

v1.7.0
  • added compatibility code for OcRam_Lights
  • improved compatibility code for KhasUltraLighting

v1.7.1
  • fixed some issues in compatibility code for OcRam_Lights

v1.7.2
  • fixed issues with Yanfly's Grid-Free Doodads in deployed builds
  • fixed issues with terrain tag lights in OcRam_Lights
  • added safeguards to prevent faulty compatibility code to affect other compatibility code
  • limited NEAR_CLIP_Z to a minimum of 1 due to issues with rendering for values of 0 or less
  • disabled CHARACTERS_USE_FADE_Z by default due to performance issues

v1.7.3
  • fixed loading issues with OcRam_Lights

v1.7.4
  • added compatbility for SAN_AnalogMove when PLAYER_ADJUST_MOVE_DIRECTION is turned on
  • added roll angle support

v1.7.5
  • added compatbility for Galv Map Projectiles

v1.7.6
  • fixed a minor issues with compatbility for Galv Map Projectiles

v2.0.0
  • implemented compatibility with RPG Maker MZ

v2.0.1
  • fixed a minor rendering issue
  • improved unified shader code structure

v2.0.2
  • fixed roll-rotation issue with ZephAM_YEPDoodadExt
  • fixed performance issues on larger maps in RPG Maker MZ
  • fixed issue with looping maps in RPG Maker MZ
  • fixed minor offset issue with map display in RPG Maker MZ
  • enabled CHARACTERS_USE_FADE_Z again by default (RPG Maker MZ has no performance issues)

v2.0.3
  • fixed a minor issues with compatbility for several other plugins

v2.0.4
  • fixed some more issues with compatbility for several other plugins

v2.0.5
  • added CHARACTERS_SHIFT_Y option

v2.0.6
  • fixed issues with MZ v1.5.0 core scripts

v2.0.7
  • changed NEAR_CLIP_Z to DEFAULT_NEAR_CLIP_Z
  • changed FAR_CLIP_Z to DEFAULT_FAR_CLIP_Z
  • added map parameters for Near Clip Z and Far Clip Z
  • updated custom Terrax Plugins - Lighting system compatibility code

v2.0.8
  • fixed some new issues with Yanfly's Grid-Free Doodads

v2.0.9
  • fixed bug with invisible looped maps

v2.1.0
  • refactored some code to improve general compatibility

v2.1.1
  • fixed issues with fade color setter
  • fixed issues with fade begin setter
  • fixed issues with fade end setter

v2.1.2
  • added LOOP_MAPS_EXTEND_TILES_SMART option
  • fixed configuration issue when upgrading plugin
  • fixed crash with looping maps and FOV=90
  • fixed a bug in looping maps rendering optimization

v2.2.0
  • fixed compatibility with MZ Core 1.7.0 and later
  • fixed handling of LEGACY_SCALING option

Screenshots

Spoiler: ShowHide

Spoiler: ShowHide

https://i.gyazo.com/9c7d3250509a967665e978ea608f46af

Demo

Ultra Mode 7 Demo for RPG Maker MZ
Ultra Mode 7 Demo for RPG Maker MV

Script

Script Download

Instructions

Inside the script in the first comment.

Compatibility

  • Requires WebGL. Does not work with canvas and due to how canvas works, it can never support canvas.
  • If you update from an earlier version, after replacing the actual file, you should open up the plugin settings and confirm/close them again. Sometimes new features and options are added and this ensures that the newer version of the plugin doesn't crash by adding the new options to your project's system settings.
  • Because the tilemap is rendered entirely flat, tile priority isn't used.
  • Scaling has been optimized for usage of an FOV of 60°. Using different values will cause some weird scales being used for characters.
  • Due to yaw rotation requiring turning of characters, 8-directional characters sprites might have only limited support.

Credits and Thanks

  • Boris "Blizzard" Mikić

Author's Notes

Make sure to read the instructions and study the demo before asking questions.

If you find any bugs, please report them here:
http://forum.chaos-project.com

That's it! N-Joy! =D
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

huskytrooper

September 09, 2019, 03:20:24 pm #1 Last Edit: September 09, 2019, 04:12:33 pm by huskytrooper
Hello, thank you for such awesome work.
The plugin works awesomely wonderful, the only issue I find is that the event intended to act as extra map layer are not being attached on the ground when you change the pitch of the map.

An extra plugin parameter to don't rise events by default when pitch is used, plus an event note to lock/unlock from the ground (and maybe also a plugin call) would be really appreciated.

Thank you again and I hope to see these parameters soon.

Kindly regards,
HuskyTrooper.

EDIT: I want to take this moment to report also an issue related with your zooming feature, which works wonderful, but only has very few issues.

This is related with the "touch input path indicator", which isn't resized when you zoom in, is displaced and not attached on the ground.
Spoiler: ShowHide


Additionally, for the path indicator, you could, if you want (personally I don't need it, but other people might want it), make an addon plugin to provide to the path indicator two sprites, one which is always attached on the ground much like the default white square, where the user can select any image with many frames they want by just indicating on the file name for example 1x4 to make the plugin recognize as the sprite has 4 frames; and anothers plugin parameter for, for example, provide a second arrow indicator, which isn't attached on the ground, so when the map has a pitch, the players playing from touch devices or with the mouse won't miss where the character is going, also another plugin parameter to limit the amount of vertical tiles where the player may click to avoid "endless click".

Finally, an option to zoom-in the character sight, much like in the next image (which would be wonderful to have specially on bigger resolutions) would be wonderful (sorry about the Paint "lazy" example):
Spoiler: ShowHide


And maybe a plugin command to make the character rotate like this person did on this video without the need of parallel process and extra third-party plugins.

Keep up the awesome work.

EDIT2:
Sorry about the long post, maybe everything is too much requesting for you.
The last thing which would be good to fix, is that when pitch is below x (for example, 0, or below 20), the map layers display aren't ignored like on this image (character should be behind the mountain, not above it):
Spoiler: ShowHide

Blizzard

September 12, 2019, 04:13:41 am #2 Last Edit: September 12, 2019, 04:17:14 am by Blizzard
Unfortunately making events with tile graphics work is not as easy as it may seem. The map rendering code is completely separate from the sprites on the screen and map tiles in events are rendered as sprites. In order to make them work, a complete rewrite of the sprite system in PIXI would be required to support 3D coordinates properly. Since a lot of code depends on the sprite system, it requires rewriting a lot more other code just to make the sprites work and not break everything else. So this is a feature that I won't be implementing.



Can you explain the event rise? If it's what I think it is, this plugin might help you solve that issue: https://forums.rpgmakerweb.com/index.php?threads/character-anchors.105599/



If you want to use zooming, you should use UM7 directly. Other plugins will likely cause issues, because the map rendering in UM7 had to be rewritten completely so it's mostly incompatible with map zooming plugins.
As for the path indicator, I'll fix that. It slipped my mind to apply proper zooming to it. xD

As for the additional stuff for the path indicator, this can be done as a completely separate plugin and it's actually outside of the scope of this one. I don't actually intend to make any more plugins for MV (except for maybe a good localization system). I mostly shared this plugin since I already created it for my own game and I know that people have been looking for a good Mode 7 script since the RMXP days.



You can zoom into the map by changing the camera Z distance coordinate. The rest requires a little bit of extra coding. I likely won't be implementing it, because it's a very, very specific feature and it changes the controls. I was actually asked the same question recently so you can look up some extra info here in these posts: https://forums.rpgmakerweb.com/index.php?threads/ultra-mode-7.94100/page-36#post-991164



As for the sprite priority, this is yet again a 3D issue. Since mountains are flat tiles and sprites are rendered after/above the map, this isn't fixable in a classic sense. Those are simply technical limitations of essentially using a 3D map in a 2D engine/game. Besides limiting the pitch angles the player can have in the game, I can suggest two ways to go about this:

1. When using a flat map, you might want to consider turning UM7 off for them. That way the standard code for maps will be used and the tiles that appear above characters will be rendered properly.
2. Create events for "upstanding" graphics likes mountains or trees. If you run into event render order issues, this is because MV doesn't use a Z coordinate for render order anymore as RMXP did. This guy had the same problem: https://forums.rpgmakerweb.com/index.php?threads/ultra-mode-7.94100/page-37#post-1000156 and Arend suggested to use MOG Event Sensor to fix it.

I actually had a similar issue in my game. I solved it by limiting the pitch to a value that still makes everything look good while also adding a bit of code to make sure characters are rendered from top to bottom on the screen to create the illusion of depth for sprites (along with scale obviously).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

Legal bump for some breaking news: I added RMMZ support.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

NandoGRB

Hello! Thank you for this amazing plugin.

It seems I can't set camera distance while using FOV 0 for an orthogonal map. Is there a way to do this?

I'm working in a full orthogonal project using the FOV 0 from your plugin, just wanted to set my camera for like 50% more zoom

KK20

May 06, 2024, 03:28:23 pm #5 Last Edit: May 06, 2024, 03:31:33 pm by KK20
Might want to contact Blizz directly. He doesn't frequent any of the RM forums often. Could try looking through this thread if the question has already been asked.

https://forums.rpgmakerweb.com/index.php?threads/ultra-mode-7-rmmv-rmmz.94100/

EDIT: oh I see you already posted there

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Blizzard

Ugh, I barely check either forum at this point. Usually it's best to ask me in Discord. You were lucky I came across this topic today. xD

Anyway, your use-case isn't actually viable. When using FOV=0, camera distance is meaningless as there is no perspective distortion. There are two ways to handle this:

- I don't remember if I added orthogonal zoom or not. It's been a while since I touched that script. Check if there is an explicit zoom option in the instructions.

- If you set the FOV to something small like 0.1, you will get a near-orthogonal view, but you can still use camera distance to manipulate a quasi-zoom. Keep in mind that you will need a very far initial camera to get the proper size in the first place. If you want, you get even calculate the exact distance you need for a near 1-to-1 orthogonal by using some trigonometry on the 0.1° angle of the FOV and the screen pixel width (can't remember the default width right now). (Off the top of my head I think it's "distance = cos(FOV / 2) * width / 2", just make sure to express FOV in radians instead of degrees when you do the math.)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

NandoGRB

Thank you for taking your time! I'll make some tests on that. Cheers!

Blizzard

BTW, somebody reported a bug that I fixed today. While doing that, I actually noticed that I have that exact calculation in the code. It's inside the Game_Map.refreshUltraMode7View() function. I use it to calculate how many extra tiles I need to render in looping maps in order that all tiles are visible.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.