multiDrawElementsInstancedWEBGL / select geometry to render using LOD

102 Views Asked by At

I'm looking for answer regarding the multiDrawElementsInstancedWEBGL api on the web, I'm hitting a wall on something and this is quite frustrating, and really afraid this could confirm my darkest fear haha

I did some experiments in implementing multiDrawElementsInstancedWEBGL to draw some LOD's of the same geometry.

50 Geom 1 high quality 50 Geom 2 low quality

For let say 100 instances so, I got two solutions :

1 ) either render the 100 instances with both geometry by passing instances list 100 and 100 on the command, then early return in the vertex shader one or the other geometry based on distance from the camera and determine what quality I need to render comparing the gl_DrawID

float dist = distance(cameraPosition, offset);

int renderID = 0;

if( dist > 200.0  ) {

    renderID = 1;

}

if( renderID != gl_DrawID ) {

    return;
}

Which results in bad performances anyway, cause it is rendering 200 geometries in the vertex shader, the early return wont help

2 ) either render only 50 instances ( so 50 * 2 geometries) , and passing offset / rotation / scale data via a texture, so we'd be able to determine for each instance and each gl_DrawID the uv's to extract those data Which might also results in bad performance as it needs a texture update on each frame

Is there something we can do using the multiDrawElementsInstancedWEBGL api, that allows to select which geometry to render ( the high or the low ) on the command level instead ?

0

There are 0 best solutions below