1 registered members (M_D),
1,430
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
d3d_instancing = 1;
#415816
01/24/13 08:57
01/24/13 08:57
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
OP
User
|
OP
User
Joined: Oct 2004
Posts: 900
Lgh
|
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?
///////////////////////////////
#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);
}
}
|
|
|
Re: d3d_instancing = 1;
[Re: rojart]
#415818
01/24/13 09:47
01/24/13 09:47
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
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.
|
|
|
Re: d3d_instancing = 1;
[Re: HeelX]
#415820
01/24/13 10:18
01/24/13 10:18
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
OP
User
|
OP
User
Joined: Oct 2004
Posts: 900
Lgh
|
In the manual is nothing described about sprite entities restriction and should be changed. 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%.
|
|
|
Re: d3d_instancing = 1;
[Re: jcl]
#415830
01/24/13 11:39
01/24/13 11:39
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
OP
User
|
OP
User
Joined: Oct 2004
Posts: 900
Lgh
|
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? 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.
|
|
|
Re: d3d_instancing = 1;
[Re: HeelX]
#415851
01/24/13 17:13
01/24/13 17:13
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
@sivan: complexity depends on the restrictions you dont want to have 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.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
|