Using square patterns for round particles in three.js

Having some trouble with rendering particles correctly in my three.js project. I've been trying to follow a tutorial on setting up particles, but the issue is that even though they appear in the right position and are visible, they have a rectangular shape instead of being circular. https://i.sstatic.net/5mO8c.png Here's the code snippet related to the material:

var texture = new THREE.TextureLoader().load(   
"textures/disc.png",
function(texture) {

  var material = new THREE.PointsMaterial({
    color: 0xFFFFFF,
    size: 16,
    map: texture,
    transparent: true,
    blending: THREE.AdditiveBlending,
  });

  particles = new THREE.Points( geometry, material );
});

If you want to take a look at the full code, it's available here.

I'm quite perplexed as to why the particles are displaying like this, especially since the tutorial's example works perfectly fine.

Answer №1

The problem arises when the fog affects your particles. To fix this, set the fog property to false in the PointMaterial.

var scene,
        camera, fieldOfView, aspectRatio, nearPlane, farPlane, HEIGHT, WIDTH,
        renderer, container;

function createScene() {
    HEIGHT = window.innerHeight;
    WIDTH = window.innerWidth;

  scene = new THREE.Scene();

  scene.fog = new THREE.Fog(0xf7d9aa, 100, 950)
  aspectRatio = WIDTH / HEIGHT;
  fieldOfView = 60;
  nearPlane = 1;
  farPlane = 10000;
  camera = new THREE.PerspectiveCamera(
    fieldOfView,
    aspectRatio,
    nearPlane,
    farPlane
  );

  camera.position.x = 10;
  camera.position.z = 290;
  camera.position.y = 25;

  renderer = new THREE.WebGLRenderer({
    alpha: true,
    antialias: true
  });

    renderer.setClearColor(new THREE.Color(0, 0, 0));
  renderer.setSize(WIDTH, HEIGHT)
  renderer.shadowMap.enabled = true;

  container = document.getElementById('world');
  container.appendChild(renderer.domElement);

  window.addEventListener('resize', handleWindowResize, false);
}

function handleWindowResize() {
  HEIGHT = window.innerHeight;
  WIDTH = window.innerWidth;
  renderer.setSize(WIDTH, HEIGHT);
  camera.aspect = WIDTH / HEIGHT;
  camera.updateProjectionMatrix();
}


var hemisphereLight, shadowLight;

function createLights() {
}

var sphere;
function createSphere() {
    var geometry = new THREE.SphereGeometry( 150, 32, 32 );
    var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
    sphere = new THREE.Mesh( geometry, material );
    sphere.visible = false;
    scene.add( sphere );
}

function createParticles() {
    var loader = new THREE.TextureLoader();
    var texture = loader.load(      
        "https://i.imgur.com/9fW07EI.png",
      function(texture) {
        editGeometry = sphere.geometry;
        var geometry = new THREE.Geometry();
        for ( i = 0; i < editGeometry.vertices.length; i ++ ) {

          geometry.vertices.push(editGeometry.vertices[i]);

        }

        var material = new THREE.PointsMaterial({
          color: 0xFFFFFF,
          size: 16,
          map: texture,
          transparent: true,
          blending: THREE.AdditiveBlending,
          fog: false,
          depthTest: false,
        });

        particles = new THREE.Points( geometry, material );
        particles.sortParticles = true;
        scene.add( particles );
    });
}

function loop() {
  renderer.render(scene, camera);
    requestAnimationFrame(loop);
}


