Guide on incorporating a displacement map into a vertex shader in ThreeJS

I am a beginner in ThreeJS and I am attempting to create a asteroids-like scene with textures made of particles, similar to what is showcased on this website . However, my attempt to apply a displacement map to a points material was unsuccessful. How can I troubleshoot this issue?

const dispTexture = new THREE.TextureLoader().load('NormalMap.jpg');

const sphere = new THREE.Points(
  new THREE.SphereGeometry(3, 32, 32),
  new THREE.PointsMaterial({
    size: 0.07,
    color: 0xFF325F,
    displacementMap: dispTexture,
    displacementScale : 0.2,
  })
);

scene.add(sphere);

Answer №1

Utilizing noise as mentioned in the comments, an asteroid consisting of 30K points was created. A simple lighting effect was added: points with more light appear bigger and brighter.

In case you need it, here's the link to the codepen: https://codepen.io/prisoner849/pen/mdBzjBy

This might prove helpful for someone:

body{
  overflow: hidden;
  margin: 0;
}
<script>
simplexNoise = `
//  Simplex 3D Noise 
//  by Ian McEwan, Ashima Arts
//
vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}
vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}

float snoise(vec3 v){ 
  const vec2  C = vec2(1.0/6.0, 1.0/3.0) ;
...
...
... (the script continues)

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

Optimal timing for fulfilling promises in AJAX requests

Recently, I've delved into the world of promises to handle multiple ajax calls without knowing in advance how many will be required. In my journey, I came across these valuable posts: jQuery Deferred - waiting for multiple AJAX requests to finish jQu ...

Creating Randomized Arrays in Javascript

Hey there! I'm currently working on a school project where I need to create random groups of names from a given list. The size and number of groups will depend on the user's input. I've managed to write code that randomly selects an element ...

JSON geometry imported is not following the movement of the bones

After importing a model into my Three.js scene, I encountered an issue where the bones can be moved and rotated successfully, but the model's geometry does not follow these bone movements. For importing the JSON file and adding it to the scene, here ...

What is the best way to halt a specific function in jQuery?

I recently developed a website for my photographer friend, and I implemented a feature where the home page is initially blurred. Visitors can click a button to unblur the content. While the functionality works smoothly, there's one issue - every time ...

RxJS - Only emit if another source does not emit within a specified time frame

Imagine having two observables. Whenever the first one emits, there should be a 2-second pause to check if the other observable emits something within that timeframe. If it does, then no emission should occur. However, if it doesn't emit anything, the ...

Creating a dynamic and interactive menu using three.js

In a team project, one member has utilized three.js to create the graphical elements of our software, while I have been assigned the task of developing a Menu / Display feature within the program due to time constraints. The software showcases a 3-D graph ...

Unraveling the Mysteries of AngularJS in a Tutorial Snippet

After reading through the enlightening theory snippets in Step 3 of AngularJS Tutorial, one particular passage piqued my curiosity: The scope, which connects our controller and template to create a dynamic view, is not isolated within its own bounda ...

How to Utilize findIndex to Validate the Presence of Elements in an Array of Objects using TypeScript

I need assistance in checking which properties from an array are present in another array of objects and which ones are not. My object structure is as follows: var tempObj=[{id: '1', color: 'red, blue, green', age: 27},{id: '2& ...

What is the reason behind being limited to sending only 5 requests if I fail to heed the data event?

I've come across some related questions while researching this topic, such as Why is node.js only processing six requests at a time?. However, I am still struggling to fully grasp the specifics. Below is a breakdown of my scenario: Firstly, let&apos ...

Delay loading all images on the page except for the first one until the page is completely loaded

My website has a slider feature that displays images in a sequence, but currently all the images load at once and then get hidden by a script after the page is fully loaded. I tried using CSS to set a fixed height for the slider, which worked on desktop bu ...

What is the best way to merge multiple window.onscroll events together?

One feature is a colorful RGB scroller positioned next to the standard scrollbar, indicating the progress of page scroll. The second feature is a classic "scroll to top" button. FIRST FEATURE HTML <button onclick="topFunction()" id="myB ...

Calculating the time difference in seconds between two dates using JavaScript

I am working with dates stored in MongoDB as UTC using Date(), and the format looks like Mon, 02 Apr 2012 20:16:31 GMT. My goal is to calculate the time difference in total seconds between this date and the current time (in UTC). I attempted the followin ...

Retrieve a file from a server using Angular's $http.get method

My goal is to initiate a file download when a user clicks on a "Download PDF" button. The API is called, performs some validations, and then returns the file. I want to ensure that the file does not open in the browser and instead prompts the user to save ...

Is there a way to implement this code to filter every column in the grid?

I have been using this code in my grid view, but it only filters one column of the grid. Now I want to modify the code to filter multiple columns. I tried implementing a loop, but it seems like the code is not working correctly. Is there a way to adjust t ...

Revealing the Webhook URL to Users

After creating a connector app for Microsoft Teams using the yo teams command with Yeoman Generator, I encountered an issue. Upon examining the code in src\client\msteamsConnector\MsteamsConnectorConfig.tsx, I noticed that the webhook URL w ...

Is there a specific location to view the output when adding a console.log in vue.config.js?

Currently, I am utilizing the Vue cli 3 UI for my latest project and am faced with a challenge regarding modifying variables within a webpack plugin. Initially, my first thought was to use console.log; however, I am uncertain of where the output would be ...

Determining the Clicked Button in ReactJS

I need help with a simple coding requirement that involves detecting which button is clicked. Below is the code snippet: import React, { useState } from 'react' const App = () => { const data = [ ['Hotel 1A', ['A']], ...

When using VueJS to load an SVG file based on a variable within a for loop and utilizing v-html, the result returned is "[

I'm faced with a challenge of loading SVGs saved in separate files based on the content within a loop. Upon page load, what I see is: https://i.sstatic.net/OiwyT.png Hey there, check out my code snippet below: <div v-for="(rec, index) in stats ...

Exploring ways to display featured posts within specific category sections

I have 2 featured posts in 1 div id, one with a big class and the other with a small class. I want the big featured div to display posts based on categories. The code for the big featured post is shown below: <div class="main_feat"> ...

Does the Object3D.clone() method in three.js produce a complete duplicate of the geometry?

When using the collada loader to load models, I often encounter a scenario where the loader returns an Object3D named "dae" with multiple child meshes. My goal is to create multiple instances of the parent "dae" object without replicating the child meshes. ...