I am currently working as a Technical Artist. I am reaching out for assistance with a project involving the testing of Xbox using Raymarching HLSL. Despite following the guidelines in this YouTube tutorial(https://www.youtube.com/watch?v=dSY_8Ii-HcI), I encounter an error with the material when building for Xbox.
Here is the HLSL code I am using:
#define __XBOX_ENABLE_WAVE32 1
if (CustomDepth > 100000)
{
return float4(0, 0, 0, 1);
}
// Bring vectors into local space to support object transforms
float3 localcampos = mul(float4(ResolvedView.WorldCameraOrigin, 1.0), GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal).xyz;
localcampos += GetPrimitiveData(Parameters.PrimitiveId).LocalObjectBoundsMax;
localcampos += Vec;
// Normalize and transform camera vector to local space
float3 localcamvec = -normalize(mul(Parameters.CameraVector, (float3x3)GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal));
float3 rayForward = mul(float3(0.0, 0.0, 1.0), ResolvedView.ViewToTranslatedWorld);
// Ray-AABB intersection
float3 firstIntersections = (0 - localcampos) / localcamvec;
float3 secondIntersections = (GetPrimitiveData(Parameters.PrimitiveId).LocalObjectBoundsMax * 2 - localcampos) / localcamvec;
float3 temp0 = min(firstIntersections, secondIntersections);
float3 temp1 = max(firstIntersections, secondIntersections);
float t0 = max(temp0.x, max(temp0.y, temp0.z));
float t1 = min(temp1.x, min(temp1.y, temp1.z));
// AABB is behind the Ray || Ray doesn't intersect AABB
if (t1 < 0 || t0 > t1)
{
return float4(0, 0, 0, 0);
}
#if USE_SHELL_MESH_AS_ENTRY_POINT
// Shell mesh custom depth to optimize entry point
float3 localCustomDepthVector = mul(CustomDepth * normalize(Parameters.CameraVector), (float3x3)GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal);
float localCustomDepth = length(localCustomDepthVector) / abs(dot(rayForward, Parameters.CameraVector));
#endif
// Depth calculation
float sceneDepth = CalcSceneDepth(ScreenAlignedPosition(GetScreenPosition(Parameters)));
float3 ldv = mul(sceneDepth * normalize(Parameters.CameraVector), (float3x3)GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal);
float localSceneDepth = length(ldv) / abs(dot(rayForward, Parameters.CameraVector));
float farDistance = min(t1, localSceneDepth);
// Plane offset and step size calculation
float stepSize = StepSizeBias * (GetPrimitiveData(Parameters.PrimitiveId).LocalObjectBoundsMax * 2 / MaxSteps);
float worldStepSize = stepSize * length(TransformLocalVectorToWorld(Parameters, float3(0.0, 0.0, 1.0)).xyz);
float camDist = length(ResolvedView.WorldCameraOrigin - GetObjectWorldPosition(Parameters));
float planeOffset = GetScreenPosition(Parameters).w / worldStepSize;
float actorOffset = camDist / worldStepSize;
planeOffset = frac(planeOffset - actorOffset);
float3 offsetVec = localcamvec * stepSize * planeOffset;
t0 += planeOffset * PlaneAlignment;
float nearDistance = max(t0, 0);
#if USE_SHELL_MESH_AS_ENTRY_POINT
nearDistance = max(nearDistance, localCustomDepth);
#endif
float localThickness = farDistance - nearDistance;
float3 entrypos = localcampos + (nearDistance * localcamvec);
return float4(entrypos, localThickness);
I would like to know if there is an alternative approach to resolve this issue. Any guidance or suggestions you can provide would be greatly appreciated.
Thank you for your time and assistance.