Re: [osg-users] Issue on using pure OpenGL in custom drawables

2008-12-09 Thread Christian Heine
Hi,

thanks for the hints, the definition of a valid bounding box on my
custom drawable has solved the issue.

Best regards,
Christian

Ulrich Hertlein wrote:
> Hi Christian,
> 
> On 9/12/08 7:34 PM, [EMAIL PROTECTED] wrote:
>> What me confused is, that the point sprite is rendered correctly (on
>> the right side of
>> the coordinate system with a positive x value*) if i add any reference
>> model to the
>> scene (in my case a simple osg shape). If i remove the model, the
>> point sprite is
>> rendered on the left side of the origin, independend if i use glPush
>> or not  ...
> 
> As was already mentioned osgViewer tries to center the camera on the
> scene.  I believe the invalid bbox is messing things up and osgViewer is
> placing the camera somewhere (0,y,0) looking at (0,0,0).  You could
> check this by placing three points at (1,0,0), (0,1,0) and (0,0,0).
> 
> Give your Drawable a proper bbox and things will be okay.
> 
> Cheers,
> /ulrich
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 

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


Re: [osg-users] osgWidget::Label texturing bug?

2008-10-10 Thread Christian Heine
Hi Jeremy,

thanks for your fast reply.

> You shouldn't have to manually set the texture coordinates like that if
> you don't want; you could use ->setImage("...", true) with the right Y
> setting in the WindowManager and it should behave how you want. Either
> way is fine, though. :)

Yes i know, this was just implemented while i got no label texture
working. ;o)

> I don't think there's a bug. Try calling:
>
>   left->setColor(1.0f, 1.0f, 1.0f, 1.0f);

Damn stupid! I was blink by testing! This was my fault. Thanks for the
hint. You prevent me from sleepless nights ;o)

Best regards,
Christian




