Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faulty reflection if front- and backface of a model are drawn in a different way #41

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

I am using a cell shader implementation, where the outline is created by 
drawing the backfaces in wireframe mode with activated front face culling:
"osg::ref_ptr<osg::StateSet> linestate = node->getOrCreateStateSet();
linestate->setAttribute(new osg::LineWidth(4.0f));
linestate->setAttribute(new osg::CullFace(osg::CullFace::FRONT));
linestate->setAttribute(new osg::PolygonMode(osg::PolygonMode::BACK, 
osg::PolygonMode::LINE));"

The fragment shader draws a black fragment, if the fragment is backface and the 
regular color, if the fragment is front face:
"...
void main()
{
    if (gl_FrontFacing)
    {
        gl_FragColor = lighting();
    }
    else
    {
        gl_FragColor = vec4(0.0, 0.0, 0.0, 0.80);
    }
}
..."

In the reflection image the front- and backface is switched(as seen in the 
picture).
I changed the frontface mode to clockwise for the reflection camera to fix this 
issue.

osgOcean::OceanScene::init(), OceanScene.cpp, line 363

BEFORE:
"// clip everything below water line
            _reflectionCamera=renderToTexturePass( reflectionTexture.get() );
            _reflectionCamera->setClearColor( osg::Vec4( 0.0, 0.0, 0.0, 0.0 ) );
            _reflectionCamera->setCullMask( _reflectionSceneMask );
            _reflectionCamera->setCullCallback( new CameraCullCallback(this) );
            _reflectionCamera->getOrCreateStateSet()->setMode( GL_CLIP_PLANE0+0, osg::StateAttribute::ON );
            _reflectionCamera->getOrCreateStateSet()->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );"

AFTER:
"// clip everything below water line
            _reflectionCamera=renderToTexturePass( reflectionTexture.get() );
            _reflectionCamera->setClearColor( osg::Vec4( 0.0, 0.0, 0.0, 0.0 ) );
            _reflectionCamera->setCullMask( _reflectionSceneMask );
            _reflectionCamera->setCullCallback( new CameraCullCallback(this) );
            _reflectionCamera->getOrCreateStateSet()->setMode( GL_CLIP_PLANE0+0, osg::StateAttribute::ON );
            _reflectionCamera->getOrCreateStateSet()->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
            _reflectionCamera->getOrCreateStateSet()->setAttributeAndModes(new osg::FrontFace(osg::FrontFace::CLOCKWISE), osg::StateAttribute::ON | osg::StateAttribute::PROTECTED);"

The fix is also working, if the front and backface are drawn normally and it 
should also be helpfull if the backface is not drawn at all.

Original issue reported on code.google.com by [email protected] on 2 Jan 2012 at 2:50

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant