The problem is performance isn't good enough.
Basically I calculate all the vertices in the constructor and add them to a UT_Vector3FArray, pass those vertices to the vertex shader, which calculates the final position.
Instead of that I'd like to create a single object and instantiate it many times.
So after reading the HDK documentation I understood that if I create a custom primitive there would be a way to instantiate them (i've read something about collecting entities in the prim sample), but I don't know if that could be made into a Scene render hook.
So first thing I've made is to get the DM_BackgroundRenderHook sample and in the constructor, and modify it to create a sphere with the following method I've found in the samples folder, wondering if Houdini would handle multiple instances of such primitives internally using hardware instancing:
static GU_Detail * createSphere(bool for_default) { GU_Detail *shape = new GU_Detail; GU_PrimSphereParms sphere(shape); if (for_default) { sphere.freq = 2; sphere.type = GEO_PATCH_TRIANGLE; GU_PrimSphere::build(sphere, GEO_PRIMPOLY); } else { // Position and scale the collision sphere to account for the // deformation animation. sphere.xform.scale(1.5, 1, 1.5); sphere.xform.translate(0, 1, 0.5); GU_PrimSphere::build(sphere, GEO_PRIMSPHERE); } return shape; }
So the constructor would be like:
DM_BackgroundRenderHook(DM_VPortAgent &vport)
: DM_SceneRenderHook(vport, DM_VIEWPORT_ALL),
myCheckerTex(NULL),
myQuad(NULL)
{
m_quadPositions.append(UT_Vector3(-1.0f, 0, -1.0f));
m_quadPositions.append(UT_Vector3(-1.0f, 0, 1.0f));
m_quadPositions.append(UT_Vector3(1.0f, 0, -1.0f));
m_quadPositions.append(UT_Vector3(1.0f, 0, 1.0f));
UT_String shapelib_name = "path?shapelib";
GU_AgentShapeLibPtr shapelib = GU_AgentShapeLib::addLibrary(shapelib_name);
GU_DetailHandle skin_geo;
skin_geo.allocateAndSet(createSphere(false), /*own*/true);
shapelib->addShape("bg_", skin_geo);
}
I don't know if that even make sense for a Scene Hook to create such entities, I'd be glad if someone could clarify such things and sorry in advance, obviously I don't have much experience on this