Jeremy Moles wrote:
> On Fri, 2008-10-10 at 17:58 +0200, Christian Heine wrote:
>> Hi folks,
>>
>> I'm actually integrate osgWidget as GUI library in our engine. I know
>> it's beta status, but it's pure OSG and we think a better solution
>> than other third libraries like CEGUI.
>>
>> My first test are working well. Now i try to extend simple things,
>> i.e. add a mechanism to set textures for the widgets. I got the
>> problem that i couldn't define a texture for a Label, which is an
>> extension of the main widget class.
>>
>> This code snippet works well on a osgWidget::Widget:
>>
>> osgWidget::Widget* left   = new osgWidget::Widget("left");
>> left->addSize(300.0f, 42.0f);
>> left->setImage  ("gfx/tga/bar.tga", false);
>> left->setCanFill(true);
>> left->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
>> left->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
>> left->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
>> left->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
>> m_container->addWidget(left);
> 
> You shouldn't have to manually set the texture coordinates like that if
> you don't want; you could use ->setImage("...", true) with the right Y
> setting in the WindowManager and it should behave how you want. Either
> way is fine, though. :)
> 
>> But when i change the initialization to an osgWidget::Label instance,
>> i got the label without any texture. Is this a known bug?
> 
> I don't think there's a bug. Try calling:
> 
>   left->setColor(1.0f, 1.0f, 1.0f, 1.0f);
> 
> ...and it should be just fine. Be default, a Label object sets it's
> Widget color to be completely transparent, so I'm guessing the texture
> is there just not visible (or rather, it's alpha is 0.0f).
> 
>> I think it should be possible to define a textured background for a
>> label while you could define the label as semi or non transparent...
>>
>> Best regards,
>> Christian
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
> 
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 

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


[osg-users] osgWidget::Label texturing bug?

2008-10-10 Thread Christian Heine
Hi folks,

I'm actually integrate osgWidget as GUI library in our engine. I know
it's beta status, but it's pure OSG and we think a better solution
than other third libraries like CEGUI.

My first test are working well. Now i try to extend simple things,
i.e. add a mechanism to set textures for the widgets. I got the
problem that i couldn't define a texture for a Label, which is an
extension of the main widget class.

This code snippet works well on a osgWidget::Widget:

osgWidget::Widget* left   = new osgWidget::Widget("left");
left->addSize(300.0f, 42.0f);
left->setImage  ("gfx/tga/bar.tga", false);
left->setCanFill(true);
left->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
left->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
left->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
left->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
m_container->addWidget(left);

But when i change the initialization to an osgWidget::Label instance,
i got the label without any texture. Is this a known bug?

I think it should be possible to define a textured background for a
label while you could define the label as semi or non transparent...

Best regards,
Christian

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


[osg-users] Bug in regarding uniform values?

2008-06-13 Thread Christian Heine

Hello,

in the last few day's i posted in the Issue on sharing shaders between 
objects thread, that i've trouble in sharing shaders and unfiorms. If 
i create two shaders (dot3) and two objects i got the same shader 
result on each object.


Now i figured out, that the failure occurs if i use the same code for 
the geometry generation of the objects and transform them with 
osg::PositionAttitudeTransform on differend positions. It seems too 
me, that this transformations are ignored on shader execution. If i 
create (simple plane) the transformed object with transformation 
values on geometry generation all seems to handled correct ...


Is this a possible bug? Or is this intend and i have to consider 
something else?


Best regards,
Chrisitan

P.S.: I've added the manipulated shadertest source where the 2nd quad 
has a generated geometry regarding the transformation...




// Copyright (C) 2007 Binary Revolution - http://www.binary-revolution.org
//
//  This file is part of ##NAME##.
//
// ##NAME## is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// ##NAME## is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see .

#include 
#include 
#include 
#include 

#include 
#include 
#include 

#include "OSGView.h"
#include "OSGCompositeViewer.h"

#include 
#include 
#include 
#include 

#include 
#include 
#include 

osg::Light* light;
osg::ref_ptr sphereXForm;

enum keyCode{KEY_UP = 0xFF52, KEY_DOWN=0xFF54, KEY_LEFT=0xFF51 , 
 KEY_RIGHT=0xFF53, KEY_PAGE_DOWN = 0xFF56, KEY_PAGE_UP = 0xFF55};

const float MOVE_VALUE = 0.5f;

/** Update-Callback for light source updates */
class updateLightSource : public osg::Uniform::Callback
{
public:
   virtual void operator() 
  ( osg::Uniform* uniform, osg::NodeVisitor* nv )
   {  
  osg::Vec4 pos = light->getPosition();
  uniform->set(osg::Vec4(pos.x(), pos.y(), pos.z(), 1.0f));
   }
};


/** Update-Callback for light source updates */
class updateCamera : public osg::Uniform::Callback
{
public:
   updateCamera(osg::ref_ptr camera):m_camera(camera){}

   virtual void operator() 
   ( osg::Uniform* uniform, osg::NodeVisitor* nv )
   {  
 	osg::Vec3 eye, up, center;
   	m_camera->getViewMatrixAsLookAt(eye,up,center);
uniform->set(eye);
   }

private:
   osg::ref_ptr m_camera;
};

/** Simple key event handler to move light source */
class myKeyboardEventHandler : public osgGA::GUIEventHandler
{
public:
   virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
   virtual void accept(osgGA::GUIEventHandlerVisitor& v)   { v.visit(*this); };
};

bool myKeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
 {
   switch(ea.getEventType())
   {
   case(osgGA::GUIEventAdapter::KEYDOWN):
  {
 switch(ea.getKey())
 {
 case KEY_UP:
 {  
	osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x(), pos.y(), pos.z()+ MOVE_VALUE, pos.w()));
sphereXForm->setPosition(osg::Vec3(pos.x(), pos.y(), pos.z()+ MOVE_VALUE));

return false;
break;
 }
	 case KEY_DOWN:
 {  
 	osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x(), pos.y(), pos.z()- MOVE_VALUE, pos.w()));
sphereXForm->setPosition(osg::Vec3(pos.x(), pos.y(), pos.z()- MOVE_VALUE));

return false;
break;
 }
	 case KEY_LEFT:
 {  
 	osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x() - MOVE_VALUE, pos.y(), pos.z(), pos.w()));
	sphereXForm->setPosition(osg::Vec3(pos.x()- MOVE_VALUE, pos.y(), pos.z()));

return false;
break;
 }
	 case KEY_RIGHT:
 {  
 	osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x() + MOVE_VALUE, pos.y(), pos.z(), pos.w()));
sphereXForm->setPosition(osg::Vec3(pos.x()+ MOVE_VALUE, pos.y(), pos.z()));

return false;
break;
 }
	 case KEY_PAGE_UP:
 {  
osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x(), pos.y() + MOVE_VALUE , pos.z(), pos.w()));
sphereXForm->setPosition(osg::Vec3(pos.x(), pos.y()+ MOVE_VALUE, pos.z()));
return false;
break;
 }
	 case KEY_PAGE_DOWN:
 {  
osg::Vec4 pos = light->getPosition();
	light->setPosition(osg::Vec4(pos.x(), pos.y(

Re: [osg-users] Issue on sharing shaders between objects

2008-06-05 Thread Christian Heine

Hi Mike,

thanks for the hint, but this is not the failure. This is the normal 
way to bind the program to the different state sets and it works.


Meenwhile I think that I've a problem with the actualization of the 
program and/or shaders. So I've called the setDirty methods on all

but with no positive result ...

Best regards,
Christian



Mike Weiblen wrote:

This caught my eye:


 state->setAttributeAndModes(prg.get(), osg::StateAttribute::ON);
 }
 // otherwise bind the program and deactivate it.
 else{
 state->setAttributeAndModes(m_program.get(),

osg::StateAttribute::OFF);

 }


osg::StateAttribute::ON/OFF does not work on osg::Program, as GL does
not use glEnable/glDisable on glPrograms.  GL disables an active
glProgram with glUseProgram(0); the equiv in OSG is to attach an "empty"
osg::Program (one that has no osg::Shaders attached)  Perhaps that is
confusing the OSG state manager, causing this failure?

-- mew




-Original Message-
From: [EMAIL PROTECTED] [mailto:osg-users-
[EMAIL PROTECTED] On Behalf Of Christian Heine
Sent: Thursday, June 05, 2008 11:34 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Issue on sharing shaders between objects

Hello,

i've played arround with this issue, but i could solve it until now.
First i thought there may be a problem with the reusage of the
program, but when i copy it instead of sharing, nothing happends, i
got the same failure.

// finaly bind the program and activate it if it is user enabled
 if(this->m_userEnabled){

 for(uniforms_t::iterator uniIter =

m_uniformCache.begin();

 uniIter != m_uniformCache.end();
 uniIter ++){
 // add all uniforms from the list to the state
 state->addUniform((*uniIter).second.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE |
osg::StateAttribute::PROTECTED);
 }

/* fake for copy program
 osg::ref_ptr prg = new osg::Program;
 prg->addBindAttribLocation("tangent",
osg::Drawable::ATTRIBUTE_6);
 prg->addBindAttribLocation("binromal",
osg::Drawable::ATTRIBUTE_7);

 boost::shared_ptr technique =
 this->getOSGTechnique(AbstractTechnique::VERSION_PS30);

 // convert BinRev shader params to osg::Uniform and
osg::Attribute objects
 for( unsigned int i = 0;
  i <  technique->getNumberOfShaders();
  i++)
 {
 boost::shared_ptr shader =

boost::dynamic_pointer_cast(technique->getShader(i));
 prg->addShader(shader->getShader().get());
 }
*/

 state->setAttributeAndModes(prg.get(),
osg::StateAttribute::ON);
 }
 // otherwise bind the program and deactivate it.
 else{
 state->setAttributeAndModes(m_program.get(),
osg::StateAttribute::OFF);
 }
 }

There is nothing realy special...
I've attached an image to show what's going wrong.

Has anyone a hint what could be going wrong? I'm running out of

ideas..

Best regards,
Christian






[EMAIL PROTECTED] wrote:

Hello,

i've successfully implemented a simple dot3 object shading for my

scene and

it works fine with single objects. Now i try to share the shaders

between

different objects in the scene and got some trouble:

To share the shaders i've one osg::Program, where i've added two

osg::Shader

objects. The osg::Program instance is shared between the objects and

applied

to their osg::StateSet objects. The required osg::Uniform objects

are

created

explicit for each object and bind to their osg::StateSet in a

separated process.

So only the osg::Program and osg::Shader are Shared (later i will

share the

equal uniforms too).

The shader works, but it's effected on all objects equals to the

object where

the osg::Program has applied first. I.e. i've added two normal

mapped

cubes in

the scene. When i set the light between both cubes i expect that

both

cube faces

are enlighted arround the light, but on the 2nd cube the thame face

of the first

cube is enlighted...

Have i consider something special for the sharing of (object)

shaders

between

objects?

Best regards,
Christian



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

openscenegraph.org


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



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


Re: [osg-users] Dilemma with the usage of object Shaders in differend views ...

2008-04-08 Thread Christian Heine
Hello Guy,

>I think attaching a shader to each view instead of to object X would be
>fine.

I'm not sure if this may be the right thing. Correct me if I'm wrong but 
this causes
in some other issues:

1. I lost the reference to the specifiv object states like Textures, 
Geometries etc. How
does the shader should access this values by differend objects?

2. If i bind it to the view, each object is rendered with this shader. 
So i shouldn't have
the ability to separate shaders and effects between objects ...

>If you want to use the callback I think you should create a pre-draw
>callback to the object, which I'm not sure possible. The update
>callbacks won't help you since it run on all the scene before the
>rendering and then only the last setting of the shader will be set, and
>it also might affect performance. So I still think attaching shaders to
>the views would do what you want.

Ok, this is an argument i've to agree. But if If i overload the render 
method of the
composite viewer i could implement "callbacks" (better update sequences) 
for each
object before calling the parent rendering method, so this should be 
possible. But i
am not sure about possible perfomance lacks ...

Best regards,
Chrsitian



Guy wrote:
> Hello,
>  I think attaching a shader to each view instead of to object X would be
> fine.
>  If you want to use the callback I think you should create a pre-draw
> callback to the object, which I'm not sure possible. The update
> callbacks won't help you since it run on all the scene before the
> rendering and then only the last setting of the shader will be set, and
> it also might affect performance. So I still think attaching shaders to
> the views would do what you want.
>
> Guy.
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> [EMAIL PROTECTED]
> Sent: Tuesday, April 08, 2008 10:55 AM
> To: osg-users@lists.openscenegraph.org
> Subject: [osg-users] Dilemma with the usage of object Shaders in
> differend views ...
>
> Hi folks,
>
> actually i am working on object shading with OSG (i.e. Dot3). All works
> fine
> with single views. Now i am using the osgViewer::Composite viewer and
> getting
> some dielemma with the usage of object based shaders in differend views
> based
> on the same scene graph.
>
> I.e.: I've a single scene node with an object X where i bind the shaders
> (at 
> the object StateSet) for execution. In a single view no problem. If i
> use this scene in 
> multiple views (i.e. A, B) i've the dilemma, that i've to use diffrend
> shader params
> on the same shader instance. In each rendering pass the params of the
> camera
> are differend from the point of view of the views, if the views are
> rendered. But
> the shader has no knowledge about this, it uses only a single uniform to
> hook bind
> param ...
>
> I've thought about the following sollutions:
>
> 1. Using for each view a single shader instance at the same object
> StateSet.
> Is this usefull? If the scene is complex i could get a huge count of
> shaders
> which have to be executed. Additionally i'm not sure, if the binding of
> the "unused"
> shaders produces render artifacts or perfomance issues...
>
> 2. Using a callback mechanism which switches this values at the shader
> before 
>rendering
>
> How i could achieve this aim in best way? Has anyone a better solution? 
>
> Best regards,
> Christian 
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
> g
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>   

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


Re: [osg-users] Issue on blur test

2007-11-20 Thread Christian Heine
Hello,

to get my blur shader working I've modified my code in the last few
hours, based on an old OSG thread of Marcus Fritzen and Shuxing Xiao,
where they have tried to implement a multipass based shader. To follow
theirs instructions I've added another camera to render the 2nd RTT. So
i got these steps, where each step implements a camera:

1. Render Scene to RTT1  (texture)
2. Render Scene to RTT2 (texture2) and bind Shader to the camera
StateSet where the RTT1 is the input for the shader and RTT2 the output
3. Create Render-Quad bind RTT2 as texture and render it.

If i disable step 2 nothing is rendered, because the RTT2 is invalid,
what is correct. If i enable Step 2 i got the scene result on the quad.
But the shader is not executed. Is it impossible to execute a shader
using the camera states?

If i bind the shader to the quad StateSet the shader is executed
(colored shader output) but the blurring is missed. The blur code is
quite simple and should work:

vec4 currentValue = texture2D (Next, vTexCoord).rgba;
 vec4 lastValue = texture2D (Prev, vTexCoord).rgba;
   
 // the resulting color value is the combination of blurred and
non-blurred map
gl_FragColor = mix(currentValue, lastValue, fBlur); //*vec4(1.0, 1.0,
0.0, 0.0);

I'm running out of ideas what could be conceptional wrong. Every help is
preferable.
Best regards,
Christian

P.S.: I've attached the new modified code fragment to this post.

Christian Heine wrote:
> Hello,
>
> actually i try to integrate a blur shader to my test scene. To realize
> this I've implemented a small scene with a dot3 textured quad (done by a
> shader). This scene is rendered to a texture oriented on the distortion
> example. This works fine, but when i bind the secondary blur shader on
> this render to texture pass i got no blur effect. The 2nd shader is
> definitively executed, if i set the glFragColor of this second shader to
> some test value (i.e. blue) the texture is rendered by this color value.
> I've attached the actual rtt-Pass with the 2nd shader binding. Have i
> overseen something?
>
> Best regards,
> Christian
>
>   

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


[osg-users] Issue on blur test

2007-11-18 Thread Christian Heine
Hello,

actually i try to integrate a blur shader to my test scene. To realize
this I've implemented a small scene with a dot3 textured quad (done by a
shader). This scene is rendered to a texture oriented on the distortion
example. This works fine, but when i bind the secondary blur shader on
this render to texture pass i got no blur effect. The 2nd shader is
definitively executed, if i set the glFragColor of this second shader to
some test value (i.e. blue) the texture is rendered by this color value.
I've attached the actual rtt-Pass with the 2nd shader binding. Have i
overseen something?

Best regards,
Christian

   
   // set up the render to texture camera.
   {
float m_height = 1024.0f;
float m_width = 1280.0f;

osg::Geode* m_geode = new osg::Geode();
osg::Geometry* m_geometry = new osg::Geometry();   

osg::ref_ptr vertices = new osg::Vec3Array();
vertices->push_back( osg::Vec3( 0,0,-1) );  //Lower-left 
vertex 
vertices->push_back( osg::Vec3(m_width,  0,-1) );   
//Lower-right vertex
vertices->push_back( osg::Vec3(m_width, m_height,-1) ); //Upper-right 
vertex
vertices->push_back( osg::Vec3( 0, m_height, -1) ); 
//Upper-left vertex
m_geometry->setVertexArray(vertices.get());

// Set the normal in the positive z direction (torwards the user)
osg::ref_ptr normals = new osg::Vec3Array();
normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
m_geometry->setNormalArray(normals.get());
m_geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);   

osg::ref_ptr texcoords = new osg::Vec2Array();
texcoords->push_back(osg::Vec2(0.0f,0.0f));
texcoords->push_back(osg::Vec2(1.0f,0.0f));
texcoords->push_back(osg::Vec2(1.0f,1.0f));
texcoords->push_back(osg::Vec2(0.0f,1.0f));
m_geometry->setTexCoordArray(0,texcoords.get());
 
