Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into debloip/HYDRA-1098/viewport-filters-hydra-data
Browse files Browse the repository at this point in the history
debloip-adsk committed Dec 16, 2024
2 parents a37d7c8 + 46a733f commit 5a24bca
Showing 79 changed files with 1,351 additions and 208 deletions.
10 changes: 10 additions & 0 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
# MAYA_HAS_DISPLAY_LAYER_API Presence of MFnDisplayLayer
# MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API Presence of MDisplayLayerMemberChangedFunction
# MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API Presence of MRenderItem has HideOnPlayback API
# MAYA_HAS_RENDER_ITEM_CULL_MODE_API Presence of MRenderItem has CullMode API
# MAYA_HAS_VIEW_SELECTED_OBJECT_API Presence of M3dView::viewSelectedObject
# MAYA_LINUX_BUILT_WITH_CXX11_ABI Maya Linux was built with new cxx11 ABI.
# MAYA_MACOSX_BUILT_WITH_UB2 Maya OSX was built with Universal Binary 2.
@@ -404,6 +405,15 @@ if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
endif()
endif()

set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API FALSE CACHE INTERNAL "hasRenderItemCullModeFunction")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h MAYA_HAS_API REGEX "cullMode")
if(MAYA_HAS_API)
set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API TRUE CACHE INTERNAL "hasRenderItemCullModeFunction")
message(STATUS "MRenderItem has CullMode API")
endif()
endif()

set(MAYA_HAS_VIEW_SELECTED_OBJECT_API FALSE CACHE INTERNAL "hasViewSelectedObject")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/M3dView.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/M3dView.h MAYA_HAS_API REGEX "numViewSelectedObjects")
17 changes: 0 additions & 17 deletions cmake/modules/FindUSD.cmake
Original file line number Diff line number Diff line change
@@ -107,23 +107,6 @@ find_library(USD_LIBRARY

get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)

# Get the boost version from the one built with USD
if(USD_INCLUDE_DIR)
file(GLOB _USD_VERSION_HPP_FILE "${USD_INCLUDE_DIR}/boost-*/boost/version.hpp")
list(LENGTH _USD_VERSION_HPP_FILE found_one)
if(${found_one} STREQUAL "1")
list(GET _USD_VERSION_HPP_FILE 0 USD_VERSION_HPP)
file(STRINGS
"${USD_VERSION_HPP}"
_usd_tmp
REGEX "#define BOOST_VERSION .*$")
string(REGEX MATCH "[0-9]+" USD_BOOST_VERSION ${_usd_tmp})
unset(_usd_tmp)
unset(_USD_VERSION_HPP_FILE)
unset(USD_VERSION_HPP)
endif()
endif()

# See if MaterialX shaders with color4 inputs exist natively in Sdr:
# Not yet in a tagged USD version: https://github.com/PixarAnimationStudios/USD/pull/1894
set(USD_HAS_COLOR4_SDR_SUPPORT FALSE CACHE INTERNAL "USD.Sdr.PropertyTypes.Color4")
2 changes: 2 additions & 0 deletions cmake/test.cmake
Original file line number Diff line number Diff line change
@@ -313,6 +313,8 @@ finally:
"${CMAKE_INSTALL_PREFIX}/lib/usd")
list(APPEND MAYAUSD_VARNAME_MAYA_PLUG_IN_PATH
"${CMAKE_INSTALL_PREFIX}/lib/maya")
list(APPEND MAYAUSD_VARNAME_MAYA_SCRIPT_PATH
"${CMAKE_INSTALL_PREFIX}/scripts")

