0

我关注了这篇文章,希望能添加我自己的观点。我注意到 这里的示例使用的是 Three.JS (49) 的一个非常旧的版本。当我将源文件更改为更新版本时,纹理不再出现。看演示

我一直在花费大量时间试图弄清楚发生了什么折旧,并且我已经将搜索范围缩小到这些行。

// material

uniforms = {
                sunDirection: { type: "v3", value: new THREE.Vector3(0,1,0) },
            dayTexture: { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "/images/world2.png" ) },
                nightTexture: { type: "t", value: 1, texture: THREE.ImageUtils.loadTexture( "/images/world5.png" ) }
            };

            uniforms.dayTexture.texture.wrapS = uniforms.dayTexture.texture.wrapT = THREE.Repeat;
            uniforms.nightTexture.texture.wrapS = uniforms.nightTexture.texture.wrapT = THREE.Repeat;

  material = new THREE.ShaderMaterial( {

                uniforms: uniforms,
                vertexShader: document.getElementById( 'vertexShader' ).textContent,
                fragmentShader: document.getElementById( 'fragmentShader' ).textContent

                } );

更多可能与我的问题有关的杂项

<script id="fragmentShader" type="x-shader/x-fragment">

        uniform sampler2D dayTexture;
        uniform sampler2D nightTexture;

        uniform vec3 sunDirection;

        varying vec2 vUv;
        varying vec3 vNormal;

        void main( void ) {
            vec3 dayColor = texture2D( dayTexture, vUv ).rgb;
            vec3 nightColor = texture2D( nightTexture, vUv ).rgb;

            // compute cosine sun to normal so -1 is away from sun and +1 is toward sun.
            float cosineAngleSunToNormal = dot(normalize(vNormal), sunDirection);

            // sharpen the edge beween the transition
            cosineAngleSunToNormal = clamp( cosineAngleSunToNormal * 10.0, -1.0, 1.0);

            // convert to 0 to 1 for mixing
            float mixAmount = cosineAngleSunToNormal * 0.5 + 0.5;

            // Select day or night texture based on mix.
            vec3 color = mix( nightColor, dayColor, mixAmount );

            gl_FragColor = vec4( color, 1.0 );
            //gl_FragColor = vec4( mixAmount, mixAmount, mixAmount, 1.0 );
        }
    </script>

    <script id="vertexShader" type="x-shader/x-vertex">

        varying vec2 vUv;
        varying vec3 vNormal;

        void main()
        {
            vUv = uv;
            vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
            vNormal = normalMatrix * normal;
            gl_Position = projectionMatrix * mvPosition;
        }

    </script>

我已经在这里检查了迁移 docx 没有太多关于“制服”或“着色器”的事实。

4

1 回答 1

0

在您引用的迁移 Wiki中,它指定了从 r.51 开始将纹理分配给制服的新模式:

{ type: "t", value: 0, texture: map } => { type: "t", value: map }

所以在你的情况下,它会是

dayTexture: { type: "t", value: THREE.ImageUtils.loadTexture( "/images/world2.png" ) },
nightTexture: { type: "t", value: THREE.ImageUtils.loadTexture( "/images/world5.png" ) }

三.js r.59

于 2013-08-02T03:46:07.597 回答