[X3D-Public] help w/ X3DOM cube map and refraction/reflection
Michalis Kamburelis
michalis.kambi at gmail.com
Sun Jun 24 00:56:02 PDT 2012
John Carlson wrote:
> Can someone help me get this X3DOM code into a cube map and using
> refraction/reflection? Thanks!
Maybe some general notes regarding cube maps and X3D, and how they work
in my engine and view3dscene, will help. What I write below doesn't
(necessarily) apply to X3DOM, so I don't know how much it will be useful
for you, but here goes...
The standard way to use cube maps and reflections is to use one of the
XxxCubeMapTexture nodes (see
http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/env_texture.html
) and use texture coordinate generator on your shape. Standard X3D
provides you TextureCoordinateGenerator with
mode="CAMERASPACEREFLECTIONVECTOR" (see
http://www.web3d.org/files/specifications/19775-1/V3.2/Part01/components/texturing.html#TextureCoordinateGenerator
) which is almost, but not quite correct, a way to get mirrors, by a
code like
Shape {
appearance Appearance {
material Material { }
texture GeneratedCubeMapTexture {
update "ALWAYS"
size 512
}
}
geometry IndexedFaceSet {
texCoord TextureCoordinateGenerator { mode
"CAMERASPACEREFLECTIONVECTOR" }
# ... other IndexedFaceSet fields
}
}
My engine and view3dscene give you two extensions to make this really work:
- texCoord field is available for all geometry nodes (not just for a few
chosen ones), so it's also available for primitives like Sphere, Box,
and our Teapot.
- TextureCoordinateGenerator with mode="WORLDSPACEREFLECTIONVECTOR" is
available. This makes a truly correct reflection.
See
http://castle-engine.sourceforge.net/x3d_implementation_cubemaptexturing.php
, in particular section "Tutorial: How to make a mirror" there, for
pointers how to make reflections easy with cube maps. You can test them
with view3dscene (http://castle-engine.sourceforge.net/view3dscene.php )
on demo models (http://castle-engine.sourceforge.net/demo_models.php ),
there are examples in demo_models/cube_environment_mapping/ showing cube
maps and reflections. There are also examples in demo_models/water/
showing how to use GLSL shaders (also with the help of some of my
extensions, for GLSL Effects) to get water, with reflections and
refractions by cube maps.
Hope this helps :),
Michalis
More information about the X3D-Public
mailing list