Kentae
Member
Hi
I'm trying to optomize the way I render models that are reused a bunch of times, like trees, rocks, bushes, and so on. In this example I use the trees.
Usually I would do it this way.
CREATE:
DRAW:
This gives me pretty decent performance but I feel like there would be a better way. This way I have a ***kload of vertex batches and texture swaps.
So I tried this.
Same create event, but this draw event:
This reduces the texture swaps by a huge lot but for some reason also the fps. in other words I get worse perfomance from this.
Then I figured I'd try to get all the tree-models into the same vertex_submit using this create event:
And a simple draw event:
This gives me exellent performance but all the trees are stuck at 0,0,0 coordinates.
Or maybe there is just one tree being rendered? i'm not sure about this.
So I assume that the matrix functions don't do much in the create event, or am I doing something wrong?
Btw, In the tree_gml and leaves_gml scripts there are just bunch of lines like this:
vertex_position_3d
vertex_normal
vertex_colour
vertex_texcoord
And I pass in the vertex_buffer it's supposed to be bound to.
This works fine though
I'm trying to optomize the way I render models that are reused a bunch of times, like trees, rocks, bushes, and so on. In this example I use the trees.
Usually I would do it this way.
CREATE:
Code:
tree_buffer = vertex_create_buffer();
vertex_begin( tree_buffer, vertex_format );
tree_gml( tree_buffer );
vertex_end( tree_buffer );
vertex_freeze( tree_buffer );
tree_tex = background_get_texture( tex_tree );
leaves_buffer = vertex_create_buffer();
vertex_begin( leaves_buffer, vertex_format );
leaves_gml( leaves_buffer );
vertex_end( leaves_buffer );
vertex_freeze( leaves_buffer );
leaves_tex = background_get_texture( tex_leaves );
Code:
with ( obj_tree )
{
var wmat = matrix_get( matrix_world );
var mat = matrix_build( x, y, z - 5, 0, 0, zr, 10, 10, 10 );
matrix_set( matrix_world, mat );
vertex_submit( other.tree_buffer, pr_trianglelist, other.tree_tex );
d3d_set_culling( false );
draw_set_alpha_test( true );
draw_set_alpha_test_ref_value( 128 );
vertex_submit( other.leaves_buffer, pr_trianglelist, other.leaves_tex );
draw_set_alpha_test( false );
d3d_set_culling( true );
matrix_set( matrix_world, wmat );
}
So I tried this.
Same create event, but this draw event:
Code:
with ( obj_tree )
{
var wmat = matrix_get( matrix_world );
var mat = matrix_build( x, y, z - 5, 0, 0, zr, 10, 10, 10 );
matrix_set( matrix_world, mat );
vertex_submit( other.tree_buffer, pr_trianglelist, other.tree_tex );
matrix_set( matrix_world, wmat );
}
d3d_set_culling( false );
draw_set_alpha_test( true );
draw_set_alpha_test_ref_value( 128 );
with ( obj_tree )
{
var wmat = matrix_get( matrix_world );
var mat = matrix_build( x, y, z - 5, 0, 0, zr, 10, 10, 10 );
matrix_set( matrix_world, mat );
vertex_submit( other.leaves_buffer, pr_trianglelist, other.leaves_tex );
matrix_set( matrix_world, wmat );
}
draw_set_alpha_test( false );
d3d_set_culling( true );
Then I figured I'd try to get all the tree-models into the same vertex_submit using this create event:
Code:
// !!! Tree TEST !!!
var wmat = matrix_get( matrix_world );
tree_buffer = vertex_create_buffer();
vertex_begin( tree_buffer, vertex_format );
for ( i = 0; i < 10; i++; )
{
for ( j = 0; j < 10; j++; )
{
var xx = 100 + ( i * 40 );
var yy = 100 + ( j * 40 );
var zz = terrain_get_z( xx, yy );
var mat = matrix_build( xx, yy, zz, 0, 0, 0, 10, 10, 10 );
matrix_set( matrix_world, mat );
tree_gml( tree_buffer );
matrix_set( matrix_world, wmat ); // Added this to see if it would fix the issue of all the trees being in the same place.
}
}
vertex_end( tree_buffer );
vertex_freeze( tree_buffer );
matrix_set( matrix_world, wmat );
tree_tex = background_get_texture( tex_tree );
Code:
vertex_submit( other.tree_buffer, pr_trianglelist, other.tree_tex );
Or maybe there is just one tree being rendered? i'm not sure about this.
So I assume that the matrix functions don't do much in the create event, or am I doing something wrong?
Btw, In the tree_gml and leaves_gml scripts there are just bunch of lines like this:
vertex_position_3d
vertex_normal
vertex_colour
vertex_texcoord
And I pass in the vertex_buffer it's supposed to be bound to.
This works fine though