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 

Very basic example ?


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


Joined: 03 Aug 2011
Posts: 297

PostPosted: Sat Oct 01, 2011 9:25 am    Post subject:
Very basic example ?
Reply with quote

Hi,

After 2 days playing with osgPPU examples, I stil did not succeed to do a very basic PPU unit...

Is there any very basic example for osgPPU ?

Something like :

* create PPU
* add PPU unit which use a shader for a very basic operation (like switch red and green color components)
* attach PPU to camera

So with that, anybody could start coding PPU units easily.

Regards,
Aurelien
Back to top
View user's profile Send private message
Aurelien
Appreciator


Joined: 03 Aug 2011
Posts: 297

PostPosted: Mon Oct 03, 2011 10:10 am    Post subject:
Reply with quote

Currently, I have this code.

I try to do a simple operation : invert Red and Green color components, but I get only a black screen.

Could anyone help me ?

Thanks.

Code:
// Configure Camera
p_osgCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
p_osgCamera->setViewport(new osg::Viewport(0,0,800,600));

// Create render texture
osg::Texture2D* textureColor = new osg::Texture2D();
textureColor->setDataVariance(osg::Object::DYNAMIC);
textureColor->setNumMipmapLevels(0);
textureColor->setUseHardwareMipMapGeneration(false);
textureColor->setResizeNonPowerOfTwoHint(false);
textureColor->setTextureSize(800, 600);
textureColor->setInternalFormat(GL_RGBA);
textureColor->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
textureColor->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
textureColor->setInternalFormat(GL_RGBA16F_ARB);
textureColor->setSourceFormat(GL_RGBA);
textureColor->setSourceType(GL_FLOAT);

// Attach the texture and use it as the color buffer.
p_osgCamera->attach(osg::Camera::COLOR_BUFFER, textureColor);

// Create PPU pipeline
osgPPU::Processor* processor = new osgPPU::Processor();
processor->setCamera(p_osgCamera);

// Create colorby pass
osgPPU::UnitCameraAttachmentBypass* colorBypass = new osgPPU::UnitCameraAttachmentBypass;
colorBypass->setBufferComponent(osg::Camera::COLOR_BUFFER);

// Create test unit
osgPPU::UnitInOut* testUnit = new osgPPU::UnitInOut;
osg::Shader* fpShader = new osg::Shader(osg::Shader::FRAGMENT);

fpShader->setShaderSource("uniform sampler2D colorTexture;\n"
"void main() {\n"
" vec4 color = texture2D(colorTexture, gl_TexCoord[0].xy);\n"
" vec4 colorTmp = (color.x, color.y, color.z, color.w);\n"
"   gl_FragData[0] = colorTmp;\n"
"}\n");

// create shader attribute and setup one input texture
osgPPU::ShaderAttribute* shader = new osgPPU::ShaderAttribute;
shader->addShader(fpShader);
shader->add("colorTexture", osg::Uniform::SAMPLER_2D);
shader->set("colorTexture", 0);

// attach the shader
testUnit->getOrCreateStateSet()->setAttributeAndModes(shader);

// Create PPU output
osgPPU::UnitOut* ppuout = new osgPPU::UnitOut;
ppuout->setInputTextureIndexForViewportReference(-1);

// Setup pipeline ("p_osgRoot" is the OSG node used as sceneData for the "p_osgCamera" camera)
p_osgRoot->addChild(processor);
processor->addChild(colorBypass);
colorBypass->addChild(testUnit);
testUnit->addChild(ppuout);
Back to top
View user's profile Send private message
Aurelien
Appreciator


Joined: 03 Aug 2011
Posts: 297

PostPosted: Mon Oct 03, 2011 2:23 pm    Post subject:
Reply with quote

Ok, I found the solution...

An error in my shader code....

Embarassed
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 Select StateSet subset to render basi... chunyanggou General 0 Wed Jul 26, 2017 9:17 am View latest post
No new posts basic understanding wrong or my calcu... Assassin General 0 Sat Apr 18, 2015 7:31 pm View latest post
No new posts XCode + OSG - Basic shapes display pr... felipeberquo General 1 Fri Aug 29, 2014 5:27 pm View latest post
No new posts Basic intersection problem error General 0 Tue Feb 25, 2014 10:27 am View latest post
No new posts Basic intersection problem error General 0 Wed Dec 25, 2013 9:16 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