OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Render backfaces of a cube into unit output texture

Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgPPU [osgPPU]
View previous topic :: View next topic  
Author Message

Joined: 12 Jan 2010
Posts: 4

PostPosted: Fri May 21, 2010 1:06 pm    Post subject:
Render backfaces of a cube into unit output texture
Reply with quote


I guess I'm missing something really obvious here.

I'm trying to render a simple scene (just a cube), keep the result in a texture and use this texture as a state texture attribute. Only the backfaces of the scene need to be rendered.

My approach so far is as follows:
1. Create the scene which is simply a Geode with a osg::Box attached.
2. Create the osgPPU::Processor attach it to the root node and set the main camera.
3. Create new osgPPU:UnitInOut and add it to the processor. Also create new osg:Texture2D to render into and pass it to the unit as output texture.
4. Setup a simple shader which will output the vertex positions as color values. Setup a CullFace::FRONT and pass both as attributes to the unit.
5. Create a new osg::StateSet and use the output texture of the unit as texture attribute.

I was expecting a result similar to the following image:

But the actual result looks like this:

My code is as follows:

const char* fpFront =
"void main () {\n"
"gl_FragColor = gl_Color;\n"

const char* vpFront =
"void main () {\n"
"gl_FrontColor = gl_Vertex; \n"
"gl_Position = ftransform();\n"

// output unit
osgPPU::UnitInOut* unitCullFront = new osgPPU::UnitInOut();

// output texture to render into
osg::Texture2D* texCullFront = createRenderTexture(256, 256);

osg::Viewport* vp = processor->getCamera()->getViewport();

//setup unit

unitCullFront->setOutputTexture(texCullFront, 0);

// setup shader
osg::Program* programCullFront = new osg::Program();
osg::Shader* fpCullFront = new osg::Shader(osg::Shader::FRAGMENT);
osg::Shader* vpCullFront = new osg::Shader(osg::Shader::VERTEX);



// set shader as attribute

// cull face
osg::CullFace* cullFrontFace = new osg::CullFace(osg::CullFace::FRONT);

// set cullface as sttribute

// create the result state
osg::StateSet* state = new osg::StateSet;

// set output texture as texture attribute
state->setTextureAttributeAndModes(0, texCullFront, osg::StateAttribute::ON);

return state;

Changing the last lines in the above code like this gives me the correct result:


instead of

state->setTextureAttributeAndModes(0, texCullFront, osg::StateAttribute::ON);

So the shader and the cullface attributes seem to work correctly. I was expecting the same results when applying the same properties to the unit and just using the output as a texture attribute?

It would be great if anyone could give me a hint on what I'm doing wrong.

Thank you!

Back to top
View user's profile Send private message
art (Art Tevs)
Site Admin

Joined: 20 Dec 2008
Posts: 414
Location: Saarbrücken, Germany

PostPosted: Fri May 21, 2010 1:30 pm    Post subject:
Reply with quote

Hi Martin,

ok, first of all, it seems the way how you use osgPPU is not correct. Second, this problem is actually osg related, since osgPPU has nothing to do with back/front face culling.

Ok, now lets try to solve your issue:

- In your code I see you attach the UnitInOut directly to the processor. This wouldn't work in your case, since you need a unit which will first bypass your camera's texture into the pipeline. Do this by placing first a UnitCameraAttachmentBypass under the processor and then your UnitInOut under this unit.

- why you setup front face culling on your unit??? This is non-sense. You probably might want to setup front-face culling on your rendered box and not on the Unit. If you do so with the unit, you might end up in having no results at all, since the internal screen sized quad used to by the unit whill not be rendered at all.


I would propose you to take a look on some examples provided with osgPPU in order to understand how the internal works. Also to understand that osgPPU is a tool which works on textures and not on geometry. That means in osgppu pipeline you put a texture (in 90% of the cases this is some texture from a camera) and as output a texture comes out. It is not, that you put a geometry or a scene into the pipeline, and it will come out to the texture.

Back to top
View user's profile Send private message Visit poster's website

Joined: 12 Jan 2010
Posts: 4

PostPosted: Fri May 21, 2010 3:34 pm    Post subject:
Reply with quote

Hi Art,

thank you for clearing this up to me, it works perfectly now!

What I was trying to accomplish was the rendering of a cube frontface/backface culled in order to generate a "direction texture" for a volume rayaster I'm currently working on.

Thanks again!

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgPPU [osgPPU] All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Wrapping Text around object as texture johansson_gbg General 0 Tue Oct 15, 2019 7:45 am View latest post
No new posts How do I move a Texture in an model ... newlife958 General 10 Tue Sep 17, 2019 1:16 am View latest post
No new posts Render to Texture and osgQt (osgQOpenGL) wroos General 3 Mon Sep 16, 2019 5:47 pm View latest post
No new posts I want to move the texture to rain. H... robertosfield General 4 Thu Jul 25, 2019 12:06 am View latest post
No new posts 回复: Is it possible to load text... GarfieldPig General 118 Fri May 10, 2019 4:32 pm View latest post

Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP