[osg-users] How to mix ViewDependentShadowMap with any other shader?

2014-02-18 Thread Angel
Hi,

I'm Angel Rodriguez.

Working in my application I have found a situation I do not know how to
solve.
How to mix ViewDependentShadowMap with any other shader? The idea is that
any child of shadowedscene have some extra shader.

I have tried differents mechanisms:

- VirtualProgram. As in the example of osgVirtualProgram, I can link
multiple shaders at different levels of the scene graph. Shaders merge
right, but it seems that run level node that has the lowest shader in the
graph, and the shadows are on top, so all cuts and properties of vdsm are
lost.

- ShaderAttribute. I tried to run the example of osgShaderComposition with
vdsm, but I still have the same problem above. Differents shaders are
merged as the graph be flown, but vdsm properties are lost.

- Deferred Shaders. As the Kornerr Implementation, OSG Deferred Shading
http://www.youtube.com/watch?v=AjWOSuLxZ68. With this method I have
combined the output of a shader with another implementing several RTT. But
in this case the final result is a texture that should put it in a HUD for
"falsifying" the view of the scene graph. For a good resolution in the
final textura I need to use big textures between shaders (output-input),
leading to hardware limitations on many computers.

What is the best solution to preserve ViewDependentShadowMap properties
adding new shaders at lower nodes of the scene graph.

Any help or advide will be appreciated.

Thannks in advance.

Angel.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problem with osgCamera->setColorMask() or bug?

2012-09-06 Thread Angel
Hi,

Thank you for the quick answer.

I have changed my code using your advice by the following lines, but it
doesn't work yet.

int main ( int argc, char * argv[] )
{
osgViewer::Viewer viewer;

const std::string filename = "..\\data\\cessna.osg";
 osg::ref_ptr model = osgDB::readNodeFile(filename);

if ( !model.valid() ) {
 std::cout << "Could not find: " << filename << std::endl;
}
 viewer.setSceneData(model.get());

viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );

// ColorMask
osg::ColorMask *color_red = new osg::ColorMask();
color_red->setMask(true, false, false, true);

viewer.getCamera()->setColorMask(color_red);  //<= DOES NOTHING!!

viewer.run();
}


I use OSG 3.0.1 for more information.

Thanks.


Angel Rodriguez.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Problem with osgCamera->setColorMask() or bug?

2012-09-06 Thread Angel
Hi everybody,

I have a very basic problem and I think I'm doing something wrong
or, maybe, there is a bug.

I've been looking for older posts but I haven't found the solution to
my problem.

In the following program I use setColorMask and it doesn't affect
the rendering in anyway, am I missing something? what am I doing wrong?

//
#include 
#include 
#include 
#include 

#include 
#include 


int main ( int argc, char * argv[] )
{
osgViewer::Viewer viewer;

const std::string filename = "..\\data\\cessna.osg";
osg::ref_ptr model = osgDB::readNodeFile(filename);

if ( !model.valid() ) {
std::cout << "Could not find: " << filename << std::endl;
}

viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );

// GraphicContext
osg::ref_ptr traits =
new osg::GraphicsContext::Traits;
traits->displayNum = 0;
traits->screenNum = 1;
traits->x = 10;
traits->y = 10;
traits->width = 1024;
traits->height = 768;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->samples = 8;
traits->alpha = 8;
traits->stencil = 8;
osg::ref_ptr gc
= osg::GraphicsContext::createGraphicsContext(traits.get());

// Camera
osg::Camera * camara = new osg::Camera();
camara->setGraphicsContext(gc.get());
camara->setViewport( new osg::Viewport(0,0, 1024, 768));
// ColorMask
osg::ColorMask *color_green = new osg::ColorMask( false, true, false, true);

camara->setColorMask(color_green ); //<= DOES NOTHING!!
 viewer.addSlave(camara);

viewer.setSceneData(model.get());

viewer.run();

return 0;
}

//

If I set the setColorMask directly to the cessna model it works perfectly
but I want to do it in the camera because I use the same model in other
cameras (that should not have the colorMask).

Thanks in advance for any help you can give me.



Angel Rodriguez.
Universidad de Valencia.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Export a vertex animation

2012-01-16 Thread Angel
Hi, I'm Angel,

How I can export a vertex animation from 3d studio to load in osg?
... I usally exported in a ive file format ... maybe I should use a
different file format.

Thanks.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgPPU] osgPPU and the stencil buffer

2011-07-16 Thread Miguel Angel Exposito
Hi,

As promised, here is the source code for the Jimenez's MLAA demo for OSG using 
OSGPPU. I haven't managed to figure out the stencil buffer thing yet, so if any 
of you guys is up to the challenge, any help would be greatly appreciated!

http://pixelclock.wordpress.com/2011/07/16/jimenezs-mlaa-port-to-openscenegraph/

... 


Thank you!

Cheers,
Miguel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=41402#41402





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgPPU] osgPPU and the stencil buffer

2011-06-06 Thread Miguel Angel Exposito
Thanks David!

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40121#40121





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgPPU] osgPPU and the stencil buffer

2011-06-03 Thread Miguel Angel Exposito
Come on, guys!!, a little help here :D

Sorry for bumping this but I couldn't figure out this yet :(

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40065#40065





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [osgPPU] osgPPU and the stencil buffer

2011-05-31 Thread Miguel Angel Exposito
aderAttribute();

blendShader->addShader(osgDB::readShaderFile("Shaders\\blend_frag.frag", 
fragmentOptions.get()));

blendShader->addShader(osgDB::readShaderFile("Shaders\\offset_vert.vert", 
vertexOptions.get()));
blendShader->setName("BlendShader");

pixelBlend->setInputToUniform(weightsCalculation, "blendMap", true);

blendShader->add("pixelSize", osg::Uniform::FLOAT_VEC2);
blendShader->set("pixelSize", pixelSize);


pixelBlend->setInputToUniform(bypass, "colorMapL", true);

pixelBlend->getOrCreateStateSet()->setAttributeAndModes(blendShader);

// Attach the 'useMask' stencil
pixelBlend->getOrCreateStateSet()->setAttributeAndModes(useMaskStencil, 
osg::StateAttribute::ON);
pixelBlend->getOrCreateStateSet()->setMode(GL_STENCIL_TEST, 
osg::StateAttribute::ON);

}


   // This output unit just acts as a switch for displaying the original RTT, 
the final processed image or the textures inbetween (edges and weights)
   unitOut= new osgPPU::UnitOut(); 
   shaderAttributeOut= new osgPPU::ShaderAttribute(); 
   { 
  osg::Shader* shader= new osg::Shader(osg::Shader::FRAGMENT); 
  const char* shaderSource= 
 "uniform sampler2D finalMap;\n" 
 "uniform sampler2D edgesMap;\n"
 "uniform sampler2D weightsMap;\n"
 "uniform sampler2D colorMap;\n"
 "uniform int switchFlag;\n"
 "void main()\n" 
 "{\n" 
 "if(switchFlag == 0)\n" 
 "  gl_FragColor=texture2D(edgesMap,gl_TexCoord[0].st);\n" 
 "else if(switchFlag == 1)\n" 
 "  gl_FragColor=texture2D(weightsMap,gl_TexCoord[0].st);\n" 
 "else if(switchFlag == 2)\n" 
 "  gl_FragColor=texture2D(finalMap,gl_TexCoord[0].st);\n" 
 "else if(switchFlag == 3)\n" 
 "  gl_FragColor=texture2D(colorMap,gl_TexCoord[0].st);\n" 
 "}"; 
  shader->setShaderSource(shaderSource); 
  shaderAttributeOut->addShader(shader); 
  shaderAttributeOut->setName("nomShaderAttribute"); 

  shaderAttributeOut->add("switchFlag", osg::Uniform::INT);
  shaderAttributeOut->set("switchFlag", 2);


  unitOut->setInputToUniform(pixelBlend, "finalMap", true);
  unitOut->setInputToUniform(edgeDetection, "edgesMap", true);
  unitOut->setInputToUniform(weightsCalculation, "weightsMap", true);
  unitOut->setInputToUniform(bypass, "colorMap", true);
  unitOut->setInputTextureIndexForViewportReference(1);// Choose to 
have an output the same size as edgesMap has


  unitOut->setName("MLAA.finalOutputUnit"); 
  unitOut->setViewport(new osg::Viewport(0,0, 
camera->getGraphicsContext()->getTraits()->width,
  
camera->getGraphicsContext()->getTraits()->height));

  
unitOut->getOrCreateStateSet()->setAttributeAndModes(shaderAttributeOut.get()); 

  // It looks like for some reason no stencil testing is performed at 
all unless I enable the GL_STENCIL_TEST in this unit
  // Let's recall that the testStencil does always pass
  unitOut->getOrCreateStateSet()->setAttributeAndModes(testStencil, 
osg::StateAttribute::ON);
  unitOut->getOrCreateStateSet()->setMode(GL_STENCIL_TEST, 
osg::StateAttribute::ON);

   } 

// Link the units
   
   bypass->addChild(edgeDetection);
bypassDepth->addChild(edgeDetection);
edgeDetection->addChild(areaTexture);
edgeDetection->addChild(weightsCalculation);
areaTexture->addChild(weightsCalculation);
weightsCalculation->addChild(pixelBlend);
pixelBlend->addChild(unitOut);

   m_processor->addChild(bypass);
