Why not using WebGL on Mobile?

I have some doubts on RPG Maker Engine.


WebGL is clearly faster than Canvas in any comparison ever made until this present date. I know that because of other engines like Construct 2 that i use and already played with all theses settings. 


So...


1) Why mobile versions of projects doesn't support WebGL even on smartphones that does support the technology and have an Webview embed just for it?


2) Why even on an Quad-Core Device with 1gb of ram that supports WebGL the game runs poorly in battles? (Moto G 2nd gen, usually running at 5 FPS)


I don't know if its a code issue or the game is actually intended to run in Canvas Mode on Mobiles that support WebGL.


But I don't think RPG Maker MV is quite good yet to mobile gaming if anything below an device with 2gb of ram is incompatible.


WebGL is faster working and rendering multiple canvas, I believe that Battle Animations is the main issue on performance. Maybe that would solve it?


PS: I tried the new 1.3.0 version already, and the problems still persist.


PS²:  I'm using no plugins its simply like that.


I may be speaking stupidities, but if anyone have a solution i'm really thankful.
You can force it to use WebGL, however that can introduce stability issues on some devices. Not every device does support WebGL, and so instead of trying to figure out some way to make them all work and sell a potentially unstable product, KDKW (The original software publisher) decided to make mobile devices use Canvas instead, as it's been supported by almost all devices for years and shouldn't present any issues.


In order to force WebGL, there are a few things you can do. The first is to go into the rpg_managers file, find the SceneManager, and change the shouldUseCanvasRenderer function to just return false. This should allow devices that support WebGL to work, however those that do not support WebGL won't be able to play the game.


Additionally, when compiling the game using crosswalk, there is a compilation option called "--ignore-gpu-blacklist". If you compile with this option, devices whose video cards support WebGL, but are considered too unstable, will also be able to play the game. However keep in mind that these devices were not allowed to use WebGL for a reason: They aren't considered to be very stable, and so this could present issues with people on such devices playing your game. Issues caused by an unstable device gpu would be very difficult to diagnose because the issue can be very inconsistent and may not happen on every device, even other ones of the same model.


The main reason 1.3.0 wouldn't improve the performance of the canvas game is because it's an update geared toward WebGL, but since not everything can support it, it isn't enabled by default. The company makes it easy to enable, but by not technically making it an option, they are not liable for any issues experienced when trying to make it run on WebGL.
@Phaelitico thank you for constructive topic


@Zalerinian +1


I'm responsible for graphics stuff, and I'm also one of "pixi.js-v4" authors, so that's my answer:


1. There is no memory management mechanism, which is critical, especially on mobiles. If someone will write a guide, like "Use three types of cache, images with type X go to cache Y and stored only in videomemory, and if it takes more than 256MB then unload old stuff" I will be happy.


2. There are still many places in rpgmv that are heavily using 2d context. Every time some 2d texture goes updated, pixi uploads it to videomemory and that takes time AND extra memory.


3. I wrote a library for very fast tilemaps, and I still could not enable webgl on mobiles because there are device-specific bugs 🙁  Especially in Safari.


4. We really need a mechanism to tune memory-related stuff for specific project. Every time someone uses 4k textures for some object and then complains why authors did not think about that, I become very angry.


5. May be we need compressed textures for really big stuff like parallax maps.


Try to use .3.1, find the function that forces CanvasRenderer in case of isMobile() and hack it (exactly like @Zalerinian said)
I feel like RMMV is trying so hard to force brand itself as an RPG engine for mobile games, but looking at the forum itself, it seems that most of the developers are still developing towards PC/OSX platform.


Until when are KDKW gonna be pushing this mobile agenda, for you guys to work on optimizing for PC/OSX platform?


