ugluk

09-22-2010, 11:55 PM

I am baffled by the signed vector component conversions into float vector components below:

ubyte c/(2^8 &#8722; 1)

byte (2c + 1)/(2^8 &#8722; 1)

ushort c/(2^16 &#8722; 1)

short (2c + 1)/(2^16 &#8722; 1)

uint c/(2^32 &#8722; 1)

int (2c + 1)/(2^32 &#8722; 1)

for unsigned types, apparently there are no negative vector components possible. But for signed ones, GL multiples by 2 giving the interval [-2^n, 2^n - 2] of possible values, adds 1 giving [-(2^n - 1), 2^n - 1] and divides by (2^n - 1) for the interval [-1, 1].

Somehow the lighting I get from using signed shorts, isn't as sharp as the one I get from using floats directly (IMO 16 bits ought to be enough, but it is very noticeable). Maybe there's a catch somewhere with rounding? Are you rounding the integer parts of floats in your code to get the signed ints? Do the signed ints give you satisfactory results in your apps?

Currently I use the inverse of the GL formulas to derive signed short components, I've tried with rounding and no rounding. Maybe I should use some custom normal compression scheme and use a shader to decompress?

ubyte c/(2^8 &#8722; 1)

byte (2c + 1)/(2^8 &#8722; 1)

ushort c/(2^16 &#8722; 1)

short (2c + 1)/(2^16 &#8722; 1)

uint c/(2^32 &#8722; 1)

int (2c + 1)/(2^32 &#8722; 1)

for unsigned types, apparently there are no negative vector components possible. But for signed ones, GL multiples by 2 giving the interval [-2^n, 2^n - 2] of possible values, adds 1 giving [-(2^n - 1), 2^n - 1] and divides by (2^n - 1) for the interval [-1, 1].

Somehow the lighting I get from using signed shorts, isn't as sharp as the one I get from using floats directly (IMO 16 bits ought to be enough, but it is very noticeable). Maybe there's a catch somewhere with rounding? Are you rounding the integer parts of floats in your code to get the signed ints? Do the signed ints give you satisfactory results in your apps?

Currently I use the inverse of the GL formulas to derive signed short components, I've tried with rounding and no rounding. Maybe I should use some custom normal compression scheme and use a shader to decompress?