Store multiple attributes per instance in few vertex shader constants

Hi,

I've been thinking in a new algorithm to render huge quantities of grass vegetation without performing vertex shader lookups. The idea is simple:

1 Generate a density map for the terrain (0 means low density, 1 high density)
2 Generate a grass patch with a fixed size (m x n meters)
3 Generate a n-tree where leaf nodes have the size of the patch.
4 Store the following attributes in each leaf node:
- 1 float4: 3d position+density (density value extracted from density map)
- 4 float4: 4 planes that define the convex space of the terrain cell
- 1 float: angle of rotation arround xz plane (y is up)

5 In the culling pass, get the visible leaf nodes
6 Render the grass patch with instancing using attributes from the nodes

In total, I have 21 floats per instance (6 float4, 3 floats unused). I'd like to store 8 floats (2 float4) as maximum per instance. And the questions are:

Q1. How can I compress the data without losing a lot accuracy?
Q2. The convex space is the key. Do you know another method to store a space defined by 4 convex planes?

Cheers,

S.
 
Last edited by a moderator:
HW instancing

My options are hardware instancing or to replicate n meshes in a single mesh. btw, I can remove the position.y component. So I have 20 floats (5 constants).

I think I will use SM3.0 hardware instancing because I can draw all the patches with a single draw call. The other method will work in SM2.0 though, but I will only be able to render 51 patches per call.

In my recent tests, using a far distance of 200 meters, the culling pass leave 300 visible patches, so 6 draw calls is also acceptable.
 
Ah, I got it the wrong way around.

You could store the data in textures, and put a texture selector in the map instead of only the density.
 
Back
Top