[osg-users] Trouble with a simple shader program.

Alexander Wieser alexander.wieser at crystalbyte.de
Sat Apr 11 10:21:30 PDT 2015


Hi,

I am currently working on my bachelor thesis using which involves the OpenSceneGraph. One task is to apply a distortion Shader to a rendered texture.

Unfortunately I am failing in getting any Shader to work at all.
After spending the last couple of days researching and reading books, I managed to get several shaders running in other libraries, be it online using WebGL or directly using OpenGL. I simply can't get it running using OSG.

The code initializing the program is this.


Code:

// A simple 4 vertex rectangular geometry drawable.
Plane* plane = new Plane(40);
this->addDrawable(plane);

osg::Program* program = new osg::Program();
program->setName("Debug Shader");

// This refers to a Geode.
osg::StateSet& state = *this->getOrCreateStateSet();
state.setAttributeAndModes(program, osg::StateAttribute::ON);

boost::filesystem::path currentPath(boost::filesystem::current_path());

// Init vertex shader.
RTT::log(RTT::Debug) << "Loading vertex shader."<< RTT::endlog();
osg::Shader* vertexShader = new osg::Shader(osg::Shader::VERTEX);
vertexShader->loadShaderSourceFromFile(currentPath.string() + "/../resources/shaders/debug.vert");
program->addShader(vertexShader);

// Init fragment shader.
RTT::log(RTT::Debug) << "Loading fragment shader."<< RTT::endlog();
osg::Shader* fragmentShader = new osg::Shader(osg::Shader::FRAGMENT);
fragmentShader->loadShaderSourceFromFile(currentPath.string() + "/../resources/shaders/debug.frag");
program->addShader(fragmentShader);





Vertex Shader

Code:

#version 430

uniform mat4 osg_ModelViewProjectionMatrix;
in vec4 osg_Vertex;

void main() {
gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;
}





Fragment Shader

Code:

#version 430

layout(location = 0) out vec4 FragColor;

void main() {
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}




As you can see, the program is not that complicated and does compile fine.
Unfortunately I don't see anything on the screen. There is no model.
If I remove the program and simply use the built in lighting, coloring and texturing support it renders fine.

Any help is greatly appreciated.


Thank you!

Cheers,
Alexander

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=63328#63328








More information about the osg-users mailing list