A problem when using Optix

I met a problem when I try to decide the color of the objects with my algorithm,it is done like that:
There are two objects in the scene,one object is covered with texture,which is grayscale image of 8-bits, and the range of the pixel value is between 0 and 255. The other object’s color will be decided by my algorithm.
The value of each pixel is calculated, which are between 0 and x(value is unknown ),they are all float number, as you know, the float number must be transform into unsigned char type to form an image. So the minimum value and maximum value must be found out. And I use the
formula (x-min)/(max-min)*255 to get the range I need.

The problem is that the pixel value of the first object needn’t transformation, but the second needs transformation. However the two objects’ pixel value are in the same output buffer, I can’t figure out which values come from the first object, and which are from the second object. That is to say, I can’t find out the minimum and maximum pixel value of the second object, and I also can’t know which data should be transformed and which needn’t.

So is there anyone who can solve my problem? Thank you very much!

I am new to these forums but I have worked a lot on raytracing, directX, and OpenGL code.
This sounds a lot like High Dynamic Range. If that is the case then the whole image will need to be remapped using any one of a number of algorithms, your preference for the desired output being more the determining factor on which algorithm to use.

Otherwise we may need to know exactly what you are using the pixel values for that might extend outside the [0,1] range.

To directly answer the problem as posted, the best option I have found is to perform multi-pass rendering. In one pass I store the object ID, could be a primitive object or a texture object or any other type. As a remapping I pass I used the ‘Object ID’ buffer to guide a full-screen, in this case full-image, pass that remapped color values to constant buffers parameters. This is similar to deferred rendering passes if you want to look at similar types of code.

Any additional information on how you intend to use the color remapping would probably help in determining how best to approach the solution for your particular case.

The ray payload in OptiX is user defined, so it can be more than just a color. Why not return some identifying information in an extra channel of the output buffer (or a second output buffer) so that you can identify the object in each pixel?