View Full Version : [maybe OT] HDR texture
09-20-2005, 01:39 AM
i need to convert a HDRE image in BMP,PNG format without loosing information (all formats are 32 bit/color). I ask this because i want calculate float color in my shader. With photoshop when i open hdr images, that are converted to 32bit/channel and then i cannot save it in bmp or png format. Do you know a program that can make this conversion?
If its an uncompressed RGBE format you can try to load it into photoshop as raw data and then save it as an RGBA image. The Alpha channel will contain your exponent channel. The conversion to float can be done in your pixel shader.
Please post any conversion tools for this which you might find. :)
09-20-2005, 11:02 PM
OK, i didn't find anything so i realized a little console application that convert from HDR to PNG (4 channel), you can find it here
HDRtoPNGConverter (http://mio.discoremoto.virgilio.it/capedica/) (download HDRtoPNGConverter.zip).
I don't know if this application is correct, i use the famous code rgbe.h e rgbe.c, to load a HDR image and convert float value to RGBA value.
To test an image converted i've created a shader that in fragment part, calculate float value and then convert it again in 8 bit value (with an exponent passed as uniform), this is the code:
vec4 col = vec4(texture2D(EnvMap, index));
float red = 0.0;
float green = 0.0;
float blue = 0.0;
float f = 0.0;
f = pow(2.0,col.a*255.0-136.0);
red = 0.0;
green = 0.0;
blue = 0.0;
red = col.r * f;
green = col.g * f;
blue = col.b * f;
// now in red,green,blue i have float value
vec3 te = vec3(0.0,0.0,0.0);
te.r = 1.0 - 1.0 / (exp * red + 1.0);
te.g = 1.0 - 1.0 / (exp * green + 1.0);
te.b = 1.0 - 1.0 / (exp * blue + 1.0);the last part of code i think it is correct because if i use directly a float texture with that piece of code i can retrieve the correct RGB value, the first part i don't know, i've copied what is present in rgbe.c class.
At the end, this method it doesn't function, colors are not correct. Here the results:
in left part this method, in the right part using directly a float texture and convert to 8bit in shader.
Someone knows what the error could be?
My exponent code is as follows:
exp = 128 - ( col.a * 255.0 ) + exposure; exposure is an +- integer value and will give you "longer" exposure with positive and "shorter" exposure with negative values.
If I remember correctly I also applied a gamma correction on the final color values.
09-22-2005, 08:14 PM
Originally posted by def:
If its an uncompressed RGBE format you can try to load it into photoshop as raw data and then save it as an RGBA image. The Alpha channel will contain your exponent channel. The conversion to float can be done in your pixel shader.Converting 8bit RGBE in the pixel shader to float is bound to have severe quality issues. A better solution is to use 16bits and normalize E to use the entire range. It only take three instructions to decode and has very good quality.
Originally posted by Humus:
Converting 8bit RGBE in the pixel shader to float is bound to have severe quality issues. A better solution is to use 16bits and normalize E to use the entire range.Are you talking about HDR in general? The RGBE format is limited to 8 bits per channel and there should be no loss of precision or range when used in a pixel shader...
09-23-2005, 05:59 AM
i've implemented float cubemap and now all goes right but it's strange; i have an RGBE texture, if i calculate float values inside main program, build a float texture and in my shader calculate RGB value it'all right, instead, if i directly pass to my shader an RGBE texture and then calculate float value,make some operation and reconvert to RGB i obtain results like in the previous image...looking at image may it be a precision problem but the operations that i do in my program and shader are the same...
09-24-2005, 10:41 PM
Originally posted by def:
Are you talking about HDR in general? The RGBE format is limited to 8 bits per channel and there should be no loss of precision or range when used in a pixel shader...The problem arises as soon as you enable texture filtering. It's only interpolated at 8bits, so when the last bit of E toggles you suddenly double the value.
Right, I forgot about the limitation of just using "nearest" filtering mode. But since we are using a pixel shader we could also do our own filtering...
This shader approach ist just a nice "hack" to integrate hdr textures into an (closed) application which does not offer hdr features in the first place.
09-26-2005, 09:28 PM
If you're going to do your own filtering, then it's probably a better idea to just expand it to floating point on the CPU instead of decoding it in the shader.
Even better would be to use the method I suggested though, since that works well to decode after filtering in general.
09-27-2005, 03:12 AM
Thank you very much to all
09-27-2005, 03:41 PM
Looks like a nasty case of overflow wrapping to me.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.