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
MPanknin
Newbie


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

Hi,

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:
Code:


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

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


..........................
// output unit
osgPPU::UnitInOut* unitCullFront = new osgPPU::UnitInOut();
processor->addChild(unitCullFront);

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

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

//setup unit
unitCullFront->setViewport(vp);

unitCullFront->setOutputTextureType(osgPPU::UnitInOut::TEXTURE_2D);
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);

fpCullFront->setShaderSource(fpFront);
vpCullFront->setShaderSource(vpFront);

programCullFront->addShader(fpCullFront);
programCullFront->addShader(vpCullFront);

// set shader as attribute
unitCullFront->getOrCreateStateSet()->setAttributeAndModes(programCullFront);

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

// set cullface as sttribute
unitCullFront->getOrCreateStateSet()->setAttributeAndModes(cullFrontFace);

// 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:
Code:

state->setAttributeAndModes(cullFrontFace);
state->setAttributeAndModes(programCullFront);

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!

Cheers,
Martin
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.


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


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!

Cheers,
Martin
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 obj plugin does not support diffuse ... Ralf Habacker Submission 0 Tue Nov 14, 2017 4:18 pm View latest post
No new posts Get RGB Values from Texture dieslower81 General 6 Tue Nov 07, 2017 3:56 pm View latest post
No new posts Problem With Osg Texture Colors! Bobykhani General [forum] 1 Tue Oct 10, 2017 8:20 am View latest post
No new posts obj plugin does not support diffuse a... Ralf Habacker General 5 Tue Sep 19, 2017 6:21 am View latest post
No new posts Problem blending multiple render passes antiro42 General 5 Sat Sep 09, 2017 9:44 am 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