重复凹凸贴图

时间:2013-02-15 00:07:02

标签: javascript three.js webgl 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));

注意我如何设置纹理沿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>

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

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:5)

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

如果您有漫反射mapbumpMap,则它们必须具有相同的offset/repeat设置。例如,请参阅this回答。

three.js r.55

相关问题