/** Initializes the tables used to calculate SH values. */ static INT InitSHTables() { INT L = 0, M = 0; for(INT BasisIndex = 0;BasisIndex < MAX_SH_BASIS;BasisIndex++) { BasisL[BasisIndex] = L; BasisM[BasisIndex] = M; NormalizationConstants[BasisIndex] = appSqrt( (FLOAT(2 * L + 1) / FLOAT(4 * PI)) * (FLOAT(Factorial(L - Abs(M))) / FLOAT(Factorial(L + Abs(M)))) ); if(M != 0) NormalizationConstants[BasisIndex] *= appSqrt(2.f); M++; if(M > L) { L++; M = -L; } } return 0; }
/** * Dump allocation information. */ void FBestFitAllocator::DumpAllocs( FOutputDevice& Ar/*=*GLog*/ ) { // Memory usage stats. INT UsedSize = 0; INT FreeSize = 0; INT NumUsedChunks = 0; INT NumFreeChunks = 0; // Fragmentation and allocation size visualization. INT NumBlocks = MemorySize / AllocationAlignment; INT Dimension = 1 + NumBlocks / appTrunc(appSqrt(NumBlocks)); TArray<FColor> AllocationVisualization; AllocationVisualization.AddZeroed( Dimension * Dimension ); INT VisIndex = 0; // Traverse linked list and gather allocation information. FMemoryChunk* CurrentChunk = FirstChunk; while( CurrentChunk ) { FColor VisColor; // Free chunk. if( CurrentChunk->bIsAvailable ) { NumFreeChunks++; FreeSize += CurrentChunk->Size; VisColor = FColor(0,255,0); } // Allocated chunk. else { NumUsedChunks++; UsedSize += CurrentChunk->Size; // Slightly alternate coloration to also visualize allocation sizes. if( NumUsedChunks % 2 == 0 ) { VisColor = FColor(255,0,0); } else { VisColor = FColor(192,0,0); } } for( INT i=0; i<(CurrentChunk->Size/AllocationAlignment); i++ ) { AllocationVisualization(VisIndex++) = VisColor; } CurrentChunk = CurrentChunk->NextChunk; } check(UsedSize == AllocatedMemorySize); check(FreeSize == AvailableMemorySize); // Write out bitmap for visualization of fragmentation and allocation patterns. appCreateBitmap( TEXT("..\\..\\Binaries\\TextureMemory"), Dimension, Dimension, AllocationVisualization.GetTypedData() ); Ar.Logf( TEXT("BestFitAllocator: Allocated %i KByte in %i chunks, leaving %i KByte in %i chunks."), UsedSize / 1024, NumUsedChunks, FreeSize / 1024, NumFreeChunks ); Ar.Logf( TEXT("BestFitAllocator: %5.2f ms in allocator"), TimeSpentInAllocator * 1000 ); }
FSHVector FSHVector::LowerSkyFunction() { static FSHVector LowerSkyFunctionSH( 1.0f / appSqrt(PI), 0, -appSqrt(3.0f / PI) / 2.0f, 0, 0, 0, 0, 0, 0 ); return LowerSkyFunctionSH; }
FSHVector FSHVector::UpperSkyFunction() { static FSHVector UpperSkyFunctionSH( 1.0f / appSqrt(PI), 0, +appSqrt(3.0f / PI) / 2.0f, 0, 0, 0, 0, 0, 0 ); return UpperSkyFunctionSH; }
void GCylinder::SetCylinder( const GBoxAA *pBoxAA ) { assert( pBoxAA!=NULL && "GCylinder:: SetCylinder's parameter is null!" ); vecCenter = pBoxAA->vecCenter; fRadius = appSqrt( appSquare((pBoxAA->vecMax.X-pBoxAA->vecMin.X)/2.0f) + appSquare((pBoxAA->vecMax.Z-pBoxAA->vecMin.Z)/2.0f) ); if( fRadius < pBoxAA->vecSize.X/2.0f ) fRadius = pBoxAA->vecSize.X/2.0f; if( fRadius < pBoxAA->vecSize.Z/2.0f ) fRadius = pBoxAA->vecSize.Z/2.0f; vecCenter.Y = pBoxAA->vecMin.Y; fHeight = Abs( (pBoxAA->vecMax.Y-pBoxAA->vecMin.Y) /2.0f ); }
void GSphere::SetSphereXZ( const GBoxAA *pBox ) { if( !pBox ) { Init(); return; } vecCenter = pBox->vecCenter; fRadius = appSqrt( appSquare(pBox->vecCenter.X-pBox->vecMax.X) + appSquare(pBox->vecCenter.Z-pBox->vecMax.Z) ); if( fRadius < pBox->vecSize.X/2.0f ) fRadius = pBox->vecSize.X/2.0f; if( fRadius < pBox->vecSize.Z/2.0f ) fRadius = pBox->vecSize.Z/2.0f; fRadiusSq = appSquare(fRadius); }
FSHVector FSHVector::AmbientFunction() { static FSHVector AmbientFunctionSH( 1.0f / (2.0f * appSqrt(PI)), 0, 0, 0, 0, 0, 0, 0, 0 ); return AmbientFunctionSH; }
void GSphere::SetSphere( const GBoxAA *pBox, bool bYIgnore ) { if( !pBox ) { Init(); return; } vecCenter = pBox->vecCenter; if( bYIgnore ) { fRadius = appSqrt( appSquare(pBox->vecSize.X/2.0f) + appSquare(pBox->vecSize.Z/2.0f) ); } else { SVector v = pBox->vecCenter - pBox->vecMax; fRadius = v.Size(); } if( fRadius < pBox->vecSize.X/2.0f ) fRadius = pBox->vecSize.X/2.0f; if( !bYIgnore && fRadius < pBox->vecSize.Y/2.0f ) fRadius = pBox->vecSize.Y/2.0f; if( fRadius < pBox->vecSize.Z/2.0f ) fRadius = pBox->vecSize.Z/2.0f; fRadiusSq = appSquare(fRadius); }
void DComputeBoundingSphere( SVector& vCenterOut, float& fRadiusOut, const SVector *pVertices, dword dwNumVertices ) { if( dwNumVertices==0 ) return; vCenterOut.X = vCenterOut.Y = vCenterOut.Z = 0.0; for( dword nVert=0; nVert<dwNumVertices; ++nVert ) { vCenterOut += pVertices[nVert]; } vCenterOut /= (float)dwNumVertices; SVector vSub; float fTest; for(int nVert=0; nVert<dwNumVertices; ++nVert ) { vSub = vCenterOut - pVertices[nVert]; fTest = vSub.SizeSquared(); if( fTest>fRadiusOut ) { fRadiusOut = fTest; } } fRadiusOut = appSqrt(fRadiusOut); }
/** So that e.g. LP(1,1,1) which evaluates to -sqrt(1-1^2) is 0.*/ FORCEINLINE FLOAT SafeSqrt(FLOAT F) { return Abs(F) > KINDA_SMALL_NUMBER ? appSqrt(F) : 0.f; }
/** * Copyright 1998-2009 Epic Games, Inc. All Rights Reserved. */ #include "CorePrivate.h" // // Spherical harmonic globals. // FLOAT NormalizationConstants[MAX_SH_BASIS]; INT BasisL[MAX_SH_BASIS]; INT BasisM[MAX_SH_BASIS]; const FLOAT FSHVector::ConstantBasisIntegral = 2.0f * appSqrt(PI); FSHVectorRGB::FSHVectorRGB(const FQuantizedSHVectorRGB& Quantized) : R(Quantized.R), G(Quantized.G), B(Quantized.B) {} FSHVector::FSHVector(const FQuantizedSHVector& Quantized) { appMemzero(V, sizeof(V)); const FLOAT MinCoefficient32 = Quantized.MinCoefficient.GetFloat(); const FLOAT MaxCoefficient32 = Quantized.MaxCoefficient.GetFloat(); for (INT BasisIndex = 0; BasisIndex < MAX_SH_BASIS; BasisIndex++) { // Dequantize from 8 bit with stored min and max V[BasisIndex] = (MaxCoefficient32 - MinCoefficient32) * Quantized.V[BasisIndex] / 255.0f + MinCoefficient32; } }