d3d_instancing = 1;

Posted By: rojart

d3d_instancing = 1; - 01/24/13 08:57

I tested sprite instancing with infinite_level.c example, and indeed works.

But, if I try with particle sprites, like code below the fps went down.

Is d3d_instancing = 1 restricted for sprite particles?

Code:
///////////////////////////////
#include <default.c>
#include <particles.c>

///////////////////////////////

function p_fountain(PARTICLE* p)
{
	VECTOR vTemp;
	vec_randomize(vTemp,2);
	vec_add(p.vel_x,vTemp);
	vec_set(p.blue,vector(random(255),random(255),255));
	set(p, MOVE | BRIGHT | TRANSLUCENT);
	p.alpha = 100;
	p.size = 2;
	p.gravity = 0.2;
	p.skill_a = 3; // fade factor
	p.event = p_fade;
}

function p_fountain_sprite(ENTITY* p)
{
	VECTOR vTemp;
	vec_randomize(vTemp,2);
	vec_add(p._VEL_X,vTemp);
	vec_set(p.blue,vector(random(255),random(255),255));
	set(p, _MOVE | BRIGHT | TRANSLUCENT);
	p.alpha = 100;
	p._SIZE = 6;
	p._GRAVITY = 0.2;
	p._FADE = 3; 
	p.event = p_fade_sprite;
}


function main()
{
	d3d_instancing = 1;
	max_entities = max_particles;
	fps_max = 1000;
	level_load(NULL);
	video_window(NULL,NULL,0,"Sprite particle demo");
	vec_set(camera.x,vector(-150,0,50));

	while(1)
	{
		if(key_s) {
			effect_sprite(NULL,p_fountain_sprite,maxv(2,40*time_step),vector(0,0,0),vector(0,0,5));
			draw_text(str_printf(NULL,
			"%d fps for %d sprites",
			(long)(16/time_frame),(long)num_entities),
			5,5,COLOR_WHITE);
			} else {
			effect(p_fountain,maxv(2,2*time_step),vector(0,0,0),vector(0,0,5));
			draw_text(str_printf(NULL,
			"%d fps for %d particles (press [S] for emulation with sprites)",
			(long)(16/time_frame),(long)num_particles),
			5,5,COLOR_WHITE);
		}
		
		if(key_i)
		camera.flags |= ISOMETRIC;
		else	
		camera.flags &= ~ISOMETRIC;
		
		wait(1);
	}
}

Posted By: HeelX

Re: d3d_instancing = 1; - 01/24/13 09:47

Originally Posted By: rojart
if I try with particle sprites, like code below the fps went down. Is d3d_instancing = 1 restricted for sprite particles?


d3d_instancing = 1 is for sprite entities only and doesn't affect particles. The Pro Edition automatically uses instancing which can be turned off by particle_mode = 1.
Posted By: rojart

Re: d3d_instancing = 1; - 01/24/13 10:18

In the manual is nothing described about sprite entities restriction and should be changed.

Quote:
Renders objects with instancing; as many objects as possible are rendered with a single draw function, thus reducing the rendering time in levels with many similar objects f.i. for vegetation sprites. Instancing can increase the frame rate by up to 30%.
Posted By: jcl

Re: d3d_instancing = 1; - 01/24/13 11:13

HeelX is right, particle instancing is automatically activated with the Pro Edition. "Objects" means entities, not particles. This will be made clearer in the manual.
Posted By: rojart

Re: d3d_instancing = 1; - 01/24/13 11:39

Ok thanks, but if particle instancing is automatically activated but not for sprite particle entities.

But by default, internal image is set, like ackfont.pcx, is this not sprite entity?

Quote:
When the particle has no bmap, it is a colored dot, taken from an internal image that also contains the default font. This font can be replaced by providing an external ackfont.pcx image. Note that this will also replace the default particle image, which is taken from position (100,56) of the ackfont.pcx image.
Posted By: sivan

Re: d3d_instancing = 1; - 01/24/13 11:40

maybe a bit offtopic, but is there any chance to have once some kind of model instancing in 3DGS (Pro)? as I remember I read once it was developed, but was cancelled finally because of the complexity and low resulting performance increase. but as I know static and dynamic batching is used widely in games to run faster, and offered by some other engines, probably having different entity management system...
Posted By: HeelX

Re: d3d_instancing = 1; - 01/24/13 12:39

Originally Posted By: sivan
is there any chance to have once some kind of model instancing in 3DGS (Pro)?
I support this feature request! If you have developed this already, why not dropping it into the engine? Would be a nice addendum to the already neglected beta page wink
Posted By: Rackscha

Re: d3d_instancing = 1; - 01/24/13 17:13

@sivan: complexity depends on the restrictions you dont want to have tongue

i.e.:
- Load mesh, if its a new mesh: create a pointer to an empty entity_instancelist. The model saves the pointer. The list_pointer is also registerd for the engine

-on visiblity cheeck for entity:
if its visible:
add the entity to the list of its model

on drawing:
engine runs through all registerd entity_instancelists. On each list, it creates the instance buffers
1 static buffer linking to the mesh
1 dynamic buffer with an entry array. One entry per entity in current instancelist. each entry holds position, rotation, texture.

then these 2 instance buffers are send to the instancing drawcall.

for the entities, you have to write a shader which incoorporates thes instancebuffers. Because the given instance mesh is rendered for each entry. the entry is given to the shader(which param is specified in the instancebuffers)

Basic instancing, restricted to position, rotation, texture

Important: the above is the rough description on doing it in DX11. In DX9 it might be a bit different. But i dont think its TOO diferent.
Posted By: sivan

Re: d3d_instancing = 1; - 01/24/13 21:23

I would be happy with DX11 too laugh
© 2024 lite-C Forums