osg::ref_ptr colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(0.8f,0.8f,0.8f,0.8f));
m_geometry->setColorArray(colors.get());
m_geometry->setColorBinding(osg::Geometry::BIND_OVERALL);

// define render mode and attach to geode
m_geometry->addPrimitiveSet(new osg::DrawArrays 
(osg::PrimitiveSet::QUADS, 0, vertices->size()));
m_geode->addDrawable(m_geometry);

// new we need to add the texture to the Drawable, we do so by creating 
a 
// StateSet to contain the Texture StateAttribute.
osg::StateSet* stateset = m_geometry->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0, 
texture,osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);

// create Shader sources
osg::Program* m_program = new osg::Program();
osg::Shader* m_vertexShader = new osg::Shader(osg::Shader::VERTEX);
osg::Shader* m_pixelShader  = new osg::Shader( osg::Shader::FRAGMENT );

bool ok = loadShaderSource(m_vertexShader, "shader/motion.vert") 
&& loadShaderSource(m_pixelShader, "shader/motion.frag") ; 

if(!ok)
{
std::cout << "Couldn't load shaders" << std::endl;
exit(1);
}

m_program->addShader(m_vertexShader);
m_program->addShader(m_pixelShader);

osg::Texture2D* texture2 = new osg::Texture2D;
texture2->setTextureSize(tex_width, tex_height);
texture2->setInternalFormat(GL_RGBA);
texture2->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture2->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
stateset->setTextureAttributeAndModes(1, 
texture2,osg::StateAttribute::ON);

