The challenge of transparent maps in three.js

I'm currently working on generating a large number of particles (exactly 80,000) and I have applied a transparent map to them. However, not all the particles appear to be completely transparent.

The material map I am using is a transparent PNG image (although it may be difficult to see, it is indeed present), but some particles are showing a black background as illustrated here:

Upon closer inspection, I noticed that some particles blend seamlessly without any overlapping black edges, while others do show this issue. Could this be due to the high volume of overlapping transparent objects, or should this not be a concern?

Here is the code snippet responsible for creating the particles:

// load the texture
var map = THREE.ImageUtils.loadTexture('img/particle.png');

// create temporary variables
var geometry, material;

// create an array to hold ParticleSystems (I require multiple systems for different colors and materials)
var systems = [];

// Iterate through each color
for(var i = 0; i < colors.length; i++) {
    // Create a new geometry
    geometry = new THREE.Geometry();

    // create a new material
    material = new THREE.ParticleBasicMaterial({
        color: colors[i],
        size: 20,
        map: map, // set the map here
        transparent: true // transparency enabled!!!
    });

    // create a new particle system
    systems[i] = new THREE.ParticleSystem(geometry, material);

    // add the system to the scene
    scene.add(systems[i]);
}

// vertices are added to the ParticleSystems' geometry here

What could be causing some particles to display a black background?

Answer №1

To achieve a specific level of transparency, consider adjusting the alphaTest property in the material settings rather than using traditional transparency methods. Here's an example:

material.alphaTest = 0.5;
material.transparent = false;

In the latest version of three.js (r.85), particles are no longer sorted and are rendered based on their order in the buffer.

Answer №2

Particles with black corners are displayed first, making it difficult for GL to blend them with objects behind. To achieve the correct appearance, render these particles based on their z coordinates from back to front.

Answer №3

Turn off the depthWrite property in the material settings.

// initializing a new material
material = new THREE.ParticleBasicMaterial({
    color: colors[i],
    size: 20,
    map: map,
    transparent: true,
    depthWrite: false,
});

Answer №4

Check out the webgl_particles_billboards.html page. It should deliver the exact outcome you're looking for.

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

How can we reduce the size of a JSON object in Typescript before sending it to the client?

Currently, I am faced with a common challenge. I have a database object that is a standard JS object originating from a document database, and my goal is to transmit this object to the client. However, certain fields contain sensitive information that shou ...

Incorporate a versatile navigation menu into your HTML pages

At the moment, my website is built with static hand-coded HTML pages. I manually add a navigation menu to each page individually. However, I am looking for a more efficient way to manage this process by maintaining a single user resource file that contains ...

Guide on utilizing index.html, incorporating ui.router, and effectively redirecting back to the homepage

When testing my Angular app, I am using a Python simpleserver. I am new to ui.router and I am trying to get my index.html file to work properly. When attempting to navigate back home, I use the following code: <a class="navbar-brand" ui-sref="/">My ...

What function does listener() serve within the Redux store?

I'm currently studying Dan Abramov's Redux tutorials on Egghead. At the part where he constructs the Redux Store from scratch, there is this code snippet (around 1:28 - ): const dispatch = (action) => { state = reducer(state, action); lis ...

Access control and permissions in Angular's UI router

I am struggling to figure out how to implement permissions and access control in our Angular app. Currently, our setup looks like this: app.config(['$stateProvider', function ($stateProvider) { $stateProvider .state('default', { ...

Animate images using mouse vertical movement

Creating websites is just a hobby for me, not something professional. Recently, I came across a beautifully designed website that had some unique features I hadn't seen before, like placing three images in one div (which I researched and learned how t ...

Sending string variable from Perl CGI script to HTML frontend

Having just begun experimenting with AJAX, I'm encountering difficulties in passing variables back to my HTML script. In this setup, I'm using a combination of a XAMPP webserver, JavaScript, and jQuery for the HTML script, along with a Perl cgi ...

Performing a Javascript validation to ensure that a value falls within

How can I check if an input number falls within a specified range? I need to display if it is within the range, higher, or lower than the acceptable range. My current Javascript code seems to be causing an error message stating it is an invalid entry. It ...

Turn on and off scrolling of DIV content when hovering over it

How can I create a div that automatically scrolls to the bottom on hover? I tried implementing the code below, but it doesn't work as expected. It jumps to the bottom of the div's height on first hover and transitions smoothly on second hover. . ...

Retrieving information using an ajax request in JavaScript

Although this question may have been asked several times before, I have yet to find a satisfactory answer. I passed a URL in an Ajax call and I am trying to retrieve data from the database through a query in the success method of the Ajax request, but for ...

What is Reddit's approach to creating a login/signup modal?

Attempting to create a modal similar to the one on Reddit, I am puzzled about how they achieve the following: Scroll is disabled when the modal is open Scroll is enabled when the window is smaller than the modal I have experimented with various CSS ...

Modify the icon in the header of MaterializeCSS Collapsible when it is opened

I'm struggling to figure out how to change the icon of a toggled collapsible element. I have been reviewing their documentation but am having trouble making it work as intended. $('.collaps_roles_permission').collapsible({ accordion: tr ...

"Implement a JavaScript function to dynamically alter the background color of a div element upon the

I have a 5x5 grid and I have successfully implemented the functionality where tapping on a square changes its background color. Now, I want to enhance this by allowing the user to drag their finger across the screen and change the color of multiple squares ...

Utilize AJAX to update the quantity

I have attempted to update the rows in a table using AJAX, and it works for the first row but not for subsequent rows. Can someone assist me in implementing this functionality with AJAX for multiple rows? Here is an example code snippet from cart.php: &l ...

Display Bootstrap modal automatically upon page load three times for each individual user

i need the bootstrap modal to appear on page load and i have come across the following code. However, there are a couple of issues: 1- I want the modal to display for every user three times, not just the first time! How can I achieve that, my friends? 2 ...

Problem encountered while attempting to insert chunk data into an array correctly with Node.js

I am currently working on a project where I need to read a text file and store each word in an array using Node.js. However, I am facing difficulties as my current code is not producing the desired result. Below is an overview of my txt file. CHANGES: C ...

The UIManager could not find the required native component in requireNativeComponent

I understand that this question has been raised multiple times, but previous inquiries have focused on integrating a third-party dependency in a react-native app. In my case, the issue stems from my own native code, and I am struggling to resolve it. My cu ...

Having trouble with missing elements while looping through Javascript Node.AppendChild()?

I encountered an issue with a basic function designed to relocate items from one div to another using a drag and drop widget. It seems that when multiple items are being moved, the appendchild function is modifying the list directly and causing elements to ...

Saving a JSON file in an AngularJS variable for seamless integration with 'ng-repeat' functionality

This project aims to showcase Oracle PL/SQL records on a website. I followed the steps outlined in this tutorial () to establish a connection with the database. While I successfully stored and displayed values for a single record, I encountered difficultie ...

Step-by-step guide on compressing a JavaScript array

What is the best way to compress an array? I am currently attempting to compress an array using the lz-string library and converting it to/from strings. However, I am encountering issues with decompression, as I am getting null, 0, or [] as the output. B ...