World position and Object position in Shader Fragment

table, th, td {
border: 1px solid black;
}

When you write a Shader Fragment, you should use the right naming conventions. For example if you check parameters like “mayaUvCoordSemantic” the name should be “uvCoord”, for “tangent” the name should be “mayaTangentIn”.

Even if you check the “Object Space Position” the name and the semantic both should be “Pm”. Check the below example.

<fragment uiName="depthShaderPluginInterpolantFragment" name="depthShaderPluginInterpolantFragment" type="interpolant" class="ShadeFragment" version="1.0">"
<description><![CDATA[Depth shader vertex fragment]]></description>"
<properties>
<float3 name="Pm" semantic="Pm" flags="varyingInputParam" />
<float4x4 name="worldViewProj" semantic="worldviewprojection" />
</properties>
<vertex_source><![CDATA["
float idepthShaderPluginInterpolantFragment(float3 Pm, float4x4 worldViewProj)
{
float4 pCamera = mul(worldViewProj, float4(Pm, 1.0f));
return (pCamera.z - pCamera.w*2.0f); n"
} ]]>
</vertex_source>

If you are defining, “World Space Position” the semantic and the name should be “Pw” instead of any other string like “out”, “outPosition”,… like below. If you use any other string, Maya won’t consider it as varyingInputParameters.

<float3 name="Pw” semantic="Pw” flags="varyingInputParam" />"
...
<![CDATA[float4 fragTexture(float2 uv, texture2D map, sampler2D textureSampler, float4x4 texMatrix, float3 Pw)
...
Semantic Name Type Meaning
Pm Pm 3-float Object space position
Pw Pw 3-float World space position
Pv Pv 3-float View space position
Nm Nm 3-float Object space normal
Nw Nw 3-float World space normal

For more information please check “Varying Parameters and System Parameters” section in the following document

http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=filesGUID585F565640694D82B9BB3D1AB2D0DFE6_htm


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading