question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get background and SelectiveBloom to work

See original GitHub issue

Hi, it looks like a great library with a very nice surface API, unfortunately I can’t get a basic example to work properly. I would like to have a background pass combined with main scene render pass and outline + bloom upon selecting a mesh.

Below is my test code, I can see the mesh and the outline is working upon selecting the sphere, however I can get the bloom effect to work and the background is plain black. Is there anything obviously stupid I am ding there?

    import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
    import Background from './Background'

    import { 
      PerspectiveCamera, 
      MeshPhongMaterial,
      DirectionalLight,
      SphereGeometry,
      WebGLRenderer,
      AmbientLight,
      Clock, 
      Scene,
      Mesh
    } from "three"

    import { 
      SelectiveBloomEffect, 
      EffectComposer, 
      OutlineEffect, 
      EffectPass, 
      RenderPass 
    } from "postprocessing"

    export default class TestViewer {
      
      constructor (container) {   
        super()
        this.container = container
      }

      start () {

        this.container.addEventListener(
          'click', this.onClick)

        const renderer = new WebGLRenderer({
          // powerPreference: 'high-performance',
          // logarithmicDepthBuffer: false,
          // physicallyCorrectLights: true,
          // preserveDrawingBuffer: false,
          // premultipliedAlpha: true,
          // precision: "highp",
          // gammaOutput: true,
          // gammaFactor: 2.2,
          // antialias: false,
          // alpha: true
        })

        const height = this.container.offsetHeight
        const width = this.container.offsetWidth

        renderer.setPixelRatio(window.devicePixelRatio)
        renderer.setSize(width, height)
        renderer.autoClear = false

        this.container.appendChild(
          renderer.domElement)

        this.composer = new EffectComposer(renderer)
        this.camera = new PerspectiveCamera(
          40, width / height, 1, 10000)
        this.camera.position.set(20, 20, 20)

        this.controls = new OrbitControls(
          this.camera, renderer.domElement)

        this.scene = new Scene()
        this.clock = new Clock()

        const ambientLight = new AmbientLight(0x212121)
        const mainLight = new DirectionalLight(0xff7e66, 1.0)
        const backLight = new DirectionalLight(0xff7e66, 0.1)

        mainLight.position.set(14.4, 2, 20)
        backLight.position.copy(mainLight.position).negate()

        this.scene.add(ambientLight, mainLight, backLight)
      
        const geometry = new SphereGeometry(5, 24, 24)
      
        const material = new MeshPhongMaterial( {
          flatShading: true,
          transparent: true,
          color: 0x00ffff,
          opacity: 0.7
        })

        const mesh = new Mesh(geometry, material)
        this.scene.add(mesh)

        this.background = new Background(renderer)

        const backgroundPass = new RenderPass(
          this.background.scene, 
          this.background.camera)

        backgroundPass.clear = true

        this.composer.addPass(backgroundPass)
        
        const scenePass = new RenderPass(
          this.scene, this.camera)

        scenePass.clear = false  

        this.composer.addPass(scenePass)

        this.selectiveBloom = new SelectiveBloomEffect(
          this.scene, this.camera)

        this.composer.addPass(new EffectPass(
          this.camera, this.selectiveBloom))

        this.outline = new OutlineEffect(
          this.scene, this.camera)

        this.composer.addPass(new EffectPass(
          this.camera, this.outline))

        this.render()
      }

      render = () => {
        requestAnimationFrame(this.render)
        this.composer.render(
          this.clock.getDelta())
      }

      getIntersects (event, selectables) {
        
        const pointer = event.changedTouches 
          ? event.changedTouches[0]
          : event

        const rect = this.container.getBoundingClientRect()
        
        const pos = new THREE.Vector3(
          (pointer.clientX - rect.left) / rect.width  * 2 - 1,
          -(pointer.clientY - rect.top)  / rect.height * 2 + 1,
          0.5)

        const raycaster = new THREE.Raycaster()  

        raycaster.setFromCamera(
          pos, this.camera)

        return raycaster.intersectObjects(
          selectables, 
          true)
      }

      onClick = (event) => {
        const intersects = this.getIntersects(
          event, this.scene.children)
        const nodes = intersects.length
          ? [intersects[0].object]
          : [] 
        console.log(nodes)
        this.selectiveBloom.selection.set(nodes)
        this.outline.selection.set(nodes)
      }
    }

Thanks for any insights!

Screen Shot 2020-04-05 at 10 14 00

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leefsmpcommented, Apr 5, 2020

Some mistake in my shader, got it working fine now. So I have two RenderPass (background, main scene, with clear=false). Then the effects, all good. Thanks a lot for quick response!

1reaction
vanruesccommented, Apr 5, 2020

So like this https://codesandbox.io/s/selective-bloom-outline-7rubg?

I’ll add a note to the docs regarding layers and lights for selective bloom.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ThreeJS: selective bloom - Stack Overflow
I use EffectComposer and BloomPass to make my scene overbright. However, I need to disable it for whole scene and use for selected...
Read more >
How to use bloom effect not for all object in scene? - Questions
I've been unsuccessful in getting the “Glow” effect to overlay onto non bloom effect background objects. I would expect that some of the ......
Read more >
Troubleshooting Zoom Virtual Background not working
Virtual backgrounds do work with the free account, and if you are having issues getting virtual backgrounds to appear, here is my solution....
Read more >
Zoom virtual backgrounds not working? Solution by Chris ...
Zoom virtual backgrounds are extremely popular. Many users have commented on my channel that their virtual background is not working.
Read more >
Zoom Virtual Backgrounds NOT Working? Watch THIS
Want to Look More Professional on Zoom?Check out this video - https://youtu.be/JnD1gQcL9fgZoom virtual backgrounds NOT working ?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found