Re: [osg-users] Uniform arrays not working for me using Visual Studio 2010
Version 3.1.3 worked! Thank you everyone for your help. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50860#50860 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays not working for me using Visual Studio 2010
Hi David, Had the same problem. You probably need changeset 12816, which is a post 3.0.1 fix. Cheers, Patrick -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50832#50832 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays not working for me using Visual Studio 2010
Hi David, I don't personally use Windows, it must a decade now since I last used one for development... so I can't answer your question specifically. Best I can do is say in general OpenGL releated features not working across different systems is usually down to either a problem with the driver/hardware or a problem in the portability of the OpenGL being used. Something shaders might be permitted by one driver but cause a problem in an another, but the problem can be traced back to use of OpenGL (shders in particular) in ways that are at edge of the official GLSL spec. This type of problem isn't usually affected by compilers used. I recall a tweak made to the OSG to address percularities in driver implementations in the OSG-3.x era, but can't recall the specific dates, perhaps this fix might address the problems you have. Could you try out the svn/trunk or OSG-3.1.3 dev release? Robert. On 24 October 2012 16:17, David Sellin davse...@student.liu.se wrote: Hi, I ported my program from mingw and Code Blocks to Visual Studio 2010 Express and found that I couldn't get uniform arrays to work. Has anyone experienced this? I'm new to Visual Studio so I might have missed something. I made a small test program that works on my old system but not on my new system: (sorry for the weird symbols and that the include dirs fell off) Code: #include osg/Group #include osgDB/ReadFile #include osgViewer/Viewer #include osgGA/TrackballManipulator int main( int argc, char **argv ) { osg::setNotifyLevel( osg::WARN ); osg::Group *root = new osg::Group; std::string url = cow.osg; osg::Node* modelNode = osgDB::readNodeFile( url ); //setup shaders osg::Shader *vertshader = new osg::Shader( osg::Shader::VERTEX ); vertshader-loadShaderSourceFromFile( uniformarray.vert ); osg::Shader *fragshader = new osg::Shader( osg::Shader::FRAGMENT ); fragshader-loadShaderSourceFromFile( uniformarray.frag ); osg::Program *shaderprog = new osg::Program(); shaderprog-addShader( vertshader ); shaderprog-addShader( fragshader ); modelNode-getOrCreateStateSet()-setAttributeAndModes( shaderprog ); // Array uniform osg::Uniform *arrayUFM = new osg::Uniform( osg::Uniform::FLOAT, array, 2 ); arrayUFM-setElement( 0, 0.5f ); arrayUFM-setElement( 1, 1.0f ); modelNode-getOrCreateStateSet()-addUniform( arrayUFM ); root-addChild( modelNode ); // Graphics Context and Traits osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; traits-x = 10; traits-y = 10; traits-width = 800; traits-height = 600; traits-doubleBuffer = true; const std::string version( 3.1 ); traits-glContextVersion = version; osg::ref_ptrosg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); // Viewer osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer(); viewer-getCamera()-setGraphicsContext( gc.get() ); viewer-getCamera()-setViewport( new osg::Viewport( 0, 0, traits-width, traits-height ) ); viewer-setSceneData( root ); viewer-setCameraManipulator( new osgGA::TrackballManipulator() ); viewer-run(); return 0; } Vertex shader: Code: #version 140 uniform mat4 osg_ModelViewProjectionMatrix; in vec4 osg_Vertex; void main() { gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; }; Fragment shader using the array: Code: #version 140 uniform float array[2]; out vec4 fragData; void main() { fragData = vec4( 1.0, array[0], array[1], 1.0 ); } Old system: OSG 3.0 (revision 12753) MinGW and Code Blocks NVIDIA GEFORCE 260 WIN 7 New system OSG 3.0.1 (stable release) Visual C++ 2010 Express NVIDIA GEFORCE 680 WIN 7 Thank you! Cheers, David[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50756#50756 ___ 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] Uniform arrays not working for me using Visual Studio 2010
Hi David, On 25/10/12 2:17, David Sellin wrote: I ported my program from mingw and Code Blocks to Visual Studio 2010 Express and found that I couldn't get uniform arrays to work. Has anyone experienced this? I'm new to Visual Studio so I might have missed something. ... Old system: OSG 3.0 (revision 12753) MinGW and Code Blocks ... New system OSG 3.0.1 (stable release) Visual C++ 2010 Express ... What's the error? Did you check that it's not the usual debug vs. release libraries issue? (I'm feeling like a parrot right now.) /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Uniform arrays not working for me using Visual Studio 2010
Hi, I ported my program from mingw and Code Blocks to Visual Studio 2010 Express and found that I couldn't get uniform arrays to work. Has anyone experienced this? I'm new to Visual Studio so I might have missed something. I made a small test program that works on my old system but not on my new system: (sorry for the weird symbols and that the include dirs fell off) Code: #include osg/Group #include osgDB/ReadFile #include osgViewer/Viewer #include osgGA/TrackballManipulator int main( int argc, char **argv ) { osg::setNotifyLevel( osg::WARN ); osg::Group *root = new osg::Group; std::string url = cow.osg; osg::Node* modelNode = osgDB::readNodeFile( url ); //setup shaders osg::Shader *vertshader = new osg::Shader( osg::Shader::VERTEX ); vertshader-loadShaderSourceFromFile( uniformarray.vert ); osg::Shader *fragshader = new osg::Shader( osg::Shader::FRAGMENT ); fragshader-loadShaderSourceFromFile( uniformarray.frag ); osg::Program *shaderprog = new osg::Program(); shaderprog-addShader( vertshader ); shaderprog-addShader( fragshader ); modelNode-getOrCreateStateSet()-setAttributeAndModes( shaderprog ); // Array uniform osg::Uniform *arrayUFM = new osg::Uniform( osg::Uniform::FLOAT, array, 2 ); arrayUFM-setElement( 0, 0.5f ); arrayUFM-setElement( 1, 1.0f ); modelNode-getOrCreateStateSet()-addUniform( arrayUFM ); root-addChild( modelNode ); // Graphics Context and Traits osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; traits-x = 10; traits-y = 10; traits-width = 800; traits-height = 600; traits-doubleBuffer = true; const std::string version( 3.1 ); traits-glContextVersion = version; osg::ref_ptrosg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); // Viewer osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer(); viewer-getCamera()-setGraphicsContext( gc.get() ); viewer-getCamera()-setViewport( new osg::Viewport( 0, 0, traits-width, traits-height ) ); viewer-setSceneData( root ); viewer-setCameraManipulator( new osgGA::TrackballManipulator() ); viewer-run(); return 0; } Vertex shader: Code: #version 140 uniform mat4 osg_ModelViewProjectionMatrix; in vec4 osg_Vertex; void main() { gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; }; Fragment shader using the array: Code: #version 140 uniform float array[2]; out vec4 fragData; void main() { fragData = vec4( 1.0, array[0], array[1], 1.0 ); } Old system: OSG 3.0 (revision 12753) MinGW and Code Blocks NVIDIA GEFORCE 260 WIN 7 New system OSG 3.0.1 (stable release) Visual C++ 2010 Express NVIDIA GEFORCE 680 WIN 7 Thank you! Cheers, David[/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50756#50756 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
Hi, I am having the same problem with uniform vec4 arrays with new nvidia driver. We are still back on a pretty old version of osg, 2.8.3. Which files from the current subversion contain the fix. Program, Uniform, some others? Cheers, Jonathan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47652#47652 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
On 05/10/2012 08:26 PM, Jonathan Diaz wrote: Hi, I am having the same problem with uniform vec4 arrays with new nvidia driver. We are still back on a pretty old version of osg, 2.8.3. Which files from the current subversion contain the fix. Program, Uniform, some others? Hi, Jonathan, The fix is in Program.cpp, in the Program::PerContextProgram::linkProgram method. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
lyceel wrote: The problem actually only occurs with recent NVIDIA drivers (older versions didn't have this issue). As David mentioned, the latest SVN and the most recent developer releases also include this workaround, so you won't need to add the [0] yourself if you use one of those. Obviously, it'll be in the next public OSG release, too. Yes, in fact I just tried porting my code from Linux to Windows and found that adding [0] actually breaks things, and removing it fixes it. I will try using more recent version of OSG(I am indeed on the stable OSG 3.0.1) and see how it works. Cheers Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47691#47691 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
I had the same experience; this was an ATI vs. NVIDIA difference. One liked the [0] and the other did not (can't remember which). The OpenGL spec says that either is acceptable. Ended up writing an ArrayUniform helper class to deal with it. http://github.com/gwaldron/osgearth/blob/master/src/osgEarth/ShaderUtilshttps://github.com/gwaldron/osgearth/blob/master/src/osgEarth/ShaderUtils Glenn Waldron / @glennwaldron On Mon, May 14, 2012 at 10:02 AM, Eldar Insafutdinov e.insafutdi...@gmail.com wrote: lyceel wrote: The problem actually only occurs with recent NVIDIA drivers (older versions didn't have this issue). As David mentioned, the latest SVN and the most recent developer releases also include this workaround, so you won't need to add the [0] yourself if you use one of those. Obviously, it'll be in the next public OSG release, too. Yes, in fact I just tried porting my code from Linux to Windows and found that adding [0] actually breaks things, and removing it fixes it. I will try using more recent version of OSG(I am indeed on the stable OSG 3.0.1) and see how it works. Cheers Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47691#47691 ___ 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] Uniform arrays.
Well, adding [0] actually did the trick! Mismatch of the array sizes did not matter in the end(I want to pass arrays of variable length to glsl with sizes up to 20 elements, so that's fine with me). Not sure why my drivers don't work here, I'm on Linux with NVIDIA card and fairly up to date drivers. Thanks for helping me out! Cheers, Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47609#47609 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
On 05/09/2012 05:37 AM, Eldar Insafutdinov wrote: Well, adding [0] actually did the trick! Mismatch of the array sizes did not matter in the end(I want to pass arrays of variable length to glsl with sizes up to 20 elements, so that's fine with me). Not sure why my drivers don't work here, I'm on Linux with NVIDIA card and fairly up to date drivers. Thanks for helping me out! Hi, Eldar, The problem actually only occurs with recent NVIDIA drivers (older versions didn't have this issue). As David mentioned, the latest SVN and the most recent developer releases also include this workaround, so you won't need to add the [0] yourself if you use one of those. Obviously, it'll be in the next public OSG release, too. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Uniform arrays.
Hi I am trying to use uniform arrays with OSG, but it fails. Here are the snippets of code that a'm using: Code: osg::StateSet *ss = node-getOrCreateStateSet(); // one way of populating uniform array that I tried for(int i = 0; i sz; ++i) { char buf[30]; sprintf(buf, colourPoints[%d], i); osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); ss-addUniform(new osg::Uniform(buf, osg::Vec4(colour, 1.0))); } // another way osg::Uniform *colourPoints = new osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints, 20); for(int i = 0; i sz; ++i) { osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); colourPoints-setElement(i, osg::Vec4(colour, 1.0)); } ss-addUniform(colourPoints); // and glsl uniform vec4 colourPoints[5]; void main(void) { vec4 col = colourPoints[1]; gl_FragColor = col; } I tried to set up uniforms both ways but neither of them worked and all I get is a black colour. It must be something obvious that I am missing.. Cheers, Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47598#47598 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Uniform arrays.
Hi Eldar Only the second way is good, but create an uniform with 5 element and not 20. in your for loop be sure sz == 5. Otherwise all is good in the code you show us. HTH David 2012/5/8 Eldar Insafutdinov e.insafutdi...@gmail.com Hi I am trying to use uniform arrays with OSG, but it fails. Here are the snippets of code that a'm using: Code: osg::StateSet *ss = node-getOrCreateStateSet(); // one way of populating uniform array that I tried for(int i = 0; i sz; ++i) { char buf[30]; sprintf(buf, colourPoints[%d], i); osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); ss-addUniform(new osg::Uniform(buf, osg::Vec4(colour, 1.0))); } // another way osg::Uniform *colourPoints = new osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints, 20); for(int i = 0; i sz; ++i) { osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); colourPoints-setElement(i, osg::Vec4(colour, 1.0)); } ss-addUniform(colourPoints); // and glsl uniform vec4 colourPoints[5]; void main(void) { vec4 col = colourPoints[1]; gl_FragColor = col; } I tried to set up uniforms both ways but neither of them worked and all I get is a black colour. It must be something obvious that I am missing.. Cheers, Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47598#47598 ___ 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] Uniform arrays.
Hi, Eldar Try to create your uniform with second way, but use osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints[0], 20);// note [0] in uniform name some drivers need this syntax to work propertly with uniform arrays Cheers 08.05.2012, 18:12, Eldar Insafutdinov e.insafutdi...@gmail.com: Hi I am trying to use uniform arrays with OSG, but it fails. Here are the snippets of code that a'm using: Code: osg::StateSet *ss = node-getOrCreateStateSet(); // one way of populating uniform array that I tried for(int i = 0; i sz; ++i) { char buf[30]; sprintf(buf, colourPoints[%d], i); osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); ss-addUniform(new osg::Uniform(buf, osg::Vec4(colour, 1.0))); } // another way osg::Uniform *colourPoints = new osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints, 20); for(int i = 0; i sz; ++i) { osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); colourPoints-setElement(i, osg::Vec4(colour, 1.0)); } ss-addUniform(colourPoints); // and glsl uniform vec4 colourPoints[5]; void main(void) { vec4 col = colourPoints[1]; gl_FragColor = col; } I tried to set up uniforms both ways but neither of them worked and all I get is a black colour. It must be something obvious that I am missing.. Cheers, Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47598#47598 ___ 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] Uniform arrays.
Hi Sergey The [0] was require by some driver and not by other. Specification was not clear about this. Since 19 09 2011, OSG fix automatically this and we didn't need anymore to care about [] take a look to osg:Program::linkProgram(...) in src/osg/Program : line747 cheers David 2012/5/8 Sergey Polischuk pol...@yandex.ru Hi, Eldar Try to create your uniform with second way, but use osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints[0], 20);// note [0] in uniform name some drivers need this syntax to work propertly with uniform arrays Cheers 08.05.2012, 18:12, Eldar Insafutdinov e.insafutdi...@gmail.com: Hi I am trying to use uniform arrays with OSG, but it fails. Here are the snippets of code that a'm using: Code: osg::StateSet *ss = node-getOrCreateStateSet(); // one way of populating uniform array that I tried for(int i = 0; i sz; ++i) { char buf[30]; sprintf(buf, colourPoints[%d], i); osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); ss-addUniform(new osg::Uniform(buf, osg::Vec4(colour, 1.0))); } // another way osg::Uniform *colourPoints = new osg::Uniform(osg::Uniform::FLOAT_VEC4, colourPoints, 20); for(int i = 0; i sz; ++i) { osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0); colourPoints-setElement(i, osg::Vec4(colour, 1.0)); } ss-addUniform(colourPoints); // and glsl uniform vec4 colourPoints[5]; void main(void) { vec4 col = colourPoints[1]; gl_FragColor = col; } I tried to set up uniforms both ways but neither of them worked and all I get is a black colour. It must be something obvious that I am missing.. Cheers, Eldar -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=47598#47598 ___ 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