[maybe OT] HDR texture

Hi,
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?
thank you

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. :slight_smile:

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 (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);

if (col.a==0.0)
{
 red = 0.0;
 green = 0.0;
 blue = 0.0;
}
else
{
   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?
Thank you

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.

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…

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…

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.

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.

Thank you very much to all

Looks like a nasty case of overflow wrapping to me.