【问题标题】:Repeating a bump map重复凹凸贴图
【发布时间】:2013-02-15 00:07:02
【问题描述】:

我正在尝试将凹凸贴图应用于平面,以使用 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(缩小版)。

任何帮助表示赞赏。

【问题讨论】:

    标签: javascript three.js webgl bump-mapping


    【解决方案1】:

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

    如果您有一个漫反射map 和一个bumpMap,它们必须具有相同的offset/repeat 设置。例如,请参阅this 答案。

    three.js r.55

    【讨论】:

    • 我会在接下来的 24 小时内试一试,然后回复您。非常感谢您的帮助。
    • 我现在又在看这个了。将凹凸贴图和漫反射贴图设置为同一个实例仍然会给我与图片相同的问题。在尝试另一种材质纹理的方法之前,我将尝试快速重现此问题。
    • 我已经用可以帮助您重现问题的代码更新了我的问题。我已经在 Ubuntu 12.04 上的 Firefox 和 Chrome 中进行了测试。
    • 您更新的代码对我来说很好用。但是,当我使用非二次幂纹理时,我能够重现您的问题。是这样吗?
    • 太棒了!是的,现在你指出它似乎很明显,但我的纹理是矩形的,两个维度都不是 2 的幂。非常感谢。如果加载的纹理具有非二维幂次方维度,如果 Three.js 退出控制台警告,您认为这会有用吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多