stateset->setAttributeAndModes(m_program, osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("Prev", 0));
stateset->addUniform(new osg::Uniform("Next", 1));
stateset->addUniform(new osg::Uniform("fBlur", 0.90500f));

// set up the camera to render the textured quad
osg::CameraNode* camera = new osg::CameraNode;

// just inherit the main cameras view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);

// set the camera to render before the main camera.
camera->setRenderOrder(osg::CameraNode::NESTED_RENDER);

// tell the camera to use OpenGL frame buffer object where supported.

camera->setRenderTargetImplementation(osg::CameraNode::FRAME_BUFFER_OBJECT);

// attach the texture and use it as the color buffer.
camera->attach(osg::CameraNode::COLOR_BUFFER, texture2);

// add subgraph to render
camera->addChild(m_geode);

quadNode->addChild(camera);
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org

Re: [osg-users] Multipass shading, black texture coming out of the first pass

2007-10-18 Thread Christian Heine
Hello Swen,

i will take a look at your code when i am back from office. Before i
have an
additional information for you:

Yesterday i've played a little bit arround with my solution and try to
solve the
problem in a first dirty solution. For that i've created two HUD
surfaces. The
first where i bind the 2nd Pass shader (set glFragColor to red to check
if it is
executed) and a second where i bind the texture of the second pass RTT.

This 2nd RTT shows me the same result as the first rtt and not the red
colored
result of the 2nd pass. First i thought this was an other bug, but i've
thought
a little bit about it and now i think it's correct... I think the
failure could
be in the binding of the cameras of the rrt's!

The RTT camera of the second pass points to the same object like the
first RTT
camera. The result of the second pass is shown to the hud, so it's
impossilbe
that the second RTT shows a red colored object ...

Perhaps it help's you to find a solution.

Best regards,
Chrsitian


Swen Walkowski wrote:
> Hello Christian,
>
> thanks for your answerer. I modified my code the last days a lot. Now
> I am sure that my shaders are executed.
> Now I still have the same problem like you. I always get the last
> shader displayed.
>
> To add the shaders to the graph I use that code:
> Shader* invertShader = new Shader(Shader::INVERT, false, NULL, 0);
> videoBackground->addChild(invertShader->getCamera());
>
> Shader* discardShader = new Shader(Shader::DISCARD, true,
> invertShader->getTexture(), 1);
> videoBackground->addChild(discardShader->getCamera());
>
> videoBackground.get()->setStateSet(discardShader->getStateSet());
> videoBackground.get()->init();
>
> I add my new code if you want take a look in.
> Hope we will find a way to solve that problem. I am still on it.
>
> Please let me know when you found out something.
>
> Best,
> Swen
> 
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>   

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


Re: [osg-users] Multipass shading, black texture coming out of the first pass

2007-10-17 Thread Christian Heine
Hello Swen,

