After a texture is added, the shine of the Three.js MeshPhongMaterial diminishes

Check out this intriguing Codepen showcasing a white, glossy "cup" loaded using Three's GLTFLoader:

https://codepen.io/snakeo/pen/XWOoGPL

However, when I try to add a texture to a section of the mug, the shiny cup mysteriously transforms into a lackluster and patchy version:

You can experiment with applying the texture on the Codepen by uncommenting line 102:

// Create MeshPhongMaterial with the texture
const phongMaterial = new THREE.MeshPhongMaterial({
   color: 0xFFFFFF,       // White color for the ceramic look
   shininess: 30,         // Adjust shininess for the ceramic effect
   specular: 0x222222,    // Specular color
   // map: texture           // Apply the texture
});

The image is only displayed on the "face" of the cup.

I'm puzzled by this sudden change. As a newcomer in this field, any guidance would be greatly appreciated.

Thank you.

I've experimented with altering texture.wrapS, texture.wrapT, and texture.repeat without success, leading to strange outcomes that do not restore the original white and shiny appearance of the cup.

Answer №1

MeshPhongMaterial may not be the best choice when working with reflective or glassy materials. While it is more GPU-friendly, it may not achieve the desired visual quality.

There are other alternatives available, such as MeshStandardMaterial, which offers impressive results without sacrificing performance.

Alternatively, if you only need to work with a specific item like a cup or a single object, consider using MeshPhysicalMaterial. This material provides enhanced features like Clearcoat, Physically-based transparency, Advanced reflectivity, and Sheen.

