Is it possible for a three.js material to have different repeat values for a bump map compared to a texture map?

I'm attempting to reduce the repetitive nature of my texture by implementing a bump map that repeats less frequently. However, it appears to adopt the repeat value of 'landTexture' (64) below instead of the value I assigned it (1).

landTexture.wrapS = landTexture.wrapT = THREE.RepeatWrapping;
landTexture.repeat.set(64, 64);
bumpTexture.wrapS = bumpTexture.wrapT = THREE.RepeatWrapping;
bumpTexture.repeat.set(1, 1);
var m = new THREE.MeshPhongMaterial({map:landTexture, 
                                     ambient: 0x552811, 
                                     specular: 0x333333, 
                                     shininess: 25, 
                                     bumpMap: bumpTexture, 
                                     bumpScale: 1, 
                                     metal: false });

If I remove map:landTexture, then the bump map scale is 1. Is there a way to combine these two repeat values somehow?

Answer №1

It is important to note that the default values for offset and repeat are prioritized in a specific order:

// Prioritization of uv repeat and offset settings
//  1. color map
//  2. specular map
//  3. displacement map
//  4. normal map
//  5. bump map
//  5. roughness map
//  5. metalness map
//  6. alpha map
//  7. emissive map

In your scenario, this priority would apply to the landTexture settings.

If needed, you can adjust your textures accordingly or opt to create a customized ShaderMaterial.

UPDATE: An exception to this rule is the light map and ambient occlusion map, which utilize the second set of UVs. This feature allows for higher detail in other textures compared to the light/AO map.

Version used: three.js r.84

Answer №2

Absolutely. The latest versions of three.js now offer an API that allows for customization of built-in materials using GLSL.

While it may not be a simple task, there is an example available:

https://github.com/pailhead/three.js/blob/aa72250835b82f7dde2e8375775a4b039cb719c6/examples/webgl_materials_extended_multiple_uvs.html

https://github.com/mrdoob/three.js/pull/14174

The built-in materials are essentially shader templates, consisting of #include <some_chunk> statements in a specific order.

Within these "chunks," you will find code snippets like this:

/*...*/ texture2D( foo, vUv ) /*...*/

In this snippet, 'foo' could represent 'alphaMap', 'map', 'specularMap', and so on. This indicates a texture lookup being performed on the sampler at the interpolated uv attribute without consideration for preceding or following code.

To achieve your desired effect, such as applying an offset or a mat3 transform like three.js does, the GLSL code needs to resemble this:

texture2D( foo, foo_transform * vUv )

The main challenge lies in supplying this uniform value to the shader. The provided example takes a brute force approach by compiling the shader first and then searching through its entirety for the necessary modifications.

This method proves more efficient than directly altering textures and can be simpler than creating a custom ShaderMaterial.

Note: While three.js isn't typically intended for this level of customization, it is still feasible. For instance, while most maps are prefixed with 'somethingMap,' the albedo map stands out as just 'map.' Adjusting the regular expression in the example accordingly would simplify the process if 'albedoMap' were used instead.

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

Build a PHP-driven form for data collection

Previously, I posted this question but didn't receive a clear answer. Here's what I'm confused about: Below is the HTML snippet: <body onload="showcontent()"> <!-- onload optional --> <div id="content"><img src ...

Improve loading speed of thumbnail and full images in HTML

I'm struggling with slow loading images on my blog website. Can anyone help me figure out how to improve loading speed and: Is it possible to use a separate thumbnail image that is smaller in size instead of the full image for both thumbnails and th ...

Can the image be adjusted based on different time zones around the world?

How can I create an HTML banner that changes images based on the time of day? I want one image to display between 7pm and 6am, and another image during the rest of the day. I came across a helpful website that achieves this by changing the image according ...

What is the best method for importing gltf files in three.js?

let manager = new THREE.LoadingManager(); const loader = new THREE.GLTFLoader(manager); // Function for setting up models with a position parameter // Load a glTF resource **line90** loader.load( // resource URL 'static/ElmTree.glt ...

What is the best way to access the functions within an object?

