Creating a see-through effect in Three.js with React Fiber

I'm currently working with react fiber and struggling to make the background of my child scene transparent.

Below is my root component containing the main Canvas element:


    export const Splash = () => {
      const { intensity, distance, color, ambientIntensity } = useControls('Main lights', {
        intensity: { value: 9, min: 0, max: 200, step: 0.5 },
        distance: { value: 100, min: -100, max: 100, step: 0.5 },
        color: "#7c0505",
        ambientIntensity: { value: 0.5, min: -3, max: 3, step: 0.1 },
      });

      return (
        <>
          <Canvas
            dpr={window.devicePixelRatio}
            onCreated={({ gl }) => {
              gl.setClearColor(0xFF0000, 0);
              gl.autoClear = false;
              gl.clearDepth()
            }}
            gl={{ antialias: true, alpha: true }}
            camera={{ fov: 65, position: [0, 0, 30] }}>
            <Main>
              <ambientLight intensity={ambientIntensity} color={color} />
              <RadialGradientPlane />
            </Main>
            <ApplyEffects>
              <RadialGradientPlane />
            </ApplyEffects>
          </Canvas>
        </>
      )
    }
  

The Main Component is responsible for rendering the child scene:


    function Main({ children }) {
      const scene = useRef()
      const { gl, camera } = useThree()
    
      useFrame(() => {
        gl.autoClear = false
        gl.clearDepth()
        gl.render(scene.current, camera)
      }, 1)
    
      return <scene ref={scene}>{children}</scene>
    }
  

Initially, the scene is transparent without the ApplyEffects component, but once added, it affects the background. Below is the ApplyEffects component causing the issue:


    import { Effects } from '@react-three/drei';
    import { UnrealBloomPass, RenderPass, WaterPass } from 'three-stdlib';
    
    export default function ApplyEffects({ children }: { children: React.ReactNode }) {
      ...
    }
  

I've attempted various solutions and still can't seem to resolve the transparency problem. Any assistance on this matter would be highly appreciated!

For a detailed example demonstrating the issue, please refer to this small example.

When the "Effects" component is removed, the background becomes transparent, displaying the white body color.

Thank you,

Answer №1

This issue has been widely acknowledged and there have been many discussions about it, which you can see here.

A potential solution has been implemented in this project and appears to resolve the problem, as showcased in this demonstration.

Please inform me if this proves to be helpful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to use CSS to ensure that dynamic, data-driven characters can be properly displayed within a div

I'm in the process of updating a data-centric website that relies on information from an automated database engine. In the HTML, there's a fixed-size button containing text pulled from the database. I'm looking to incorporate some CSS styles ...

Can Next.js 13 support the usage of axios?

Despite trying to implement the SSG operation with the fetch option {cache: 'force-cache'}, I consistently received the same data even when the mock server's data changed. I found that using the fetch option {cache: 'no-store'} do ...

Having trouble retrieving a hidden value in JavaScript when dealing with multiple records in a Coldfusion table

In this table, there is a column that allows users to select a predicted time. <cfoutput query="getReservations"> <tbody> <td><input class="form-control predicted" name="predicted" id="ReservaTempoPrevisto" placeholder= ...

Utilizing Three.js to instantiate a variety of objects and interact with each one separately

Recently, I managed to create a cube in 'three.js', and now I'm looking to replicate that cube three more times and animate them individually using 'Tweenmax'. As a newcomer to three.js, I would greatly appreciate any guidance or ...

The clearInterval function in Javascript may not effectively halt an ongoing animation

Whenever I press a button, the element rotates using setInterval and clearInterval to stop rotation at a specific value by clearing the interval time t. Everything works perfectly except when I continually click the same button before the current animation ...

Encountering Flow type errors when declaring global variables in React

type Props = { checkedItems:any }; class MyApp extends Component<Props> { constructor(props) { super(props); this.checkedItems = []; } } In this code snippet, I am utilizing Flow for type checking within a React class component. However ...

Styling the content within Template Strings is not supported by VSCode

Recently, I've noticed that there are two scenarios in which my VSCode doesn't properly style the content within my template strings. One is when I'm writing CSS in a JavaScript file, and the other is when I'm fetching data from GraphQL ...

Utilizing Vue.js to connect with a Node.js server

After setting up a basic Node.js server, the following code is running successfully: var http = require('http'); var server = http.createServer(); server.on('request', function(req, res) { res.writeHead(200, { 'content ...

Display navigation bar upon touch or lift

In the mobile version of a website, there is a fixed navigation bar at the top. The positioning of this navbar is achieved using position:absolute: .navbar-fixed-top{position:absolute;right:0;left:0;z-index:1000; The goal is to make the navbar invisible ...

Ways to incorporate external JavaScript files into a React component

I have been attempting to incorporate external javascript files into my react component. When I included them in a basic html file using script tags, everything worked smoothly. However, I am unsure of how to achieve this within a react component. < ...

Can anyone recommend a drag-and-drop feature in Javascript that functions seamlessly on both iPad and PC devices?

Can anyone recommend a JavaScript plugin that allows for drag and drop functionality on both touch and mouse enabled devices, including IOS, Android, PC, and Mac? For touch-enabled devices, I found an example here: And for mouse-enabled devices, there is ...

What steps can be taken to create a progress bar in the input field that spans the entire width of its parent div, reaching

I received assistance from a friend in creating this progress bar. Everything seems to be working well, except for the fact that the progress bar is not extending to the full width of the parent div. The new width after each input tag is entered using Java ...

The module in the relative path cannot be located by Node.js

Node.js is giving me some trouble with exporting and importing classes from multiple files. In one file, I have two classes that I'm exporting using the following code: module.exports = {TrigInter, Hilbert}; However, when I try to import these classe ...

Navigational packages for React applications

As I make decisions for my React project, I am considering which routing library to choose. Are there any alternatives to "react-router," "ui-router," and "react-navigation" that you would recommend? ...

The Express application fails to receive a response from a Mongodb query function

In my current project, I am implementing a simple API Key authentication system. The main goal is to validate the provided key against the user's input. There is a separate file containing a function that queries the database and returns either true/ ...

Error: Unable to set reference. The initial argument includes an undefined value in the 'gender' property of 'Users.ji8A7TkSldfdvieDqGxko9eV3Jy1'

I followed along with a Firebase Web Tutorial on YouTube about adding data to Firebase Database for an account settings tutorial. However, when I tried to implement the code provided, it didn't work. Can anyone offer any assistance? // Code snippet fo ...

Dynamic Color Transformation of Threejs Vehicles during Execution

I have been experimenting with the Threejs cars example found at the following URL: It's a great way to test realistic objects. I was trying to change the materials for the car on runtime, but I hit a roadblock due to the way the mesh is being added ...

What kind of impact does the question mark at the conclusion of a function title make?

I came across the following TypeScript code snippet: class Foo { start?(): void {} } What caught my attention was the ? at the end of start. It appears to be making the function optional (but how can a function be optional and when would you need tha ...

What is the best method for purging a previously stored variable from the cache when making an Ajax call and simultaneously passing a

I am encountering an issue with variable loading during the ajax call. Upon clicking, I pass a variable to the ajax call which then sends the value to a PHP script. The data obtained is from: rnc.csv DLRNC01 DLRNC02 DLRNC03 DLRNC04 DLRNC05 DLRNC06 DLR ...

Icon for closing Mui Snackbar

I am facing an issue with my notification component that uses the mui snackbar to display alerts. I want to display multiple notifications stacked vertically, but when I try to close one notification using the "Close" icon, it ends up closing both that o ...