Hi Mr. J.P. and Mr. Art Tevs,

Thanks for the quick reply. Mr. J.P. the pointers you gave to image reduction 
are very interesting. I am going through those since they will help me in the 
long run, but it would take some time to get to it. 
Below, I am attaching the fragment shader code for the unit that accesses the 
mipmap:

// The input image
uniform sampler2DImage;

// Mean and MeanSquared values
uniform sampler2DMeanStdImage;

vec3 floatToRGB(float Val)
{
float D = Val * 16777215.0;
float R = floor(D / 65536.0);
D = D - R * 65536.0;
float G = floor(D/256.0);
D = D - G*256.0;
float B = floor(D);
return vec3(R/255.0, G/255.0, B/255.0);
}

void main (void)
{
// get the image gray value -- C.r = C.g = C.b;
vec4 C = texture2D(Image, gl_TexCoord[0].st);
float Gray = C.r; 

// grab the image mean and std dev;
vec4 Avg = texture2D(MeanStdImage, vec2(0.5,0.5), 100.0);
float M = Avg.r;// Mean 
float M2 = Avg.g;// Mean of squares

// Compute the variance & Std. Dev.
float Var = clamp(M2 - M*M, 0.0, 1.0);
float Std = sqrt(Var);
float Factor = 0.5/Std;// Compute the scale factor
// grab the pixel color
Gray = (Gray - M) * Factor + 0.5;
Gray = clamp(Gray, 0.0, 1.0);
gl_FragColor = vec4(Gray, Gray, Gray, 1.0);
}

I have separately tried to convert the floating values M, M2, Std and 
unprocessed Gray into RGB (using floatToRGB) and grabbed using UnitCapture. 
Importing to Matlab revealed that the image has the following parameters: 
Min = 0.09, Max = 0.12, Mean ~ 0.11, std. dev = 0.01.., 
However, the mean and std dev as computed by Mipmapping are 0.115 and  ~0.12 
respectively. So it looks like the mean is more or less proper, but the std. 
dev. is improper. 
One doubt that I have is -- whether the placing of mean in red and sq. mean in 
green components is improper?

Regards

Harash


________________________________
From: Art Tevs <arti_t...@yahoo.de>
To: osg-users@lists.openscenegraph.org
Sent: Thu, December 3, 2009 5:55:24 PM
Subject: Re: [osg-users] [osgPPU] Problem Passing Lookup Table to Processing 
Unit

Hi Harash, J.P.


J.P. Delport wrote:
> 
> I'm not sure your shader is doing a proper mean. For the GPU to do 
> mean/sum you need to do what is called a reduction. Search for reduction 
> on www.gpgpu.org. This is different from doing per pixel operations like 
> changing luminance e.g.
> 


The posted code seems to be similar to the luminance computation in the HDR 
example (quick overview over the code). Using mipmaps one can compute an 
average or arithmetic mean value, I am not aware if reduction is really needed 
here. Maybe reduction means exactly the same. To compute it I would do the way, 
you described here: using UnitInMipmapOut to crete a mipmap with the average 
value in the highest level.

What do you mean, that the values are not the same? In order to get the 
computed value out of the mipmap you have to access the last mipmap level in 
your shader. Take a look into brightpass/tonemap shader, where the last level 
with scene luminance is accessed. Also make sure that in the last level you 
access not on (0,0) position, but on (0.5,0.5), because otherwise you will get 
interpolated values. It is actually better to disable GL_LINEAR filtering for 
the textures used by the unit.

art

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=20803#20803





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



      
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to