Cube map

From H3D.org

Jump to: navigation, search

The example here demonstrates the use of the ComposedCubeMapTexture node with the CAMERASPACEREFLECTIONVECTOR mode of TextureCoordinateGenerator to model a reflective surface.

Image:Note-tip.pngThis tutorial refers to the source code. You can download it from SVN at H3D release branch, or find it at H3D/H3DAPI/examples/cubemap/.
 
<!!-- CubeMap.x3d-->
  <Scene>
    <NavigationInfo type = "NONE" />
    <Viewpoint position="0 0 0.6" />
    <Background
       backUrl  ="../textures/b_arch_00000.png"
       frontUrl ="../textures/f_arch_00000.png"
       leftUrl  ="../textures/l_arch_00000.png"
       rightUrl ="../textures/r_arch_00000.png"
       bottomUrl="../textures/d_arch_00000.png"
       topUrl    ="../textures/t_arch_00000.png"   />
 

The NavigationInfo type is set to NONE to disable scene navigation. The position of Viewpoint is then set to a value from which the user will observe the scene. Background is then added, composing of 2D images which are placed at the front, back, left, right, top and bottom of the scene.

 
<!!-- CubeMap.x3d-->
    <DynamicTransform angularMomentum="0.1 0.25 0">
      <FitToBoxTransform boxCenter="0 0 0" boxSize="0.25 0.25 0.25"
                         uniformScalingOnly="true" active="true">
 

If we run the source code we will see that the shape in our program rotates in place. This is achievable with the DynamicTransform node. The value of angularMomentum determines the angular momentum of the DynamicTransform and its children, causing them to be continually rotated.

FitToBoxTransform transforms its contents into a box-region of size specified in boxSize positioned at boxCenter. In this example, the transformation does uniform scaling to fit its contents into the box. active is True to enable updates on the transformation matrix.

 
<!!-- CubeMap.x3d-->
        <Shape>
          <Appearance>
            <Material />
            <ComposedCubeMapTexture>
              <ImageTexture url="../textures/b_arch_00000rot.png"
                            containerField="back"/>
              <ImageTexture url="../textures/f_arch_00000rot.png"
                            containerField="front"/>
              <ImageTexture url="../textures/l_arch_00000rot.png"
                            containerField="left"/>
              <ImageTexture url="../textures/r_arch_00000rot.png"
                            containerField="right"/>
              <ImageTexture url="../textures/t_arch_00000.png"
                            containerField="top"/>
              <ImageTexture url="../textures/d_arch_00000.png"
                            containerField="bottom"/>
            </ComposedCubeMapTexture>
          </Appearance>
 

Shape is then added with its usual Appearance and Material nodes. To enable cube map environmental texturing, we inlcude an X3DEnivonmentTexture node as the value to the texture field of Appearance. In this example we use the ComposedCubeMapTexture node, which defines a cubic environment map source as an explicit set of images drawn from individual 2D texture nodes. We use the ImageTexture as these individual 2D texture nodes, and are assigned to the back, front, left, right, top and bottom faces of the cube map respectively. These images are the same as those defining Background.

Having set up the cube map we proceed to create a reflection of the cube map environment on our shape.

 
<!!-- CubeMap.x3d-->
          <TexGenGeometry>
            <SuperShape DEF="SS" resolution="128"
                        ss1_m="1" ss1_a="1.1" ss1_b="1.88"
                        ss1_n1="3.41" ss1_n2="-0.24" ss1_n3="19.07"
                        ss2_m="4" ss2_a="1" ss2_b="1"
                        ss2_n1="110" ss2_n2="100" ss2_n3="90"  />
            <TextureCoordinateGenerator mode="CAMERASPACEREFLECTIONVECTOR" />
          </TexGenGeometry>
        </Shape>
      </FitToBoxTransform>
    </DynamicTransform>
  </Scene>
 

To create a reflective surface we disable the default texturing of our geometry (in this case a SuperShape). Instead of using the default texture coordinates assigned by H3D, our intention is to texture our geometry with generated texture coordinates that would simulate reflection from our cube map. We indicate this to the system with the TexGenGeometry node. We then generate the texture coordinates by adding TextureCoordinateGenerator, and set the mode to CAMERASPACEREFLECTIONVECTOR.

Reflective appearance created with ComposedCubeMapTexture.
Enlarge
Reflective appearance created with ComposedCubeMapTexture.

References

Personal tools
go to