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 

Transformation nodes with shaders


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
csklu
Newbie


Joined: 26 Jan 2011
Posts: 13

PostPosted: Sun May 15, 2011 8:44 am    Post subject:
Transformation nodes with shaders
Reply with quote

Hi,

I'm working on implementing some lighting effects with shaders and
I've run into the problem that vertex positions are passed to the
shader in local coordinates. This means that if there are any
transformation nodes in the scenegraph underneath where the shader is
active, the lighting calculations won't be transformed correctly.

I've dug into the OSG source code a bit and found the following:

- special osg_* uniforms are maintained in the State class, the ones
of interest are osg_ModelViewProjectionMatrix, osg_Vertex, etc

- the updating of these uniforms during draw traversal must be enabled
by calling State::setUseModelViewAndProjectionUniforms(true)
I'm not quite sure where to set this though since States are used in
multiple places, I've tried the following:

osgViewer::Viewer * viewer = new osgViewer::Viewer;
osgViewer::Renderer * renderer = dynamic_cast<osgViewer::Renderer
*>(viewer->getCamera()->getRenderer());
osgUtil::SceneView * sceneView = renderer->getSceneView(0); // Do
this also for 2nd sceneview
sceneView->setActiveUniforms( osgUtil::SceneView::ALL_UNIFORMS );
sceneView->getState()->setUseModelViewAndProjectionUniforms(true);


- Modify the shader source to use the special osg_* built-in uniforms:

osg::ref_ptr<osg::State> state = new osg::State;
state->convertVertexShaderSourceToOsgBuiltIns( srcString );
shader->setShaderSource(srcString);

(Couldn't osg::State::convertVertexShaderSourceToOsgBuiltIns() be a
static method or free function?)

But when I do this, then nothing appears. What am I doing wrong or are
there other things I should be doing?

Thanks,
Chris


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11152

PostPosted: Mon May 16, 2011 7:49 am    Post subject:
Transformation nodes with shaders
Reply with quote

Hi Chris,

On Sun, May 15, 2011 at 9:45 AM, SkullCheck <> wrote:
Quote:
I've dug into the OSG source code a bit and found the following:

- special osg_* uniforms are maintained in the State class, the ones
of interest are osg_ModelViewProjectionMatrix, osg_Vertex, etc

This are drop in replacements for the traditional gl_ variables that
are provided in
OpenGL 2.x's GLSL. These replaements are required for GL3+ (with backwards
compatibility) and GLES 2 as neither provide the gl_ varaibles. For a
GL 2.x app
it's safe to just target the gl_ variables.

Quote:
- the updating of these uniforms during draw traversal must be enabled
by calling State::setUseModelViewAndProjectionUniforms(true)
 I'm not quite sure where to set this though since States are used in
multiple places, I've tried the following:

   osgViewer::Viewer * viewer = new osgViewer::Viewer;
   osgViewer::Renderer * renderer = dynamic_cast<osgViewer::Renderer
*>(viewer->getCamera()->getRenderer());
   osgUtil::SceneView * sceneView = renderer->getSceneView(0); // Do
this also for 2nd sceneview
   sceneView->setActiveUniforms( osgUtil::SceneView::ALL_UNIFORMS );
   sceneView->getState()->setUseModelViewAndProjectionUniforms(true);

The osg::State object is held by the GraphicsContext, you don't need
to go chasing
up internal implementation details like SceneView.

If you have just one master camera that maintains the only one
graphics context the code is simply:

osg::State* state = viewer.getCamera()->getGraphicsContext()->getState();

For the GL3 and GLES2 profiles the OSG automaitcally
setUseModelViewAndProjectionUniforms(true);


Quote:
- Modify the shader source to use the special osg_* built-in uniforms:

   osg::ref_ptr<osg::State> state = new osg::State;
   state->convertVertexShaderSourceToOsgBuiltIns( srcString );
   shader->setShaderSource(srcString);

  (Couldn't osg::State::convertVertexShaderSourceToOsgBuiltIns() be a
static method or free function?)

