Hi,
Roman Grigoriev wrote:
> Hi guys!
>
> I try to implement HDR. And I got some problem when I compute average
> luminance
>
> I have to render it to 1X1 texture and here is the main problem
>
> When I setup viewport with setVewport(0,0,1,1) – I’ve got clearcolor
> i.e. (1,0,0,0)
Is this for a 1x1 target, or for your 2x2 target? I guess your shader is
not executed at all. What are you doing in the vertex shader? I have not
tried 1x1 textures myself.
>
> When I setup viewport with setVewport(0,0,2,2) - I’ve got average
> luminance – but here I’ve got 2X2 texture but I need 1X1 texture
At some texture size (search gpgpu.org or experiment) it becomes faster
to copy the texture to CPU and do final calculation there.
>
> What should I do?
Debug more :) See if your shader is executed for 1x1 case at all. Turn
on more OSG (see OSG_NOTIFY_LEVEL) messages to see if there are not
other problems, e.g. non-power of two texture resampling. Try texture
rectangles...
jp
>
> Here is my source (luminance2 texture has size of 4X4)
>
> osg::ref_ptr<osg::Texture2D> finalluminance = new osg::Texture2D;
>
> finalluminance->setTextureSize( 2, 2);
>
>
>
> finalluminance->setInternalFormat(GL_RGBA16F_ARB);
>
> finalluminance->setSourceFormat(GL_RGBA);
>
> finalluminance->setSourceType(GL_FLOAT);
>
>
>
>
> finalluminance->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
>
>
> finalluminance->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
>
> finalluminance->setWrap(osg::Texture::WRAP_S,
> osg::Texture::CLAMP);
>
> finalluminance->setWrap(osg::Texture::WRAP_T,
> osg::Texture::CLAMP);
>
>
>
> osg::ref_ptr<osg::Camera> luminance3Camera = new osg::Camera;
>
> osg::ref_ptr<osg::Geode> geode = new osg::Geode;
>
> osg::ref_ptr<osg::Geometry> geom
> =osg::createTexturedQuadGeometry(osg::Vec3(0,0,-1),osg::Vec3(1.0,0.0,-1.0),osg::Vec3(0.0,1.0,-1.0));
>
>
> geom->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
>
> geode->addDrawable(geom.get());
>
> luminance3Camera->setName("luminance3");
>
>
> luminance3Camera->setClearColor(osg::Vec4f(1.0f,0.0f,0.0f,1.0f));
>
>
> luminance3Camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));
>
>
> luminance3Camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>
> luminance3Camera->setViewMatrix(osg::Matrix::identity());
>
> luminance3Camera->setViewport(0,0,2,2);
>
>
> luminance3Camera->setRenderOrder(osg::Camera::POST_RENDER,13);
>
>
> luminance3Camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>
>
> luminance3Camera->attach(osg::Camera::COLOR_BUFFER,finalluminance.get());
>
> luminance3Camera->addChild(geode.get());
>
>
>
> osg::ref_ptr<osg::StateSet> luminance3stateset
> =luminance3Camera->getOrCreateStateSet();
>
>
> luminance3stateset->setTextureAttributeAndModes(0,luminance2.get(),osg::StateAttribute::ON);
>
> luminance3stateset->setAttribute(clamp,
> osg::StateAttribute::ON);
>
>
>
> root->addChild(luminance3Camera.get());
>
> osg::Program* luminance3prg = new osg::Program;
>
> luminance3stateset->setAttribute(luminance3prg);
>
>
> luminance3prg->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX,
> osgDB::findDataFile("Shaders/downLumExp_vp.glsl")));
>
>
> luminance3prg->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
> osgDB::findDataFile("Shaders/downLumExp.glsl")));
>
> osg::Uniform* DownSampler = new
> osg::Uniform("DownSampler",0);
>
> luminance3stateset->addUniform(DownSampler);
>
>
>
> here is downLumExp.glsl
>
>
>
> /*FRAGMENT_SHADER*/
>
> uniform sampler2D DownSampler;
>
> const vec2 samples[16]={
>
> -0.375, -0.375, -0.125, -0.375, 0.125, -0.375, 0.375, -0.375, -0.375,
> -0.125, -0.125, -0.125, 0.125, -0.125, 0.375, -0.125, -0.375, 0.125,
> -0.125, 0.125, 0.125, 0.125, 0.375, 0.125, -0.375, 0.375, -0.125, 0.375,
> 0.125, 0.375, 0.375, 0.375
>
> };
>
>
>
> void main(void)
>
> {
>
> float lum = 0.0;
>
> float maximum = 0.0;
>
> vec4 color;
>
> vec2 sample;
>
> for(int i = 0; i < 16; i++)
>
> {
>
> sample = vec2(samples[i].x,samples[i].y);
>
> color = texture2D(DownSampler, gl_TexCoord[0].xy +
> sample);
>
> maximum = max( maximum, color.g );
>
> lum += color.r;
>
> }
>
>
>
> lum *= 0.0625;
>
> lum = exp(lum);
>
> gl_FragColor = vec4(lum, maximum, 0.0, 1.0);
>
> }
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
This message is subject to the CSIR's copyright terms and conditions, e-mail
legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at
http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their
support.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org