Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Grigoriy Mylnikov
Thank you, it works.

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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Chris Hanson
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);
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Grigoriy Mylnikov
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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-19 Thread Chris Hanson
Let me check with Thomas.

On Mon, Nov 19, 2018 at 5:46 PM Grigoriy Mylnikov 
wrote:

> 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
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. xe...@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  facebook.com/alphapixel (775)
623-PIXL [7495]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-19 Thread 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?

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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-18 Thread Grigoriy Mylnikov
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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-16 Thread Grigoriy Mylnikov
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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-16 Thread Werner Modenbach
Hi Grigoriy,

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

- Werner -

Am 16.11.2018 um 12:29 schrieb 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.
>
> 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
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-16 Thread 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.

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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-12 Thread Chris Hanson
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.

On Mon, Nov 12, 2018 at 1:45 PM Grigoriy Mylnikov 
wrote:

> 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
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. xe...@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  facebook.com/alphapixel (775)
623-PIXL [7495]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-12 Thread 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

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





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


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2012-06-12 Thread Jordi Torres
Hi John,

You need use your own shaders as GLES2 does not support materials or OpenGL
lighting. AFAIK shader generator to emulate fixed pipeline is a work in
progress, but it's not completed yet.

Cheers.

2012/5/27 John Moore kahar...@gmail.com

 Hi,

 I am developing an application for iPhone and iPod touch using
 OpenSceneGraph. In origin I written my own shaders and I used to control
 light using a uniform. It was working. Now I wanted to switch to use
 osg::Light and osg::LightSource because I think it is more object-oriented,
 but when I run my code I obtain this warning:


 Code:
 Warning: Light::apply(State) - not supported.



 Does this mean that I can't use this approach with OpenGL ES 2.0 ?


 I post the code I use for managing light:


 Code:

 #define LIGHT_0 0
 - (osg::ref_ptrosg::Light)createLight:(osg::Vec4)color
 atPosition:(osg::Vec4)position
 {
osg::ref_ptrosg::Light light = new osg::Light;
// each light must have a unique number
light-setLightNum(LIGHT_0);
// we set the light's position via a PositionAttitudeTransform object
light-setPosition(position);
light-setDiffuse(color);
light-setSpecular(osg::Vec4(1.0, 1.0, 1.0, 1.0));
light-setAmbient( osg::Vec4(0.0, 0.0, 0.0, 1.0));

return light;

 }

 - (void)setupLights
 {

osg::StateSet* state = _root-getOrCreateStateSet();
state-setMode( GL_LIGHTING, osg::StateAttribute::ON );
state-setMode( GL_LIGHT0, osg::StateAttribute::ON );

// Create a MatrixTransform to position the Light.
osg::ref_ptrosg::MatrixTransform mt = new osg::MatrixTransform;
osg::Matrix m;
m.makeTranslate( osg::Vec3( -3.f, 2.f, 5.f ) );
mt-setMatrix( m );

osg::ref_ptrosg::Light light = [self
 createLight:osg::Vec4(1.0,0.0,0.0,1.0)
 atPosition:osg::Vec4(3.0,2.0,1.0,1.0)];

// Add the Light to a LightSource. Add the LightSource and
// MatrixTransform to the scene graph.
osg::ref_ptrosg::LightSource ls = new osg::LightSource;
_root-addChild( mt.get() );
mt-addChild( ls.get() );
ls-setLight( light.get() );

 }

 - (void) viewDidLoad
 {
//some other code

//initialize the model and attach it to _root
[self initModel];

//setup the lights
[self setupLights];

//initialize the shaders and attach them to _root
[self initShaders];


//create scene and attach it to _viewer
_viewer-setSceneData(_root.get());

//some other code
 }





 Thank you!

 Cheers,
 John

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





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




-- 
Jordi Torres Fabra

gvSIG 3D blog
http://gvsig3d.blogspot.com
Instituto de Automática e Informática Industrial
http://www.ai2.upv.es
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2012-06-12 Thread Chris Hanson
On Sun, May 27, 2012 at 10:45 AM, John Moore kahar...@gmail.com wrote:

 Hi,
  I am developing an application for iPhone and iPod touch using
 OpenSceneGraph. In origin I written my own shaders and I used to control
 light using a uniform. It was working. Now I wanted to switch to use
 osg::Light and osg::LightSource because I think it is more object-oriented,
 but when I run my code I obtain this warning:
 Code:
 Warning: Light::apply(State) - not supported.
 Does this mean that I can't use this approach with OpenGL ES 2.0 ?



  Correct.

  There is some interest from several people in having this work. If you
decide you want to extend the osg::Light code to make it setup new, custom
uniforms to replicate the legacy GLSL Uniforms. Refer to the quick
reference chart here:

http://mew.cx/glsl_quickref.pdf

See gl_LightSourceParameters and gl_LightSource[gl_MaxLights];

  In the Good Old Days, OpenGL pre-loaded all interesting light values
here. You will need to add code to the osg::Light::apply() to create and
populate new osg_ uniforms to replace the legacy GLSL
uniform gl_LightSource, and then your code will have access to the info it
needs to re-create the lighting defined by osg::Light. Refer to some of the
other apply() methods for parts of OSG that already support GLSL uniforms
(maybe Texture) to see how and when to perform this uniform setup, as many
people (not using GLES2 or GL3/GL4) may NOT want these uniforms pre-loaded
for them.


-- 
Chris 'Xenon' Hanson, omo sanza lettere. xe...@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
Digital Imaging • GIS • GPS • Telemetry • Cryptography • Digital Audio •
LIDAR • Kinect • Embedded • Mobile • iPhone/iPad/iOS • Android
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org