Keep in mind that applying textures on these materials will not compromise their shiny appearance. However, if you must use MeshPhongMaterial for some reason, you can refer to this example. Please note that you can also inspect the code by accessing the Three.js GitHub repository (#webgpu_lights_phong) or opening the inspector tool.

Additional Helpful Resources

Check out this physical material example

Learn about transparency in Physical material

Watch a practical demonstration of using Physical Material (YouTube)

Explore Textures & Texture Mapping in Three.js (YouTube)

Answer №2

If you've already experimented with adjusting the shininess and specular properties, like setting them to shininess: 100 and specular: 0x444444, without success.

Have you considered using MeshStandardMaterial instead?

const standardMaterial = new THREE.MeshStandardMaterial({
         color: 0xFFFFFF,
         roughness: 0.4,
         metalness: 0.7,
         map: texture 
      });

However, if you specifically require MeshPhongMaterial, you can try this alternative approach:

const originalSpecularMap = mesh.material.specularMap;
const phongMaterial = new THREE.MeshPhongMaterial({
         color: 0xFFFFFF,
         specularMap: originalSpecularMap,
         shininess: 60,
         map: texture,
         specular: 0x666666,
         emissive: 0x444444,
         emissiveIntensity: 0.6
      });

Feel free to experiment with these settings to achieve your desired outcome easily.

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

What could be the reason for this JavaScript malfunctioning in both Chrome and Safari browsers?

Why is it that the javascript works fine in Firefox for the gallery on the page below, but doesn't seem to be functioning properly in Chrome and Safari? In Chrome, the big image isn't displaying but the thumbnails are, and in Safari nothing show ...

Discover the magic of Bootstrap 3.0 Popovers and Tooltips

I'm struggling with implementing the popover and tooltip features in Bootstrap. While I have successfully implemented drop downs and modals, the tooltips are not styled or positioned correctly as shown in the Bootstrap examples, and the popover featur ...

Switch out a character with its corresponding position in the alphabet

Starting out, this task seemed simple to me. However, every time I attempt to run the code on codewars, I keep getting an empty array. I'm reaching out in hopes that you can help me pinpoint the issue. function alphabetPosition(text) { text.split ...

Creating a dynamic tbody element on button click with the help of javascript or jquery

I am working with the following code: $(document).ready(function() { //Optimizing by selecting tbody first using jquery children var tbody = $('#myTable').children('tbody'); //If no tbody found, select the table itself ...

Issue arises when trying to implement sidebar navigation in Angular with Materialize CSS

Just starting my Angular journey and running into some trouble trying to set up a practical and responsive menu using SidebarNav and Dropdown. I used CLI to install and configure angular2-materialize and materialize-css. To create the menu, I made a comp ...

Creating a calculator with JQuery and encountering challenges with performing multiple calculations

I've been working on a calculator using jQuery, but I'm encountering issues with the clear button not functioning properly after multiple calculations. On top of that, subsequent calculations are producing inaccurate results. I am seeking to enh ...

Troubleshooting problems with AngularJS placeholders on Internet Explorer 9

On my partial page, I've included a placeholder like this: <input name="name" type="text" placeholder="Enter name" ng-class="{'error':form.name.$invalid}" ng-model="Name" required /> I have also set up client side validation for the ...

Exploring the concept behind the Javascript ternary statement code snippet

Recently, I stumbled upon this code snippet and I'm trying to grasp its purpose. I do understand that it involves using a ternary operator to add an active class on menu click, but a more detailed explanation would be greatly appreciated. navClick: f ...

Open the HTML document and access the file contents

I'm having trouble reading a text file from my computer onto a website. It works fine in Internet Explorer, but won't work in Chrome. I don't have much experience with HTML, so any help would be much appreciated! <html> <body> ...

Protecting an AJAX interface against unauthorized exploitation by external websites

We are in the process of creating a website that utilizes a basic JSON API (RoR) for displaying information on the page. This data is accessible to our clients, but crucial to our service, so we are taking precautions to prevent competitors from accessin ...

What is the best way to streamline the creation of a "products filter" using Node.js and Angular?

I have decided to build an angular application for an online computer store, and I am using a node/express backend. One of the key features of the application is the products page, where users can view all the products available in our database. Each produ ...

Preventing a webpage's CSS from affecting an iframe loading an HTML document

Whenever I load an iframe, it seems to change a bit. Do I need to apply some kind of reset or adjustment? How can I ensure that the content within the iframe looks consistent no matter what page it's loaded into? ...

HTML integration of JavaScript not working as expected

My experience with separating files in HTML and JS has been positive - everything works smoothly when I link the JS file to the HTML. However, an issue arises when I decide to include the JS code directly within <script> tags in the HTML itself. The ...

Tips for displaying Facebook comments with JavaScript

Can anyone help me figure out how to customize the data-href for Facebook comments using JavaScript (jQuery)? I tried incorporating the code below, but it's not displaying anything in the div col2. $("#col2").html( id+"<div class='fb-comm ...

Arrays contain multiple elements, not just a single item

Is it possible to display multiple objects in one container? For instance, I have an array let array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; array.forEach((item, index) => ( <div> <div> item 1, 2, 3 </div> <div> item 4, 5, 6 </div ...

Creating a response in Node JS

I'm struggling with crafting a response to the server. Currently, I have a login form that sends data to the server. On the backend, I verify if this data matches the information in a .json file and aim to send a response upon successful validation. ...

Javascript is not recognizing if and elseif conditions

I recently developed an IQ Test using JavaScript. I implemented specific conditions for different score ranges, however, the test only displays the IQ score based on the last condition, regardless of the number of correct answers. Despite numerous attempts ...

How can you implement a bootstrap navigation bar in a vue.js project?

I have encountered a problem with using html in my vue project. Despite following the documentation, it seems that the html is not working properly. I am unsure if this issue could be related to the import of popper.js. I have checked my code and I believe ...

The AJAX callback is unable to access the method of the jQuery plugin

I have a scenario where I am fetching data from an AJAX response and attempting to update a jQuery plugin with that value within the success callback: $.ajax({ url: '/some/url', type: 'GET', dataType: 'json', succ ...

In my React JS project, I am using an <Add /> component on two distinct pages. However, I am encountering an issue where only one of the pages is correctly receiving the add count prop

I could use some assistance in understanding why the logic for my counter button is not functioning properly on one specific instance. My aim is to have the count displayed by the counter look like this: https://i.sstatic.net/VdJ8o.png In order to add it ...