重复凹凸贴图

Dre*_*kes 3 javascript webgl three.js bump-mapping

我正在尝试将凹凸贴图应用于平面,以使用Three.js r55创建一个模糊的感觉表面.

这是我的代码:

var mapHeight = THREE.ImageUtils.loadTexture("images/felt.png");
mapHeight.repeat.set(2, 2);
mapHeight.wrapS = mapHeight.wrapT = THREE.RepeatWrapping;
mapHeight.format = THREE.RGBFormat;

var groundMaterial = new THREE.MeshPhongMaterial({
    ambient: 0x008800, color: 0x008800, specular: 0x888888,
    shininess: 25, bumpMap: mapHeight, bumpScale: 10, metal: false
} );

scene.add(new THREE.Mesh(new THREE.PlaneGeometry(0.3, 0.3), groundMaterial));
Run Code Online (Sandbox Code Playgroud)

注意我如何设置纹理沿x/y轴重复两次.然而,我所看到的仅在一个象限中应用纹理:

我希望这可以用夹子/重复包装(或者不管它叫什么),但我在RepeatWrapping这里要求.

如何在平面上正确重复凹凸贴图重复任意次数.


编辑 - 完整代码

我着手制作一个简单的复制案例.这是非常小的并且再现下面的图像(从略微不同的摄像机角度.)输出具有相同的问题.

<!DOCTYPE html>
<html>
<head>
    <script src="scripts/libs/three.min.js" type="text/javascript"></script>
</head>
<body>
<div id="scene-container"></div>

<script>

    init();

    function init() {
        var camera, scene, renderer;

        scene = new THREE.Scene();
        scene.add( new THREE.AmbientLight( 0x555555 ) );

        var light = new THREE.DirectionalLight( 0x555555 );
        light.position.set( 0, 0, 10 );
        scene.add( light );

        var bumpMapTexture = THREE.ImageUtils.loadTexture( "images/felt.png", undefined, function () {
            requestAnimationFrame( function () {
                // render once texture has loaded
                renderer.render( scene, camera );
            } );
        } );
        bumpMapTexture.repeat.set( 2, 2 );
        bumpMapTexture.wrapS = bumpMapTexture.wrapT = THREE.RepeatWrapping;

        var groundMaterial = new THREE.MeshPhongMaterial( {
            ambient: 0x00AA00,
            color: 0x00AA00,
            bumpMap: bumpMapTexture
        } );

        scene.add( new THREE.Mesh( new THREE.PlaneGeometry( 3, 3 ), groundMaterial ) );

        camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.01, 100000 );
        camera.position.set( 0, 0, 3 );
        camera.lookAt( new THREE.Vector3( 0, 0, 0 ) );

        renderer = new THREE.WebGLRenderer( { antialias: true } );
        renderer.setSize( window.innerWidth, window.innerHeight );//        renderer.render(scene, camera);

        document.getElementById( 'scene-container' ).appendChild( renderer.domElement );
    }

</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这链接到Three.js r55(缩小).

任何帮助赞赏.

Wes*_*ley 6

如果您想要重复纹理,则每个维度的像素大小必须是2的幂(例如,512 x 256).

如果你有漫反射map和a bumpMap,它们必须具有相同的offset/repeat设置.例如,请参阅答案.

three.js r.55