function init() {
    createScene();
    createLights();
    createSphere();
    createParticles();
    loop();
}
init()
body {
  margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/three.min.js"></script>
<div id="world">
</div>

Please note that if your image is hosted on a different domain than your webpage, you will need cross-origin access and permission from the server hosting the image to use it in WebGL.

Also, using images from third-party domains requires CORS headers to be sent by the server hosting the image. In this case, the imgur server granted permission, but the postimg.org server did not.

To avoid blocking out points drawn in the back, remember to disable depthTest, especially when drawing with transparency and additive blending.

Answer №2

For me, the solution was to utilize a ShaderMaterial. Setting depthTest: false worked perfectly.

let material = new THREE.ShaderMaterial({
                uniforms: {
                    uColor: { value: new THREE.Color(0xffffff) },
                    uPointTexture: { value: new THREE.TextureLoader().load(require('./res/spark1')) }
                },
                vertexShader: _me.vertex_shader,
                fragmentShader: _me.fragment_shader,

                depthTest: false,
                transparent: true,
                // fog: false
            })

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

Styling multiple Higher Order Components (HoCs) using Material UI withStyles

When developing my application, I encountered an issue with using Higher Order Components (HoCs) and withStyles for styling. If I apply multiple HoCs to one component, the classes prop of the first HoC gets passed to the next one in the compose chain, caus ...

Is there a way to concatenate arrays without using the Array.flat method?

I am encountering an issue with a specific function that I have const flat = function(arr, n) { if (n == 0) { return arr; } else if (n == 1) { let newarr = [] for (let i = 0; i < arr.length; i++) { if (Number.isInteger(arr[i])) ...

Vuex is throwing a mysterious ReferenceError that is leaving developers

Currently, I am developing a Single Page Application (SPA) using Vue.js and Vuex. Within this project, I have set up some data in the store and displayed it in a child component. This child component includes radio buttons that trigger a function called ge ...

Navigating through various JSON arrays using Angular

I am currently working with a large JSON file in Angular and trying to iterate through it. The structure of the JSON file is as follows: { "subject1":[ { "title":"titlehere", "info":"infohere." }], ...

How can you determine when a download using NodeJS HTTPS.get is complete?

Currently, I am facing an issue while downloading a file. My goal is to perform an action immediately after the download is complete. Specifically, I aim to import a .js file as soon as it finishes downloading. var request = https.get('https://m ...

When modifying a form that contains a FileField, the file will be automatically

In my ModelForm, I have fields that are generated dynamically. While everything works well, I have an issue with editing. The input[type=file] field loses its file when editing and instead, it displays a link like <a href="/path/to/file"> with the te ...

Is it no longer possible to use v-for to iterate over translations in Nuxt 3 and @nuxtjs/i18n?

Imagine having an Array stored in our translations file en.js section: { title: 'This value is a string and it works perfectly', highlighted: [ { title: 'Highlighted title 1', text: 'Highlighted text ...

Evaluating two arrays and adding elements if the criteria are satisfied

In my attempt to filter out emails that already exist in the userData, the current issue is that my code continuously adds the same data as long as the email is not the same. Below is the code snippet: userData:[ {email: "<a href="/cdn-cgi/l/email ...

Using React Router can sometimes lead to an issue where the React components are

My server side rendering is set up for performance, but I am encountering discrepancies between the client and server renderings. The client initially renders <!-- react-empty: 1 --> instead of components, which leads to a different checksum. As a re ...

Tips for transferring a variable from Next.js to a plain JavaScript file

When it comes to Canvas Dom operations in my NextJs file, I decided to include a Vanilla JS file using 'next/script'. The code for this is: <Script id="canvasJS" src="/lib/canvas.js" ></Script>. Everything seems to ...

Loop through a nested array of objects within the same row using ng-repeat

Struggling with binding data from a nested array in the same row. Here is my Array of Objects: $scope.Record = [ { Name:'Adam', Months:[ {Month: 'Jan', Value: 10, cust:2}, {Month: 'Feb', Value: 30, cust:2} {Month: 'M ...

Is this example a strong demonstration of implementing simple inheritance in JavaScript?

Having transitioned from using Dojo, there's one specific thing that I deeply miss - Dojo's declare() function. Developing a rather complex application, I found myself extensively modifying Node's lang.inherits() to enhance its functionality ...

What is the reason for jQuery's inability to recognize ":not(#menu *)" in a selector?

I have created a Javascript-based navigation bar that is triggered by clicks instead of hover for better mobile usability. I have made sure to keep the HTML, CSS, and JavaScript code as simple as possible. To ensure that clicking anywhere outside the menu ...

verify the current version of your web browser

Is there a way for me to detect the browser version being used by a user and prompt them to update it? ...

How can communication be established between JavaScript and a .NET app?

I've been developing a help system using HTML, and I want to include clickable links that can trigger commands in a .NET application (such as guiding users through tutorials or workflows). I have explored the TCard() method for HTML help, but it seems ...

Why is my Ajax utilizing PHP _POST not functioning as expected?

I am facing an issue with the JavaScript code below: <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script> <script> function deletUserInfo(id_user){ console.log(id_user); ...

Calculating the sha1 hash of large files using JavaScript in the browser without causing excessive memory usage

Is there a method to calculate the hash of large files in JavaScript without needing to load the entire file in a FileReader? Specifically, I'm interested in finding out if it's possible to stream a file and calculate its sha1 hash in JavaScript. ...

The functionality of HTML5 Camera is experiencing issues while being used with Tomcat7

My Angular2 project includes HTML5 camera access functionality. I launch the project using Angular CLI (ng serve), which starts the web container for testing purposes. When trying to access the camera, the browser prompts me for permission. Once granted, e ...

Encountering the error "Invalid URL. Please provide only absolute URLs" while trying to integrate the Airtable JavaScript library in a Next.js application

I am currently working on a Next JS application that includes a Page called somePage.js. In this page, I am attempting to make an XHR request to the Airtable API from within the getServerSideProps function. The relevant components look like this: pages/so ...

Avoid storing js files in cache during the development phase

When I use django runserver for development, I encounter the issue of my javascript file being cached. It's difficult to determine if the file is cached or not unless I manually add alert or console.log statements each time I make a change just to che ...