Challenges with UV wrapping in THREE.js ShaderMaterial when using SphereBufferGeometry

Currently, I am attempting to envelop a SphereBufferGeometry with a ShaderMaterial that incorporates noise to mimic the surface of Jupiter. However, the wrapping on the sphere geometry is turning out peculiarly. Instead of wrapping around the 'planet' in a normal texture manner, all the animated texture seems to be concentrated in a narrow band around one specific line of latitude. Images illustrating this issue have been provided below.

The shader works flawlessly on a plane, but my assumption that it would wrap like a standard texture was likely naive. Since I am relatively new to Shader programming, I find myself at a bit of an impasse.

Here is the plane with correct wrapping

This image shows the incorrect wrapping

I suspect that moving the noise equations to the fragmentShader might offer a solution, but my current knowledge is insufficient as my attempts resulted in failure. I also tried transforming the plane targets into a sphere; however, ShaderMaterial does not inherently support morphTargets and despite numerous efforts using

#include <morphtarget_pars_vertex>
within onBeforeCompile, I couldn't get it to function correctly. Additionally, using THREE's wrapping equations on the uniform texture yielded similar outcomes.

Below is all of my code, where the shaderMaterial implementation can be found in addPlanet():

[Code example here]

Answer №1

The issue might be arising from the magnitude of the uv displacement you are using. This is essentially how your shader functions:

vWave = pos.z;
float wave = vWave * 0.25;
vec3 texture = texture2D(uTexture, vUv + wave);

Considering that your SphereGeometry has a radius of 25, you are displacing your UVs by 25 * 0.25 based on their z-axis depth. This results in UVs ranging approximately between [-6.25, 6.25].

You might want to recalibrate this value to a smaller scale (remember that UVs typically range from

[0, 1]</code), so a displacement of 6 will go beyond this range. Alternatively, you can maintain a large UV displacement and enable texture repetition with:</p>
<pre class="lang-js"><code>texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;

For more information on wrapping, refer to the Texture documentation page

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

Having difficulty understanding and parsing JSON using JQuery

I have a jQuery function that is returning data in the following format: {"Suggestions":[{"name":"RR Restaurant","category_id":"166","locality":"Gayathri Nagar","listing_info":"listing","random_id":"1ll0f0wJ"},{"name":"Oko Restaurant","category_id":"166", ...

Tips for safely storing JWT tokens in a react/next.js app:

After a valid user login following proper registration through REST API, I am looking for the best way to store the JWT token that is generated. I have researched various methods of storing JWT on the client side, including local storage, session storage, ...

having trouble installing vue on macOS using npm

Here are the steps you should follow: Instead of using node v14+, switch to node v10+. (IMPORTANT) Add the following paths to your ~/.zshrc file (if you use zsh): /Users/[yourUsername]/.npm-packages/bin /Users/[yourUsername]/.npm-global/bin After ...

"Combining jQuery and JavaScript to handle form submissions in un

What happens when you combine the Javascript onSubmit handler and jQuery submit handler? <form action="" method="post" onSubmit="myJavascriptHandler();"> <input type="submit" /> </form> <script type="text/javascript"> $("form") ...

Jquery button click event is malfunctioning after the inclusion of jquery keyboard plugin

When I try to gather user input from a textbox using jQuery keyboard.js, the functionality works perfectly fine if I exclude the virtual keyboard code. For more information on keyboard.js, you can visit: https://github.com/Mottie/Keyboard/wiki Below is t ...

Hiding a div using swipe gestures in Angular

What am I trying to achieve? I aim to hide a div when swiped right. This specific action will close the pop-up that appears after clicking a button. What tools are at my disposal? I am utilizing Ionic framework for this task. Within my app.js, I have i ...

Troubleshooting issues with Javascript ES6 module functionality

I'm struggling to solve a problem with my small app setup. In my project, I have an index.html file that includes a javascript file and another file named myJsModule.js in the same directory. Here's the code inside myJsModule.js: export default ...

Navigating through props provided within a setup function in Vuejs using the Composition API

I am facing an issue when trying to pass an object into a child component using props in the Composition API setup function of Vue. Instead of utilizing 'Abe', I want to run a query from firebase based on the displayName property of the user. As ...

What is the best way to refresh a navigation bar after making an API request, such as when using Google Sign-In?

Struggling to grasp the hook concept in this particular scenario: The flow goes like this - the user logs in with Google, which updates the session state. Consequently, the visitorType state transitions from 'viewer' to 'buyside'... A ...

How can one easily remove the parent directory from a path when working with Node.js?

If the path is /foo/bar/baz.json and I need only /bar/baz.json, how can this be achieved using Node.js's path functionality? ...

JavaScript API for Tableau

Could you please clarify the functions described below? newViz = createTableauViz(containerDiv, url, options); function listenForMarkSelection() { newViz.addEventListener(tableau.TableauEventName.MARKS_SELECTION, handleMarksSelection); } funct ...

The equivalent of ESM for resolving modules using the `createRequire` function with a specified

In the process of developing a JavaScript instrumentation engine, I am currently focused on traversing a source file's Abstract Syntax Tree (AST) and queuing imported modules for instrumentation in a recursive manner. In order to achieve this, it is c ...

Once the PostgreSQL container is stopped with docker-compose down, the previously used port becomes unavailable for use again

Currently, I am involved in a project which utilizes express as the server and postgres as the database to delve into dockerization. The server relies on the database being operational. Initially, when running docker-compose up everything functions correct ...

While troubleshooting the app, I encountered an error that says: "The property 'answers' cannot be read as it is undefined."

Everything was going smoothly with my app until it suddenly crashed, displaying the error message "Cannot read property 'answers' of undefined". Let's take a look at the specific piece of code causing the issue: function mapStateToProps({ ...

Dividing a string using regex to deal with numerical issues

My task involves processing a list of strings that look like this: Client Potential XSS2Medium Client HTML5 Insecure Storage41Medium Client Potential DOM Open Redirect12Low The goal is to split each string into three parts, like so: ["Client Potential X ...

Getting a string from JSON using Javascript

I am trying to retrieve a specific skill from a variable: const skillsData = [ { name: "React", value: 390 }, { name: "CSS", value: 1200 }, { name: "JavsScript", value: 540 }, { name: "HTML", value: 1900 }, ...

Add a class to alternate elements when mapping over data in React

Check out the code snippet below: <div className="grid md:grid-cols-2 sm:grid-cols-2 grid-cols-1 gap-16 mt-24 px-4"> {status === "success" && delve(data, "restaurants") && data.r ...

"Beginner's guide to utilizing JQuery and AJAX with PHP

I am struggling to grasp the concept of using AJAX and jQuery to post data without reloading the page. Specifically, I am facing issues with the form reloading the page and not updating variables. Here is the code I have been working on: Initially, I was ...

classes_1.Individual is not a callable

I am facing some difficulties with imports and exports in my self-made TypeScript project. Within the "classes" folder, I have individual files for each class that export them. To simplify usage in code, I created an "index.ts" file that imports all class ...

Guide to sending AJAX requests to SQL databases and updating the content on the webpage

One way I have code to showcase a user's name is by using the following snippet: <div><?php echo 'My name is ' . '<span id="output">' . $_SESSION['firstname'] . '</span>' ?></div> ...