个人在使用threejs的outlinepass中的各种问题

30 阅读1分钟

使用threejs的outlinepass遇到了特效不显示,显示后场景变黑的情况,花了一天时间终于解决了 render中代码的执行顺序要正确

以下是参考

render(){
    requestAnimationFrame(this.render.bind(this));
    this.renderer.render(this.scene, this.camera);
    if (this.composer) {
        this.composer.render()
    }
}
animate(): void {
    if (this.scene) {   
        this.render();
    }
}

然后是模型高亮后整体环境会变黑

以下是解决办法在renderPass下方加上gammaCorrectionShader来修正颜色

  this.renderPass = new RenderPass(this.scene, this.camera)
  this.composer.addPass(_this.renderPass);

  // 颜色修正
  const gammaCorrectionShader = new ShaderPass(GammaCorrectionShader);
  this.composer.addPass(gammaCorrectionShader);