Last pixel drawn

Hello,

My problem is that I want the minimum and the maximum of a color component over the entire texture. Then I want to use these 2 data in an other shader processing the same texture.

From what I read, the problem is that a shader has no customizable outputs, and the only way to retrieve data from a shader (so to simulate outputs), is to render something with colors which “contain” the wanted data.

In my case, I have the result when the very last pixel is processed in the shader. For example I could set for this last pixel :
col.r=minimum;
col.g=maximum;
then connect the shader to a renderer, then to a DX9Texture node, then use the pipet to retrieve the color of this last pixel.
But where is this last pixel ? Is it (Width-1,Height-1) ? Is it the same at each processing of the shader ?

Hope my explanation is not too unclear…

Could you give me an advice, a tip, a trick… to do this or something equivalent ?

Thank you,

Matthieu

I don’t think it’s defined in what order fragments(pixels) are processed by the GPU and in any case it isn’t done sequentially but in parallel chunk by chunk. Knowing what the last pixel was is not possible.

Not sure how to solve your problem.

hello, you cannot retrive the information like that, because you cannot store any data between pixel shader calls, for example:

//does not work:
float minR = 1;
float4 PS(In)
{

minR = min(pix.r, minR);

}

in that case minR is for all pixels 1, no matter what you have written into it.

there is one solution i can think of, but have never tried it.
make a renderer and set the backbuffer to 1x1 pixel, this means you will have only one pixelshader call. then in the pixelshader make two for loops over the whole texture and calculate your min/max there and put that in the output color, then pipe has only on pixel to read… i would be really interested if that works?

Thank you for your responses. I learned some things.

tonfilm :

Your idea is interesting. Trying to apply it, I have 2 problems :

1/ The loop overt the whole texture in the unique call of the shader seems to be impossible, due to its size (1920x2160 = 2x FullHD). Indeed, the shader doesn’t compile and says that :
error X3511:loop does not appear to terminate in a timely manner (1024 iterations)
Maybe a solution would be to split the loop into several little loops…

2/ I’m not sure to understand how a shader works when it has in inputs 2 textures with different size (here, 1x1 and the whole texture) : how to tell it what size has the output ?

MixVideos5bis.zip (3.5 kB)

1/ I maybe have the solution for the problem n°1
So in order to avoid big loops on my texture in one pass, I have to do it iteratively. I will try, but I’m stopped by the problem n°2 !

2/ For the problem n°2, I really really don’t get it ! It’s desperating…
When we have 2 textures with different size, which one is the “In” texture ?
In other words, what size will have the output “texture” ?

Thank you