Skip to content

Commit

Permalink
HYDRA-1326 : Various fixes for the custom GLSLFX shader (#224)
Browse files Browse the repository at this point in the history
* HYDRA-1326 : Various fixes for the custom GLSLFX shader

* Add comments
  • Loading branch information
lanierd-adsk authored Dec 10, 2024
1 parent 64d769b commit 7082e71
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 38 deletions.
31 changes: 31 additions & 0 deletions lib/flowViewport/usdPlugins/shadersDiscoveryPlugin/README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -76,11 +76,15 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,37 @@
//
// createNode("MhCustomShaders")
//
// To use the custom shader into a usd file, please add 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 = ...
...
}
*/
////////////////////////////////////////////////////////////////////////

//maya headers
Expand Down Expand Up @@ -608,6 +639,11 @@ void MhCustomShaders::addedToModelCb()
//Data producer scene index interface is used to add the retained scene index to all viewports with all render delegates
auto& dataProducerSceneIndexInterface = Fvp::DataProducerSceneIndexInterface::get();
dataProducerSceneIndexInterface.addDataProducerSceneIndex(_retainedSceneIndex, noPrefix, (void*)&obj, FvpViewportAPITokens->allViewports,FvpViewportAPITokens->allRenderers);

//Update color
MPlug colorPlug(obj, mColor);
const double3& color = colorPlug.asMDataHandle().asDouble3();
UpdateColorInShader(color);
}

void MhCustomShaders::removedFromModelCb()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7082e71

Please sign in to comment.