Re: [osg-users] ShaderGen and OpenGL ES2

166 views
Skip to first unread message

Ankur Gandhi

unread,
Apr 15, 2011, 8:21:06 AM4/15/11
to osg-...@lists.openscenegraph.org
Hi Robert,

I am using OSG 2.9.11 dev release. recently I have started working on OSG over GLES2. Although my OSG based code is working fine on OpenGL based system, i face similar issues that of Yun-Ta on GLES2. My test application is importing a plain 3ds max object onto screen along with light source. when i run the program, i get following output.


libEGL warning: failed to create DRM screen
libEGL warning: use software fallback
GraphicsWindowX11::init() - eglInitialize() succeded eglMajorVersion=1 iMinorVersion=4
GraphicsWindowX11::init() - window created =1
VERTEX glCompileShader "" FAILED
VERTEX Shader "" infolog:
0:0(0): error: `osg_Normal' redeclared
0:19(34): error: `gl_LightSource' undeclared
0:19(46): error: type mismatch

FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0:20(20): error: syntax error, unexpected NEW_IDENTIFIER, expecting ',' or ';'

glLinkProgram "" FAILED
Program "" infolog:
linking with uncompiled shaderlinking with uncompiled shader
Warning: detected OpenGL error 'invalid enumerant' at after RenderBin::draw(..)
Warning: detected OpenGL error 'invalid enumerant' at end of SceneView::draw()
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50


I was just wondering if work on ShaderGen is going on in some other branch or something? or am i doing anything wrong here to run 3ds max object over GLES2?

any help would be appreciated.

Thanking you in anticipation.

Regards,
Ankur

robertosfield wrote:
> Hi Yun-Ta,
>
> ShaderGen assumes OpenGL 2 feature set, so items like the built in
> gl_* uniforms and vertex attributes are used. osg::State does map
> automatically a number of these uniforms for GLE2 but doing a search
> and replace of them, this isn't exhaustive though.
>
> The work I'm just starting now on shader composition will make
> ShaderGen completely redundant and will properly support GLES 2, GL3
> and GL4, so the issues you are seeing should disappear completely.
>
> Robert.
>
> On Wed, Jun 30, 2010 at 6:08 PM, <> wrote:
>
> >  Hi all,
> >
> > I am trying to test OSG (2.9.8) on N900 with OpenGL ES2.
> > However, ShaderGen.cpp seems to be not fully compatible with OpenGL ES2
> > standard.
> >
> > For instance, gl_LightSource is not defined in ES2 and precision
> > attribute (mediump / highp / lowp) has been missing. The later one can
> > be easily fixed while the first one using undefined variables is more
> > difficult to work around.
> >
> > Here is the GLSL code generated from ShaderGen.cpp:
> > Nokia-N900:/home/user/osg-data# /opt/osg/bin/osgviewer cessna.osg
> > GraphicsWindowX11::init() - eglInitialize() succeded eglMajorVersion=1
> > iMinorVersion=4
> > GraphicsWindowX11::init() - window created =1
> > State::convertShaderSourceToOsgBuiltIns()
> > ++Before Converted source
> > varying vec3 normalDir;
> > varying vec3 lightDir;
> > varying vec3 viewDir;
> >
> > void main()
> > {
> >   gl_Position = ftransform();
> >   normalDir = gl_NormalMatrix * gl_Normal;
> >   vec3 dir = -vec3(gl_ModelViewMatrix * gl_Vertex);
> >   viewDir = dir;
> >   vec4 lpos = gl_LightSource[0].position;
> >   if (lpos.w == 0.0)
> >     lightDir = lpos.xyz;
> >   else
> >     lightDir = lpos.xyz + dir;
> > }
> >
> > ++++++++
> > -------- Converted source
> > uniform mat3 osg_NormalMatrix;
> > uniform mat4 osg_ModelViewProjectionMatrix;
> > uniform mat4 osg_ModelViewMatrix;
> > attribute vec4 osg_Vertex;
> > attribute vec3 osg_Normal;
> > varying vec3 normalDir;
> > varying vec3 lightDir;
> > varying vec3 viewDir;
> >
> > void main()
> > {
> >   gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;
> >   normalDir = osg_NormalMatrix * osg_Normal;
> >   vec3 dir = -vec3(osg_ModelViewMatrix * osg_Vertex);
> >   viewDir = dir;
> >   vec4 lpos = gl_LightSource[0].position;
> >   if (lpos.w == 0.0)
> >     lightDir = lpos.xyz;
> >   else
> >     lightDir = lpos.xyz + dir;
> > }
> >
> > ----------------
> > VERTEX glCompileShader "" FAILED
> > VERTEX Shader "" infolog:
> > Compile failed.
> > ERROR: 0:16: 'gl_LightSource' : undeclared identifer
> > ERROR: 0:16: 'gl_LightSource' : left of '[' is not of type array,
> > matrix, or vector
> > ERROR: 0:16: 'position' : illegal vector field selection
> > ERROR: 0:16: 'assign' :  cannot convert from 'float' to '4-component
> > vector of float'
> > ERROR: 4 compilation errors. No code generated.
> >
> >
> > FRAGMENT glCompileShader "" FAILED
> > FRAGMENT Shader "" infolog:
> > Compile failed.
> > ERROR: 0:1: 'vec3' : No precision defined for this type
> > ERROR: 0:2: 'vec3' : No precision defined for this type
> > ERROR: 0:3: 'vec3' : No precision defined for this type
> > ERROR: 0:7: 'vec4' : No precision defined for this type
> > ERROR: 0:8: 'vec3' : No precision defined for this type
> > ERROR: 0:9: 'vec3' : No precision defined for this type
> > ERROR: 0:10: 'vec3' : No precision defined for this type
> > ERROR: 0:11: 'vec4' : No precision defined for this type
> > ERROR: 0:11: 'gl_FrontLightModelProduct' : undeclared identifer
> > ....
> >
> > Any suggestion?
> >
> > Thanks.
> > Best Regards,
> > Yun-Ta
> > _______________________________________________
> > osg-users mailing list
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> _______________________________________________
> osg-users mailing list
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ------------------
> Post generated by Mail2Forum


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

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Apr 18, 2011, 5:08:24 AM4/18/11
to osg-...@lists.openscenegraph.org
HI Ankur,