m_processor->addChild(bypassDepth);
finalGroup->addChild(m_processor);

m_processor->dirtyUnitSubgraph();


// Set the edges texture properties
{
osg::Texture2D *outTex = 
static_cast(edgeDetection->getOrCreateOutputTexture());
if(outTex)
{

outTex->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);

outTex->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

outTex->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER); 

outTex->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER); 
}
}

// Set the weights texture properties
{
osg::Texture2D *outTex = 
static_cast(weightsCalculation->getOrCreateOutputTexture());
if(outTex)

[osg-users] [osgPPU] osgPPU and the stencil buffer

2011-05-28 Thread Miguel Angel Exposito
Hi,

I'm pretty new to osgPPU and I'm working on a port of Jimenez's MLAA full scene 
antialiasing algorithm.

It's a 3-pass post processing effect and I got it working on osgPPU.

- The first step detects the edges of the RTT'd scene and makes an 'edge 
texture'.
- The second step uses the previous texture and a precomputed one to calculate 
the area which pixels belonging to an edge would cover from an ideal trapeze.
- The final step blends each pixel in its 4-neighborhood according to the 
weights calculated in the previous step.

I got it fully working in osgPPU, however, an important optimization can be 
done by using the stencil buffer. The idea behind this is:

- Initially the stencil is cleared out to 0

- The first step of the post effect (edges detection) creates a stencil mask 
writing 1's to the stencil wherever there's an edge pixel. The pixels not 
belonging to an edge are discarded in the shader, so no writting to the stencil 
will occur in that case.

- In the subsequent steps the stencil test discards every pixel not covered by 
the mask, hence only the edge pixels are processed (weights calculation and 
final blend).

And this is how I tried to achieve it:

- I created two osg::Stencils, one for creating the mask and other for using 
the mask and discarding everything else.
- I attached the stencils to their corresponding osgPPU::Unit's.

(now, I need to clear the stencil at the beginning of the postFX chain, but not 
between each pass)
- I'm not sure about where glClear (with the clear mask of the camera the 
osgPPU::Processor is using) is called, but my guess is when rendering the scene 
to texture, not between units so I think that setting the clearMask in the 
camera is pointless.
- I tried to call glClear(GL_STENCIL_BUFFER_BIT) in a notify callback set in 
the first unit of my chain.


This has been driving me nuts for a couple of days now. It seems that the 
stencil buffer is not being written, or cleared prematurely between passes. And 
the stencil test only seems to be done if I enable it in the last unit's 
stateset.

What am I missing?

I can post the code if you want!

... 


Thank a lot in advance!

Cheers,
Miguel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=39894#39894





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] MLAA port

2011-05-28 Thread Miguel Angel Exposito
Hi,
Thank you for your answer.

I got it working on osgPPU and I'll be releasing the source code in a few days. 
I'll keep you guys updated.

Before releasing I want to see if I can solve a problem I'm having with osgPPU 
and the stencil buffer which would yield a great performance boost.

I think I'm gonna ask in the osgPPU subforum :D


> 
> I've also created a post-processing framework in the osgXI project
> (...), called osgPostEffect
> 


That sounds extremely interesting to me!. Is it documented or has any 
demos/tutorial?

... 

Thank you!

Cheers,
Miguel[/quote]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=39893#39893





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] MLAA port

2011-05-22 Thread Miguel Angel Exposito
Hi,

I'm porting Jimenez's Morphological Antialiasing implementation to GLSL. It's 
implemented as a multipass (three passes) post processing effect.

I already got the shaders working and an OpenGL demo and now I'm wondering 
about making it work on OSG.

My question is: What would be the best way to do it? (making an osgPPU, 
osgPlugin, ...?

... 

Thank you!

Cheers,
Miguel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=39617#39617





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] The models I load in OSG look blue

2009-06-27 Thread Miguel Angel
Hi,
The 3D models i use (using OsgCal3D) looks blue (sometimes yellow) when the 
view is far away from them, but if i get really close to them, they look as 
they are supposed to look, indeed they look okey in the osgViewer.

I coded my own Camera manipulator, but even with the osg ones (trackball, 
drive...) it looks blue, so i think it is a problem about how i create the 
window (or maybe the viewer)

Has anyone got any idea of what i am doing wrong?

Here some pics: 
  http://img514.imageshack.us/i/yo1n.jpg/  >> The humans models which use 
osgcal are blue, but not the others that are directly loaded
  http://img194.imageshack.us/img194/2739/closeh.jpg  >> If i move closer, 
the models look as they are

Here the code:
http://utilitybase.com/paste/14973  >> I use some other classes i 
define, but that is the main code of the visual part  

I am running OSG 2.4.0

Thank you!

Cheers,
Miguel

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=14618#14618





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org