2013-08-02 35 views
0

我跟着this post希望能加入我自己的東西。我注意到位於 here的示例正在使用Three.JS(49)的非常舊版本。當我將源文件更改爲更新的版本時,紋理不再顯示。請參閱Demo紋理更新時不顯示Three.js版本

我一直花費大量時間來弄清楚發生了什麼貶值,並且我將搜索範圍縮小到這些行。這可能有事情做與我的問題

// 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 here 沒有太多的「制服」或「着色」爲事實。

回答

0

Migration 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

+0

我之前做過這個改變(忘了在原文中提到),整個代碼都不起作用。 –

+0

我在代碼中做了更改,紋理渲染正常。這是你原來的問題的答案。您可能還有其他問題。 – WestLangley

+0

你有代碼工作的小提琴嗎? –