• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D How to optimize 3D blocks ?

hijong park

Member
I'm making a 3D game that uses blocks created with d3d_draw_block.
In most maps blocks will always take the greatest numbers in the total amount of the objects and I can't stretch the wall objects unlike when making 2D games, so optimizing blocks is very important. Here are some of my trials:

1. Using collision_line to check if the wall is shaded by the other walls and not draw itself when collision_line is true. It was a bad idea, as I can frequently see the blocks being invisible.

2. It's a wolfenstein 3D-style single depth game, so I don't need upper and downer parts of the block. i tried using 4 d3d_draw_wall codes to only draw the sides, But it was rather slower than d3d_draw_block.

3. drawing walls with billboarding... it looks just terrible.

Are there any good ways to optimize 3D blocks at best ? my theory is only rendering the part of the walls shown in the camera but I can't figure out how to do that, as collsion_line just don't work well with this issue.
 
A

Andy

Guest
Don't use collision lines.
Get the angle (yaw) the camera is facing.
Then get the angle from the camera to the block.
Angle difference can be used to figure out if the block is visible.
Example: If the camera angle is 0, and the angle to the block is 0, you are looking straight at the block.

Merge groups of blocks into 1 model. So, here you would draw 2 blocks and not 20.

If the bottom/top of a block wont be visible, don’t use a block. Make a custom "block" model without the bottom/top faces.
Similarly, if you wont see the other side of a block, draw a flat plane.

Draw static blocks to a surface which only updates when the camera changes.
 
Last edited by a moderator:

hijong park

Member
If the bottom/top of a block wont be visible, don’t use a block. Make a custom "block" model without the bottom/top faces.
Similarly, if you wont see the other side of a block, draw a flat plane.

Draw static blocks to a surface which only updates when the camera changes.
Problem is that I have no idea how to achieve it. Can you give me a hint fot it ?
 
A

Andy

Guest
I don’t have much experience using the D3D functions provided in older version of GMS. But this channel might be help you. It has 3d tutorials that deal with creating and importing models, targeting both GMS1 and GMS2 users.

Understanding how to create and draw a vertex buffer will probably be important.
https://docs.yoyogames.com/source/dadiospice/002_reference/shaders/primitive building/index.html
https://docs.yoyogames.com/source/dadiospice/002_reference/drawing/drawing 3d/3d models/index.html

If you want to understand what the D3D functions are actually doing check out these scripts.
http://www.filedropper.com/d3dcompatibilityscripts

You can find 3d Model Creator here:
https://www.maartenbaert.be/model-creator/
 
Last edited by a moderator:

marasovec

Member
I'm trying to do the same. I have a lot of d3d blocks and this is how I "optimize" them
Blocks draw event
Code:
if up d3d_draw_floor(x,y+iy,z+height,x+ix,y,z+height,tup,ix/8,iy/8);
if s1 d3d_draw_wall(x,y,z,x+ix,y,z+height,t1,ix/8,height/8);
if s2 d3d_draw_wall(x+ix,y,z,x+ix,y+iy,z+height,t1,iy/8,height/8);
if s3 d3d_draw_wall(x+ix,y+iy,z,x,y+iy,z+height,t1,ix/8,height/8);
if s4 d3d_draw_wall(x,y+iy,z,x,y,z+height,t1,iy/8,height/8);
if fl d3d_draw_floor(x,y+iy,z,x+ix,y,z,tup,ix/8,iy/8);
And this is how I disable the sides that you can't see

obj_control:
Alarm: every 10 steps
Code:
obj = par_texture; // parent of all blocks

with(obj)
    {
    if global.camz < z+height
        up = false else up = true;
    if global.camz > z
        fl = false else fl = true;
    }

if global.camdir > 45 and global.camdir < 90+45
    obj.s1 = false else obj.s1 = true;
if global.camdir > 90+45 and global.camdir < 180+45
    obj.s4 = false else obj.s4 = true;  
if global.camdir > 180+45 and global.camdir < 270+45
    obj.s3 = false else obj.s3 = true;
if global.camdir > 270+45 or global.camdir < 45
    obj.s2 = false else obj.s2 = true;
(it's made for 3rd person camera)
 
Top