Re: [osg-users] Model Matrix in Vertex Shader
I've just been doing some testing and the `view matrices` seem fine after all. It's my gl_Position that's confusing my glsl. I'm porting a Three.js shader to Open Scene Graph and I almost got Phong completely working. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=70060#70060 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Hi Johny, osg_ViewMatrixInverse is not set on 3.4.0? This is always zero for me. How did you find out it is actually zero? I use right settings: Code: state->setUseModelViewAndProjectionUniforms(true); state->setUseVertexAttributeAliasing(true); Did you set this at the camera's state set (Although I think the osg_ViewMatrix* are not related to the ModelViewProjectionUniform setting) Is the osg_ViewMatrix working correctly? Cheers Sebastian (osg_ProjectionMatrix, osg_NormalMatrix, osg_ModelViewMatrix do work properly) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=70058#70058 ___ 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] Model Matrix in Vertex Shader
osg_ViewMatrixInverse is not set on 3.4.0? This is always zero for me. I use right settings: Code: state->setUseModelViewAndProjectionUniforms(true); state->setUseVertexAttributeAliasing(true); (osg_ProjectionMatrix, osg_NormalMatrix, osg_ModelViewMatrix do work properly) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=70058#70058 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
I looked around the web to try to figure out how to also get the camera XYZ in world space. According to sources I should be able to get the camera world coordinates from the last column of the inverse view matrix. Is this correct? Code: vec3 cameraPositionWorldCoordinates; cameraPositionWorldCoordinates[0] = osg_ViewMatrixInverse[3][0]; cameraPositionWorldCoordinates[1] = osg_ViewMatrixInverse[3][1]; cameraPositionWorldCoordinates[2] = osg_ViewMatrixInverse[3][2]; -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51672#51672 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Hi this is correct, camera position is osg_ViewMatrixInverse[3].xyz Cheers. 21.12.2012, 17:25, Ethan Fahy ethanf...@gmail.com: I looked around the web to try to figure out how to also get the camera XYZ in world space. According to sources I should be able to get the camera world coordinates from the last column of the inverse view matrix. Is this correct? Code: vec3 cameraPositionWorldCoordinates; cameraPositionWorldCoordinates[0] = osg_ViewMatrixInverse[3][0]; cameraPositionWorldCoordinates[1] = osg_ViewMatrixInverse[3][1]; cameraPositionWorldCoordinates[2] = osg_ViewMatrixInverse[3][2]; -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51672#51672 ___ 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] Model Matrix in Vertex Shader
Thanks, and I appreciate you pointing out the short-hand version. hybr wrote: Hi this is correct, camera position is osg_ViewMatrixInverse[3].xyz Cheers. 21.12.2012, 17:25, Ethan Fahy : I looked around the web to try to figure out how to also get the camera XYZ in world space. According to sources I should be able to get the camera world coordinates from the last column of the inverse view matrix. Is this correct? Code: vec3 cameraPositionWorldCoordinates; cameraPositionWorldCoordinates[0] = osg_ViewMatrixInverse[3][0]; cameraPositionWorldCoordinates[1] = osg_ViewMatrixInverse[3][1]; cameraPositionWorldCoordinates[2] = osg_ViewMatrixInverse[3][2]; -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51672#51672 ___ 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=51674#51674 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Is there one definitive list that explains all the built-in osg uniforms? This one would have come handy earlier, but I did not know about it. Christian ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Christian Buchner writes: Is there one definitive list that explains all the built-in osg uniforms? This one would have come handy earlier, but I did not know about it. Take a look at Mike Weiblen's GLSL cheatsheet, although it could be outdated: http://mew.cx/glsl_quickref.pdf -- Alberto ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Hi Not sure if it is still true, but last time i used this stuff with stereo setups (not sure but it can hold for any offset-based slave cameras setup) osg_ViewMatrix and it's inverse was containing main camera view (and inverse) matrix and was same for both eyes. Cheers,Sergey. 20.12.2012, 00:12, "Glenn Waldron" gwald...@gmail.com:vec4 worldVert = osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex; ...where osg_ViewMatrixInverse is a built-in OSG uniform (type mat4). Just be aware: GLSL is single-precision, so you will lose some precision doing this.Glenn Waldron / @glennwaldronOn Wed, Dec 19, 2012 at 3:03 PM, Ethan Fahy ethanf...@gmail.com wrote:Hello all, I would like to have access to vertex world coordinates in my GLSL vertex shader that is attached to an osg::Node. In GLSL the Model Matrix and the View Matrix are combined into the ModelViewMatrix, so you cannot get access to the Model Matrix without either passing in the Model Matrix itself or the Inverse View Matrix (which could be multiplied by the ModelViewMatrix to get the Model Matrix). I am familiar with how to attach an osg::Uniform to pass uniforms into the shader; my question is, what is the best way to obtain either the Model Matrix or the Inverse View Matrix from a given osg::Node? I think I may be able to use osg::getLocalToWorld() to obtain the Model Matrix? I have read through this thread: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2008-April/009903.html but it doesn't really arrive at a satisfying conclusion and may or may not be out of date. Any advice is appreciated. Thanks, -Ethan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51639#51639 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ,___osg-users mailing listosg-users@lists.openscenegraph.orghttp://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] Model Matrix in Vertex Shader
The OpenSceneGraph Reference Manual at lulu.com also has this info, but both resources are out of date. You can easily get a list of OSG's built-in uniforms by doing a recursive grep in your OSG source tree for getOrCreateUniform. All OSG built-in uniforms are created using this function. -Paul On 12/20/2012 4:57 AM, Alberto Luaces wrote: Christian Buchner writes: Is there one definitive list that explains all the built-in osg uniforms? This one would have come handy earlier, but I did not know about it. Take a look at Mike Weiblen's GLSL cheatsheet, although it could be outdated: http://mew.cx/glsl_quickref.pdf ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
If I insert the line: vec4 worldVerts = osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex; into my vertex shader (without actually using it for anything, just declaring it) I get the following error: error C1008: undefined variable osg_ViewMatrixInverse Do I have to pass osg_ViewMatrixInverse as a uniform from the osg side or should I be able to use osg_ViewMatrixInverse in any GLSL code attached to an osg::Node without any extra effort? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51660#51660 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
Nevermind, I figured out that you have to put the following at the top of the vertex shader before being able to use osg_ViewMatrixInverse: uniform mat4 osg_ViewMatrixInverse; -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51661#51661 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Model Matrix in Vertex Shader
Hello all, I would like to have access to vertex world coordinates in my GLSL vertex shader that is attached to an osg::Node. In GLSL the Model Matrix and the View Matrix are combined into the ModelViewMatrix, so you cannot get access to the Model Matrix without either passing in the Model Matrix itself or the Inverse View Matrix (which could be multiplied by the ModelViewMatrix to get the Model Matrix). I am familiar with how to attach an osg::Uniform to pass uniforms into the shader; my question is, what is the best way to obtain either the Model Matrix or the Inverse View Matrix from a given osg::Node? I think I may be able to use osg::getLocalToWorld() to obtain the Model Matrix? I have read through this thread: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2008-April/009903.html but it doesn't really arrive at a satisfying conclusion and may or may not be out of date. Any advice is appreciated. Thanks, -Ethan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51639#51639 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Model Matrix in Vertex Shader
vec4 worldVert = osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex; ...where osg_ViewMatrixInverse is a built-in OSG uniform (type mat4). Just be aware: GLSL is single-precision, so you will lose some precision doing this. Glenn Waldron / @glennwaldron On Wed, Dec 19, 2012 at 3:03 PM, Ethan Fahy ethanf...@gmail.com wrote: Hello all, I would like to have access to vertex world coordinates in my GLSL vertex shader that is attached to an osg::Node. In GLSL the Model Matrix and the View Matrix are combined into the ModelViewMatrix, so you cannot get access to the Model Matrix without either passing in the Model Matrix itself or the Inverse View Matrix (which could be multiplied by the ModelViewMatrix to get the Model Matrix). I am familiar with how to attach an osg::Uniform to pass uniforms into the shader; my question is, what is the best way to obtain either the Model Matrix or the Inverse View Matrix from a given osg::Node? I think I may be able to use osg::getLocalToWorld() to obtain the Model Matrix? I have read through this thread: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2008-April/009903.html but it doesn't really arrive at a satisfying conclusion and may or may not be out of date. Any advice is appreciated. Thanks, -Ethan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51639#51639 ___ 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