Jump to content

a bug in ObjectBillboards render?


photo

Recommended Posts

Hi,

 

ObjectBillboards uses unsigned short for indices, so maximum value for indices is 2^16 - 1 (65535), but if you type 15 as size in this sample then you got 30*30*30*6 indices (162000) which is much more than 65535.

 

If you want such many triangles, you should use more than one ObjectBillboards.

Link to comment

I've to say that using short as index buffer is not enough for real world vegetation, each billboard need 6 index, so using short as indices can only use about 10922 vegetations.

 

I've successfully modified the engine to use unsigned int as indices buffer.

and another question, in manual, ObjectBillboards::setTexCoord says:

Sets texture coordinates for a given billboard (a texture atlas can be used).

The first pair of coordinates (x and y) set texture scale by X and Y axes. For example, by the scale of 2 the texture is repeated twice on the billboard.

The second pair (z and w) set texture offset along X and Y axes. For example, by the offset of 0.5 along X axis the texture is repositioned to the right (so that the edge of the texture is rendered in the center).

The default is vec4(1,1,0,0).

but when I want to use a atlas, the texture coordinate needs to be x, y, width, height, how to use these with texture atlas? I searched the code for billboards_02.cpp, it seems the first pair are used as width and height, But I'm not sure I'm right, if I'm right, then these info should added to the manual.

Link to comment

The first pair is not actually width and height. It's a scale. You can interpret this as texture coords transformation.

 

Lets take a closer look at billboards_02 sample:

 

By scaling texture to factor 0.25 you'll get 'zero digit' from texture. So here is transformed texcoords (I assume billboard has (0,0),(1,0),(0,1),(1,1) texture coordinates at its vertices):

 

* 0.25

(0,0) -> (0,0)

(1,0) -> (0.25,0)

(0,1) -> (0,0.25)

(1,1) -> (0.25,0.25)

 

Transformed region will contain only 'zero digit'. If you apply offset, you can 'move' this region to other 'characters'.

 

P.S. Use ObjectGrass for vegetation instead of ObjectBillboards (please look at grass_00 and grass_01 samples).

Link to comment

I've noticed the problem, but in ungine, ObjectGrass and ObjectBillboards sample assume the texture has some fixed number of items in every row,

 

But when I want to use this with speedtree generated atlas, the number of billboard texture in atlas is different in each row, calculate that pair of number has much pain than directly assign the vec4(x,y,width,height).

 

I hope there will be some option to support this kind of atlas texture.

Link to comment

For ObjectsBillboards, check the Generator. It is the most convenient option for random assigning a texture slot from atlas (especially for vegetation). it has width and height for the number of slots.

ObjectGrass can have only be 4 slots horizontally. You can write a custom script that will assign texture coordinates instead of doing it manually.

Link to comment
×
×
  • Create New...