Creating a lifelike metallic finish using three.js

Looking to achieve a more polished and lifelike chrome effect. The texture quality in my demo is currently jagged and pixelated. What methods can be used to achieve a flawless reflective surface on a customized object?

https://i.sstatic.net/dfPKv.gif

     var path = "textures/reflection/";
      var format = '.jpg';

      var urls = [
          path + 'px' + format, path + 'nx' + format,
          path + 'py' + format, path + 'ny' + format,
          path + 'pz' + format, path + 'nz' + format
      ];

  var envMap = THREE.ImageUtils.loadTextureCube( urls, THREE.CubeReflectionMapping );

  var chrome = new THREE.MeshPhongMaterial( {
      color: 0xffffff,
      specular:0xffffff,
      envMap: envMap,
      combine: THREE.MultiplyOperation,
      shininess: 50,
      reflectivity: 1.0
  } );

Answer №1

To achieve crisp edges, consider replacing the cube texture with a function embedded within the shader. However, this task may prove challenging if you are new to writing shaders.

If you are familiar with shaders, simply utilize the same 3D reflection vector intended for the 3D texture lookup. Instead, implement a cut-off function based on the 'y' value, such as:

reflVec = normalize(reflVec);
vec3 reflectColor = (reflVec.y > 0.3) ? vec3(1,1,1) : vec3(0,0,0);

By incorporating this code snippet within the shader, you can expect minimal aliasing but extremely sharp results. Comprehensive anti-aliasing techniques extend beyond the scope of a brief response like this one. Nonetheless, if you are using FXAA or similar methods, the aliasing may not be noticeable.

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

Conceal the Div containing the specified class

I was hoping to hide the first DIV if the second DIV is displayed on the front end, and vice versa upon page load. If the first DIV is set to 'block,' then the second DIV should be set to 'none.' And If the second DIV is set to &apos ...

Retrieve all MongoDB documents that match multiple regular expressions

I'm looking to search a database for documents that match multiple regex terms in one field and also match another list of regex terms in a different field. For example: .find({ fieldA: { $regex: /stringA/i } OR fieldA: { $regex: /st ...

Troubles with IE7 regarding jQuery [clicking and changing events]

My code snippets are designed to loop through cached JSON data on the 1st click function and display any values that exist for a specific id. The 2nd change function captures when elements' values change (e.g., from yes to no). Since these elements a ...

JQuery does not recognize modifications in input values triggered by Ajax

I am working on a website that utilizes a Gravity Forms form along with the GF Populate Anything add-on plugin to load data dynamically using ajax. I am facing an issue when trying to implement a simple JavaScript function to detect changes in one of the i ...

Condense a lineup of names into only two rows

I have a challenge where I need to showcase a list of names separated by commas, pulled from an array in my React component. The HTML output should appear as follows: <div> <span>Liza</span>, <span>Eric</span>, <span>Mic ...

What are the benefits of keeping JavaScript and HTML separate in web development?

Recently, I came across the concept of Unobtrusive JavaScript while researching best practices in the realm of JavaScript. One particular point that grabbed my attention was the idea of separating functionality (the "behavior layer") from a web page's ...

What is the best way to perform a keyword search in AngularJS?

My data consists of code:description pairs (e.g. cmsc100: Web Programming). I have a search box where users can enter either the code or description. Upon clicking the button, the program should display the data that matches the entered code/description or ...

Determine the name of the chosen item during program execution

Apologies for my limited English skills: I have loaded multiple JSON objects and am using Ray to select them, changing their color upon intersection. However, I am trying to determine which object is being selected at runtime. Currently, with the code be ...

Is there a method to run code in the parent class right after the child constructor is called in two ES6 Parent-Child classes?

For instance: class Parent { constructor() {} } class Child { constructor() { super(); someChildCode(); } } I need to run some additional code after the execution of someChildCode(). Although I could insert it directly there, the requirement is not to ...

Can a PHP script be executed through an Ajax event?

Is it feasible to execute the script of a PHP file when an AJAX event is triggered? Consider this scenario: on the AJAX error, could we send the data to the error.php file, record the error, notify the admin via email, and perform any other desired action ...

Struggling to retrieve information from a JSON file and display it within a component?

After accessing the JSON data and storing the necessary values in a dictionary named details, I am encountering an issue where the values are displayed when console logged from inside the function but appear as undefined when console logged in the parent f ...

Creating a pair of interconnected drop-down menus linked to arrays within a Rails model

I have spent hours searching on Google and Stack Overflow, but I haven't been able to find a solution that fits my requirements. As a newcomer to Rails, I am currently working on a bug tracking system in Rails 4.2.4. Within this system, I have a class ...

Oops! It seems like there was an error that occurred because the document was not

I have created a simple app to assist diabetics in calculating various factors to help regulate their blood sugar levels. However, I am facing an issue when trying to pull the Carbs down to my list at the bottom of the page. The code snippet is provided be ...

retrieve items from an array according to the hierarchy of the objects

I am working with an array of objects that looks like this: let obj = [ { name: "Qwerty1", status: "Development" }, { name: "Qwerty2", status: "Development" }, { name: "Qwerty3", status: "Staging" }, { name: "Qwerty4", status: "Production" }, { ...

Is there a way to automatically set all object properties to false if one property is set to true in React?

The Issue: My task at work involves creating 3 buttons with separate filters to display different tickets in a table. All the functionality is completed, and the filtered tickets are displayed correctly. However, I am facing an issue that is preventing m ...

Adding a line and text as a label to a rectangle in D3: A step-by-step guide

My current bar graph displays values for A, B, and C that fluctuate slightly in the data but follow a consistent trend, all being out of 100. https://i.stack.imgur.com/V8AWQ.png I'm facing issues adding lines with text to the center of each graph. A ...

Retrieving specific fields from a MongoDB document through Mongoose for flexible querying

Is there a way to exclude certain attributes such as email, logoUri, and personal info from a seller object when dynamically populating? Below is the messageSchema: const messageSchema = mongoose.Schema({ chatId: { type: mongoose.Schema.Types.Object ...

The intricacies of how Node.js handles asynchronous execution flow

I wanted to ask about the best approach for displaying data retrieved from MySQL. Do you think this workflow is correct? app.get('/demo/:id', function(req, res) { var query = csql.query('SELECT * FROM table_videos WHERE id=? LIMIT 1' ...

Sorting in Vuejs fails to function properly when a filter is applied

Having recently delved into Laravel and Vue, I am eager to develop a site for our Intranet. Pulling data from the Laravel database has been successful, displaying the data works well, and the search functionality is also up and running smoothly. However, I ...

Error message "Assignment operation cannot occur on the left side" occurs when attempting to use the NOT operator

Currently, I have this function in use: $scope.myFunction = function(indexParent, childrenLength) { // close all inner accordion tabs for(i=0; i < childrenLength; i++) { !$scope.lettersandnumbers[indexParent].things[i].open = $scope.le ...