osgUtil::ShaderGen was written for GL2 rather than GLES2, and we've
just quickly used this class as a fallback to provide some basic
fallback functionality, it's certainly not a ideal solution for GLES2
or able to cope with all fixed function state.

I'm not personally working on updating ShaderGen for GLES2, and I'm
not aware of others doing this work, but they may be. Feel free to
dive in an help improve ShaderGen's support for GLES2.

Robert.

Thomas Hogarth

unread,
Apr 18, 2011, 3:47:08 PM4/18/11
to osg-...@lists.openscenegraph.org
 Hi

Have been doing a little work on this, the main hurdles I faced where getting hold of light / texture matrix information and adding the GLES2 precision stuff. So for the moment I copied the original shadergen func (ShaderGenCache::createStateSet) into my own material class for testing as it had direct access to the materials texture matrix and that was the main thing I needed at the time (if your not using them it won't matter, but it's something I think should certainly be available).

So this won't work directly in osg as I added a few other bits as experimentation, but how to handle the precision and applying the texture matrix uniform is demonstrated.

Attached is my material class, it basically just wraps a stateset and supplies some convenience functions. the function you're looking for is ComposeShaderFromMaterialState and any variable I have added to the generated shader is prefixed with hb_, rather then osg_.

This is something I would like to get moved into core osg so would be happy to lend advice, as might be a while till I find the time to do this myself. The main issue I think is dynamic variables like texture matrices and light position. If we want people to be able to update these on the fly without having to redo the entire shadergen pass, then the uniforms would have to be retained some how so that they could be updated anytime the light was moved for example. This might be doable from the shader gen visitor, but updating all the uniforms every frame could be expensive.

In the end though it would be nice just to get the existing gl2 version working in gles2 just as a fallback for the examples. Think it would a big help to anyone using gles2 for the first time.

Cheers
Tom



HogBoxMaterial.h
HogBoxMaterial.cpp
Reply all
Reply to author
Forward
0 new messages