in the last few days i've figured out, that i have a bug in my multipass
soluiton.
For this bug, i've actually no idea how i could solve the problem

The problem occurs with the execution of the passes. Each pass holds an
osg::StateSet
where the Shaders and textures are bound for execution. Actually this
StateSet must
be an element of the SceneGraph for execution. This is not the problem,
if the Shader
is an object refered shader like a dot3 Shader.

But the dilemma is, that you don't have allways object refered shaders,
sometimes
the shader is not part of an object (Blur, HDR ect.), which will
actually not be
executed. The other problem of the dilemma occurs, if you got more
shaders which are
object refered (p.e. dot3, phong lighting). If you bind more than one
state to the
object, only the last state will be executed ...

One Solution may be a render quad for each pass, which is executed
(rendered)
explicit outside the graph, to force the execution. But i  don't have a
solution how this
could be realized...

I think this could be a part of your issue. Are you sure, that your
first shader is executed?

Best regards,
Christian



Swen Walkowski wrote:
> Hello all,
>
> first I am sorry that I start a new thread, but I do not have the old
> mail here that I can answer it. That thread refer to: [osg-users]
> Multipassshading in OSG v1.2
>
> I done a look in the source code from Christian, with that code I
> tried to extend my shader for a static 2 pass shader.
>
> That is the shader class is in the attachmend (Shader.cpp).
> In the attachmend you will see the output (2Pass.JPG).
> You just will see the the point (right upper corner) but not the live
> video stream from the camera and the output from the discard shader.
>
> I try to use osgart. The first texture, who the constructor gets and
> put it to the first shader pass is the live picture. What I get out of
> that pass I try to put in the second pass and than display it.
>
> So maybe someone can help me!
>
> Thanks Swen
>   
> 
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>   

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


Re: [osg-users] Multipassshading in OSG v1.2

2007-10-11 Thread Christian Heine
Hi Sven,
i must agree Gerrick, one possible way to implement a multipass shading
in OSG is using the osgFX libary. It's stable and work well, but i think
a big disadvantage of this libary is the inflexibility. Each Shader you
will have to bind must be implemented separatly by overwriting special
traverse methods. If you want to be more flexible, it's up to you, to
make it possible.

Actually i work on a more flexible approach (many other members too),
which should allow to get this flexibility by using configuration files.
This way is not easy but possible. If you look in the threads of this
month, you can find one post of me with all sources of the actually test
code. My code works, but i have some trouble with the RTT cameras. Fell
free to check my sources, perhaps it could push you on the right track,
if you want to make your own solution.

Best regards,
Christian


Gerrick Bivins wrote:
> I think osgFX is where you want to look. That nodekit has some classes
> Technique, Effect etc that allow you to define multiple passes. I
> haven't used it personally but a developer in our group has used it
> quite a bit. If you look at  osgfxbrowser example, I think it has
> sample code but I'm not sure if it shows how to do multipass.
>
> On 10/11/07, *Swen Walkowski* <[EMAIL PROTECTED]
> > wrote:
>
> Hello all,
>
> i try to do Multipassshading in OSG v1.2.
> I have written my own shader class in the class I use the osg::shader
> for shading. At the time my shading code looks like that:
> Shader::Shader(void) {
> //creating program
> program = new osg::Program;
>
> //creating shader
> vertShader = new osg::Shader(osg::Shader::VERTEX);
> fragShader = new osg::Shader(osg::Shader::FRAGMENT);
> }
>
> Shader::~Shader(void) {
> }
>
> void Shader::apply(osg::StateSet& state) {
> state.setAttributeAndModes(program, osg::StateAttribute::ON);
>
> vertShader->loadShaderSourceFromFile("shaders/Fixed_Functionality.vert");
> fragShader->loadShaderSourceFromFile("shaders/Fixed_Functionality.frag");
>
> program->addShader(vertShader);
> program->addShader(fragShader);
>
> //parameterize the shader with video texture (0 by default)
> state.addUniform(new osg::Uniform("texture", 0));
>
> posXUniform = new osg::Uniform("posX", (float)0.0);
> posYUniform = new osg::Uniform("posY", (float)0.0);
> intensityUniform = new osg::Uniform("intensity", (float)1.0);
> radiusUniform = new osg::Uniform("radius", (float)0.2);
>
> state.addUniform(posXUniform);
> state.addUniform(posYUniform);
> state.addUniform(intensityUniform);
> state.addUniform(radiusUniform)
> }
>
> That works well.
>
> Now i try to add an secend shading pass. I have read a lot over
> rendering to texture (RTT) in OSG in the mailinglist. So I tryed to
> find the examples or something in the OSG documentation.But without
> luke.
>
> Hope someone can tell me were I find the documentation for
> Multipassshading in OSG or an example or maybe how it works.
>
> Thangs,
> Swen
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
> 
>
>
> 
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>   

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


