Using float values for textures

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Using float values for textures

Scyla
Hi there,

In my jogl application I want to use pixel data I get from OpenExr Images (16 or 32 bit float values). I already wrote an application that stores the values in a java.nio.FloatBuffer in the order red, green, blue, alpha, red... and so on and so forth.

From there on I would like to create a texture as show in this example: http://http.developer.nvidia.com/GPUGems/gpugems_ch26.html

But It wont work properly with this jogl call:

gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_FLOAT_RGBA32_NV, textureHDR.getWidth(), textureHDR.getHeight(), 0, GL2.GL_RGBA, GL2.GL_HALF_FLOAT, textureHDR.getPixels());

I'm sorry if this is a stupid question but it seems that people rarely use FloatBuffer for the pixel data so I found no example how to do it correctly.

Unfortunately I can't include a working example because the loading of the pixel data is done via a dll that I wrote to access the ILM OpenExr library from a java program but I will add the java files to this post.

Greetings

OpenExrTextureTest.java
JoglApp.java
OpenExrReaderMain.java

Reply | Threaded
Open this post in threaded view
|

Re: Using float values for textures

Pixelapp
What's your question?
Reply | Threaded
Open this post in threaded view
|

Re: Using float values for textures

Sven Gothel
Administrator
In reply to this post by Scyla
On 06/01/2012 04:44 PM, Scyla [via jogamp] wrote:

> Hi there,
>
> In my jogl application I want to use pixel data I get from OpenExr Images (16
> or 32 bit float values). I already wrote an application that stores the values
> in a java.nio.FloatBuffer in the order red, green, blue, alpha, red... and so
> on and so forth.
>
> From there on I would like to create a texture as show in this example:
> http://http.developer.nvidia.com/GPUGems/gpugems_ch26.html
>
> But It wont work properly with this jogl call:
>
> gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_FLOAT_RGBA32_NV, textureHDR.getWidth(), textureHDR.getHeight(), 0, GL2.GL_RGBA, GL2.GL_HALF_FLOAT, textureHDR.getPixels());
>
>
> I'm sorry if this is a stupid question but it seems that people rarely use
> FloatBuffer for the pixel data so I found no example how to do it correctly.
>
> Unfortunately I can't include a working example because the loading of the
> pixel data is done via a dll that I wrote to access the ILM OpenExr library
> from a java program but I will add the java files to this post.
ARB_half_float_pixel - http://www.opengl.org/registry/specs/ARB/half_float_pixel.txt
+++
The floating-point format is very similar
to the IEEE single-precision floating-point standard, except that it
has only 5 exponent bits and 10 mantissa bits.
+++
GL_HALF_FLOAT_ARB                 0x140B


http://http.developer.nvidia.com/GPUGems/gpugems_ch26.html
+++
The 16-bit, or "half-precision," floating-point format is modeled after the IEEE 754 single-precision and double-precision formats. A half-precision number consists of a sign bit, a 5-bit exponent, and a 10-bit mantissa. The smallest and largest possible exponent values are reserved for representing zero, denormalized numbers, infinities, and NaNs.
+++
GL_FLOAT_RGBA16_NV                0x888A
GL_FLOAT_RGBA32_NV                0x888B

I guess the OpenExr uses 16 bit half float values
as described in your links.

Both (I assume) encode a signed half float pixel value
in 16 bit ('unsigned short' in 'C', 'short' in Java):
  1+5+10 (see above).

Hence you cannot use a float buffer, since short values are expected.
Use a Short NIO buffer and make sure you receive short values.

Maybe using the ARB variant of the extension helps using your code
on platform other than NV.

~Sven

>
> Greetings
>
> OpenExrTextureTest.java <http://forum.jogamp.org/file/n4025119/testClass.java>
> JoglApp.java <http://forum.jogamp.org/file/n4025119/JoglApp.java>
> OpenExrReaderMain.java
> <http://forum.jogamp.org/file/n4025119/OpenExrReaderMain.java>
>


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using float values for textures

Scyla
Tanks for your post Sven and I'm sorry I couldn't respond earlier because I was not at work.

I think my problem needs further explanation.

You’re right I about the half data-type but there is no OpenExr library for Java so I wrote a dll that gives me the pixel values as floats because I cast them in the c++ program from half to float (which is lossless according to the OpenExr docs). So now I have already a FloatBuffer with the pixel values as Java floats (they range from 0.0f to 1.0f).

The question is: how to tell jogl to use this data from the FloatBuffer as pixel-data for a texture?

If I do understand your post correctly then the nvidia example casts the half values into an unsigned short. So is there a way to use the float values directly or do I have to use short values?

I would rather not use a short buffer because then I lose the benefits of having HDR-images as texture-data (i.e. a greater dynamic range). I guess I would still have some advantage over byte values because of the larger range of the values but I would prefer to use float.

Thanks for your efforts in advance.

Greetings
Reply | Threaded
Open this post in threaded view
|

Re: Using float values for textures

Scyla
Hi there.

Lately I had some time to revisit the problem and after al little bit of fiddling I found a solution. So for everyone who is interested...

1. I forget the
pixelBuffer.flip()
 method call in the
getImageTile
 method (so no more allocation errors)

2. The correct call of the
glTexImage2D
 method is
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA32F, textureHDR.getWidth(), textureHDR.getHeight(), 0, GL2.GL_RGBA, GL2.GL_FLOAT, textureHDR.getPixels());

Now everything ist working properly and I'm one happy programmer

Thanks to everyone who tried to help.

Greetings