Hi, Christian Can't help you with crash, but i think you can find this usefull: 1) noise functions for glsl not implemented in hardware\drivers of most vendors, so dont even bother to use them. 2) why do you ever need to recreate program and all that stuff, if all you need is to change randomUniform value like randomUniform->set(randomNumber(-255, 255)) in a frame loop? 3) i think you are just chosen wrong way to do it. Most common approach is to use one or several pre-generated noise textures and mix and match them in shader with various texture coordinate sets (if you need some kind of animation - change texcoords by function of time or some uniform value).
Cheers, Sergey. 24.09.2012, 18:15, "Christian Rumpf" <[email protected]>: > hello! > > I'm trying to simulate noise effects in real time using OSG and GLSL. > > I rendered to texture a scene to get a sampler2D. Mu and Sigma for noise > simulation are static. My idea is to reload fragment shader in a while loop > with a random number as uniform because GLSL's noise() function doesn't seem > to work on my computer. Therefore I wrote a function "randomNumber(int from, > int to)" which returns a random int between "from" and "to". > > Code: > > void loadNoiseShader(int width, int height, osg::Vec3d& mue, osg::Vec3d& > sigma, osg::Geode* geode) > { > osg::ref_ptr<osg::Shader> vertShader = > osgDB::readShaderFile(osg::Shader::VERTEX, "noise.vert"); > osg::ref_ptr<osg::Shader> fragShader = > osgDB::readShaderFile(osg::Shader::FRAGMENT, "noise.frag"); > > osg::ref_ptr<osg::Program> program = new osg::Program; > program->addShader(vertShader.get()); > program->addShader(fragShader.get()); > > osg::StateSet* ss = geode->getOrCreateStateSet(); > ss->setAttributeAndModes(program.get()); > > osg::ref_ptr<osg::Uniform> texUniform = new osg::Uniform("RTScene", > 0); > osg::ref_ptr<osg::Uniform> windowSize = new osg::Uniform("screen", > osg::Vec2(width, height)); > osg::ref_ptr<osg::Uniform> mueUniform = new osg::Uniform("mue", mue); > osg::ref_ptr<osg::Uniform> sigmaUniform = new osg::Uniform("sigma", > sigma); > osg::ref_ptr<osg::Uniform> randomUniform = new osg::Uniform("random", > randomNumber(-255, 255)); > ss->addUniform(texUniform.get()); > ss->addUniform(windowSize.get()); > ss->addUniform(sigmaUniform.get()); > ss->addUniform(mueUniform.get()); > ss->addUniform(randomUniform.get()); > } > > /*...*/ > > while(!viewer.done()) > { > loadNoiseShader(width, height, mu, sigma, geode.get()); > viewer.frame(); > } > > I thought that this would work, but unfortunately the executive crashes at > the beginning. Can someone explain me that please? > > lg Chris > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=50258#50258 > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

