代码之家  ›  专栏  ›  技术社区  ›  Piotr Adam Milewski

使用三立方棱镜进行折射

  •  1
  • Piotr Adam Milewski  · 技术社区  · 8 年前

    example a-frame mirror component .

    创建立方体立方体,初始化时将其渲染目标提取为envMap纹理:
    初始化:

    this.refractionCamera = new THREE.CubeCamera( 0.5, 3000, 128);
    this.el.object3D.add( this.refractionCamera );
    this.refractionMaterial = new THREE.MeshBasicMaterial({ 
            color: 0xffffff, 
            refractionRatio: 0.4, 
            envMap: this.refractionCamera.renderTarget.texture });
    


    勾选:

    this.refractionCamera.updateCubeMap( AFRAME.scenes[0].renderer,                         
    this.el.sceneEl.object3D );
    this.mesh.material = this.refractionMaterial;
    

    当然,图像是镜像的,因为三者是如何映射的。CubeCamera可以工作,所以我尝试旋转纹理或以某种方式翻转它,这样我就没有镜子了。

    正如我所见,李·斯特姆科斯基只使用了:

    refractSphereCamera.renderTarget.mapping = new THREE.CubeRefractionMapping();
    
    • 我试着在init上这样做,但没有任何改变。查看 fiddle .

    • 此外,我尝试偏移纹理,或垂直翻转,但什么也没有 happens .

    2 回复  |  直到 8 年前
        1
  •  1
  •   prisoner849    8 年前

    你知道

    refractSphereCamera.renderTarget.mapping = THREE.CubeRefractionMapping;
    

    如果你想要折射,最好这样做

    refractSphereCamera.renderTarget.texture.mapping = THREE.CubeRefractionMapping;
    

    jsfiddle 实例

        2
  •  1
  •   M -    8 年前

    Date: July 2013 (three.js v59dev)

    你应该看看 this example

    // Load textureCube, change mapping from reflection to refraction
    var textureCube = new THREE.CubeTextureLoader().load( urls );
    textureCube.mapping = THREE.CubeRefractionMapping;
    
    // Assign textureCube to background
    scene = new THREE.Scene();
    scene.background = textureCube;
    
    // Use textureCube as environment map, which will use refraction mapping.
    var cubeMaterial3 = new THREE.MeshPhongMaterial( { color: 0xccddff, envMap: textureCube, refractionRatio: 0.98, reflectivity: 0.9 } );