Discussion:
[osg-users] OpenGL ES 2.0 and LIGHTING
Grigoriy Mylnikov
2018-11-11 16:58:39 UTC
Permalink
Hi,

Is this issue solved in OSG somehow? I need to use some basic lighting on Android (GLESv3). It should use parameters from osg::Light. Are there any ready-made solutions?
if not, where can I get some shaders/shader generator to start with? I'm new in shaders.

Thank you!

Cheers,
Grigoriy

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75183#75183
Chris Hanson
2018-11-12 19:05:10 UTC
Permalink
I think the osgUtil/ShaderGen code might be GLES2 compatible now. Try
running it on your model, and dump the shader that it creates to see if
it's creating Uniforms for lighting or not.

It might or might not be using the osg::Light as a basis. Do you HAVE to
use osg::Light or could you get by with some light Uniforms?

Describe to us your lighting requirements better and maybe we can suggest
solutions.
Post by Grigoriy Mylnikov
Hi,
Is this issue solved in OSG somehow? I need to use some basic lighting on
Android (GLESv3). It should use parameters from osg::Light. Are there any
ready-made solutions?
if not, where can I get some shaders/shader generator to start with? I'm new in shaders.
Thank you!
Cheers,
Grigoriy
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75183#75183
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
Chris 'Xenon' Hanson, omo sanza lettere. ***@AlphaPixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel <https://twitter.com/alphapixel> facebook.com/alphapixel (775)
623-PIXL [7495]
Grigoriy Mylnikov
2018-11-16 11:29:55 UTC
Permalink
Sorry for delayed reply.

My goal is to open and display .osgt files on android the same way they can be opened on desktop. This includes using several lights inside a model, both directional and point lights.

I have some progress with writing shaders, but I have troubles with understanding OSG states. I've updated osg::Light apply() code to pass light position (relative to camera) as uniform:


Code:
void LightShader::apply(osg::State& state) const
{
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
... // Original code
#else
...
osg::Vec4 relPos = state.getModelViewMatrix() * _position;
lightPosUniform.get()->set(relPos);
...
#endif
}




But it seems that state.getModelViewMatrix() does not gives me valid view matrix.

If I could get light position (relative to camera), I can use it in shaders like this:


Code:
vec3 APos = vec3(gl_ModelViewMatrix * gl_Vertex);
...
vec3 fromPointToLight = lightPos.xyz - APos;




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75204#75204
Werner Modenbach
2018-11-16 11:36:39 UTC
Permalink
Hi Grigoriy,

why don't you do the multiply in the shader like you do with gl_vertex?

- Werner -
Post by Grigoriy Mylnikov
Sorry for delayed reply.
My goal is to open and display .osgt files on android the same way they can be opened on desktop. This includes using several lights inside a model, both directional and point lights.
void LightShader::apply(osg::State& state) const
{
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
... // Original code
#else
...
osg::Vec4 relPos = state.getModelViewMatrix() * _position;
lightPosUniform.get()->set(relPos);
...
#endif
}
But it seems that state.getModelViewMatrix() does not gives me valid view matrix.
vec3 APos = vec3(gl_ModelViewMatrix * gl_Vertex);
...
vec3 fromPointToLight = lightPos.xyz - APos;
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75204#75204
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Grigoriy Mylnikov
2018-11-16 16:00:39 UTC
Permalink
After some trial and errors, I managed to do it in shader. But this means one redundant matrix multiplication per each vertex. Isn't it more effective to compute it once per frame on cpu side?

What's the purpose of state.getModelViewMatrix()? I expected to get a camera*model matrix there. Or it is not yet defined at the moment lights are applied?

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75206#75206
Grigoriy Mylnikov
2018-11-18 16:07:17 UTC
Permalink
I tried to use osgUtil/ShaderGen. As far as I understand, it does not supports GLES2/3: it references gl_LightSource, gl_FrontLightProduct etc. in shader code, and I could not find such uniforms created. Also, it assumes only one light source.
Maybe there is some more advanced version of ShaderGen? I have seen somebody mentioned it somewhere on this forum.
Does anyone work on supporting GLES in OSG? I could try to help with this, if somebody will point me in right direction

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75211#75211
Grigoriy Mylnikov
2018-11-19 16:46:54 UTC
Permalink
At the moment, I implemented ShaderLight class that extends osg::Light and allows to use several point lights with per-pixel lighting (using my shaders). It works on android emulator.

I'm not sure about where is a best place to add that lights' uniforms to scene graph (e.g. rootStateSet->addUniform(myLight0->positionUniform); ). For now, I just call it after creating every light. I think ShaderLight object should do it itself, but how can it get a StateSet to which uniforms should be added?

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75213#75213
Chris Hanson
2018-11-19 20:26:33 UTC
Permalink
Let me check with Thomas.
Post by Grigoriy Mylnikov
At the moment, I implemented ShaderLight class that extends osg::Light and
allows to use several point lights with per-pixel lighting (using my
shaders). It works on android emulator.
I'm not sure about where is a best place to add that lights' uniforms to
scene graph (e.g. rootStateSet->addUniform(myLight0->positionUniform); ).
For now, I just call it after creating every light. I think ShaderLight
object should do it itself, but how can it get a StateSet to which uniforms
should be added?
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75213#75213
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
Chris 'Xenon' Hanson, omo sanza lettere. ***@AlphaPixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel <https://twitter.com/alphapixel> facebook.com/alphapixel (775)
623-PIXL [7495]
Grigoriy Mylnikov
2018-11-20 12:16:10 UTC
Permalink
Hi,

One more question. If I use gl_ModelViewMatrix in shaders to transform Light position, it gets transformed by both camera matrix and current node's matrix, that is not right.
Is there some build-in OSG uniform that holds only camera matrix or only model matrix? Or I should compute it and pass as my own uniform?

Thank you!

Cheers,
Grigoriy

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75218#75218
Chris Hanson
2018-11-20 21:48:37 UTC
Permalink
http://alphapixel.com/faqs/

src\osgUtil\SceneView.cpp(422): osg::Uniform* uniform =
_localStateSet->getOrCreateUniform(“osg_ViewMatrix”,osg::Uniform::FLOAT_MAT4);

src\osgUtil\SceneView.cpp(428): osg::Uniform* uniform =
_localStateSet->getOrCreateUniform(“osg_ViewMatrixInverse”,osg::Uniform::FLOAT_MAT4);
Grigoriy Mylnikov
2018-11-21 04:56:59 UTC
Permalink
Thank you, it works.

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

Continue reading on narkive:
Search results for '[osg-users] OpenGL ES 2.0 and LIGHTING' (Questions and Answers)
4
replies
what is swiftshader ?
started 2011-11-19 01:33:05 UTC
software
Loading...