【发布时间】:2019-11-30 22:59:30
【问题描述】:
我正在从 https://github.com/stemkoski/stemkoski.github.com/blob/master/Three.js/Bubble.html 复制气泡着色器,但代码已过时,并且示例会折射其背后的任何内容:
我的是黑色的。我在 animate() 中收到的警告(以及我相信的问题所在):
animate() {
this.controls.update();
this.renderer.render(this.scene, this.camera);
this.sphere.visible = false;
//this.refractSphereCamera.updateCubeMap( this.renderer, this.scene );
this.refractSphereCamera.update();
this.sphere.visible = true;
//this.renderer.render( this.scene, this.camera );
requestAnimationFrame(this.animate.bind(this));
}
this.refractSphereCamera.updateCubeMap( this.renderer, this.scene ); 是控制台给我的原始行:
THREE.CubeCamera:.updateCubeMap() 现在是 .update()。
这是实际的着色器/球体:
this.refractSphereCamera = new THREE.CubeCamera( 0.1, 5000, 512 );
this.scene.add( this.refractSphereCamera );
var fShader = THREE.FresnelShader;
var fresnelUniforms =
{
"mRefractionRatio": { type: "f", value: 1.02 },
"mFresnelBias": { type: "f", value: 0.1 },
"mFresnelPower": { type: "f", value: 2.0 },
"mFresnelScale": { type: "f", value: 1.0 },
"tCube": { type: "t", value: this.refractSphereCamera.renderTarget } //textureCube
};
// create custom material for the shader
var customMaterial = new THREE.ShaderMaterial(
{
uniforms: fresnelUniforms,
vertexShader: fShader.vertexShader,
fragmentShader: fShader.fragmentShader
} );
var sphereGeometry = new THREE.SphereGeometry( 100, 64, 32 );
this.sphere = new THREE.Mesh( sphereGeometry, customMaterial);
this.sphere.position.set(0, 50, 100);
this.scene.add(this.sphere);
this.refractSphereCamera.position.set(this.sphere.position);
我可以将一个纹理立方体输入到着色器中,它可以工作,但我不仅希望天空盒,而且希望球体后面的所有对象都发生折射。这里有什么问题?
如果我更改为 .update(),一切都会变黑
其他警告是:
THREE.WebGLRenderer.setTextureCube:不要使用立方体渲染目标作为 纹理。请改用他们的 .texture 属性。
【问题讨论】:
-
你能发布一些工作代码吗?这里似乎没有任何问题,但它没有显示你如何渲染背景。为了进行健全性检查,您能否关闭天空盒,将背景清除为非黑色的东西,然后渲染飞机?
-
stemkoski.github.io/Three.js/Bubble.html - 这是有效的。我这样做了——如果我输入纹理立方体,它不会在折射中渲染它后面的任何对象,否则它不会渲染黑色。但是看到我上面也遇到的错误
标签: javascript html three.js shader