|
|
|
|
|
|
return mul(plane, InvProjection); |
|
|
|
} |
|
|
|
|
|
|
|
float4 EvalPlanePair(float2 posXY_in, float r) |
|
|
|
float4 EvalPlanePair(out bool validPlanes, float2 posXY_in, float r) |
|
|
|
{ |
|
|
|
// rotate by 90 degrees to avoid potential division by zero |
|
|
|
bool bMustFlip = abs(posXY_in.y)<abs(posXY_in.x); |
|
|
|
|
|
|
float D = posXY.y * sqrt(fLenSQ - r*r); |
|
|
|
float diffSq = fLenSQ - r*r; |
|
|
|
float D = posXY.y * sqrt(max(0.0, diffSq)); |
|
|
|
|
|
|
|
float4 res; |
|
|
|
res.x = (-r*posXY.x - D) / fLenSQ; |
|
|
|
|
|
|
// rotate back by 90 degrees |
|
|
|
res = bMustFlip ? float4(res.y, -res.x, res.w, -res.z) : res; |
|
|
|
|
|
|
|
validPlanes = diffSq>0.0; |
|
|
|
|
|
|
|
float4 planeX = EvalPlanePair(float2(pos_view_space.x, pos_view_space.z), r); |
|
|
|
float4 planeY = EvalPlanePair(float2(pos_view_space.y, pos_view_space.z), r); |
|
|
|
bool validX, validY; |
|
|
|
float4 planeX = EvalPlanePair(validX, float2(pos_view_space.x, pos_view_space.z), r); |
|
|
|
float4 planeY = EvalPlanePair(validY, float2(pos_view_space.y, pos_view_space.z), r); |
|
|
|
|
|
|
|
|
|
|
|
#if USE_LEFTHAND_CAMERASPACE |
|
|
|
|
|
|
|
|
|
|
bIsMinValid = bool2(planeX.z<0, planeY.z<0); |
|
|
|
bIsMaxValid = bool2((-planeX.x)<0, (-planeY.x)<0); |
|
|
|
bIsMinValid = bool2(planeX.z<0, planeY.z<0) && bool2(validX,validY); |
|
|
|
bIsMaxValid = bool2((-planeX.x)<0, (-planeY.x)<0) && bool2(validX,validY); |
|
|
|
|
|
|
|
// hopefully the compiler takes zeros into account |
|
|
|
// should be the case since the transformation in TransformPlaneToPostSpace() |
|
|
|