bool isInFrustum(float4 clipSpacePosition, float screenExpansion) {
    float nearClippingPlane = _ProjectionParams.y; // y near plane, z far plane
    
    float3 weirdspace = clipSpacePosition.xyz;
    weirdspace /= -clipSpacePosition.w;
    weirdspace.x = weirdspace.x / 2.0f + 0.5f;
    weirdspace.y = weirdspace.y / 2.0f + 0.5f;
    weirdspace.z = -clipSpacePosition.w;
    const bool notClippedByNearClippingPlane = weirdspace.z >= -nearClippingPlane ? 0 : 1;
    const bool inFrustum =
        (weirdspace.x > -screenExpansion) && (weirdspace.x < (1+screenExpansion))
        && notClippedByNearClippingPlane;
    return inFrustum;
}
