53 using namespace HDK_Sample;
81 const int theNumPoints = 4;
82 const int theNumFaces = 4;
83 const int theNumVertices = theNumFaces * 3;
85 const int theFacePoints[theNumFaces][3] =
94 const uint32 theWireIndices[] =
100 const char *theWireColorName =
"WireCd";
104 const int theTriangleGroup = 0;
105 const int theWireGroup = 1;
106 const int thePointGroup = 2;
120 const char *myProgram;
121 const char *myDefines;
122 } theShaderInfo[] = {
123 {
"material/VK/psurf_headlight.prog",
nullptr},
124 {
"material/VK/psurf_material.prog",
nullptr},
125 {
"material/VK/psurf_const.prog",
nullptr},
126 {
"material/VK/psurf_wireframe.prog",
nullptr},
127 {
"pick/VK/object_pick.prog",
nullptr},
128 {
"material/VK/psurf_matte.prog",
nullptr},
129 {
"material/VK/psurf_depth.prog",
nullptr},
130 {
"material/VK/psurf_depth.prog",
"#define GEN_CASCADING"},
131 {
"material/VK/psurf_depth.prog",
"#define GEN_CUBEMAP"},
132 {
"material/VK/psurf_depth.prog",
133 "#define GEN_CASCADING\n#define GEN_ONE_SHADOWMAP"},
134 {
"material/VK/psurf_depth.prog",
135 "#define GEN_CUBEMAP\n#define GEN_ONE_SHADOWMAP"},
146 if (!theShaderLoaded[type])
150 theShaderLoaded[
type] =
true;
153 theShaderInfo[
type].myDefines);
155 return theShaders[
type];
194 mat = atlas.
get(0, dp);
203 if (m && m->checkCompatible(r, shader))
220 if (instances && instances->
entries() > 1)
222 const int num_inst = instances->
entries();
237 for (
int i = 0; i < num_inst; i++)
249 if (instances && instances->
entries() == 1)
250 prim_xform = prim_xform * (*instances)(0);
269 geo, connect_group, nullptr, instance_group)
270 , myUseLightMask(use_light_mask)
271 , myLightMask(light_mask)
293 :
GR_Primitive(info, cache_name, GA_PrimCompat::TypeMask(0))
300 int64 decor_mask = 0;
302 decor_mask |=
int64(1) << theDecorations[i];
317 if (geo_type == myID)
331 getGEOPrimFromGT<GEO_PrimTetra>(primh, tet);
346 myGeo = UTmakeUnique<RV_Geometry>();
348 myGeo->setNumPoints(theNumPoints);
349 myGeo->setVertexBufferSize(theNumVertices);
353 myGeo->createAttribute(
"pointID",
RV_GPU_INT32, 1, -1,
false);
359 myGeo->createVertexBuffer(
"PointIndex",
RV_GPU_INT32, 1, -1,
false);
360 myGeo->createVertexBuffer(
367 myGeo->connectSomeVerts(
369 myGeo->connectIndexedPrims(
374 if (!myGeo->populateBuffers(r))
380 const fpreal32 col[4] = {1.0, 1.0, 1.0, 1.0};
383 myGeo->getAttribute(
"Cd")->uploadData(r, col,
sizeof(col));
384 myGeo->getAttribute(
"Alpha")->uploadData(r, &alpha,
sizeof(alpha));
385 myGeo->getIndexBuffer(theWireGroup)->uploadData(r, theWireIndices);
395 if (primh->getPrimitiveTransform())
396 primh->getPrimitiveTransform()->getMatrix(prim_xform);
398 grUpdateInstances(r, myGeo.get(), prim_xform, p);
402 if (myGeo->getAttributeVersion(
"P", pos_version)
413 for (
int v = 0;
v < 4;
v++)
424 const UT_Vector3F center = (pt[0] + pt[1] + pt[2] + pt[3]) * 0.25
f;
426 int32 vtx_pt[theNumVertices];
428 for (
int f = 0;
f < theNumFaces;
f++)
430 int va = theFacePoints[
f][0];
431 int vb = theFacePoints[
f][1];
432 int vc = theFacePoints[
f][2];
438 if (
dot(n, a - center) > 0)
447 vtx_pt[
f * 3 + 1] = vb;
448 vtx_pt[
f * 3 + 2] = vc;
452 for (
int v = 0;
v < theNumPoints;
v++)
457 myGeo->getAttribute(
"P")->uploadData(r, pos);
458 myGeo->getAttribute(
"pointID")->uploadData(r, pt_num);
459 myGeo->getAttribute(
"N")->uploadData(r, nml);
460 myGeo->getAttribute(
"PointIndex")->uploadData(r, vtx_pt);
461 myGeo->getAttribute(
"polygonVertexIdx")->uploadData(r, vtx_pt);
500 drawWire(rc,
true, dp);
507 drawSurface(rc, grGetDepthShader(rc, render_mode), flags, dp);
524 drawWire(rc,
false, dp);
531 drawWire(rc,
false, dp);
537 drawWire(rc,
true, dp);
546 GR_PrimTetra::drawSurface(
548 ShaderType shader_type,
562 mat = grGetMaterial(r, shader, flags, dp);
587 if (!u->
prepareForDraw(r, myObjectSets[shader_type], mySurfaceBlock, shader)
588 || (mat && !mat->bind(r, shader, dp.
opts)))
615 r->
draw(UTmakeUnique<grLightMaskDrawTask>(
616 myGeo.get(), theTriangleGroup, instanced ? inst_group : -1,
617 use_light_mask, light_mask));
622 r->
draw(myGeo.get(), theTriangleGroup);
626 GR_PrimTetra::drawWire(
646 wire_color.
w() = 1.0f;
652 RV_Buffer *wire_cd = myGeo->createAllocatedAttribute(
661 overrides.
append(theWireColorName);
692 r->
draw(myGeo.get(), theWireGroup, &overrides);
706 int connect_group = theTriangleGroup;
713 connect_group = thePointGroup;
732 unsigned int pick_type,
void drawInstanced(RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr)
const GR_MaterialAtlas * vk_materials
UT_IntrusivePtr< GR_Material > GR_MaterialPtr
#define SYS_STATIC_ASSERT(expr)
#define UT_AT_SCOPE_EXIT(...)
RV_PushConstants & getPushConstants()
constexpr size_t size(const OIIO::span< T, E > &c)
const GR_MaterialPtr & getFactoryMaterial() const
GR_DecorationRender * myDecorRender
GU_ConstDetailHandle geometry
const GR_DisplayOption * opts
RE_CacheVersion geo_version
void setAlphaBlendFunction(RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor)
Set the blending weights for alpha only.
void draw(RV_Geometry *geo, int connect_index, const RV_OverrideList *override_list=nullptr)
Draw the geometry 'geo' with the given connectivity group.
GT_API const UT_StringHolder cache_name
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
GLboolean GLboolean GLboolean GLboolean a
static RV_ShaderProgram * loadShaderProgram(RV_Instance *inst, const char *program, const char *extra_defines=nullptr)
SYS_FORCE_INLINE const GA_PrimitiveTypeId & getTypeId() const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
RE_CacheVersion instance_version
void setConstInstanceGroupTransform(int instance_group, const UT_Matrix4F &xform, bool remove_instanced_xform)
bool getMultiview() const
Temporary container for either a RV_Render and an RE_Render.
void setBlendEnable(bool blend)
Enable framebuffer blending.
const char * getCacheName() const
The base GL cache name assigned to this primitive.
set of parameters sent to GR_Primitive::update()
bool hasSet(int set_num) const
Query if set 'set_num' is used by the shader.
void drawDecorationForGeo(RE_RenderContext r, RV_Geometry *geo, GR_Decoration dec, const GR_DisplayOption *opts, GR_DecorRenderFlags flags, bool overlay, bool override_vis, int instance_group, GR_SelectMode smode, GR_DecorationRender::PrimitiveType t=GR_DecorationRender::PRIM_TRIANGLE, RE_OverrideList *override_list=NULL)
GR_PrimAcceptResult acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle &ph, const GEO_Primitive *prim) override
bool populateBuffers(RV_Render *r)
Populates all RV_Buffers declared above which haven't been populated yet.
GLint GLint GLsizei GLint GLenum GLenum type
void popPipeState()
Restore the pipeline state from a previous pushPipeState().
~GR_PrimTetraHook() override
const GR_DisplayOption & dopts
GR_CommonDispOption & common()
GR_DecorRenderFlags render_flags
const GR_DisplayOption * opts
void renderDecoration(RE_RenderContext r, GR_Decoration decor, const GR_DecorationParms &p) override
void setSupportedDecorations(int64 mask)
int renderPick(RE_RenderContext r, const GR_DisplayOption *opt, unsigned int pick_type, GR_PickStyle pick_style, bool has_pick_map) override
void setShader(RV_ShaderProgramBase *sh)
Set the current shader to 'sh'.
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
UT_Matrix4T< fpreal32 > UT_Matrix4F
GLfloat GLfloat GLfloat alpha
bool bindInt(const UT_StringRef &name, int v, int array_index=0, int *opt_idx=nullptr)
SYS_FORCE_INLINE int get() const
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
void render(RE_RenderContext r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp) override
bool getInstanceAttribVersion(int instance_group, const UT_StringHolder &name, RE_CacheVersion &out_ver) const
Fetch the per-instance attribute version (to avoid refilling)
RV_Instance * instance()
The instance associated with this render.
exint entries() const
Alias of size(). size() is preferred.
SYS_FORCE_INLINE GA_Index pointIndex(GA_Offset offset) const
Given a point's data offset, return its index.
bool setInstanceGroupAttrib(int instance_group, const UT_StringHolder &name, RV_GPUType data_type, int vector_size, int instance_step, int num_instances, exint capacity=-1, bool normalized=true)
Create an per-instance attribute Reserve an buffer for per-instance data (call populateBuffers() to c...
SYS_FORCE_INLINE GA_Index getMapIndex() const
Gets the index of this primitive in the detail containing it.
RV_Buffer * getInstanceGroupAttrib(int instance_group, const UT_StringHolder &name) const
Fetch the buffer backing an per-instance attribute, usually to fill it.
ShaderType
The builtin shader programs used to draw the tetra.
UT_Vector4T< fpreal32 > UT_Vector4F
RV_Framebuffer * getDrawFramebuffer()
Get the current framebuffer (may be null)
bool runDraw(RV_Render *r) override
void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p) override
void setDepthState(bool enable, RE_ZFunction func=RE_ZLESS, bool writing=true, float near=0.0, float far=1.0, bool clamp=false)
Set the depth state for zbuffer operations.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
GR_Primitive * createPrimitive(const GT_PrimitiveHandle >_prim, const GEO_Primitive *geo_prim, const GR_RenderInfo *info, const char *cache_name, GR_PrimAcceptResult &processed) override
constexpr SYS_FORCE_INLINE T & w() noexcept
bool uploadData(RV_Render *r, VkBufferUsageFlags new_usage, const void *data, exint data_size, exint data_offset=0)
Upload data to the buffer Upload data to the buffer and add a barrier based on its usage...
bool freeInstanceGroupAttrib(int instance_group, const UT_StringHolder &name)
Remove per-instance attribute and free its resource.
GR_DecorationOverride required_dec
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
void setInstanceAttribVersion(int instance_group, const UT_StringHolder &name, const RE_CacheVersion &ver)
Set the per-instance attribute version (to avoid refilling)
GR_PrimTetra(const GR_RenderInfo *info, const char *cache_name, const GEO_Primitive *prim)
Simple class for a mutli-integer cache tag.
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
void setupFromDisplayOptions(const GR_DisplayOption &opts, GR_DecorationOverride select_dec, GR_UpdateParms &parms, const GR_Decoration *supported, GR_AttribMask mask)
const GR_MaterialPtr & getDefaultMaterial() const
void setBlendFunction(RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor)
Set the blending weights for color and alpha.
GR_MaterialPtr get(int material_id) const
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
const GU_Detail * getGdp() const
const UT_Matrix4DArray * instances