Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Aressera

Member Since 25 Mar 2007
Offline Last Active Today, 10:15 PM

Posts I've Made

In Topic: Passing an Object Constructor as Default Parameter : Bad Idea?... Not working...

Today, 05:42 PM

Try passing your parameter by const reference, that will avoid the copy constructor.


In Topic: Font Rendering without bitmap textures for localization

03 May 2015 - 11:49 PM

You may find signed-distance-field fonts useful. It's not quite vector graphics but will render lighting fast without aliasing at almost any scale/rotation. You should use Freetype to render binary glyphs, then compute the signed distance to the nearest 0/1 boundary for each pixel (brute force). Rendering just requires alpha testing against a threshold value, you can also do anti-aliasing by widening the transition from the inside to outside of the glyph. Read the Valve paper for more info on this versatile technique.


In Topic: C++ cant find a match for 16 bit float and how to convert 32 bit float to 16...

10 April 2015 - 01:35 PM

You may find the following well-commented code useful for converting between half-float and float types while handling special values like infinity and NAN. For me, these functions are wrapped in a HalfFloat class that has all of the standard arithmetic and conversion operators.


/// A static constant for a half float with a value of zero.
static const UInt16 ZERO = 0x0000;


/// A static constant for a half float with a value of not-a-number.
static const UInt16 NOT_A_NUMBER = 0xFFFF;


/// A static constant for a half float with a value of positive infinity.
static const UInt16 POSITIVE_INFINITY = 0x7C00;


/// A static constant for a half float with a value of negative infinity.
static const UInt16 NEGATIVE_INFINITY = 0xFC00;


/// A mask which isolates the sign of a half float number.
static const UInt16 HALF_FLOAT_SIGN_MASK = 0x8000;


/// A mask which isolates the exponent of a half float number.
static const UInt16 HALF_FLOAT_EXPONENT_MASK = 0x7C00;


/// A mask which isolates the significand of a half float number.
static const UInt16 HALF_FLOAT_SIGNIFICAND_MASK = 0x03FF;


/// A mask which isolates the sign of a single precision float number.
static const UInt32 FLOAT_SIGN_MASK = 0x80000000;


/// A mask which isolates the exponent of a single precision float number.
static const UInt32 FLOAT_EXPONENT_MASK = 0x7F800000;


/// A mask which isolates the significand of a single precision float number.
static const UInt32 FLOAT_SIGNIFICAND_MASK = 0x007FFFFF;


/// Convert the specified single precision float number to a half precision float number.
static UInt16 floatToHalfFloat( Float floatValue )
{
	// Catch special case floating point values.
	if ( math::isNAN( floatValue ) )
		return NOT_A_NUMBER;
	else if ( math::isInfinity( floatValue ) )
		return POSITIVE_INFINITY;
	else if ( math::isNegativeInfinity( floatValue ) )
		return NEGATIVE_INFINITY;
	
	UInt32 value = *((UInt32*)&floatValue);
	
	if ( floatValue == Float(0) )
		return UInt16( value >> 16 );
	else
	{
		// Start by computing the significand in half precision format.
		UInt16 output = UInt16((value & FLOAT_SIGNIFICAND_MASK) >> 13);
		
		register UInt32 exponent = ((value & FLOAT_EXPONENT_MASK) >> 23);
		
		// Check for subnormal numbers.
		if ( exponent != 0 )
		{
			// Check for overflow when converting large numbers, returning positive or negative infinity.
			if ( exponent > 142 )
				return UInt16((value & FLOAT_SIGN_MASK) >> 16) | UInt16(0x7C00);
			
			// Add the exponent of the half float, converting the offset binary formats of the representations.
			output |= (((exponent - 112) << 10) & HALF_FLOAT_EXPONENT_MASK);
		}
		
		// Add the sign bit.
		output |= UInt16((value & FLOAT_SIGN_MASK) >> 16);
		
		return output;
	}
}




/// Convert the specified half float number to a single precision float number.
static Float halfFloatToFloat( UInt16 halfFloat )
{
	// Catch special case half floating point values.
	switch ( halfFloat )
	{
		case NOT_A_NUMBER:
			return math::nan<Float>();
		case POSITIVE_INFINITY:
			return math::infinity<Float>();
		case NEGATIVE_INFINITY:
			return math::negativeInfinity<Float>();
	}
	
	// Start by computing the significand in single precision format.
	UInt32 value = UInt32(halfFloat & HALF_FLOAT_SIGNIFICAND_MASK) << 13;
	
	register UInt32 exponent = UInt32(halfFloat & HALF_FLOAT_EXPONENT_MASK) >> 10;
	
	if ( exponent != 0 )
	{
		// Add the exponent of the float, converting the offset binary formats of the representations.
		value |= (((exponent - 15 + 127) << 23) & FLOAT_EXPONENT_MASK);
	}
	
	// Add the sign bit.
	value |= UInt32(halfFloat & HALF_FLOAT_SIGN_MASK) << 16;
	
	return *((Float*)&value);
}


In Topic: check it out, real-time opencl ray tracer

02 April 2015 - 03:59 PM

Nice, now try in a non-trivial scene like Sponza, Sibenik, etc.


In Topic: Encapsulate 2 spheres

29 March 2015 - 09:58 PM

My guess is that you want something like this:

/// Enlarge this bounding sphere so that it encloses both its original volume and the new sphere.
template < typename T >
void Sphere3D<T>:: enlargeFor( const Sphere3D<T>& other )
{
	// Compute the vector from the child's bounding sphere to current bounding sphere.
	Vector3D<T> v = other.position - position;
	T distanceSquared = v.getMagnitudeSquared();
	T radiusDiff = other.radius - radius;
	
	if ( distanceSquared < radiusDiff*radiusDiff )
	{
		// The other bounding sphere completely contains the previous bounding sphere.
		if ( other.radius > radius )
		{
			position = other.position;
			radius = other.radius;
		}
	}
	else
	{
		// the other sphere is outside the previous bounding sphere. Resize the bounding
		// sphere to fit the other sphere.
		T distance = math::sqrt( distanceSquared );
		T newRadius = (distance + other.radius + radius)*T(0.5);
		
		if ( distance > math::epsilon<T>() )
			position += v*((newRadius - radius) / distance);
		
		radius = newRadius;
	}
}

PARTNERS