This method is called when required, you never need to call it
yourself. This method is purely there
to help with backwards compatibility between GL 2.x and GL3/GLES2 apps.

Quote:
But when I do this, then nothing appears. What am I doing wrong or are
there other things I should be doing?

It does sound rather like you might be putting too much effort in, you
may well be able to
just use the standard gl_ built-ins.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
csklu
Newbie


Joined: 26 Jan 2011
Posts: 13

PostPosted: Tue May 17, 2011 9:34 pm    Post subject:
Transformation nodes with shaders
Reply with quote

Hi Robert,

Thanks for the tips and I set the UseModelViewAndProjectionUniforms
flag on the Viewer->Camera->GraphicsContext->State object. However
when I do this then absolutely nothing shows up on screen. Basically
what I've had to do is manually append the view matrix onto each
light's model transformation each frame and that gives the expected
transformation. I'm not really sure why the OSG way isn't working but
will have to debug it later.

Chris

On Mon, May 16, 2011 at 9:50 AM, Robert Osfield
<> wrote:
Quote:
Hi Chris,

On Sun, May 15, 2011 at 9:45 AM, SkullCheck <> wrote:
Quote:
I've dug into the OSG source code a bit and found the following:

- special osg_* uniforms are maintained in the State class, the ones
of interest are osg_ModelViewProjectionMatrix, osg_Vertex, etc

This are drop in replacements for the traditional gl_ variables that
are provided in
OpenGL 2.x's GLSL.  These replaements are required for GL3+ (with backwards
compatibility) and GLES 2 as neither provide the gl_ varaibles.  For a
GL 2.x app
it's safe to just target the gl_ variables.

Quote:
- the updating of these uniforms during draw traversal must be enabled
by calling State::setUseModelViewAndProjectionUniforms(true)
 I'm not quite sure where to set this though since States are used in
multiple places, I've tried the following:

   osgViewer::Viewer * viewer = new osgViewer::Viewer;
   osgViewer::Renderer * renderer = dynamic_cast<osgViewer::Renderer
*>(viewer->getCamera()->getRenderer());
   osgUtil::SceneView * sceneView = renderer->getSceneView(0); // Do
this also for 2nd sceneview
   sceneView->setActiveUniforms( osgUtil::SceneView::ALL_UNIFORMS );
   sceneView->getState()->setUseModelViewAndProjectionUniforms(true);

The osg::State object is held by the GraphicsContext, you don't need
to go chasing
up internal implementation details like SceneView.

If you have just one master camera that maintains the only one
graphics context the code is simply:

  osg::State* state = viewer.getCamera()->getGraphicsContext()->getState();

For the GL3 and GLES2 profiles the OSG automaitcally
setUseModelViewAndProjectionUniforms(true);


Quote:
- Modify the shader source to use the special osg_* built-in uniforms:

   osg::ref_ptr<osg::State> state = new osg::State;
   state->convertVertexShaderSourceToOsgBuiltIns( srcString );
   shader->setShaderSource(srcString);

  (Couldn't osg::State::convertVertexShaderSourceToOsgBuiltIns() be a
static method or free function?)

This method is called when required, you never need to call it
yourself.  This method is purely there
to help with backwards compatibility between GL 2.x and GL3/GLES2 apps.

Quote:
But when I do this, then nothing appears. What am I doing wrong or are
there other things I should be doing?

It does sound rather like you might be putting too much effort in, you
may well be able to
just use the standard gl_ built-ins.

Robert.




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General 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 Mirror transformation Ale General 9 Wed Sep 13, 2017 12:52 pm View latest post
No new posts using modern shaders with osg - setti... antiro42 General 18 Fri Sep 01, 2017 9:30 am View latest post
No new posts Custom data within nodes or drawables arennuit General 2 Thu Aug 24, 2017 9:52 am View latest post
No new posts RTT + shaders example Michael Maurus General 42 Wed Jul 12, 2017 11:28 am View latest post
No new posts Render Geographic/Projected coordinat... Bruno Oliveira General 0 Mon Jun 05, 2017 2:58 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