I am looking to execute a function that is an object attribute. For instance, let's take a look at the following code snippet: var obj={ a:"One", b:"two", c:'three', d:function f(){ console.log("Hello World"); } } I am trying ...

Saving an ASCII effect on Three.js using html2canvas does not work as expected

I've created a website using three.js and ascii effect renderer, where there is a constantly moving image that can be controlled with mouse interaction. I'm trying to save the entire generated image using html2canvas, but it doesn't seem to ...

Converting a multi-dimensional array to a single array in JavaScript: the ultimate guide!

I have encountered a scenario in my application where there is an array with multiple arrays nested inside: https://i.sstatic.net/3uHP9.png I am looking to transform this structure: [ { "tag": [ { "key": "asda ...

Troubleshooting the lack of deep linking functionality in an AngularJS web application when using Node Express server

(Update: The problem has been successfully solved. Check the end of the question for details) I am currently facing a seemingly trivial issue that is causing me a great deal of frustration as I struggle to find a solution: After scaffolding an Angular ap ...

What steps can I take to modify the class of a button once it has been clicked using JQuery?

Currently, I am experimenting with Jquery to dynamically change the classes of bootstrap buttons when they are clicked. However, I have encountered a limitation while using toggleClass. The issue is that I am only able to toggle between two classes, whic ...

Chosen option within the AntD Select component

Using the AntD select component, there seems to be an issue where it displays "id" instead of "name" when selecting options. Is there a solution available for this problem? const MyComponent = () => { const data = [ { id: "5c83c2d ...

What is causing my website to refresh before I can save the edits I have made after clicking on the edit button

My website is fairly simple, allowing users to add blog posts with a title, author, and content. Each post has two buttons - one for deleting and one for editing. These actions add, delete, or edit the chosen posts within a .json file through a local json ...

UCS-2 in Node.JS: Understanding Big-Endian Byte Order

Currently, I am utilizing Node.JS. In my project, I require support for big-endian UCS-2 buffers, which is not natively offered by Node's buffers that only support little-endian format. How can I achieve this specific requirement? ...

Warning: Angular.js encountered a max of 10 $digest() iterations while iterating through array slices. Operation aborted

JSbin: http://jsbin.com/oxugef/1/edit I am attempting to slice an array into smaller subarrays and iterate through them in order to create a table of divs that are evenly divided. Unfortunately, there seems to be an issue where I am unknowingly overwritin ...

Is your Ajax jQuery live search not functioning properly with JSON data?

My programming code is not functioning properly. Here is the file I am working on. When it does work, it does not display the list and gives an error in the Json file. I am unsure of the reason behind this issue. You will be able to view the error in the C ...

My AJAX requests do not include any custom headers being sent

I'm facing an issue with making an AJAX request from my client to my NodeJS/ExpressJS backend. After firing the request, my backend successfully receives it but fails to recognize the custom headers provided. For example: $.ajax({ type: " ...

Issues with importing Bootstrap in JavaScript

Utilizing Bootstrap in both HTML and JavaScript/TypeScript has been my recent endeavor. I have successfully imported the minified versions of Bootstrap JS and CSS in my HTML file and incorporated this line of code in my TypeScript: import * as bootstrap fr ...

Managing the ERR_NAME_NOT_RESOLVED issue

Currently, I am facing a task related to the health check endpoint where I need to receive a response from the backend or encounter a net::ERR_NAME_NOT_RESOLVED error if we are outside of a specific network. When attempting to send a request to my endpoin ...

Utilizing React and Material-UI to Enhance Badge Functionality

I am exploring ways to display a badge icon when a component has attached notes. I have experimented with three different methods and interestingly, the results are consistent across all of them. Which approach do you think is the most efficient for achiev ...

Having trouble retrieving data passed between functions

One of my Vue components looks like this: import '../forms/form.js' import '../forms/errors.js' export default{ data(){ return{ form: new NewForm({ email: '&apos ...

Tips for preserving scroll location on Angular components (not the window) when navigating

My current layout setup is like this: https://i.sstatic.net/hOTbe.png In essence <navbar/> <router-outlet/> The issue I'm facing is that the router-outlet has overflow: scroll, making it scrollable (just the outlet section, not the ent ...