本文整理汇总了C#中float3.Max方法的典型用法代码示例。如果您正苦于以下问题:C# float3.Max方法的具体用法?C# float3.Max怎么用?C# float3.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类float3
的用法示例。
在下文中一共展示了float3.Max方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSHRGBEEncoding
void TestSHRGBEEncoding()
{
float3[] coeffs = null;
System.IO.FileInfo coeffsFileName = new System.IO.FileInfo( "SHCoeffs.sh3" );
using ( System.IO.FileStream S = coeffsFileName.OpenRead() )
using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {
uint coeffsCount = R.ReadUInt32();
coeffs = new float3[coeffsCount * 9];
for ( int i=0; i < 9*coeffsCount; i++ ) {
coeffs[i] = new float3( R.ReadSingle(), R.ReadSingle(), R.ReadSingle() );
// The exponent bias allows us to support up to 512 in luminance!
//coeffs[i] *= 5.0f;
}
}
uint test1_packed = EncodeRGBE( new float3( 1, 0, 1.5f ) );
float3 test1_unpacked = DecodeRGBE( test1_packed );
// float3 coeffMin = new float3( float.MaxValue, float.MaxValue, float.MaxValue );
float3 coeffMax = new float3( -float.MaxValue, -float.MaxValue, -float.MaxValue );
float3 coeffMinAbs = new float3( float.MaxValue, float.MaxValue, float.MaxValue );
int coeffsWithDifferentSignsInRGBCount = 0;
for ( int i=0; i < coeffs.Length; i++ ) {
float3 coeff = coeffs[i];
float3 absCoeff = new float3( Math.Abs( coeff.x ), Math.Abs( coeff.y ), Math.Abs( coeff.z ) );
if ( coeff.x * coeff.y < 0.0f || coeff.x * coeff.z < 0.0f || coeff.y * coeff.z < 0.0f )
coeffsWithDifferentSignsInRGBCount++;
// coeffMin.Min( coeff );
coeffMax.Max( absCoeff );
if ( absCoeff.x > 0.0f ) coeffMinAbs.x = Math.Min( coeffMinAbs.x, absCoeff.x );
if ( absCoeff.y > 0.0f ) coeffMinAbs.y = Math.Min( coeffMinAbs.y, absCoeff.y );
if ( absCoeff.z > 0.0f ) coeffMinAbs.z = Math.Min( coeffMinAbs.z, absCoeff.z );
}
double expMin = Math.Min( Math.Min( Math.Log( coeffMinAbs.x ) / Math.Log(2), Math.Log( coeffMinAbs.y ) / Math.Log(2) ), Math.Log( coeffMinAbs.z ) / Math.Log(2) );
double expMax = Math.Max( Math.Max( Math.Log( coeffMax.x ) / Math.Log(2), Math.Log( coeffMax.y ) / Math.Log(2) ), Math.Log( coeffMax.z ) / Math.Log(2) );
// Measure discrepancies after RGBE encoding
// float3 errorAbsMin = new float3( +float.MaxValue, +float.MaxValue, +float.MaxValue );
// float3 errorAbsMax = new float3( -float.MaxValue, -float.MaxValue, -float.MaxValue );
float3 errorRelMin = new float3( +float.MaxValue, +float.MaxValue, +float.MaxValue );
float3 errorRelMax = new float3( -float.MaxValue, -float.MaxValue, -float.MaxValue );
int minExponent = +int.MaxValue, maxExponent = -int.MaxValue;
int largeRelativeErrorsCount = 0;
for ( int i=0; i < coeffs.Length; i++ ) {
float3 originalRGB = coeffs[i];
uint RGBE = EncodeRGBE( originalRGB );
float3 decodedRGB = DecodeRGBE( RGBE );
// Compute absolute error
// float3 delta = decodedRGB - originalRGB;
// float3 distanceFromOriginal = new float3( Math.Abs( delta.x ), Math.Abs( delta.y ), Math.Abs( delta.z ) );
// errorAbsMin.Min( distanceFromOriginal );
// errorAbsMax.Max( distanceFromOriginal );
// Compute relative error
float3 errorRel = new float3( Math.Abs( originalRGB.x ) > 0.0f ? Math.Abs( decodedRGB.x / originalRGB.x - 1.0f ) : 0.0f, Math.Abs( originalRGB.y ) > 0.0f ? Math.Abs( decodedRGB.y / originalRGB.y - 1.0f ) : 0.0f, Math.Abs( originalRGB.z ) > 0.0f ? Math.Abs( decodedRGB.z / originalRGB.z - 1.0f ) : 0.0f );
// Scale the relative error by the magnitude of each component as compared to the maximum component
// This way, if we happen to have a "large" relative error on a component that is super small compared to the component with maximum amplitude then we can safely drop that small component (it's insignificant compared to the largest contribution)
float maxComponent = Math.Max( Math.Max( Math.Abs( originalRGB.x ), Math.Abs( originalRGB.y ) ), Math.Abs( originalRGB.z ) );
float3 magnitudeScale = maxComponent > 0.0f ? new float3( Math.Abs( originalRGB.x ) / maxComponent, Math.Abs( originalRGB.y ) / maxComponent, Math.Abs( originalRGB.z ) / maxComponent ) : float3.Zero;
errorRel *= magnitudeScale;
// Don't account for dernomalization
// if ( decodedRGB.x == 0.0 && originalRGB.x != 0.0f ) errorRel.x = 0.0f;
// if ( decodedRGB.y == 0.0 && originalRGB.y != 0.0f ) errorRel.y = 0.0f;
// if ( decodedRGB.z == 0.0 && originalRGB.z != 0.0f ) errorRel.z = 0.0f;
const float errorThreshold = 0.2f;
if ( Math.Abs( errorRel.x ) > errorThreshold || Math.Abs( errorRel.y ) > errorThreshold || Math.Abs( errorRel.z ) > errorThreshold )
largeRelativeErrorsCount++;
errorRelMin.Min( errorRel );
errorRelMax.Max( errorRel );
int exp = (int) ((RGBE >> 24) & 31) - EXPONENT_BIAS;
minExponent = Math.Min( minExponent, exp );
maxExponent = Math.Max( maxExponent, exp );
}
}
示例2: Combine
public void Combine( AABB a, AABB b )
{
m_Min = a.m_Min;
m_Min.Min( b.m_Min );
m_Max = a.m_Max;
m_Max.Max( b.m_Max );
}
示例3: EncodeRGBE
// uint packR8G8B8A8( float4 value ) {
// value = saturate( value );
// return ( ( ( uint( value.x * 255.0 ) ) << 24 ) | ( ( uint( value.y * 255.0 ) ) << 16 ) | ( ( uint( value.z * 255.0 ) ) << 8 ) | ( uint( value.w * 255.0 ) ) );
// }
//
// float4 unpackR8G8B8A8( uint value ) {
// return float4( ( value >> 24 ) & 0xFF, ( value >> 16 ) & 0xFF, ( value >> 8 ) & 0xFF, value & 0xFF ) / 255.0;
// }
//
// // RGBE (ward 1984)
// uint packRGBE( float3 value ) {
// const float sharedExp = ceil( ApproxLog2( max( max( value.r, value.g ), value.b ) ) );
// return packR8G8B8A8( saturate( float4( value / ApproxExp2( sharedExp ), ( sharedExp + 128.0f ) / 255.0f ) ) );
// }
//
// float3 unpackRGBE( uint value ) {
// const float4 rgbe = unpackR8G8B8A8( value );
// return rgbe.rgb * ApproxExp2( rgbe.a * 255.0f - 128.0f );
// }
uint EncodeRGBE( float3 _RGB )
{
float3 Sign = new float3( Math.Sign( _RGB.x ), Math.Sign( _RGB.y ), Math.Sign( _RGB.z ) );
_RGB *= Sign;
float maxRGB = _RGB.Max();
int sharedExp = (int) Math.Ceiling( Math.Log( maxRGB ) / Math.Log(2) );
sharedExp = Math.Max( 0, Math.Min( 31, sharedExp + EXPONENT_BIAS ) ) - EXPONENT_BIAS;
// float pow2 = (float) Math.Pow( 2.0f, sharedExp );
// float3 reducedRGB = _RGB / pow2;
float invPow2 = (float) Math.Pow( 2.0f, -sharedExp );
float3 reducedRGB = _RGB * invPow2;
reducedRGB.x = Math.Max( 0.0f, Math.Min( 1.0f, reducedRGB.x ) );
reducedRGB.y = Math.Max( 0.0f, Math.Min( 1.0f, reducedRGB.y ) );
reducedRGB.z = Math.Max( 0.0f, Math.Min( 1.0f, reducedRGB.z ) );
byte R = (byte) (255.0f * reducedRGB.x);
byte G = (byte) (255.0f * reducedRGB.y);
byte B = (byte) (255.0f * reducedRGB.z);
byte exp = (byte) (EXPONENT_BIAS + sharedExp);
exp |= (byte) ((Sign.x < 0.0f ? 128 : 0) | (Sign.y < 0.0f ? 64 : 0) | (Sign.z < 0.0f ? 32 : 0));
uint RGBE = (uint) ((exp << 24) | (R << 16) | (G << 8) | B);
return RGBE;
}
示例4: Mesh
public Mesh( Scene _Owner, idTech5Map.Map.Entity _Entity )
: base(_Owner, _Entity)
{
// BUild primitives and local space BBox
m_Primitives = new Primitive[_Entity.m_Model.m_Surfaces.Length];
m_BBoxMin_Local = float.MaxValue * float3.One;
m_BBoxMax_Local = -float.MaxValue * float3.One;
int PrimitiveIndex = 0;
foreach ( idTech5Map.Model.Surface S in _Entity.m_Model.m_Surfaces ) {
m_Primitives[PrimitiveIndex] = new Primitive( this, S );
m_BBoxMin_Local.Min( m_Primitives[PrimitiveIndex].m_BBoxMin );
m_BBoxMax_Local.Max( m_Primitives[PrimitiveIndex].m_BBoxMax );
PrimitiveIndex++;
}
// Convert BBox to world space
m_BBoxMin_World = float.MaxValue * float3.One;
m_BBoxMax_World = -float.MaxValue * float3.One;
for ( int CornerIndex=0; CornerIndex < 8; CornerIndex++ ) {
float X = (CornerIndex >> 0) & 1;
float Y = (CornerIndex >> 0) & 1;
float Z = (CornerIndex >> 0) & 1;
float3 D = m_BBoxMax_Local - m_BBoxMin_Local;
float3 lsCorner = m_BBoxMin_Local + new float3( X * D.x, Y * D.y, Z * D.z );
float3 wsCorner = (float3) (new float4( lsCorner, 1.0f ) * m_Local2Parent);
m_BBoxMin_World.Min( wsCorner );
m_BBoxMax_World.Max( wsCorner );
}
}