[英]Three.JS updating camera breaks shader?
我正在從https://github.com/stemkoski/stemkoski.github.com/blob/master/Three.js/Bubble.html復制Bubble着色器,但代碼已過期,示例中的代碼都折射了在它后面:
我的是黑色的。 我在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 );
是控制台給我的原始行:
三個.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);
我可以將textureCube輸入到着色器中,並且可以工作,但我不僅希望天空盒,還希望球體后面的所有對象都折射。 怎么了
如果我更改為.update(),一切都會變黑
其他警告是:
THREE.WebGLRenderer.setTextureCube:不要將立方體渲染目標用作紋理。 請改用其.texture屬性。
嘗試將.far
增加到5,001或10,000。 該示例似乎是將天空盒渲染為場景中的一個立方體,如果您的攝像機以5,000的速度剪輯並且該立方體具有相同的大小,則很可能是它只是被剪輯在攝像機的后面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.