Reversed Channel in Three.js Normal Maps Mirror Effect

After adding a normal map to a mirrored model in Three.js, I noticed that one of the channels (possibly green) is flipped on the mirrored side.

The model has an ambient light, a directional headlight, and a spotlight. Below is the code used to create the material:

// Defining a MeshPhongMaterial for the model
var material = new THREE.MeshPhongMaterial();
material.map = THREE.ImageUtils.loadTexture(texture_color);
// Wrapping modes
material.map.wrapS = THREE.RepeatWrapping;
material.map.wrapT = THREE.MirroredRepeatWrapping;
if (texture_normal != null) {
    material.normalMap = THREE.ImageUtils.loadTexture(texture_normal);
    material.normalMap.wrapS = THREE.RepeatWrapping;
    material.normalMap.wrapT = THREE.MirroredRepeatWrapping;
}
material.wrapAround = true;
material.morphTargets = true;
material.shininess = 15;
material.specular = new THREE.Color(0.1, 0.1, 0.1);
material.ambient = new THREE.Color(0, 0, 0);
material.alphaTest = 0.5;
var mesh = new THREE.MorphAnimMesh(geometry, material);
// Enabling shadows
mesh.castShadow = true;

if (shadows) {
    mesh.receiveShadow = true;
}

scene.add(mesh);

I tried various combinations of material.normalMap.wrapS and material.normalMap.wrapT, along with the diffuse map, but the issue persists. What could be causing this problem?

Appreciate any help!

Answer №1

Normal maps rely heavily on the geometry, so simply mirroring it won't yield the same results as with a diffuse texture.

To achieve the desired outcome, it is necessary to invert the normal map's red channel in areas where the UVWs are mirrored on the model.

Check out this thread for more information

Answer №2

It turned out that the reason for my issue was due to using an outdated version (1.2) of the Blender Three.js exporter. Once I made the switch to the most recent version (1.5) from the r67 repository, Three.js was able to effectively handle mirrored normal maps with its Phong shader right out of the gate.

Edit: Despite this improvement, there were still problems with the flipped channel in the Phong Shader. I ultimately resolved this by utilizing the "Normal Map Shader" as shown in the Three.js examples, which provided accurate results. Unfortunately, it's worth noting that the Normal Map Shader is incompatible with Morph animations, only functioning properly with Skeletal ones.

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

Retrieve the name of the page instead of the page number using PHP in combination with AJAX

I found a helpful tutorial on using AJAX to load content on a website. However, the tutorial uses generic page names like "page1, page2, page3, etc." and I want to use specific page names like "products, about, etc.". I've been working on the code in ...

Updating choices within a div in real-time by changing the select box dynamically

I need to swap out the select box that is nested inside this div <div class="models"> <select disabled="disable"> <option>Model Name</option> </select> </div> I am attempting to target the div and manipul ...

Utilize webpack to import functions from separate files

I am looking to streamline the process of importing and using functions from a different file. Ideally, I would like to simply call these functions by their name without any extra prefixes or naming conventions. However, I am aware that using eval() can po ...

The PHP-generated table is not being appended to the specified div with jQuery

I am currently working on developing a webpage that displays live forex rates to users. I am pulling the values from a feed and echoing them into a table. My goal now is to use jQuery to show this table to the user. The issue I am facing is that when I tr ...

Issues with Javascript .map function failing to return accurate components

Encountered an issue with the .map method in my React project not returning the expected value. This is the desired output: const prepInfo = [ <PrepInfo uniqueKey={1} type={'prep'} quantity={'1'} unit={'unit'} suf ...

Error in Gulp caused by attempting to minify JavaScript files

I've been struggling with this issue for the past 2 days and I'm a bit of a novice when it comes to task runners. I decided to ask for help because I can't seem to figure it out on my own. Currently, I am using Gulp with Slush generated by ...

Chrome browser exhibits a phenomenon where the Bootstrap modal will erroneously print the same page multiple times based on the

When I open a modal, there's a print button inside it. I've researched solutions provided here and here to enable printing of Bootstrap modals, but I'm encountering a Chrome-specific bug. The issue doesn't occur in Safari, Firefox, or E ...

Exploring the ancestors of an element

JS <script> $('.btn').click(function(e){ target = e.target; parent = target.parentNode.parentNode; console.log(parent); }); </script> HTML <div class="card" sty ...

Unable to automate the selection of a dropdown menu using Selenium WebDriver

I am currently utilizing http://www.makemytrip.com/ This is the HTML code. <div class="mrgnBot30 clearFix"> <span class="watch_icn flL"></span> <div class="widget_inner clearFix suggest_me padBot15 flL"> <h3 class="clearFix has ...

Build an object using a deeply nested JSON structure

I am working with a JSON object received from my server in Angular and I want to create a custom object based on this data. { "showsHall": [ { "movies": [ "5b428ceb9d5b8e4228d14225", "5b428d229d5b8e4 ...

Dropzone ceased functioning following the transition from version "4.2.0" to "5.7.0" while utilizing jquery version "3.3.1"

Currently, I am loading my libraries in the following way: <link href="~/lib/dropzone/dropzone.min.css" rel="stylesheet" /> <script src="~/lib/dropzone/dropzone.min.js"></script> <script src="~/Scripts/jquery-3.3.1.min.js"></sc ...

Reordering div elements with JQuery

As soon as my page loads, I have a div set to display:block and another div set to display:none. I have implemented a toggle switch that should replace the visible div with the hidden one. However, I am facing an issue where after performing the switch, ...

Strategies for transmitting computed variables from a controller to JavaScript once the computation is complete?

Within my application, I have a button that triggers an action called "method" present in the UserController. This particular action involves executing some specific tasks. def method ***performing necessary calculations and operations*** @my_variable ...

Show PHP results in an Ajax modal box

Hey everyone! I'm new to this and had some code written for me by a programmer. Unfortunately, I can't reach out to them for help anymore. I have a calculator that shows results (generated by calc.php) without refreshing the page. Check out the ...

What steps can be taken to ensure that the array of identifier tags for each student remains intact even after being re-fetched from the API

I am facing an issue where my list of students displayed on the web browser resets when filter fields are cleared. The students are fetched from an API and displayed based on name/tag filters. But, after clearing the filters, the tags associated with each ...

Ways to incorporate lighting into the instancing shader

Is there a way to incorporate ambient and directional lighting into the shader when using InstancedBufferGeometry? For example, I am looking to add lighting effects to a specific instance, like in this example: Below is the vertex shader code: precision ...

The issue lies with Express Mongoose failing to store the data

Encountering some issues when trying to save an object created in Express nodejs using mongoose. Despite receiving a confirmation that the object is saved, it cannot be located even after attempting to access it through the server. Express route for savi ...

Develop a custom time input mask in AngularJS controller

In my AngularJS controller, I have the following code snippet: $scope.detailConfig = [{ title: $filter('translate')('bundle.app.HORA_MINUTO_INICIAL_DESCONSIDERAR'), property: 'faixaHorariaInicial', type: ' ...

Continuously performing a task in Node.js every 2 minutes until a JSON file, which is being monitored for changes every few seconds

In order to modify a process while my program is running, I need to manually change a value in a .json object from 0 to 1. Now, I want the program to: periodically check the .json file for changes. refresh a browser page (using puppeteer) every 2 minutes ...

What is the method for linking to another page ID using an <a href> tag?

On one of my pages, I have a section that references another page's div id to trigger a click event for editing specific form fields. This is the profile page: <a href="<?php echo base_url('settings_pro/edit'); ?>" name="pull-righ ...