Floating point textures

What is the state of floating point textures support in Panda?

I was thinking of codding a radiosity lightmap generator for Panda. I’ve tried a couple of approaches and figured that in order for it to work at reasonable speeds, while maintaining good quality, I need to use the GPU and shaders for that. Unsurprisingly, 8, or even 16, bit textures don’t seem to do the trick for storing energy values. I’ve been trying to work around that, with some (hackish) success, but I don’t think it would work all that well outside of test scenes. So here’s the question.

  1. Is it possible in Panda to create and modify floating point textures on the fly?
  2. Is it possible to render to a floating point texture?

I have never gotten floating point textures to work.

Thanks for the answer.

It’s a typical one, unfortunately. That’s why I wanted to get clarification of whether it’s just a common place we all happen to fail at, or just a hole in Panda’s list of features. And, if it’s the later, if there are any plans for changing that in the upcoming releases.

The lack of native 32bit float buffers is hole in Panda’s feature set, and I wouldn’t hold your breath waiting for it. However, it shouldn’t really stop you either.

A simple work around is to use your own encoding functions to encode a 32 bit float into 4 x 8 bit color channels. (Let me know if you need the shader code to do this.) This is what I'm currently doing to encode the depth for Dx9 as Panda doesn't support depth textures for Dx9. It works pretty well at the cost of a few percent in speed (extremely minimal).

You can easily open 4 normal MRTs with panda, 4x4x8 = 128bits, and this will give you the equivalent of a 4x32-bit buffer. Alternatively, you can try something like logLuv/cieXY and just encode the lumonisty in one 4x8bit MRT and use a second MRT to encode 2x16bit color information. This latter approach would only require 64bits, and might actually be faster than using a full 128bit buffer.

I won’t. But can I ask why? Is it that Panda’s current code makes it difficult, or is it just considered no important enough, compared to other things that need to be worked on?

I was thinking of doing that, but I’m fairly new to shaders, so I haven’t been able to figure out how. If you could provide me with code, or even just directions, that would be greatly appreciated.

It might be faster, but it sounds a bit more complicated. At least for me right now, as I’m not very familiar with LogLuv and CIE.

I don’t know any reason why this would be particularly difficult, but it’s simply that no one has offered to write the code to do it yet. Are you offering? :slight_smile:


That’s a bit out of my league. I’ve just begun my journey into shaders, so taking on this kind of stuff is not within my reach at this moment. Trust me, if I were able to do it, I would be writing about it in Features in Development instead of here :wink:.

float4 FloatToRGBA(float value)
	float4 packedValue = frac(value * float4(16581375.0, 65025.0, 255.0, 1.0));
	float4 ret = packedValue.rgba - packedValue.xxyz * float4(0, 1.0/255, 1.0/ 255, 1.0/255);
	return ret;
float RGBAToFloat(float4 packedValue)
	float ret = dot( packedValue, float4( 1/16581375.0, 1/65025.0, 1/255.0, 1.0 ) );
	return ret;

Thank you very, very much zhao.

I forgot to add that this shader pair only stores floats within [0,1). Thus, you should bias your values with a constant ie., x’ = x/x_max before storing it.

Understood. Thanks again.

Thanks zhao!!:smiley:

Just a related note, but it is possible to write depth values from a fragment shader, and they are floating point. They have some support issues, but from what I’ve seen they usually work. I think they are just a float in the 0-1 range. I’d favor the multi channel encoding trick zhao presented though. Thats what I use.

Hi Craig, can you elaborate (hopefully with some code!) on how to write the depth directly? Is this with glsl?

in Cg, you can just write to o_Depth like you do to o_color, except its a float, not float4. Its write only (you can’t read the depth) and it simply replaces the auto computed depth value.

Ah ok. I thought you meant you were able to explicitly create a generic float texture and write a depth to it. What you actually mean is that you can write to the standard depth texture using o_depth.

This would be a clever way to get a one-channel 32 bit float texture :stuck_out_tongue: