Skip to content

Commit

Permalink
Merge pull request #1863 from marktucker/dev_opacity_primvar_fix
Browse files Browse the repository at this point in the history
Fix Storm code generation from USD PreviewSurface for GLSL bindings to primvars

(Internal change: 2237301)
  • Loading branch information
pixar-oss committed Jun 13, 2022
2 parents e6b3d02 + 65c838a commit 25e029e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pxr/imaging/hdSt/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5579,6 +5579,17 @@ HdSt_CodeGen::_GenerateShaderParameters(bool bindlessTextureEnabled)
<< "\n}\n"
<< "#define HD_HAS_" << it->second.name << " 1\n";

// Emit scalar accessors to support shading languages like MSL which
// do not support swizzle operators on scalar values.
if (_GetNumComponents(it->second.dataType) <= 4) {
accessors
<< _GetFlatType(it->second.dataType) << " HdGetScalar_"
<< it->second.name << "()"
<< " { return HdGet_" << it->second.name << "()"
<< _GetFlatTypeSwizzleString(it->second.dataType)
<< "; }\n";
}

if (it->second.name == it->second.inPrimvars[0]) {
accessors
<< "#endif\n";
Expand Down
14 changes: 14 additions & 0 deletions pxr/usdImaging/usdImagingGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,20 @@ pxr_register_test(testUsdImagingGLPreviewSurface_Primvars
)


pxr_register_test(testUsdImagingGLPreviewSurface_PrimvarReaderOpacity
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdImagingGLBasicDrawing -offscreen -lighting -shading smooth -frameAll -stage testPreviewSurfacePrimvarReaderOpacity.usda -write testPreviewSurfacePrimvarReaderOpacity.png"
IMAGE_DIFF_COMPARE
testPreviewSurfacePrimvarReaderOpacity.png
FAIL 0.05
FAIL_PERCENT 0.001
PERCEPTUAL
EXPECTED_RETURN_CODE 0
TESTENV testUsdImagingGLPreviewSurface
ENV
HGIGL_ENABLE_BINDLESS_TEXTURE=1
)


pxr_register_test(testUsdImagingGLPreviewSurface_Specular
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdImagingGLBasicDrawing -offscreen -lighting -shading smooth -frameAll -stage testPreviewSurfaceSpecular.usda -write testPreviewSurfaceSpecular.png"
IMAGE_DIFF_COMPARE
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
endTimeCode = 1
framesPerSecond = 24
metersPerUnit = 1
startTimeCode = 1
timeCodesPerSecond = 24
upAxis = "Y"
)

def Xform "torus1" (
kind = "component"
)
{
matrix4d xformOp:transform:xform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform:xform"]

def Mesh "mesh_0" (
apiSchemas = ["MaterialBindingAPI"]
)
{
float3[] extent = [(-0.7047695, -0.21650636, -0.7386058), (0.75, 0.21650644, 0.73860586)]
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
int[] faceVertexIndices = [0, 1, 10, 9, 1, 2, 11, 10, 2, 3, 12, 11, 3, 4, 13, 12, 4, 5, 14, 13, 5, 6, 15, 14, 6, 7, 16, 15, 7, 8, 17, 16, 8, 0, 9, 17, 9, 10, 19, 18, 10, 11, 20, 19, 11, 12, 21, 20, 12, 13, 22, 21, 13, 14, 23, 22, 14, 15, 24, 23, 15, 16, 25, 24, 16, 17, 26, 25, 17, 9, 18, 26, 18, 19, 28, 27, 19, 20, 29, 28, 20, 21, 30, 29, 21, 22, 31, 30, 22, 23, 32, 31, 23, 24, 33, 32, 24, 25, 34, 33, 25, 26, 35, 34, 26, 18, 27, 35, 27, 28, 37, 36, 28, 29, 38, 37, 29, 30, 39, 38, 30, 31, 40, 39, 31, 32, 41, 40, 32, 33, 42, 41, 33, 34, 43, 42, 34, 35, 44, 43, 35, 27, 36, 44, 36, 37, 46, 45, 37, 38, 47, 46, 38, 39, 48, 47, 39, 40, 49, 48, 40, 41, 50, 49, 41, 42, 51, 50, 42, 43, 52, 51, 43, 44, 53, 52, 44, 36, 45, 53, 45, 46, 1, 0, 46, 47, 2, 1, 47, 48, 3, 2, 48, 49, 4, 3, 49, 50, 5, 4, 50, 51, 6, 5, 51, 52, 7, 6, 52, 53, 8, 7, 53, 45, 0, 8]
rel material:binding = </materials/usdpreviewsurface1>
uniform token orientation = "leftHanded"
point3f[] points = [(0.75, -2.1855694e-8, -2.2649371e-7), (0.5745332, -2.1855694e-8, -0.48209083), (0.13023612, -2.1855694e-8, -0.7386058), (-0.37499994, -2.1855694e-8, -0.6495191), (-0.70476943, -2.1855694e-8, -0.2565153), (-0.7047695, -2.1855694e-8, 0.256515), (-0.37500006, -2.1855694e-8, 0.649519), (0.13023607, -2.1855694e-8, 0.73860586), (0.57453334, -2.1855694e-8, 0.4820907), (0.625, -0.21650636, -1.8874475e-7), (0.4787777, -0.21650636, -0.40174234), (0.10853009, -0.21650636, -0.61550486), (-0.31249994, -0.21650636, -0.5412659), (-0.5873079, -0.21650636, -0.21376275), (-0.58730793, -0.21650636, 0.2137625), (-0.31250003, -0.21650636, 0.54126585), (0.10853007, -0.21650636, 0.61550486), (0.47877777, -0.21650636, 0.40174228), (0.37500003, -0.21650636, -1.1324686e-7), (0.28726664, -0.21650636, -0.24104543), (0.06511806, -0.21650636, -0.36930293), (-0.18749999, -0.21650636, -0.32475957), (-0.35238475, -0.21650636, -0.12825766), (-0.35238478, -0.21650636, 0.12825751), (-0.18750004, -0.21650636, 0.32475954), (0.065118045, -0.21650636, 0.36930296), (0.2872667, -0.21650636, 0.24104539), (0.25, -7.54979e-8, -7.54979e-8), (0.19151108, -7.54979e-8, -0.16069694), (0.043412037, -7.54979e-8, -0.24620193), (-0.12499998, -7.54979e-8, -0.21650636), (-0.23492314, -7.54979e-8, -0.0855051), (-0.23492317, -7.54979e-8, 0.085505), (-0.12500001, -7.54979e-8, 0.21650635), (0.043412026, -7.54979e-8, 0.24620195), (0.19151111, -7.54979e-8, 0.16069691), (0.37499988, 0.21650629, -1.1324681e-7), (0.28726652, 0.21650629, -0.24104533), (0.06511804, 0.21650629, -0.36930278), (-0.18749991, 0.21650629, -0.32475945), (-0.3523846, 0.21650629, -0.1282576), (-0.35238463, 0.21650629, 0.12825747), (-0.18749996, 0.21650629, 0.32475942), (0.065118015, 0.21650629, 0.3693028), (0.28726658, 0.21650629, 0.24104528), (0.6249998, 0.21650644, -1.8874469e-7), (0.47877756, 0.21650644, -0.40174222), (0.10853006, 0.21650644, -0.6155047), (-0.31249985, 0.21650644, -0.5412657), (-0.5873077, 0.21650644, -0.21376269), (-0.58730775, 0.21650644, 0.21376245), (-0.31249994, 0.21650644, 0.5412657), (0.10853004, 0.21650644, 0.6155047), (0.47877765, 0.21650644, 0.40174216)] (
interpolation = "vertex"
)
float[] primvars:displayOpacity = [0.4172318, 0.0029251575, 0.8134322, 0.26238048, 0.0022482872, 0.18949378, 0.11619651, 0.6177759, 0.9162111, 0.5199168, 0.09368181, 0.11982691, 0.9744946, 0.9223701, 0.1491077, 0.0862304, 0.80475235, 0.86910784, 0.8762624, 0.024951339, 0.74814475, 0.3745625, 0.16958499, 0.35533643, 0.67235017, 0.9425061, 0.60025203, 0.39106798, 0.8550682, 0.05255854, 0.9929136, 0.722306, 0.95017123, 0.93023956, 0.5721128, 0.9952482, 0.21738088, 0.93819416, 0.33784437, 0.9948045, 0.28117776, 0.21284902, 0.79645276, 0.3431281, 0.582495, 0.86238384, 0.8141068, 0.16465974, 0.6494167, 0.39164162, 0.3589337, 0.30209255, 0.9353763, 0.9642974] (
interpolation = "uniform"
)
int[] primvars:displayOpacity:indices = None
uniform token subdivisionScheme = "none"
}
}

def Scope "materials"
{
def Material "usdpreviewsurface1"
{
token outputs:displacement.connect = </materials/usdpreviewsurface1/usdpreviewsurface1.outputs:displacement>
token outputs:surface.connect = </materials/usdpreviewsurface1/usdpreviewsurface1.outputs:surface>

def Shader "usdpreviewsurface1"
{
uniform token info:id = "UsdPreviewSurface"
color3f inputs:diffuseColor = (0.075, 0.3, 0.075)
float inputs:opacity.connect = </materials/usdpreviewsurface1/usdprimvarreader1.outputs:result>
token outputs:displacement
token outputs:surface
}

def Shader "usdprimvarreader1"
{
uniform token info:id = "UsdPrimvarReader_float"
float inputs:fallback = 1
string inputs:varname = "displayOpacity"
float outputs:result
}
}
}

0 comments on commit 25e029e

Please sign in to comment.