Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,7 @@ public override IEnumerable<string> additionalDefines
if (readsTangent || hasNormalPort) // needs tangent
yield return $"SHADERGRAPH_NEEDS_TANGENT_{kvPass.Key.ToUpper(CultureInfo.InvariantCulture)}";

needsPosWS |= graphCode.requirements.requiresPosition != NeededCoordinateSpace.None ||
graphCode.requirements.requiresScreenPosition ||
graphCode.requirements.requiresViewDir != NeededCoordinateSpace.None;
needsPosWS |= NeedsPositionWorldInterpolator(graphCode);
}

// TODO Put that per pass ?
Expand Down Expand Up @@ -748,6 +746,13 @@ public override void EndCompilation()
graphCodes.Clear();
}

private static bool NeedsPositionWorldInterpolator(GraphCode graphCode)
{
return graphCode.requirements.requiresPosition != NeededCoordinateSpace.None
|| graphCode.requirements.requiresViewDir != NeededCoordinateSpace.None
|| graphCode.requirements.requiresScreenPosition;
}

public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalReplacements
{
get
Expand Down Expand Up @@ -820,9 +825,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
callSG.builder.AppendLine("INSG.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f);");
}

if (graphCode.requirements.requiresPosition != NeededCoordinateSpace.None ||
graphCode.requirements.requiresViewDir != NeededCoordinateSpace.None ||
graphCode.requirements.requiresScreenPosition || graphCode.requirements.requiresNDCPosition || graphCode.requirements.requiresPixelPosition)
if (NeedsPositionWorldInterpolator(graphCode))
{
callSG.builder.AppendLine("float3 posRelativeWS = VFXGetPositionRWS(i.VFX_VARYING_POSWS);");
callSG.builder.AppendLine("float3 posAbsoluteWS = VFXGetPositionAWS(i.VFX_VARYING_POSWS);");
Expand Down Expand Up @@ -852,20 +855,6 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
callSG.builder.AppendLine("INSG.AbsoluteWorldSpacePositionPredisplacement = posAbsoluteWS;");
}

callSG.builder.AppendLine("{");
if (graphCode.requirements.requiresNDCPosition || graphCode.requirements.requiresPixelPosition)
callSG.builder.AppendLine("float2 localPixelPosition = i.VFX_VARYING_POSCS.xy;");
if (graphCode.requirements.requiresNDCPosition)
callSG.builder.AppendLine("float2 localNDCPosition = localPixelPosition.xy / _ScreenParams.w;");

if (graphCode.requirements.requiresScreenPosition)
callSG.builder.AppendLine("INSG.ScreenPosition = ComputeScreenPos(VFXTransformPositionWorldToClip(i.VFX_VARYING_POSWS), _ProjectionParams.x);");
if (graphCode.requirements.requiresNDCPosition)
callSG.builder.AppendLine("INSG.NDCPosition = localPixelPosition / _ScreenParams.xy;");
if (graphCode.requirements.requiresPixelPosition)
callSG.builder.AppendLine("INSG.PixelPosition = localPixelPosition;");
callSG.builder.AppendLine("}");

if (graphCode.requirements.requiresViewDir != NeededCoordinateSpace.None)
{
callSG.builder.AppendLine("float3 V = GetWorldSpaceNormalizeViewDir(VFXGetPositionRWS(i.VFX_VARYING_POSWS));");
Expand All @@ -878,6 +867,23 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
if ((graphCode.requirements.requiresViewDir & NeededCoordinateSpace.Tangent) != 0)
callSG.builder.AppendLine("INSG.TangentSpaceViewDirection = mul(tbn, V);");
}

if (graphCode.requirements.requiresScreenPosition)
{
//ScreenPosition is expected to be the raw screen pos (float4) before the w division in pixel (SharedCode.template.hlsl)
callSG.builder.AppendLine("INSG.ScreenPosition = ComputeScreenPos(VFXTransformPositionWorldToClip(i.VFX_VARYING_POSWS), _ProjectionParams.x);");
}
}

if (graphCode.requirements.requiresNDCPosition || graphCode.requirements.requiresPixelPosition)
{
callSG.builder.AppendLine("{");

if (graphCode.requirements.requiresNDCPosition)
callSG.builder.AppendLine("INSG.NDCPosition = i.VFX_VARYING_POSCS.xy / _ScreenParams.xy;");
if (graphCode.requirements.requiresPixelPosition)
callSG.builder.AppendLine("INSG.PixelPosition = i.VFX_VARYING_POSCS.xy;");
callSG.builder.AppendLine("}");
}

if (graphCode.requirements.requiresMeshUVs.Contains(UVChannel.UV0))
Expand Down