Getting rid of the white corners on points using ThreeJS

MY CURRENT PROJECT

My current project involves rendering circular points with varying vertex colors using a fragment shader. I am aiming for the points to behave like more performance-efficient spheres, especially when zoomed in for anti-aliasing.

ISSUE AT HAND

I have successfully achieved the desired effect in one direction as shown in the left photo, but the other direction displays white corners as seen in the right photo. How can I eliminate these white corners?

https://i.sstatic.net/PV8Kx.png https://i.sstatic.net/tLTjA.png

MY EFFORTS SO FAR

  • Disabling depthTest worked for points of the same color, but since my points have varying colors, it created a visual glitch resembling a wormhole.
  • I experimented with alphaTest without success. Although, I did manage to make alphaTest work with textures instead of a custom fragment shader (png image of a circle on a transparent background), but it became blurry when zoomed in.
  • I observed that the corner colors matched the value passed into renderer.setClearColor.
  • I've attempted different blending options, but my lack of familiarity with blending techniques has hindered my progress.

EXAMPLE CODE

const geometry = new THREE.BufferGeometry();
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
const material = new THREE.ShaderMaterial({
  transparent: true,
  vertexColors: THREE.VertexColors,
  uniforms: {
      size: {value: 20},
      scale: {value: 10},
  },
  defines: {
    USE_MAP: "",
    USE_SIZEATTENUATION: ""
  },
  vertexShader: THREE.ShaderLib.points.vertexShader,
  fragmentShader: `
  in vec3 vColor;
  void main() {
      vec2 xy = gl_PointCoord.xy - vec2(0.5);
      float ll = length(xy);
      gl_FragColor = vec4(vColor, step(ll, 0.5));
  }
  `
});
const points = new THREE.Points( geometry, material );
scene.add( points );

Your assistance is greatly appreciated!

Answer №1

If you want to get rid of those pesky corners, simply eliminate the pixels where the UV position's length exceeds 0.5:

  in vec3 vColor;
  void main() {
      vec2 xy = gl_PointCoord.xy - vec2(0.5);
      float ll = length(xy);
      if (ll > 0.5) discard; // this single line works wonders
      gl_FragColor = vec4(vColor, step(ll, 0.5));
  }

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

The interconnected nature of multiple asynchronous tasks can lead to a render loop when relying on each other, especially when

My asynchronous function fetches data in JSON format from an API, with each subsequent call dependent on the previously returned data. However, there are instances where I receive null values when trying to access data pulled from the API due to the async ...

What is the best way to create a mesh resembling a "window" in three.js?

Currently working on a small game project using three.js, I am trying to incorporate a "window" element that can show layers behind it. Specifically: This represents layer 0: layer 0 screenshot This is layer 1: layer 1 screenshot I then attempted to ren ...

Dealing with numerous validations upon submission in Vue.js

Greetings! I have a requirement to check and validate multiple inputs before allowing the user to submit: <button type="submit" v-on:click="validateErrors()" @click.prevent="submit">Finalize</button> I have crea ...

Having trouble creating a report with an HTML screenshot using Protractor

Need assistance with generating reports using a html screenshot in Protractor. I have followed all the necessary steps but encountered an error. Any help would be appreciated. Here is my conf.js: // Sample configuration file. var HtmlReporter = require(& ...

What steps should I follow to set JSONP as the dataType for a request in an Angular $http service?

I have a good understanding of how to use jQuery's $.ajax: $.ajax({ url: //twitter endpoint, method:"GET", dataType:"jsonp", success:function() { //stuff } }); Is there a way to set the JSONP datatype for an angular $http service reque ...

Inquiries regarding node.js

While delving into research on node.js and Mongodb, I encountered a few areas that require clarification. My aim is to query Mongodb from the web using JavaScript because of my familiarity with the language. Additionally, it aligns well with Mongodb' ...

Problem with sending data using $.ajax

I stumbled upon a strange issue. In one of my php pages, I have the following simple code snippet: echo $_POST["donaldduck"]; Additionally, there is a script included which makes a $.ajax call to this php page. $.ajax({ url: "http://provawhis ...

Discover how to shallow test for the presence of a wrapped component using Jest and Enzyme

Currently, I am in the process of testing a component that dynamically renders another wrapped component based on certain conditions. My testing tools include enzyme and jest, with the root component being rendered using the shallow() method. The main chal ...

The error message "await is only valid within an async function" surfaced while working with pageAction.getTitle() in a Firefox web extension

Based on the information provided here, the method browser.pageAction.getTitle() functions asynchronously and returns a Promise. In my code, I am attempting to use it within a function in the following manner: function title(t){ if(t===undefined){ ...

Ways to retrieve the file name and additional attributes from a hidden input type

Is it possible to access the file name and other attributes of a hidden file when submitting it using the <input type="hidden"> tag? My current project involves drag and drop file functionality on a server using Node.js. If I am able to dynamically ...

Is there a parameter I am overlooking when trying to remove an item from a state-stored array using the delete button at line 55?

Need help with the code in the app component. I know it's not ideal, any assistance would be greatly appreciated. I'm a bit lost and can't figure out how to remove an item from the list after it has been added. Everything else seems to work ...

Generate a custom JavaScript file designed for compatibility with multiple servers

I am looking to develop a JavaScript file that can be easily added to other websites, allowing them to access functions within my database using an API similar to the Facebook like button. This API should display the total likes and show which friends have ...

Pass along an event from a child component to its parent in Vue 2

As a newcomer to JS and Vue, I appreciate your patience with my learning curve :) I've set up a table using two Vue components: a parent (representing the table - orders) and a child (representing the row - order). Each row in the table has a button ...

What if we started transmitting JavaScript files as browser-specific bytecode instead?

While there is no universal bytecode for JavaScript, most JavaScript engines have their own bytecode. The source code string of JavaScript files must be parsed/compiled into bytecode before execution. Could servers store bytecode for different browsers an ...

Material-UI style is taking precedence over custom React Component styles

RELATED QUESTION ON THIS LINK: Styles being overwritten by Material-UI style I am currently developing a component library based on Material UI. I want to pass styles to my custom components using JSS. However, I am facing challenges with the higher speci ...

Leverage Vue's ability to inject content from one component to another is a

I am currently customizing my admin dashboard (Core-UI) to suit my specific needs. Within this customization, I have an "aside" component where I aim to load MonitorAside.vue whenever the page switches to the Monitor section (done using vue-router). Here ...

Discover the process of navigating a user to a different page following the submission of an Ajax form

I'm struggling with redirecting users to a thank you page after they successfully complete a form. Instead of redirecting, the form just goes to a blank page ()... I want it to go to the thank you page while still submitting the form details to the sp ...

Having trouble connecting to the Brewery API, could use some guidance from the experts (Novice)

I'm currently facing some difficulties connecting to a brewery API (). I am developing a webpage where users can input the city they are visiting and receive a list of breweries in that city. As someone unfamiliar with APIs, I am unsure about the nece ...

Accelerate Image Preloading速

I am currently in the process of creating a website that features divs with background images. Although I am new to JavaScript, I am eager to learn more about it. My main goal is to preload these images so that visitors do not encounter any delays or bla ...

Link clicking does not trigger URL routing properly

I've been tasked with updating our web application, and I'm facing a challenge that I need help with. My boss wants users to be able to click on a link in an email and have the internal company web app directly navigate to a specific page indicat ...