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 

uniform buffers for transform stack and other constants


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Gedalia Pasternak
Guest





PostPosted: Mon Mar 13, 2017 3:17 pm    Post subject:
uniform buffers for transform stack and other constants
Reply with quote

Hello,
   I've seen that OSG has some basic primitives for uniform buffers, but they seem designed for homogeneous data. Most modern engines use uniform buffers to represent various levels of shader constants based on frequency of state changing, so you might have a per frame UBO/per pass UBO, a material UBO, and a per draw call UBO. (one-off object changes might be the done with the simpler uniform system.)   


Typically that data is not homogeneous, but represented by a C structure that has to be somewhat carefully laid out.  
For example I've switched to a UBO for OSG's transform stack:
struct osg_TransformStack
{
   osg::Matrixf ModelViewMatrixInverse;
   osg::Matrixf ModelViewMatrix;
   osg::Matrixf ModelViewProjectionMatrix;
   osg::Matrixf ProjectionMatrix;
   osg::Matrix3 NormalMatrix;
};


That can get mapped to a UBO via 
   _extensions->glBufferData(GL_UNIFORM_BUFFER, sizeof(osg_TransformStack), &osg_transformstack, GL_DYNAMIC_DRAW);



And the UBO in glsl would look like:


struct osg_TransformStack

{
    mat4 ModelViewMatrixInverse;
    mat4 ModelViewMatrix;
    mat4 ModelViewProjectionMatrix;
    mat4 ProjectionMatrix;
    mat3 NormalMatrix; // Mat3's don't actually map great to std140 layouts
};


layout(std140) uniform osg_transform_stack_block

{
   osg_TransformStack osg;
};


Replacing the individual uniforms that OSG adds to replace the legacy gl_*Matrix calls in State::convertVertexShaderSourceToOsgBuiltIns() with a UBO saves me a few ms a frame, but I'm doing all the uniform buffer management by hand and I've had to significantly modify the state class. (I think some of the performance gain is from avoiding OSG's uniform management abstractions as well.)  I've had to do something similar with materials, otherwise I have significant performance degradation when switching off the fixed function pipeline.
  Has anyone else experimented with UBO's in this manor? Is there a cleaner OSG way to do that's still high performance?


Gedalia

------------------
Post generated by Mail2Forum
Back to top
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 Setting the transform matrices robertosfield General 9 Wed Aug 09, 2017 8:35 am View latest post
No new posts Near-uniform tessellation of a concav... Kanpachi General 3 Wed Apr 19, 2017 12:13 pm View latest post
No new posts [ A Stack Overflow for OSG? ] Steal General 27 Fri Feb 17, 2017 12:35 pm View latest post
No new posts Glsl structs and osg::Uniform. How? Steal General 3 Thu Jan 26, 2017 12:04 pm View latest post
No new posts Uniform set and callback Paradox General 2 Tue Apr 12, 2016 8:58 am 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