# mayaUsdPlugin
if(DEFINED MAYAUSD_LOCATION)
7 changes: 5 additions & 2 deletions lib/flowViewport/sceneIndex/fvpBBoxSceneIndex.cpp
Original file line number Diff line number Diff line change
@@ -158,6 +158,7 @@ namespace
///
class _BoundsPointsPrimvarValueDataSource final : public HdVec3fArrayDataSource
{
inline static const GfVec3f _floatMaxVec3f {FLT_MAX};
public:
HD_DECLARE_DATASOURCE(_BoundsPointsPrimvarValueDataSource);

@@ -170,16 +171,18 @@ namespace
HdExtentSchema extentSchema =
HdExtentSchema::GetFromParent(_primSource);

// Note: If the scene description doesn't provide the extents, Storm uses
// the default constructed GfRange3d which is [FLT_MAX, -FLT_MAX],
GfVec3f exts[2] = { GfVec3f(0.0f), GfVec3f(0.0f) };
bool extentMinFound = false;
if (HdVec3dDataSourceHandle src = extentSchema.GetMin()) {
exts[0] = GfVec3f(src->GetTypedValue(shutterOffset));
extentMinFound = true;
extentMinFound = (exts[0] != _floatMaxVec3f);
}
bool extentMaxFound = false;
if (HdVec3dDataSourceHandle src = extentSchema.GetMax()) {
exts[1] = GfVec3f(src->GetTypedValue(shutterOffset));
extentMaxFound = true;
extentMaxFound = (exts[1] != -_floatMaxVec3f);
}

if (!extentMinFound || !extentMaxFound) {
Original file line number Diff line number Diff line change
@@ -333,6 +333,11 @@ WireframeSelectionHighlightSceneIndex(
TF_AXIOM(_wireframeColorInterface);

auto operation = [this](const SdfPath& primPath, const HdSceneIndexPrim& prim) -> bool {

if (_IsExcluded(primPath)) {
return true;
}

if (prim.primType == HdPrimTypeTokens->instancer) {
_CreateSelectionHighlightsForInstancer(prim, primPath);
}
@@ -682,6 +687,11 @@ WireframeSelectionHighlightSceneIndex::_PrimsAdded(

_SendPrimsAdded(entries);
for (const auto& entry : entries) {

if (_IsExcluded(entry.primPath)) {
continue;
}

HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(entry.primPath);
if (prim.primType == HdPrimTypeTokens->instancer) {
_CreateSelectionHighlightsForInstancer(prim, entry.primPath);
31 changes: 31 additions & 0 deletions lib/flowViewport/usdPlugins/shadersDiscoveryPlugin/README
Original file line number Diff line number Diff line change
@@ -3,3 +3,34 @@ The shaders defined in shadersDef.usda will be loaded by usd/hydra and available

You can add the plugInfo.json file path in the environment variable PXR_PLUGINPATH_NAME or use another .json file to load it
so USD/Hydra loads it at startup.

To use the FVP_CustomBasicLightingShader GLSLFX shader into a usd file, just add this definition to your file :

def Scope "mtl"
{
def Material "CustomGLSL"
{
token outputs:surface.connect = </mtl/CustomGLSL/CustomGLSLShader1.outputs:surface>

def Shader "CustomGLSLShader1"
{
uniform token info:id = "FVP_CustomBasicLightingShader"
token outputs:surface
}
}
}

You can also assign the material binding to a prim directly by adding :

def Mesh "Mesh1" (
prepend apiSchemas = ["MaterialBindingAPI"]
)
{
uniform bool doubleSided = 1
float3[] extent = [(-1.0000002, -1, -1.0000005), (1, 1, 1.0000001)]
int[] faceVertexCounts = ...
int[] faceVertexIndices = ...
rel material:binding = </mtl/CustomGLSL>
point3f[] points = ...
...
}
Original file line number Diff line number Diff line change
@@ -70,49 +70,189 @@ BasicLightingCoeffs computeLightingCoefficients(vec3 L, vec3 N, vec3 V, float ex
return coeffs;
}

//To support dome lights
struct LightingContributions
{
vec3 diffuse;
vec3 specular;
};

mat4 GetDomeLightTransform(mat4 worldToLightTransform)
{
// transform from view space to light space
mat4 worldToViewInverse = GetWorldToViewInverseMatrix();
return worldToLightTransform * worldToViewInverse;
}

#define PI 3.1415
vec2 ProjectToLatLong(vec3 sample3D)
{
// project spherical coord onto latitude-longitude map with
// latitude: +y == pi/2 and longitude: +z == 0, +x == pi/2
float x = (atan(sample3D.z, sample3D.x) + 0.5 * PI) / (2.0 * PI);
float y = acos(sample3D.y) / PI;

return vec2(x,y);
}

LightingContributions
evaluateIndirectLighting(
vec3 diffuseColor,
vec3 specularColor,
vec3 Neye,
vec3 Reye,
float NdotE,
float EdotH,
float ior,
float metallic,
float occlusion,
float roughness,
bool useSpecularWorkflow,
float clearcoatAmount,
vec3 clearcoatColor,
float clearcoatRoughness,
mat4 worldToLightTransform)
{
LightingContributions indirect;
indirect.diffuse = vec3(0.0);
indirect.specular = vec3(0.0);

#ifdef HD_HAS_domeLightIrradiance
vec3 F0 = specularColor;
vec3 F90 = vec3(1.0);
vec3 d = diffuseColor;
const float R = (1.0 - ior) / (1.0 + ior);
if (!useSpecularWorkflow) {
vec3 specColor = mix(vec3(1.0), diffuseColor, metallic);
F0 = mix(R * R * specColor, specColor, metallic);
F90 = specColor;

// For metallic workflows, pure metals have no diffuse
d *= 1.0 - metallic;
}
// Adjust the diffuse so glazing angles have less diffuse
float fresnel = pow(max(0.0, 1.0 - EdotH), 5.0);//SchlickFresnel
vec3 F = mix(F0, F90, fresnel);
d *= (1.0 - F);

mat4 transformationMatrix = GetDomeLightTransform(worldToLightTransform);

// Diffuse Component
vec3 dir = normalize((transformationMatrix * vec4(Neye,0.0)).xyz);
vec2 coord = ProjectToLatLong(dir);
vec3 diffuse = HdGet_domeLightIrradiance(coord).rgb;

// Specular Component
const float MAX_REFLECTION_LOD =
textureQueryLevels(HdGetSampler_domeLightPrefilter());
float lod = roughness * MAX_REFLECTION_LOD;
vec3 Rdir = normalize((transformationMatrix * vec4(Reye,0.0)).xyz);
vec2 Rcoord = ProjectToLatLong(Rdir);
vec3 prefilter = HdTextureLod_domeLightPrefilter(Rcoord, lod).rgb;

vec2 brdf = HdGet_domeLightBRDF(vec2(NdotE, roughness)).rg;

vec3 specular = prefilter * (F * brdf.x + brdf.y);

// Clearcoat Component
vec3 clearcoat = vec3(0.0);
if (clearcoatAmount > 0.0) {
const vec3 clearcoatF = clearcoatAmount * mix(
R * R * clearcoatColor, // Clearcoat F0
clearcoatColor, // Clearcoat F90
fresnel);
lod = clearcoatRoughness * MAX_REFLECTION_LOD;
prefilter = HdTextureLod_domeLightPrefilter(Rcoord, lod).rgb;
clearcoat = prefilter * (clearcoatF * brdf.x + brdf.y);
}

// Indirect Lighting
indirect.diffuse = (d * diffuse) * occlusion;
indirect.specular = (specular + clearcoat) * occlusion;

#endif

return indirect;
}

vec4
surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
{
//vec2 st = HdGet_st().xy;//This doesn't work unless you add a texture node in the material network

//Get the vertex colors from the prim vars of the quad primitive
vec3 vertexColors = HdGet_displayColor().rgb;
#ifdef HD_HAS_displayColor
vec3 vertexColors = HdGet_displayColor().rgb;
#else
vec3 vertexColors = vec3(1);
#endif

vec3 ambientColor = vec3(0);//Hardcoded
//Get the value of the custom color float3 parameter from the material, it is named "FVP_CustomColor"
vec3 diffuseColor = HdGet_FVP_CustomColor() *0.5 + vertexColors*0.5;//Blend the custom color with the vertex colors
vec3 diffuseColor = HdGet_FVP_CustomColor() * vertexColors;//Blend the custom color with the vertex colors
vec3 specularColor = vec3(1);//Hardcoded

vec3 n = Neye;
vec3 e = normalize(-Peye.xyz);

vec3 directLight = vec3(0.0);
vec3 indirectLight = vec3(0.0);//For dome light
float glossiness = 30.0;//Hardcoded
float ior = 1.5; //Hardcoded
float metallic = 0.0;//Hardcoded
float occlusion = 1.0;//Hardcoded
bool useSpecularWorkflow = true;//Hardcoded
float clearcoatAmount = 0.0;//Hardcoded
vec3 clearcoatColor = vec3(1.0);//Hardcoded
float clearcoatRoughness = 0.01;//Hardcoded

//Do basic lighting
//Do lighting (with no shadows)
#if NUM_LIGHTS > 0
for (int i = 0; i < NUM_LIGHTS; ++i)
{
LightSource light = GetLightSource(i);
if (!light.isIndirectLight)
{
vec4 Plight = light.position;
vec3 l = (Plight.w == 0.0)
? normalize(Plight.xyz)
: normalize(Plight - Peye).xyz;
LightSource light = GetLightSource(i);
vec4 Plight = light.isIndirectLight //light.isIndirectLight is true for dome light.
? vec4(0,0,0,1)
: light.position;

vec3 l = (Plight.w == 0.0)
? normalize(Plight.xyz)
: normalize(Plight - Peye).xyz;

float atten = lightDistanceAttenuation(Peye, i);
float spot = lightSpotAttenuation(l, i);
float atten = lightDistanceAttenuation(Peye, i);
float spot = lightSpotAttenuation(l, i);

float intensity = 1.0 * atten * spot;
float intensity = 1.0 * atten * spot;

vec3 lightDiffuseIrradiance = intensity * light.diffuse.rgb;
vec3 lightSpecularIrradiance = intensity * light.specular.rgb;
vec3 lightDiffuseIrradiance = intensity * light.diffuse.rgb;
vec3 lightSpecularIrradiance = intensity * light.specular.rgb;

BasicLightingCoeffs coeffs = computeLightingCoefficients(l, n, e, glossiness);
directLight += (light.ambient.rgb *ambientColor + lightDiffuseIrradiance * coeffs.diffuse * diffuseColor + lightSpecularIrradiance * coeffs.specular * specularColor);
BasicLightingCoeffs coeffs = computeLightingCoefficients(l, n, e, glossiness);

if (light.isIndirectLight) {
float NdotE = max(0.0, dot(n, e));
vec3 Reye = reflect(-e, n);

vec3 h = normalize(e + l);
float NdotL = max(0.0, dot(n, l));
float NdotH = max(0.0, dot(n, h));
float EdotH = max(0.0, dot(e, h));
// Calculate the indirect light (DomeLight)
LightingContributions indirectLightContrib =
evaluateIndirectLighting(diffuseColor, specularColor,
Neye, Reye, NdotE, EdotH, ior, metallic, occlusion,
glossiness, useSpecularWorkflow,
clearcoatAmount, clearcoatColor, clearcoatRoughness,
light.worldToLightTransform);
indirectLight += (indirectLightContrib.diffuse * light.diffuse.rgb
+ indirectLightContrib.specular * light.specular.rgb);
}
else {
// All other light sources contribute to the direct lighting
directLight += (light.ambient.rgb *ambientColor + lightDiffuseIrradiance * coeffs.diffuse * diffuseColor + lightSpecularIrradiance * coeffs.specular * specularColor);
}
}
#endif

return vec4(directLight, 1.0);
return vec4(directLight+indirectLight, 1.0);
}
Loading

0 comments on commit 5a24bca

Please sign in to comment.