Re: [osg-users] Several RTT camera/shader issue(s) on multipass shading

2007-10-07 Thread Christian Heine
Hi Mihai,

>A short comment before looking at any of the code ( can't open the zip ).

I've checked the zip File, it's working for me (i've open it with 7zip)
, independent
of using windows or Linux as OS. If you got anymore trouble with this
file, i
could send the zip-file to your private mail address separately, if you
wish.

The coords for the textureUnits are hard coded in the OSGObjects class,
where i
define the quad and the hud objects. These are standard coords and there
should
be no problems with them:

osg::ref_ptr texCoords = new osg::Vec2Array();
texCoords->push_back(osg::Vec2(0.0f,0.0f));
texCoords->push_back(osg::Vec2(1.0f,0.0f));
texCoords->push_back(osg::Vec2(1.0f,1.0f));
texCoords->push_back(osg::Vec2(0.0f,1.0f));
geometry->setTexCoordArray(0,texCoords.get());

Thanks for the hint with the projection matrix. This could be the
problem, i will
check it later, if i got solved the main problem with the wrong camera view
definitions, which i could solve until yet...

I think this issue is the main problem i've. I don't understand why i
got invalid
RTT object's if i use the ABSOLUTE camera view definitions.

Best regards,
Christian


Mihai Radu wrote:
> Hi Christian,
>
> A short comment before looking at any of the code ( can't open the zip ).
>
> >From the snippets you posted, it looks to me like the texture
> coordinates used for textureUnit 0 are not correct.
> If they are set with the geometry ( per vertex ), then the first part
> should work well, if they are either object-relative or eye-relative
> with a TexGen to calculate them, that requires some calculations in the
> vertex shader ( that are done automatically by the fixed-function
> pipeline ).
>
> Looking even more closely, I can see you are rendering to a single quad
> ( z values are 0 ), and the last line scales everything in the [0.0,1.0]
> range, from the usual [-1.0,1.0], something that is done with projective
> texturing ( see osgshadow example for the way _texGen is being scaled ).
> I think the only reason your second snippet is working is because you
> are using an identity matrix for the camera, if you were using anything
> else, your results would probably be off.
>
> summary: check the texture coordinates for the pass you are referring to :)
>
> Cheers
> Mihai
>
> Christian Heine wrote:
>   
>> Hello,
>>
>> 2nd issue (Shader):
>> If i use in the vertex shader the values of the rendering pipeline with
>> the following
>> setups, the RTT result is shown like in the working screenshot. The blur
>> effect
>> of the second pass is not effected but the shader executed (set color to
>> red):
>>
>> gl_Position = ftransform();
>> vTexCoord = gl_MultiTexCoord0;
>>
>> If i use this simple code sniplet (used in RenderMonkey for Shadertest)
>> then the
>> RTT is moved to screen center and sized up where nothing is shown (See
>> defect_vertexShader
>> Screenshot):
>>
>>  vec2 Position;
>>  Position.xy = sign(gl_Vertex.xy);
>>
>>  gl_Position = vec4(Position.xy, 0.0, 1.0);
>>  vTexCoord = Position.xy *.5 + .5;
>>
>> I couldn't be explain, why this simple snipplet occurs in such an
>> effect. There is
>> nothing special done ...
>>
>> Thanks for any help,
>> best regards
>> Chris
>>
>>   
>> 
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>   

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