public void Init() { v = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * 10000, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { v[i] = new float4(1.0f); } }
public static unsafe bool GreaterThanFloat4FloatUnsafe(ref float4 a, float b) { float4 x = a; float4 *start = &x; int axis = 0; return(CompareViaIndexer(start, axis, b)); }
public static unsafe void CopyToFloat4(NativeArray <float4> param, Vector4[] outVectors) { fixed(Vector4 *resultMatrices = outVectors) { float4 *sourceMatrices = (float4 *)param.GetUnsafeReadOnlyPtr(); UnsafeUtility.MemCpy(resultMatrices, sourceMatrices, UnsafeUtility.SizeOf <Vector4>() * param.Length); } }
public static void GetFrustumPlanes(ref OrthoCam ortho, float4 *planes) { planes[0] = VectorUtility.GetPlane(ortho.up, ortho.position + ortho.up * ortho.size); planes[1] = VectorUtility.GetPlane(-ortho.up, ortho.position - ortho.up * ortho.size); planes[2] = VectorUtility.GetPlane(ortho.right, ortho.position + ortho.right * ortho.size); planes[3] = VectorUtility.GetPlane(-ortho.right, ortho.position - ortho.right * ortho.size); planes[4] = VectorUtility.GetPlane(ortho.forward, ortho.position + ortho.forward * ortho.farClipPlane); planes[5] = VectorUtility.GetPlane(-ortho.forward, ortho.position + ortho.forward * ortho.nearClipPlane); }
public void Init() { rng = new Random(1); v = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * iterations, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < iterations; ++i) { v[i] = new float4(1.0f); } }
public static void GetOrthoCullingPlanes(ref OrthoCam orthoCam, float4 *planes) { planes[0] = MathLib.GetPlane(orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.farClipPlane); planes[1] = MathLib.GetPlane(-orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.nearClipPlane); planes[2] = MathLib.GetPlane(-orthoCam.up, orthoCam.position - orthoCam.up * orthoCam.size); planes[3] = MathLib.GetPlane(orthoCam.up, orthoCam.position + orthoCam.up * orthoCam.size); planes[4] = MathLib.GetPlane(orthoCam.right, orthoCam.position + orthoCam.right * orthoCam.size); planes[5] = MathLib.GetPlane(-orthoCam.right, orthoCam.position - orthoCam.right * orthoCam.size); }
public static void MatrixVectorMultiply(float4x4 *matrixPtr, float4 *vectors, int numVectors) { float4x4 matrix = *matrixPtr; for (int i = 0; i < numVectors; i++) { vectors[i] = math.mul(matrix, vectors[i]); } }
public static void GetPerspFrustumPlanesWithCorner(ref PerspCam perspCam, float4 *planes, float3 *corners) { planes[0] = MathLib.GetPlane(corners[1], corners[0], perspCam.position); planes[1] = MathLib.GetPlane(corners[2], corners[3], perspCam.position); planes[2] = MathLib.GetPlane(corners[0], corners[2], perspCam.position); planes[3] = MathLib.GetPlane(corners[3], corners[1], perspCam.position); planes[4] = MathLib.GetPlane(perspCam.forward, perspCam.position + perspCam.forward * perspCam.farClipPlane); planes[5] = MathLib.GetPlane(-perspCam.forward, perspCam.position + perspCam.forward * perspCam.nearClipPlane); }
void Segregate(int axis, float pivot, Range range, int minItems, ref Range lRange, ref Range rRange) { Assert.IsTrue(range.Length > 1 /*, "Range length must be greater than 1."*/); Aabb lDomain = Aabb.Empty; Aabb rDomain = Aabb.Empty; float4 *p = PointsAsFloat4; float4 *start = p + range.Start; float4 *end = p + range.Length - 1; do { // Consume left. while (start <= end && (*start)[axis] < pivot) { lDomain.Include((*(start++)).xyz); } // Consume right. while (end > start && (*end)[axis] >= pivot) { rDomain.Include((*(end--)).xyz); } if (start >= end) { goto FINISHED; } lDomain.Include((*end).xyz); rDomain.Include((*start).xyz); Swap(ref *(start++), ref *(end--)); } while (true); FINISHED: // Build sub-ranges. int lSize = (int)(start - p); int rSize = range.Length - lSize; if (lSize < minItems || rSize < minItems) { // Make sure sub-ranges contains at least minItems nodes, in these rare cases (i.e. all points at the same position), we just split the set in half regardless of positions. SplitRange(ref range, range.Length / 2, ref lRange, ref rRange); SetAabbFromPoints(ref lDomain, PointsAsFloat4 + lRange.Start, lRange.Length); SetAabbFromPoints(ref rDomain, PointsAsFloat4 + rRange.Start, rRange.Length); } else { SplitRange(ref range, lSize, ref lRange, ref rRange); } lRange.Domain = lDomain; rRange.Domain = rDomain; }
public unsafe void Exec(ref float4 *stack, ref float3 pos0, ref float3 pos1, ref float3 pos2, ref float3 pos3) { float4 dists = *(stack - 1); Op.Modify(ref dists.x); Op.Modify(ref dists.y); Op.Modify(ref dists.z); Op.Modify(ref dists.w); *(stack - 1) = dists; }
public unsafe void Exec(ref float4 *stack, ref float3 pos0, ref float3 pos1, ref float3 pos2, ref float3 pos3) { float4 dists; dists.x = Op.Sample(pos0); dists.y = Op.Sample(pos1); dists.z = Op.Sample(pos2); dists.w = Op.Sample(pos3); *(stack++) = dists; }
public static void ExecuteInList(NativeList_Int cullResult, float4 *frustumPlanes, NativeList_ulong indexBuffer) { for (int i = 0; i < indexBuffer.Length; ++i) { CustomDrawRequest.ComponentData *dataPtr = (CustomDrawRequest.ComponentData *)indexBuffer[i]; if (MathLib.BoxIntersect(ref dataPtr->localToWorldMatrix, dataPtr->boundingBoxPosition, dataPtr->boundingBoxExtents, frustumPlanes, 6)) { cullResult.ConcurrentAdd(dataPtr->index); } } }
private static unsafe void V128ForLoop([NoAlias] u8 *src, [NoAlias] float4 *dst, int count) { var alignedCount = (count / 5) * 5; var alpha = set1_epi32(0xFF << 24); var _255f = set1_ps(255.0f); int i = 0; for (; i < alignedCount; i += 5) { var all = loadu_ps(src + i * 3); var v0 = srli_si128(all, 0); var v1 = srli_si128(all, 3); var v2 = srli_si128(all, 6); var v3 = srli_si128(all, 9); var v4 = srli_si128(all, 12); v0 = or_ps(v0, alpha); v1 = or_ps(v1, alpha); v2 = or_ps(v2, alpha); v3 = or_ps(v3, alpha); v4 = or_ps(v4, alpha); v0 = cvtepu8_epi32(v0); v1 = cvtepu8_epi32(v1); v2 = cvtepu8_epi32(v2); v3 = cvtepu8_epi32(v3); v4 = cvtepu8_epi32(v4); v0 = cvtepi32_ps(v0); v1 = cvtepi32_ps(v1); v2 = cvtepi32_ps(v2); v3 = cvtepi32_ps(v3); v4 = cvtepi32_ps(v4); v0 = div_ps(v0, _255f); v1 = div_ps(v1, _255f); v2 = div_ps(v2, _255f); v3 = div_ps(v3, _255f); v4 = div_ps(v4, _255f); storeu_ps(dst + i + 0, v0); storeu_ps(dst + i + 1, v1); storeu_ps(dst + i + 2, v2); storeu_ps(dst + i + 3, v3); storeu_ps(dst + i + 4, v4); } for (; i < count; i++) { dst[i] = new float4(src[i * 3 + 0] / 255.0f, src[i * 3 + 1] / 255.0f, src[i * 3 + 2] / 255.0f, 1.0f); } }
public static void GetFrustumPlanes(ref PerspCam perspCam, float4 *planes) { float3 *corners = stackalloc float3[4]; GetFrustumCorner(ref perspCam, perspCam.farClipPlane, corners); planes[0] = VectorUtility.GetPlane(corners[1], corners[0], perspCam.position); planes[1] = VectorUtility.GetPlane(corners[2], corners[3], perspCam.position); planes[2] = VectorUtility.GetPlane(corners[0], corners[2], perspCam.position); planes[3] = VectorUtility.GetPlane(corners[3], corners[1], perspCam.position); planes[4] = VectorUtility.GetPlane(perspCam.forward, perspCam.position + perspCam.forward * perspCam.farClipPlane); planes[5] = VectorUtility.GetPlane(-perspCam.forward, perspCam.position + perspCam.forward * perspCam.nearClipPlane); }
public static bool BoxIntersect(float3 position, float3 extent, float4 *planes, int len) { for (uint i = 0; i < len; ++i) { float4 plane = planes[i]; float3 absNormal = abs(plane.xyz); if ((dot(position, plane.xyz) - dot(absNormal, extent)) > -plane.w) { return(false); } } return(true); }
private static unsafe void UnpackSRGBToLinear_Table(float4 *dest, uint *src, int count, float *table) { float *destf = (float *)dest; for (int i = 0, i4 = 0; i < count; i++) { uint si = src[i]; destf[i4++] = table[si & 0xff]; destf[i4++] = table[(si >> 8) & 0xff]; destf[i4++] = table[(si >> 16) & 0xff]; destf[i4++] = (float)(si >> 24); } }
public static bool BoxIntersect(float3x3 boxLocalToWorld, float3 position, float4 *planes, int len) { for (uint i = 0; i < len; ++i) { float4 plane = planes[i]; float3 absNormal = abs(mul(plane.xyz, boxLocalToWorld)); if ((dot(position, plane.xyz) - dot(absNormal, float3(0.5f, 0.5f, 0.5f))) > -plane.w) { return(false); } } return(true); }
internal static unsafe void FillMipMapChain32(int w, int h, uint *dest, bool srgb) { uint *src = dest; dest += w * h; if (!srgb) { for (; ;) { if (w == 1 && h == 1) { break; } int wdest = w == 1 ? 1 : w >> 1; int hdest = h == 1 ? 1 : h >> 1; DownSampleBox32(src, w, h, dest, wdest, hdest); src += w * h; dest += wdest * hdest; w = wdest; h = hdest; } } else { InitSRGBToLinearTable(); InitLinearToSRGBTable(); var buf = new NativeArray <float4>(w * h * 2, Allocator.TempJob); float4 *srcf4 = (float4 *)buf.GetUnsafePtr(); float4 *destf4 = srcf4 + w * h; float * tableSRGBToLinearTable = (float *)SRGBToLinearTable.GetUnsafePtr <float>(); UnpackSRGBToLinear_Table(srcf4, src, w * h, tableSRGBToLinearTable); byte *tableLinearToSRGB = (byte *)LinearToSRGBTable.GetUnsafePtr <byte>(); for (; ;) { if (w == 1 && h == 1) { break; } int wdest = w == 1 ? 1 : w >> 1; int hdest = h == 1 ? 1 : h >> 1; DownSampleBox(srcf4, w, h, destf4, wdest, hdest); PackLinearToSRGB_Table(dest, destf4, wdest * hdest, tableLinearToSRGB); src += w * h; dest += wdest * hdest; w = wdest; h = hdest; var t = srcf4; srcf4 = destf4; destf4 = t; // swap buffers } buf.Dispose(); } }
public void Init() { f4 = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * 10000, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } u4 = (uint4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <uint4>() * 10000, UnsafeUtility.AlignOf <uint4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { u4[i] = new uint4(100, 101, 102, 103); } }
public unsafe void Exec(ref float4 *stack, ref float3 pos0, ref float3 pos1, ref float3 pos2, ref float3 pos3) { float4 distances = *(--stack); float3 *posPtr = (float3 *)stack; pos3 = *(--posPtr); pos2 = *(--posPtr); pos1 = *(--posPtr); pos0 = *(--posPtr); stack = (float4 *)posPtr; *(stack++) = distances; }
public void Init() { f4 = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * 10000, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } h4 = (half4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <half4>() * 10000, UnsafeUtility.AlignOf <half4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { h4[i] = new half4(new float4(-1.0f, -2.0f, -3.0f, -4.0f)); } }
public void Init() { rng = (Random *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <Random>() * 10000, UnsafeUtility.AlignOf <Random>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { rng[i] = new Unity.Mathematics.Random(1); } f = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * 10000, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { f[i] = new float4(0.0f); } }
public void Init() { m1 = (float4x4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4x4>() * 10000, UnsafeUtility.AlignOf <float4x4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { m1[i] = float4x4.identity; } m2 = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * 10000, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < 10000; ++i) { m2[i] = new float4(1.0f, 0.0f, 0.0f, 1.0f); } }
public void Init() { rng = new Random(1); m1 = (float4x4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4x4>() * iterations, UnsafeUtility.AlignOf <float4x4>(), Allocator.Persistent); for (int i = 0; i < iterations; ++i) { m1[i] = float4x4.identity; } m2 = (float4 *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <float4>() * iterations, UnsafeUtility.AlignOf <float4>(), Allocator.Persistent); for (int i = 0; i < iterations; ++i) { m2[i] = new float4(1.0f, 0.0f, 0.0f, 1.0f); } }
public unsafe void Exec(ref float4 *stack, ref float3 pos0, ref float3 pos1, ref float3 pos2, ref float3 pos3) { float3 *posPtr = (float3 *)stack; *(posPtr++) = pos0; *(posPtr++) = pos1; *(posPtr++) = pos2; *(posPtr++) = pos3; stack = (float4 *)posPtr; Op.Modify(ref pos0); Op.Modify(ref pos1); Op.Modify(ref pos2); Op.Modify(ref pos3); }
public unsafe void Exec(ref float4 *stack, ref float3 pos0, ref float3 pos1, ref float3 pos2, ref float3 pos3) { stack--; float4 left = *(stack - 1); float4 right = *(stack - 0); float4 dists; dists.x = Op.Combine(left.x, right.x); dists.y = Op.Combine(left.y, right.y); dists.z = Op.Combine(left.z, right.z); dists.w = Op.Combine(left.w, right.w); *(stack - 1) = dists; }
public unsafe void Transform(float4x4 MVP) { screenMin = float.MaxValue; screenMax = -float.MaxValue; float4 *vin = (float4 *)vertexData.GetUnsafePtr(); float4 *vout = (float4 *)transformedVertexData.GetUnsafePtr(); for (int v = 0; v < vertexCount; ++v, ++vin, ++vout) { *vout = math.mul(MVP, *vin); vout->y = -vout->y; screenMin.xyz = math.min(screenMin.xyz, vout->xyz); screenMax.xyz = math.max(screenMax.xyz, vout->xyz); } }
// TODO: turn into job unsafe static void FindPlanePairs(ref BrushMeshBlob mesh, ref BlobBuilderArray <int> intersectingPlanes, float4 *localSpacePlanesPtr, int *vertexUsedPtr, float4x4 vertexTransform, PlanePair *usedPlanePairsPtr, out int usedPlanePairsLength, out int usedVerticesLength) { //using (new ProfileSample("FindPlanePairs")) { // TODO: this can be partially stored in brushmesh // TODO: optimize ref var halfEdgePolygonIndices = ref mesh.halfEdgePolygonIndices; ref var halfEdges = ref mesh.halfEdges;
private static unsafe void PackLinearToSRGB_Table(uint *dest, float4 *src, int count, byte *table) { float *srcf = (float *)src; for (int i = 0, i4 = 0; i < count; i++) { Assert.IsTrue(srcf[i4] >= 0.0f && srcf[i4] <= 1.0f); uint tr = (uint)table[(int)(srcf[i4++] * (LinearToSRGBTableSize - 1))]; Assert.IsTrue(srcf[i4] >= 0.0f && srcf[i4] <= 1.0f); tr |= (uint)(table[(int)(srcf[i4++] * (LinearToSRGBTableSize - 1))] << 8); Assert.IsTrue(srcf[i4] >= 0.0f && srcf[i4] <= 1.0f); tr |= (uint)(table[(int)(srcf[i4++] * (LinearToSRGBTableSize - 1))] << 16); Assert.IsTrue(srcf[i4] >= 0.0f && srcf[i4] <= 255.0f); tr |= (uint)(srcf[i4++]) << 24; dest[i] = tr; } }
public static float4 *GetFrustumPlanes(Camera camera, float4 *planes) { Transform trs = camera.transform; float3 *corners = stackalloc float3[4]; float3 *corners2 = stackalloc float3[4]; GetFrustumCorner(camera, camera.nearClipPlane, corners); GetFrustumCorner(camera, camera.farClipPlane, corners2); planes[0] = MathUtils.GetPlane(corners[0], corners[1], corners[2]); //近 planes[1] = MathUtils.GetPlane(corners[0], corners[2], corners2[0]); //左 planes[2] = MathUtils.GetPlane(corners[1], corners[0], corners2[0]); //下 planes[3] = MathUtils.GetPlane(corners[3], corners[1], corners2[1]); //右 planes[4] = MathUtils.GetPlane(corners[2], corners[3], corners2[2]); //上 planes[5] = MathUtils.GetPlane(corners2[1], corners2[2], corners2[3]); //远 return(planes); }
/// <summary> /// Creates a new CudaRegisteredHostMemory_float4 from an existing IntPtr. IntPtr must be page size aligned (4KBytes)! /// </summary> /// <param name="hostPointer">must be page size aligned (4KBytes)</param> /// <param name="size">In elements</param> public CudaRegisteredHostMemory_float4(IntPtr hostPointer, SizeT size) { _intPtr = hostPointer; _size = size; _typeSize = (SizeT)Marshal.SizeOf(typeof(float4)); _ptr = (float4*)_intPtr; }