3d (g3d): how to draw only visible models? FPS drop!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Tabaqui
Prole
Posts: 34
Joined: Tue Mar 24, 2020 2:47 pm
Location: Italy

3d (g3d): how to draw only visible models? FPS drop!

Post by Tabaqui »

Hi all!
After trying out perspective and various stuff with a raycasting engine, i've decided to learn pure 3d with the help of groverburger's awesome g3d library.

My first goal consists in rendering a simple environment based on a tilemap (a WxH grid with indexes representing walls or floor with different textures) and i've noticed that if the map is too big the FPS will drop (in a 2d map i'd simply draw the visible tiles).

Since i'm new to 3d stuff in general i'm asking you a couple of silly questions:
  • How can i render only visible models/tiles?
  • What is the best way to draw tile-based maps? At the moment i'm using the same cube model for walls (translated for each tile) and the same square model for the floor, but i've noticed that for walls sometimes i can see strange artifacts. Is there any better option?
In the attachments you can find the .love file with my first attempt at 3d. If you increase MAP_W and MAP_H you can see the FPS drop i've mentioned earlier!

Thank you in advance

PS: cubes aren't really cubes because i was too lazy to write the bottom and top face :o:

EDIT: for the first question i've seriously considered raycasting, but there must be a better option, right? And by the way raycasting on large maps will still slow down the whole thing
Attachments
3D.love
(14.98 KiB) Downloaded 108 times
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: 3d (g3d): how to draw only visible models? FPS drop!

Post by pgimeno »

Draw calls are expensive, and you're using two draw calls per tile. With a 100x100 map, that's 20,000 draw calls. Try building a mesh with the whole map instead. Or maybe one with the ceiling and vertical walls, and another one with the floor and horizontal walls (to draw them at different intensities, but you could use a shader for that, or even vertex colours).

Also, save polygons if you can. If the floor is homogeneous, it could be just a big quad.
User avatar
Tabaqui
Prole
Posts: 34
Joined: Tue Mar 24, 2020 2:47 pm
Location: Italy

Re: 3d (g3d): how to draw only visible models? FPS drop!

Post by Tabaqui »

Thanks pgimeno, i thought of using a single mesh for the whole floor, but is there a way to apply a tiled texture to it?
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: 3d (g3d): how to draw only visible models? FPS drop!

Post by pgimeno »

Yes, using wrapping mode. Texture:setWrap. Set the UVs to be from 0 to MAP_W/MAP_H instead of from 0 to 1. That won't work with a texture atlas, though, unless you do the wrapping manually in the shader, but you seem to be using a single texture and not an atlas, so it shouldn't be a problem.
User avatar
Tabaqui
Prole
Posts: 34
Joined: Tue Mar 24, 2020 2:47 pm
Location: Italy

Re: 3d (g3d): how to draw only visible models? FPS drop!

Post by Tabaqui »

Thanks again, i’ll give it a shot! By the way i’ve found a solution for dark areas like dungeons: i’ve slightly modified the shader used by g3d by adding a fog effect and then by drawing only the part of the map that can be seen. Tested on a 10000x10000 tilemap and works like a charm! Still need to figure out how to apply a similar effect on open areas though... I wonder how minecraft can handle such large areas :roll:
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: 3d (g3d): how to draw only visible models? FPS drop!

Post by zorg »

Minecraft only renders what you can directly see; That means that anything outside your FoV (field of vision), on the sides and behind you, don't get drawn at all, plus, all the faces of the cubes that are "attached" to other opaque cubes are not drawn either, only the "exposed" faces... among other things i guess.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 88 guests