Skip to content

Commit

Permalink
Merge pull request #1617 from Autodesk/t_gamaj/UsdTexture2d_in_VP2
Browse files Browse the repository at this point in the history
Implement UsdTexture2d support in VP2 render delegate
  • Loading branch information
Krystian Ligenza authored Aug 5, 2021
2 parents 3268cab + 90faf17 commit 5c357ed
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mayaUsd/render/vp2ShaderFragments/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ list(APPEND SHADERFRAGMENTS_XMLS
UsdPrimvarReader_float3.xml
UsdPrimvarReader_float4.xml
UsdPrimvarReader_vector.xml
UsdTransform2d.xml
UsdUVTexture.xml
# USD plug info
plugInfo.json
Expand Down
75 changes: 75 additions & 0 deletions lib/mayaUsd/render/vp2ShaderFragments/UsdTransform2d.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!--
========================================================================
Copyright 2019 Autodesk
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
========================================================================
-->
<fragment uiName="UsdTransform2d" name="UsdTransform2d" type="plumbing" class="ShadeFragment" version="1.0" feature_level="0">
<description>
<![CDATA[VP2 implementation for transform 2d]]>
</description>
<properties>
<float2 name="in" />
<float name="rotation" />
<float2 name="scale" />
<float2 name="translation" />
</properties>
<outputs>
<float2 name="result" />
</outputs>
<implementation>
<implementation render="OGSRenderer" language="GLSL" lang_version="3.0">
<function_name val="UsdTransform2d" />
<source>
<![CDATA[
vec2 UsdTransform2d(vec2 uv, float rotation, vec2 scale, vec2 translation)
{
float angleRad = rotation * 3.1415926f / 180.f;
mat2 rotMat = mat2(cos(angleRad), sin(angleRad),
-sin(angleRad), cos(angleRad));
return translation + rotMat * (scale * uv);
}
]]>
</source>
</implementation>
<implementation render="OGSRenderer" language="HLSL" lang_version="11.0">
<function_name val="UsdTransform2d" />
<source>
<![CDATA[
float2 UsdTransform2d(float2 uv, float rotation, float2 scale, float2 translation)
{
float angleRad = rotation * 3.1415926f / 180.f;
float2x2 rotMat = float2x2(cos(angleRad), sin(angleRad),
-sin(angleRad), cos(angleRad));
return translation + mul(scale * uv, rotMat);
}
]]>
</source>
</implementation>
<implementation render="OGSRenderer" language="Cg" lang_version="2.1">
<function_name val="UsdTransform2d" />
<source>
<![CDATA[
float2 UsdTransform2d(float2 uv, float rotation, float2 scale, float2 translation)
{
float angleRad = rotation * 3.1415926f / 180.f;
mat2 rotMat = mat2(cos(angleRad), -sin(angleRad),
sin(angleRad), cos(angleRad));
return translation + mul(rotMat, scale * uv);
}
]]>
</source>
</implementation>
</implementation>
</fragment>
3 changes: 3 additions & 0 deletions lib/mayaUsd/render/vp2ShaderFragments/shaderFragments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ TF_DEFINE_PRIVATE_TOKENS(
(UsdPrimvarColor)

(UsdUVTexture)
(UsdTransform2d)

(UsdPrimvarReader_color)
(UsdPrimvarReader_float)
Expand Down Expand Up @@ -106,6 +107,8 @@ static const TfTokenVector _FragmentNames = { _tokens->BasisCurvesCubicColorDoma

_tokens->UsdPrimvarColor,

_tokens->UsdTransform2d,

_tokens->UsdPrimvarReader_color,
_tokens->UsdPrimvarReader_float,
_tokens->UsdPrimvarReader_float2,
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
Expand Up @@ -108,6 +108,18 @@ def testMetallicResponse(self):
else:
self.assertSnapshotClose("testMetallicResponseLightAPI1.png")

def testUsdTexture2d(self):
cmds.file(force=True, new=True)
mayaUtils.loadPlugin("mayaUsdPlugin")

cmds.xform("persp", t=(0, 0, 2))
cmds.xform("persp", ro=[0, 0, 0], ws=True)

testFile = testUtils.getTestScene("UsdPreviewSurface", "UsdTransform2dTest.usda")
mayaUtils.createProxyFromFile(testFile)

self.assertSnapshotClose('UsdTransform2dTest.png')


if __name__ == '__main__':
fixturesUtils.runTests(globals())
77 changes: 77 additions & 0 deletions test/testSamples/UsdPreviewSurface/UsdTransform2dTest.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#usda 1.0
(
defaultPrim = "pPlane1"
metersPerUnit = 0.01
upAxis = "Y"
)

def Mesh "pPlane1" (
prepend apiSchemas = ["MaterialBindingAPI"]
kind = "component"
)
{
uniform bool doubleSided = 1
float3[] extent = [(-0.5, 0, -0.5), (0.5, 0, 0.5)]
int[] faceVertexCounts = [4]
int[] faceVertexIndices = [0, 1, 3, 2]
rel material:binding = </pPlane1/Looks/usdPreviewSurface1SG>
point3f[] points = [(-0.5, 0, 0.5), (0.5, 0, 0.5), (-0.5, 0, -0.5), (0.5, 0, -0.5)]
texCoord2f[] primvars:st = [(0, 0), (1, 0), (0, 1), (1, 1)] (
customData = {
dictionary Maya = {
token name = "map1"
}
}
interpolation = "faceVarying"
)
int[] primvars:st:indices = [0, 1, 3, 2]
float3 xformOp:rotateXYZ = (90, 0, 0)
uniform token[] xformOpOrder = ["xformOp:rotateXYZ"]

def Scope "Looks"
{
def Material "usdPreviewSurface1SG"
{
token inputs:file1:varname = "st"
token outputs:surface.connect = </pPlane1/Looks/usdPreviewSurface1SG/usdPreviewSurface1.outputs:surface>

def Shader "usdPreviewSurface1"
{
uniform token info:id = "UsdPreviewSurface"
color3f inputs:diffuseColor.connect = </pPlane1/Looks/usdPreviewSurface1SG/file1.outputs:rgb>
token outputs:displacement
token outputs:surface
}

def Shader "file1"
{
uniform token info:id = "UsdUVTexture"
float4 inputs:fallback = (0.5, 0.5, 0.5, 1)
asset inputs:file = @grid.png@
token inputs:sourceColorSpace = "sRGB"
float2 inputs:st.connect = </pPlane1/Looks/usdPreviewSurface1SG/file1/UsdTransform2d.outputs:result>
token inputs:wrapS = "repeat"
token inputs:wrapT = "repeat"
float3 outputs:rgb

def Shader "TexCoordReader"
{
uniform token info:id = "UsdPrimvarReader_float2"
token inputs:varname.connect = </pPlane1/Looks/usdPreviewSurface1SG.inputs:file1:varname>
float2 outputs:result
}

def Shader "UsdTransform2d"
{
uniform token info:id = "UsdTransform2d"
float2 inputs:in.connect = </pPlane1/Looks/usdPreviewSurface1SG/file1/TexCoordReader.outputs:result>
float inputs:rotation = 13
float2 inputs:scale = (0.3, 0.5)
float2 inputs:translation = (0.1777373, 0.117708534)
float2 outputs:result
}
}
}
}
}

Binary file added test/testSamples/UsdPreviewSurface/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5c357ed

Please sign in to comment.