diff --git a/pxr/imaging/hdSt/codeGen.cpp b/pxr/imaging/hdSt/codeGen.cpp index 1cc389cb59..2315412537 100644 --- a/pxr/imaging/hdSt/codeGen.cpp +++ b/pxr/imaging/hdSt/codeGen.cpp @@ -2678,38 +2678,60 @@ HdSt_CodeGen::_GenerateShaderParameters() HdBinding::Type bindingType = it->first.GetType(); if (bindingType == HdBinding::FALLBACK) { + // vec4 HdGet_name(int localIndex) accessors << _GetUnpackedType(it->second.dataType, false) - << " HdGet_" << it->second.name << "() {\n" + << " HdGet_" << it->second.name << "(int localIndex) {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" << " return " << _GetPackedTypeAccessor(it->second.dataType, false) << "(shaderData[shaderCoord]." << it->second.name << swizzle << ");\n" << "}\n"; + + // vec4 HdGet_name() + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name + << "() { return HdGet_" << it->second.name << "(0); }\n"; + } else if (bindingType == HdBinding::BINDLESS_TEXTURE_2D) { - // a function returning sampler2D is allowed in 430 or later - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler2D\n" << "HdGetSampler_" << it->second.name << "() {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" << " return sampler2D(shaderData[shaderCoord]." << it->second.name << ");\n" - << " }\n"; + << "}\n"; } + + // vec4 HdGet_name(vec2 coord) + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name << "(vec2 coord) {\n" + << " int shaderCoord = GetDrawingCoord().shaderCoord;\n" + << " return " + << _GetPackedTypeAccessor(it->second.dataType, false) + << "(texture(sampler2D(shaderData[shaderCoord]." + << it->second.name << "), coord)" << swizzle + << ");\n}\n"; + + // vec4 HdGet_name(int localIndex) accessors << _GetUnpackedType(it->second.dataType, false) - << " HdGet_" << it->second.name << "() {\n" + << " HdGet_" << it->second.name << "(int localIndex) {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" << " return " << _GetPackedTypeAccessor(it->second.dataType, false) << "(" - << "texture(sampler2D(shaderData[shaderCoord]." << it->second.name << "), "; - + << "texture(sampler2D(shaderData[shaderCoord]." + << it->second.name << "), "; if (!it->second.inPrimvars.empty()) { accessors << "\n" << "#if defined(HD_HAS_" << it->second.inPrimvars[0] << ")\n" - << " HdGet_" << it->second.inPrimvars[0] << "().xy\n" + << " HdGet_" << it->second.inPrimvars[0] + << "(localIndex).xy\n" << "#else\n" << "vec2(0.0, 0.0)\n" << "#endif\n"; @@ -2721,36 +2743,49 @@ HdSt_CodeGen::_GenerateShaderParameters() accessors << ")" << swizzle << ");\n" << "}\n"; + + // vec4 HdGet_name() + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name + << "() { return HdGet_" << it->second.name << "(0); }\n"; + } else if (bindingType == HdBinding::TEXTURE_2D) { declarations << LayoutQualifier(it->first) << "uniform sampler2D sampler2d_" << it->second.name << ";\n"; - // a function returning sampler2D is allowed in 430 or later - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler2D\n" << "HdGetSampler_" << it->second.name << "() {\n" << " return sampler2d_" << it->second.name << ";" << "}\n"; + } else { + accessors + << "#define HdGetSampler_" << it->second.name << "()" + << " sampler2d_" << it->second.name << "\n"; } - // vec4 HdGet_name(vec2 coord) { return texture(sampler2d_name, coord).xyz; } + + // vec4 HdGet_name(vec2 coord) accessors << _GetUnpackedType(it->second.dataType, false) - << " HdGet_" << it->second.name - << "(vec2 coord) { return " + << " HdGet_" << it->second.name << "(vec2 coord) { return " << _GetPackedTypeAccessor(it->second.dataType, false) << "(texture(sampler2d_" << it->second.name << ", coord)" << swizzle << ");}\n"; - // vec4 HdGet_name() { return HdGet_name(HdGet_st().xy); } + + // vec4 HdGet_name(int localIndex) accessors << _GetUnpackedType(it->second.dataType, false) << " HdGet_" << it->second.name - << "() { return HdGet_" << it->second.name << "("; + << "(int localIndex) { return HdGet_" << it->second.name << "("; if (!it->second.inPrimvars.empty()) { accessors << "\n" << "#if defined(HD_HAS_" << it->second.inPrimvars[0] << ")\n" - << "HdGet_" << it->second.inPrimvars[0] << "().xy\n" + << "HdGet_" << it->second.inPrimvars[0] + << "(localIndex).xy\n" << "#else\n" << "vec2(0.0, 0.0)\n" << "#endif\n"; @@ -2759,19 +2794,39 @@ HdSt_CodeGen::_GenerateShaderParameters() << "vec2(0.0, 0.0)"; } accessors << "); }\n"; + + // vec4 HdGet_name() + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name + << "() { return HdGet_" << it->second.name << "(0); }\n"; + } else if (bindingType == HdBinding::BINDLESS_TEXTURE_3D) { - // a function returning sampler3D is allowed in 430 or later - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler3D\n" << "HdGetSampler_" << it->second.name << "() {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" << " return sampler3D(shaderData[shaderCoord]." << it->second.name << ");\n" - << " }\n"; + << "}\n"; } + + // vec4 HdGet_name(vec3 coord) + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name << "(vec3 coord) { \n" + << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" + << " return " + << _GetPackedTypeAccessor(it->second.dataType, false) << "(" + << "texture(sampler3D(shaderData[shaderCoord]." + << it->second.name << "), coord)" + << swizzle << ");\n}\n"; + + // vec4 HdGet_name(int localIndex) accessors << _GetUnpackedType(it->second.dataType, false) - << " HdGet_" << it->second.name << "() {\n" + << " HdGet_" << it->second.name << "(int localIndex) {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord; \n" << " return " << _GetPackedTypeAccessor(it->second.dataType, false) << "(" @@ -2781,7 +2836,8 @@ HdSt_CodeGen::_GenerateShaderParameters() accessors << "\n" << "#if defined(HD_HAS_" << it->second.inPrimvars[0] << ")\n" - << " HdGet_" << it->second.inPrimvars[0] << "().xyz\n" + << " HdGet_" << it->second.inPrimvars[0] + << "(localIndex).xyz\n" << "#else\n" << "vec3(0.0, 0.0, 0.0)\n" << "#endif\n"; @@ -2793,36 +2849,49 @@ HdSt_CodeGen::_GenerateShaderParameters() accessors << ")" << swizzle << ");\n" << "}\n"; + + // vec4 HdGet_name() + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name + << "() { return HdGet_" << it->second.name << "(0); }\n"; + } else if (bindingType == HdBinding::TEXTURE_3D) { declarations << LayoutQualifier(it->first) << "uniform sampler3D sampler3d_" << it->second.name << ";\n"; - // a function returning sampler3D is allowed in 430 or later - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler3D\n" << "HdGetSampler_" << it->second.name << "() {\n" << " return sampler3d_" << it->second.name << ";" << "}\n"; + } else { + accessors + << "#define HdGetSampler_" << it->second.name << "()" + << " sampler3d_" << it->second.name << "\n"; } - // vec4 HdGet_name(vec3 coord) { return texture(sampler3d_name, coord).xyz; } + + // vec4 HdGet_name(vec3 coord) accessors << _GetUnpackedType(it->second.dataType, false) - << " HdGet_" << it->second.name - << "(vec3 coord) { return " + << " HdGet_" << it->second.name << "(vec3 coord) { return " << _GetPackedTypeAccessor(it->second.dataType, false) << "(texture(sampler3d_" << it->second.name << ", coord)" << swizzle << ");}\n"; - // vec4 HdGet_name() { return HdGet_name(HdGet_st().xyz); } + + // vec4 HdGet_name(int localIndex) accessors << _GetUnpackedType(it->second.dataType, false) << " HdGet_" << it->second.name - << "() { return HdGet_" << it->second.name << "("; + << "(int localIndex) { return HdGet_" << it->second.name << "("; if (!it->second.inPrimvars.empty()) { accessors << "\n" << "#if defined(HD_HAS_" << it->second.inPrimvars[0] << ")\n" - << "HdGet_" << it->second.inPrimvars[0] << "().xyz\n" + << "HdGet_" << it->second.inPrimvars[0] + << "(localIndex).xyz\n" << "#else\n" << "vec3(0.0, 0.0, 0.0)\n" << "#endif\n"; @@ -2830,10 +2899,17 @@ HdSt_CodeGen::_GenerateShaderParameters() accessors << "vec3(0.0, 0.0, 0.0)"; } - accessors << "); }\n"; + accessors << ");\n}\n"; + + // vec4 HdGet_name() + accessors + << _GetUnpackedType(it->second.dataType, false) + << " HdGet_" << it->second.name + << "() { return HdGet_" << it->second.name << "(0); }\n"; + } else if (bindingType == HdBinding::BINDLESS_TEXTURE_UDIM_ARRAY) { - // a function returning sampler2DArray is allowed in 430 or later - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler2DArray\n" << "HdGetSampler_" << it->second.name << "() {\n" @@ -2846,7 +2922,6 @@ HdSt_CodeGen::_GenerateShaderParameters() << it->second.dataType << " HdGet_" << it->second.name << "()" << " {\n" << " int shaderCoord = GetDrawingCoord().shaderCoord;\n"; - if (!it->second.inPrimvars.empty()) { accessors << "#if defined(HD_HAS_" @@ -2873,12 +2948,17 @@ HdSt_CodeGen::_GenerateShaderParameters() << "uniform sampler2DArray sampler2dArray_" << it->second.name << ";\n"; - if (caps.glslVersion >= 430) { + // a function returning sampler requires bindless_texture + if (caps.bindlessTextureEnabled) { accessors << "sampler2DArray\n" << "HdGetSampler_" << it->second.name << "() {\n" << " return sampler2dArray_" << it->second.name << ";" << "}\n"; + } else { + accessors + << "#define HdGetSampler_" << it->second.name << "()" + << " sampler2dArray_" << it->second.name << "\n"; } // vec4 HdGet_name(vec2 coord) { vec3 c = hd_sample_udim(coord); // c.z = texelFetch(sampler1d_name_layout, int(c.z), 0).x - 1; diff --git a/pxr/usdImaging/plugin/usdShaders/shaders/previewSurface.glslfx b/pxr/usdImaging/plugin/usdShaders/shaders/previewSurface.glslfx index 6140f4a81d..502d415b3c 100644 --- a/pxr/usdImaging/plugin/usdShaders/shaders/previewSurface.glslfx +++ b/pxr/usdImaging/plugin/usdShaders/shaders/previewSurface.glslfx @@ -48,7 +48,7 @@ vec4 displacementShader(int index, vec4 Peye, vec3 Neye, vec4 patchCoord) { // Calculate scalar displacement. - float texDisplacement = HdGet_displacement().x; + float texDisplacement = HdGet_displacement(index).x; return Peye + vec4(Neye*texDisplacement, 0); }