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 

Getting the main camera.


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Rowley, Marlin R
Guest





PostPosted: Wed May 02, 2018 5:05 pm    Post subject:
Getting the main camera.
Reply with quote

Is there a way to get a pointer to the main rendering camera without passing the Viewer around through classes and functions?

Thanks,

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
Rowley, Marlin R
Guest





PostPosted: Wed May 02, 2018 5:59 pm    Post subject:
Getting the main camera.
Reply with quote

Here is a more informed email of what I’m trying to accomplish:

We have some old code that inherits from the ShadowMapTechnique to do most of it’s work which is based on the fixed-function pipeline. It uses the shadow map’s camera for projection of textures (among other things) and we are redesigning it so that the base class is independent of the shadow map class. I thought I had everything working when I gutted out this function in the ViewData override function called addShadowReceivingTexGen():

_texgen->setMode(osg::TexGen::EYE_LINEAR);

// compute the matrix which takes a vertex from view coords into tex coords
_texgen->setPlanesFromMatrix(
mClampCallback->getLastProjection() *
osg::Matrix::translate(1.0, 1.0, 1.0) *
osg::Matrix::scale(0.5f, 0.5f, 0.5f));

osg::RefMatrix * refMatrix = new osg::RefMatrix
(_camera->getInverseViewMatrix() * *_cv->getModelViewMatrix());

_cv->getRenderStage()->getPositionalStateContainer()->
addPositionedTextureAttribute
(*_shadowTextureUnitPtr, refMatrix, _texgen.get());

This is evidently stored in OpenGL’s built-in variables because it’s used in the vertex shader like this:

{
gl_TexCoord[1].s = dot(ecPosition, gl_EyePlaneS[1]);
gl_TexCoord[1].t = dot(ecPosition, gl_EyePlaneT[1]);
gl_TexCoord[1].p = dot(ecPosition, gl_EyePlaneR[1]);
gl_TexCoord[1].q = dot(ecPosition, gl_EyePlaneQ[1]);
}

My new solution for the addShadowReceivingTexGen() is a simple updateTextureCoordinates() function:

mTexGenMatrix = mCamera->getViewMatrix() *mCamera->getProjectionMatrix() * osg::Matrixd::translate(osg::Vec3d(1.0, 1.0, 1.0)) *
osg::Matrixd::scale(0.5, 0.5, 0.5);

And in the new vertex shader, I do this:

TexCoords[0] = TexGenMatrix0 * gl_Vertex;

Which goes from modelspace all the way to clip space. This works on simple objects created at the origin in modelspace, but it does NOT work with an entire world with large terrain.

I’d like to continue NOT using the gl_EyePlaneSTRQ and just doing a regular transformation. However, going back to the old code for any clues is leading me nowhere. I traced the ‘addPositionedTextureAttribute’ to this:

virtual void addPositionedTextureAttribute(unsigned int textureUnit, osg::RefMatrix* matrix,const osg::StateAttribute* attr)
{
_texAttrListMap[textureUnit].push_back(AttrMatrixPair(attr,matrix));
}

.. but I’m not sure what it’s doing here. The attr is the texgen object but that’s used to store a matrix. So what does the vertex shader ‘see’ from this function?

I apologize for the long and drawn out email but I’ve been thinking on this for a few hours now and am really new to OpenGL and not sure what some of this code is trying to do.

Thanks,

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)


From: osg-users [mailto:] On Behalf Of Rowley, Marlin R (US)
Sent: Wednesday, May 2, 2018 12:05 PM
To: OpenSceneGraph Users <>
Subject: EXTERNAL: Getting the main camera.



Is there a way to get a pointer to the main rendering camera without passing the Viewer around through classes and functions?

Thanks,

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Wed May 02, 2018 6:19 pm    Post subject:
Getting the main camera.
Reply with quote

Hi Marlin,

On 2 May 2018 at 18:05, Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:

Is there a way to get a pointer to the main rendering camera without passing the Viewer around through classes and functions?



In the draw traversal the main two objects that are passed around are osg::RenderInfo and osg::State.  The osg::RenderInfo has high level info such as what is the current View being rendered and what the current Camera is. 

     https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osg/RenderInfo

The RenderInfo is passed to drawables during the draw traversal via:

      osg::Drawable::drawImplementation(osg::RenderInfo&)


The CullVisitor also has a handle to the RenderInfo as well as various other useful state info:

     https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osgUtil/CullVisitor


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 Matrices with Camera and CameraManipu... Tare General 0 Fri Oct 19, 2018 12:54 pm View latest post
No new posts Resizing FBO camera while rendering romulogcerqueira General 9 Tue Oct 02, 2018 3:34 am View latest post
No new posts ReaderWriterCFG - offset for single c... Marcin Prus Submission 0 Fri Jul 06, 2018 11:27 am View latest post
No new posts osgOcean - Render to Texture Camera rob_ewbank osgOcean [osgOcean] 3 Wed Jul 04, 2018 11:27 am View latest post
No new posts osgviewer camera initial angle. Vagn General 1 Wed Jun 20, 2018 2:31 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