(I'm sorry if it deviates from the discussion but I really need to know)
I feel like RMMV is trying so hard to force brand itself as an RPG engine for mobile games, but looking at the forum itself, it seems that most of the developers are still developing towards PC/OSX platform.


Until when are KDKW gonna be pushing this mobile agenda, for you guys to work on optimizing for PC/OSX platform?


(I'm sorry if it deviates from the discussion but I really need to know)

Developers can develop towards whatever platform they wish, the PC/OSX market is easier to develop towards so most tend to go that route. We can't discuss future plans for the engine or what our roadmap has because we are under contract/NDA, so please don't ask again. The answer is, when we get to it, we react to how the developers react to the engine, and most seem to be leaning towards remaining on PC/OSX so that is why those optimizations come first, not only that but they are much easier to optimize than mobile.
I seem to ubderstand a Little better now @Hackerham.


@Zalerinian I already did this and noticed The awesome lag ??, 1.3.1 seems a Little better for mobile gaming however.


@Liquidize you are right about being easy to develop for PC because performance and easy of deploy mostly.


But is quite hard to monetize games on PC because a lot of People simply compare rpg Maker games with triple A Blockbusters 3d rpg franchises that costs about The same on Steam Summer sale.


Mobile deveolpment is hard in every single step, but i believe is way more rewarding. At least this is my opinion, is easy to distribuir games via play Store or app Store after all.


PS: Sorry for typos, my native Language isnt english and my device keeps correcting english with other dictionary.


@Hackerham maybe i'm sugesting something hard to do but... Isnt possible to do optimizations based on device and OS version on The compiler? Android 5+ comes with webgl capable webview that runs natively better than crosswalk, Android 4+ can use crosswalk, Android manages ogg better than m4a, iOS have WKWebView, Windows mobile have Microsoft Edge now as webview, wp8 had internet explorer Who wasnt capable of webgl. Maybe we can ignore The OS version and just go with The type you use instead of a single compilation for Android/iOS.
@Hackerham maybe i'm sugesting something hard to do but... Isnt possible to do optimizations based on device and OS version on The compiler? Android 5+ comes with webgl capable webview that runs natively better than crosswalk, Android 4+ can use crosswalk, Android manages ogg better than m4a, iOS have WKWebView, Windows mobile have Microsoft Edge now as webview, wp8 had internet explorer Who wasnt capable of webgl. Maybe we can ignore The OS version and just go with The type you use instead of a single compilation for Android/iOS.



Well now technically, crosswalk is just one way of doing mobile export. In order to advertise that RPG Maker MV was mobile-capable, they needed to provide a method of exporting to mobile devices. That in no way means that it's the only way. If you can get an MV game on an Android 5+ WebView as a native app, please, take the time to write a tutorial as I'm sure it'll help many people with similar issues. The troubles with doing it this way is that KDKW/Degica can't offer support in projects exported this way because it's not the official method of doing so, similar to how WebGL can be enabled on mobile, but isn't by default. By not making it something that's done by default or explained through the manual, the company isn't responsible for making sure that updates always work with these new methods.


Now you may think that's bad, but there's no real answer. For one thing, updates can be made more quickly because there are less scenarios that the new codebase has to be tested under. However, that also means that other such export options are subject to breaking between updates, because they're not officially supported, and so breaking them isn't necessarily a limiting factor for the company pushing out an update.


Overall, KDKW provides a general solution to exporting on the different platforms. It works, and so they're able to advertise it as such. In an android game, you could safely force it to use the ogg audio instead of m4a and be fine, but by default that's not how it works, because it won't work on iPhones, which is supported by MV. That's actually something I think a lot of people need to learn about RPG Maker in general. It's a very general solution to making a video game. Making it a good game that works well across platforms and devices? That's not the job of KDKW, they got you the software to make doing it relatively easy. It's up to you as the developer to make it work nicely and be a good game. After  all, you're a developer, not an office worker. You have to take the time to make decisions and change things to make it work as best as possible as the product develops, you don't sit at a desk and punch tiles into maps, add events, and then hope to sell the next greatest game ever made.
@Zalerinian, Well, there's a issue, RPG Maker MV was made in such way that can only be compiled with crosswalk. When you try to compile without crosswalk and you launch the game, the engine asks for crosswalk libraries. There is no other way to go (for now) than crosswalk.


It's like you said, the same issue with WebGL, the core engine was made in such way that you cant have multiple ways of working with it, just the default way.


I'm just saying... maybe instead of one "universal mobile compilation" it should make different compilations for iOS and Android.


I totally agree that the developer solely is responsible for the quality of his game. But when the engine doesn't allow the developer to go further away from the default without sacrificing performance is quite cruel.  


I mean... plugins is the way to extend RPG Maker MV further right?! But is sad that if you use more than 10 plugins on mobile the performance goes down alot.


I don't mean to "attack" RPG Maker MV, it's the best RPG Maker so far, but in terms of mobile capabilities, it's like a baby that is starting to walk. Its really good as long as you don't have battles in your game.


I really hope they have the same success of others mobile platforms like Construct 2, Corona SDK, Game Maker.


If i was a capable JS developer i would gladly help to integrate WebGL on RPG Maker properly. Because there's so much performance gain and a lot of 3D effects you can add to a 2D game to make awesome stuff.


I think i'm just sad that my mobile device runs pixi4 demo with 100.000 bunnies jumping on my screen bouncing and moving like hell without losing performance and when i use "Fire I" during battle my FPS goes down to 5. And that any 1GB device cant handle the game for more than 30 minutes without crashing.


--------------------


However not all things are bad, in fact, support for pixi4 really improved performance in comparison with 1.2.0. I have an Moto G4 Plus and when battling my average FPS goes down to 30 FPS on pixi2, with the newest 1.3.1 now i can achieve 55 FPS average. Its really something!


Good job @Hackerham!
@Zalerinian, Well, there's a issue, RPG Maker MV was made in such way that can only be compiled with crosswalk. When you try to compile without crosswalk and you launch the game, the engine asks for crosswalk libraries. There is no other way to go (for now) than crosswalk.





This isn't true.
@Hudell, What other way have you managed to compile for android without crosswalk?
Try using cocoonJS: https://www.ludei.com/cocoonjs/


RPG Maker generates an HTML5 project without any kind of dependency, so you can use any of those tools.
Try using cocoonJS: https://www.ludei.com/cocoonjs/


RPG Maker generates an HTML5 project without any kind of dependency, so you can use any of those tools.



Ahhh i already used Cocoon.io with construct 2 projects, but there's a limitation to the size of the project.


Projects can't be longer than 50mb. unless you pay a monthly subscription.


Which is a issue if you can't determine if the game gonna run great until you try.


Canvas+ by Ludei is really great and certainly improves performance on Canvas Only games. But i cant manage to do a game with less than 50mb.
@Zalerinian, Well, there's a issue, RPG Maker MV was made in such way that can only be compiled with crosswalk. When you try to compile without crosswalk and you launch the game, the engine asks for crosswalk libraries. There is no other way to go (for now) than crosswalk.



That's only if you compile it with crosswalk without including the crosswalk runtime, which means that needs to be installed as a separate app. This keeps your project size smaller, but you're still building your game with crosswalk, so yes, by doing it that way you will need crosswalk. There isn't a single mention of any crosswalk library in MV's code.

It's like you said, the same issue with WebGL, the core engine was made in such way that you cant have multiple ways of working with it, just the default way.


I'm just saying... maybe instead of one "universal mobile compilation" it should make different compilations for iOS and Android.


I totally agree that the developer solely is responsible for the quality of his game. But when the engine doesn't allow the developer to go further away from the default without sacrificing performance is quite cruel.  


I mean... plugins is the way to extend RPG Maker MV further right?! But is sad that if you use more than 10 plugins on mobile the performance goes down alot.



You can have multiple ways of working with RPG Maker, it's just that they provide you with one way that they will continue to make and support, and any other way is up to you or others to create, use, and maintain. People use RPG Maker to make games that are vastly different from RPGs. Like I said before, there are other ways you could export your game, but you're given one option that is fully detailed out on how to do. Any other options are up to you to figure out, but there's definitely options.


How much a plugin will affect a game's performance is entirely dependent on what the plugin does and how it does it. There's a countless number of ways to design any given system, but there are only a relative few that will perform well in all cases. Another concern is how much memory these plugins consume. A complex battle system that deals with a large number of images will cause poor performance on a mobile device because there won't be enough memory. If that plugin doesn't clean up the memory it uses once the battle is done, that poor performance will continue to occur after the battle, when the plugin is no longer used. It's really difficult to make something perfect in every case, but if a plugin is poorly designed and released because it "finally works right", chances are it'll cause problems on mobile, and probably even desktop exports as well.

I think i'm just sad that my mobile device runs pixi4 demo with 100.000 bunnies jumping on my screen bouncing and moving like hell without losing performance and when i use "Fire I" during battle my FPS goes down to 5. And that any 1GB device cant handle the game for more than 30 minutes without crashing.



While I agree that the demo is pretty cool, it can also be very misleading in terms of what it does. Every bunny uses the same sprite with a different frame. In your RPG game, most things are very different sprites. So yes, there's a large number of objects, but many objects that refer to one single bitmap is much less memory intensive than a few objects referring to many bitmaps. Take a small, 48x48 image for example, the default size of a MV tile. That's 2,304 pixels (48 * 48). Now, each pixel is either 3 or 4 bytes long, depending on how the image is saved. We'll say 4 bytes, because some tiles are partially transparent, and transparency will make it 4 bytes. That comes out to 9,216 bytes, or exactly 9KB for that one image. But now wait! Side view battlers that are animated? Oh those images are much larger, and contain transparency, so that's 4 bytes per pixel. Let's see... The side view of actor1 is 576x384 pixels for all it's animations and such. Depending on the battle, you might not use all the frames, but since they're in the same image they're loaded in anyway.


576 * 384 = 221,184 pixels.


221,184 * 4 = 884,738 bytes = 864KB for that one image.


How many images do you thing there are in one battle from the side view? Each actor will have one, each eemy will have one, there's the background image(s), all the windows refer to the window skin and have their own bitmaps for drawing, animations will add more memory, background audio files are usually large, there are also sound effects to play, etc etc etc.


Memory usage adds up fast. And that's just the battle scene. things loaded from the map and other earlier scenes probably won't all be destroyed, either by mistake or by intention. It gets to be a lot of memory for the one game. And then we have to consider that the mobile device isn't just running the game. There are other apps in memory, though the game will likely force them to close, and phone's operating system itself. Just because you have a 1GB device doesn't mean you have access to that full 1GB. For example, I have the Galaxy S6 smartphone with 3GB of memory installed. How much RAM is free if I force everything to close? Less than 1GB. Only 700MB of RAM is free after closing all applications, and then some of them just open themselves back up again.


I realize that this post is probably going to seem kind of hostile and rude, but I assure you that's not my intention. What I mean to show here is that mobile development is hard. You can't do the same things on desktop as on mobile for most games. You have to plan your game to be released on mobile from the beginning so that you're conscious of the memory usage of your game and can manage it much better than when you develop on a desktop and have the freedom of knowing that your device has a large amount of RAM. For a game to run well on mobile and on desktop, and do the exact same stuff, you have to be very, very meticulous and never let any memory be wasted. You'll probably have to add in checks when on a mobile device that when the scene changes, make sure everything from it is destroyed. Even if you're just changing maps, you don't want to leave the old tilesets in memory because a mobile device doesn't have enough to spare.


It's like we said before: Quality of a game is up to the game's developer. You can't just make a game, play it on desktop, and then expect the same quality on a mobile device. It's just not going to happen. Things have to change. The point of MV, or any engine for that matter, is to make exporting to multiple platforms both doable and easy. It doesn't make it run the same on all platforms. That's what you, the developer, take care of, because the game is created how you want it. If you can't take the time to make sure each version works as closely as you want it to, then there's not much that can be done to make everything run the same. Mobile devices are restricted in what they can do compared to desktops and laptops. In some cases, laptops are more restricted than desktops. You need to tweak the game to manage memory more closely on a mobile device so that it's more stable. On a desktop, a large cache isn't as big a problem as on a mobile device, because you can freely assume there's room to spare. On mobile devices, there really isn't that room.
I realize that this post is probably going to seem kind of hostile and rude, but I assure you that's not my intention. What I mean to show here is that mobile development is hard.



Don't worry about it, no offense taken, i'm just trying to understand how the engine works now and which optimizations needs/can be done.


I believe debates like this are important to understand what can be done to achieve the best possible result.


I'm working in ways of optimizing RMMV projects for mobile development. Everything I can learn from how the engine works (like what it keeps in memory and whats get destroyed on map transitions and battle transitions) is really helpful.


For sample i'm creating myself a snippet to optimize all imges sizes by crushing it without losing significant quality.


I'm trying to figure ways to that with audio too since MIDI isn't quite possible in HTML5 Games. (there's ways to do, but not quite good yet).


I'm personally curious how maps are rendered by the way, the game converts the map into simple canvas images based on the priority set on tileset? (below/above the character) or every single item is drawn individually? (so that drawing less trees reduces memory usage.)


If the second option is the true one, parallax mapping is better in terms of performance? how RPG Maker handles sprites that aren't visible on screen?


So many doubts, so many questions,  😀
@Phaelitico You mean you are trying to re-compress png or such? 


Maps are rendered 


1) canvas - two canvas texture, one above and one below. Scrolling is optimized, but animation is slow.


2) webgl - two meshes. Very fast. Scrolling optimized better than on canvas, and animation does not affect it at all.


In both cases, only visible tiles and some border belongs to canvas/mesh.


@Zalerinian


Exactly. But Rpgmv uses 12 bytes per pixel in some cases, due to some problems in architecture. Memory management is critical and there's no documentation on it 🙁


UPD. Sprites that aren't visible are handled by GPU itself. Its difficult to write good culling for javascript.
in 1.3.0+, if the game is running in WebGL, the GPU is directly used to draw the map, through the ShaderTilemap class. Otherwise, the Tilemap class is used to do so, and I'm not familiar with how it was designed.


Sprites that aren't visible would be handled by PIXI, most likely, and I'm not sure how that works either. I'm starting to look more into memory management myself now, as even on desktops, a large amount of memory usage could result in an unstable game depending on the system the game is played on. There's just a lot to consider and look into.
@Phaelitico You mean you are trying to re-compress png or such? 



Yes, project files are too big, specially Animation and Battleback folders. Even when using just some stuff from RTP, is quite hard to manage to make small game files for Android APKs. Specially since crosswalk already takes about 20mb extra.


Most of my projects takes about 140mb and i try to limit things like the number of musics used to 10.


M4A files are smaller than OGG, so OGG is out of the table for me.
All audio files have a 256kbps bitrate and 44.1KHz sampling rate with almost no compression applied.


I will play around with some encoding settings to see if i can make files smaller without losing quality or performance. (compressed audios usually get issues)


@Hackerham, how the engine converts/reads the map files? i'm curious about overlapping objects likes trees, and if many objects takes more memory.


(objects = sprites)


I believe this info is crucial to take account when mapping.
@Phaelitico I dont work with formats. No, objects are very lightweight, only textures matter.

Original thread: https://forums.rpgmakerweb.com/threads/why-not-using-webgl-on-mobile.66722/