Hi Michael,

Hi.
I haven't found any example of using cubemaps from GLSL in OSG examples and on the web. I only found cubemap usage in osgOcean: http://goo.gl/NwTTs9
It has the following "varying" in the vertex shader:

nCube = gl_Vertex.xyz;

And the following usage of it in the fragment one:

vec3 p = vec3(nCube.x, nCube.y, -nCube.z);
gl_FragColor = textureCube(cubeMap, p.xzy);

I used it in my example and the result is the cubemap mapped to boxes without any motion when I turn camera around (the screenshot is attached to the mail).

What's the correct way to get moving cube map when I turn camera around?
You might try the transformed normal to perform the lookup.

e.g. vec3 normal = osg_NormalMatrix * gl_Normal;
vec4 color = textureCubeMap(cubeMap, normalize(normal));

If this is not what you are after (e.g. If you are looking for sky-box like reflections), the you need to use the reflection vector which is something like:

vec3 normal = osg_NormalMatrix * gl_Normal;
vec4 view = osg_ModelViewMatrix * gl_Vertex;
vec3 reflect = reflect(normalize(-view.xyz), normal);#

Sorry this is out of my head and I didn't test it. But it should give you the idea.
Btw. This has nothing to do with OSG. Google for cubemapping glsl.

cheers
Sebastian

Thanks.


_______________________________________________
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

Reply via email to