diff options
| -rw-r--r-- | convtexture.c | 29 | ||||
| -rw-r--r-- | video.cpp | 4 | 
2 files changed, 17 insertions, 16 deletions
| diff --git a/convtexture.c b/convtexture.c index e5b603b..e5ec996 100644 --- a/convtexture.c +++ b/convtexture.c @@ -353,7 +353,7 @@ int proc_bitmap(FILE* infile, FILE* outfile, Texture_Format target) {  }  typedef struct { -	float r, g, b; +	float r, g, b, a;  } Hdr_Pixel;  Hdr_Pixel hdr_pixel(uint8_t* bytes) { @@ -362,6 +362,8 @@ Hdr_Pixel hdr_pixel(uint8_t* bytes) {  	p.r = ((float)bytes[0] + 0.5f) * f;  	p.g = ((float)bytes[1] + 0.5f) * f;  	p.b = ((float)bytes[2] + 0.5f) * f; +	p.a = 1.0f; +	/* nvidia gpus dont support 3 component sfloat so we can't have nice things :( */  	return p;  } @@ -370,8 +372,7 @@ uint16_t f2h(uint32_t i) {  	int s =  (i >> 16) & 0x00008000;  	int e = ((i >> 23) & 0x000000ff) - (127 - 15);  	int m =   i        & 0x007fffff; -	if (e <= 0) -	{ +	if (e <= 0) {  		if (e < -10)  			return s;  		m = m | 0x00800000; @@ -381,21 +382,17 @@ uint16_t f2h(uint32_t i) {  		m = (m + a + b) >> t;  		return s | m;  	} -	else if (e == 0xff - (127 - 15)) -	{ +	else if (e == 0xff - (127 - 15)) {  		if (m == 0)  			return s | 0x7c00; -		else -		{ +		else {  			m >>= 13;  			return s | 0x7c00 | m | (m == 0);  		}  	} -	else -	{ +	else {  		m = m + 0x00000fff + ((m >> 13) & 1); -		if (m & 0x00800000) -		{ +		if (m & 0x00800000) {  			m =  0;  			e += 1;  		} @@ -522,10 +519,10 @@ int proc_hdr(FILE* infile, FILE* outfile, int half) {  		}  	}  	if (half) { -		write_header(outfile, w, h, texture_format_rgb16f); -		write_halves(outfile, w * h * 3, (float*)pixels); +		write_header(outfile, w, h, texture_format_rgba16f); +		write_halves(outfile, w * h * 4, (float*)pixels);  	} else { -		write_header(outfile, w, h, texture_format_rgb32f); +		write_header(outfile, w, h, texture_format_rgba32f);  		fwrite(pixels, sizeof *pixels, w * h, outfile);  	}  	fclose(outfile); @@ -560,8 +557,8 @@ int main(int argc, const char** argv) {  		return proc_bitmap(infile, outfile, target);  	}  	if (string_equal(magic, "#?RADIANCE")) { -		int half = target == texture_format_rgb16f; -		if (!half && target != texture_format_rgb32f) { +		int half = target == texture_format_rgba16f; +		if (!half && target != texture_format_rgba32f) {  			print_err("Unsupported target format.\n");  			return 40;  		} @@ -3696,6 +3696,10 @@ size_t Texture_Loader::calc_size(  			return w * h * 6;  		case texture_format_rgb32f:  			return w * h * 12; +		case texture_format_rgba16f: +			return w * h * 8; +		case texture_format_rgba32f: +			return w * h * 16;  		default:  			print_err("Can't load this texture format.\n");   			pbreak(45498); |