Skip to content

Commit

Permalink
[HdSt] Added functions to interpolate patch coord w/o GS
Browse files Browse the repository at this point in the history
Added methods to compute interpolated PatchCoords for triangles
and quads when there is no geometry shader. These are similar to
the method recently added for triangulated quads.

This allows some additional cleanup of interstage plumbing.

(Internal change: 2200684)
  • Loading branch information
davidgyu authored and lkerley committed Jan 7, 2022
1 parent 65dad80 commit a02e484
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
8 changes: 7 additions & 1 deletion pxr/imaging/hdSt/meshShaderKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ TF_DEFINE_PRIVATE_TOKENS(
((mainTriQuadGS, "Mesh.Geometry.TriQuad"))
((mainQuadGS, "Mesh.Geometry.Quad"))
((mainPatchCoordFS, "Mesh.Fragment.PatchCoord"))
((mainPatchCoordTriangleFS,"Mesh.Fragment.PatchCoord.Triangle"))
((mainPatchCoordQuadFS, "Mesh.Fragment.PatchCoord.Quad"))
((mainPatchCoordTriQuadFS, "Mesh.Fragment.PatchCoord.TriQuad"))
((mainFS, "Mesh.Fragment"))

Expand Down Expand Up @@ -462,7 +464,11 @@ HdSt_MeshShaderKey::HdSt_MeshShaderKey(
_tokens->pointIdFallbackFS;
FS[fsIndex++] = hasTopologicalVisibility? _tokens->topVisFS :
_tokens->topVisFallbackFS;
if (isPrimTypeTriQuads) {
if (isPrimTypeTris && !gsStageEnabled) {
FS[fsIndex++] = _tokens->mainPatchCoordTriangleFS;
} else if (isPrimTypeQuads && !gsStageEnabled) {
FS[fsIndex++] = _tokens->mainPatchCoordQuadFS;
} else if (isPrimTypeTriQuads) {
FS[fsIndex++] = _tokens->mainPatchCoordTriQuadFS;
} else {
FS[fsIndex++] = _tokens->mainPatchCoordFS;
Expand Down
42 changes: 33 additions & 9 deletions pxr/imaging/hdSt/shaders/mesh.glslfx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ out VertexData
vec3 Neye;
} outData;

out vec4 gsPatchCoord;

// Fwd declare methods defined in pointId.glslfx, that are used below.
int GetPointId();
float GetPointRasterSize(int);
Expand All @@ -62,12 +60,6 @@ void main(void)

outData.Neye = GetNormal(vec3(0), 0); // normalized

// Fill out redundantly, since at this point we don't know
// the following stages include tessellation or geometry shader.
// we rely on that compiler (linker) optimizes out these redundant
// assignment and attribute plumbing.
gsPatchCoord = vec4(0);

int pointId = GetPointId();
gl_PointSize = GetPointRasterSize(pointId);
ProcessPointId(pointId);
Expand Down Expand Up @@ -316,7 +308,6 @@ out VertexData

out vec4 gsPatchCoord;


vec4 GetPatchCoord(int index)
{
return tesPatchCoord[index];
Expand Down Expand Up @@ -710,6 +701,39 @@ vec4 GetInterpolatedPatchCoord()
return gsPatchCoord;
}

--- --------------------------------------------------------------------------
-- glsl Mesh.Fragment.PatchCoord.Triangle

vec3 GetBarycentricCoord(); // codeGen

vec2 GetPatchCoordLocalST()
{
vec3 barycentric = GetBarycentricCoord();
return barycentric.yz;
}

vec4 GetInterpolatedPatchCoord()
{
return OsdInterpolatePatchCoordTriangle(
GetPatchCoordLocalST(), GetPatchParam());
}

--- --------------------------------------------------------------------------
-- glsl Mesh.Fragment.PatchCoord.Quad

vec3 GetBarycentricCoord(); // codeGen

vec2 GetPatchCoordLocalST()
{
vec3 barycentric = GetBarycentricCoord();
return barycentric.yz;
}

vec4 GetInterpolatedPatchCoord()
{
return OsdInterpolatePatchCoord(GetPatchCoordLocalST(), GetPatchParam());
}

--- --------------------------------------------------------------------------
-- glsl Mesh.Fragment.PatchCoord.TriQuad

Expand Down

0 comments on commit a02e484

Please sign in to comment.