From 10c1fedfca71951ec55f409c5f78626b2c310cdc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 May 2017 12:32:41 +0100 Subject: [PATCH] Addded a GLES2 compatible osgmovie shader --- examples/osgmovie/osgmovie.cpp | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 7221e6f37..0a62b37de 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -469,23 +469,46 @@ int main(int argc, char** argv) { //useTextureRectangle = false; - static const char *shaderSourceTextureRec = { - "uniform vec4 cutoff_color;\n" - "uniform samplerRect movie_texture;\n" + static const char *shaderSourceTextureVertex = { + "#ifdef GL_ES\n" + " precision highp float;\n" + " precision highp int;\n" + "#endif\n" + "varying vec4 texcoord;\n" "void main(void)\n" "{\n" - " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0].st); \n" + " texcoord = gl_MultiTexCoord0; \n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "}\n" + }; + + static const char *shaderSourceTextureRec = { + "#ifdef GL_ES\n" + " precision highp float;\n" + " precision highp int;\n" + "#endif\n" + "uniform vec4 cutoff_color;\n" + "uniform samplerRect movie_texture;\n" + "varying vec4 texcoord;\n" + "void main(void)\n" + "{\n" + " vec4 texture_color = textureRect(movie_texture, texcoord.st); \n" " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" " gl_FragColor = texture_color;\n" "}\n" }; static const char *shaderSourceTexture2D = { + "#ifdef GL_ES\n" + " precision highp float;\n" + " precision highp int;\n" + "#endif\n" "uniform vec4 cutoff_color;\n" "uniform sampler2D movie_texture;\n" + "varying vec4 texcoord;\n" "void main(void)\n" "{\n" - " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0].st); \n" + " vec4 texture_color = texture2D(movie_texture, texcoord.st); \n" " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" " gl_FragColor = texture_color;\n" "}\n" @@ -493,6 +516,9 @@ int main(int argc, char** argv) osg::Program* program = new osg::Program; + + program->addShader(new osg::Shader(osg::Shader::VERTEX, shaderSourceTextureVertex)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D));