Minimize the blurring of distance in three.js

I am currently working on a project in three.js where I have a large plane with a texture map. However, I am facing an issue with blurring in the mid-distance and want to adjust the depth of field (DOF) to focus more on the floor material, especially along the right side.

Check out the texture map here.

You can view the original code here.

Performance is not a concern for me, so any solution that enhances texture fidelity and focus, compatible with the latest Firefox in Xvfb using OS mesa drivers, would be appreciated.

I tried to modify the code from http://threejs.org/examples/webgl_postprocessing_dof.html, but it did not yield the expected results as it still appeared too blurry. You can see the result with DOF Postprocessing here.

Below is a snippet of the code (refer to jsFiddle link for the complete source):

doRender = function() {       
    renderer = new THREE.WebGLRenderer({antialias:true, preserveDrawingBuffer:true});

    FOV = 60;
    camera =  new THREE.PerspectiveCamera(FOV, WIDTH/HEIGHT, .1, 8000);
    camera.position.x = -100;
    camera.position.y = 300;
    camera.position.z = 1000;   
    camera.lookAt(new THREE.Vector3(0, 300, 0)); 

    // Add Floor planes
    // FLOOR
    floorTexture.needsUpdate = true;
    var floorMaterial = new THREE.MeshPhongMaterial( { map: floorTexture, side: THREE.DoubleSide } );
    var floorGeometry = new THREE.PlaneBufferGeometry(4*1024, 4*1024, 256, 256);
    var floor = new THREE.Mesh(floorGeometry, floorMaterial);
    floor.doubleSided = true;
    floor.rotation.x = Math.PI / 2;
    floor.rotation.z = Math.PI / 3.9; 
    scene.add(floor);

    var moreFloor2 = floor.clone();
    moreFloor2.translateY(-4*1024);
    scene.add(moreFloor2);
}

window.onload = function() {
    // Enable cross-origin access to images
    THREE.ImageUtils.crossOrigin = '';
    floorTexture = THREE.ImageUtils.loadTexture('http://i.imgur.com/iEDVgsN.jpg?1', THREE.UVMapping, doRender);
};

Answer №1

After some trial and error, the solution turned out to be quite simple:

floorTexture.anisotropy = renderer.getMaxAnisotropy();

This code snippet effectively sets the anisotropy value to 16.

A recent update revealed that while this works on Firefox for Windows, it fails under Xvfb/Mesa as renderer.maxAnisotropy returns 0. Are there any viable workarounds?

A subsequent discovery proved that manually setting floorTexture.anisotropy to values up to 16 does indeed work, thus disproving the incorrect value returned by maxAnisotropy in three.js under xvfb/mesa. Therefore, this solution remains effective with a slight modification:

floorTexture.anisotropy = 16;

Further investigation uncovered my own oversight – the anisotropic feature was not functioning. The actual solution involved switching the backend mesa driver to one that does support it:

DISPLAY=:5 LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=softpipe firefox &

I extend my appreciation to glennk at [email protected] for providing this resolution.

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

Utilizing dual identifiers in a Jquery plugin

I am currently working with a jQuery plugin and I need to apply the same functionality to two different IDs. How can I achieve this? It involves a next and previous functionality where clicking on the next button automatically scrolls both divs. The issu ...

Customize hover effects in tailwind css with dynamic values

I am trying to customize the text color on hover based on different category names using tailwind CSS. In my configuration, I have assigned a specific color code for each category like this : tailwind.config.js theme: { extend: { } }, co ...

Animate Scrolling on Your Website with jQuery

I'm having some trouble implementing a page scrolling function on my website using jQuery. It currently works fine, but I want it to only respond to the first scroll event and then block any subsequent events until the animation completes (700ms) befo ...

Error in Uploading Files with AngularJS - Uncaught SyntaxError: Unexpected token

I'm having trouble uploading an image file using Angular and PHP, specifically at the app.service Error line: app.service('fileUpload', ['$https:', function ($https:) { Code app.service('fileUpload', ['$https:&ap ...

I'm struggling to find a way to showcase my JSON data in HTML. Update: I have a clear vision of how I want it to look, but I'm struggling to display it in any format other than raw JSON

I've been trying to figure this out for hours, scouring every resource I can find, but I'm stuck. I've left the API URL in there, so feel free to take a look (it's public). If my message doesn't make sense due to exhaustion, please ...

Troubleshooting: jQuery fixed header glitch with slide down effect

I am new to jQuery and seeking help without harsh judgment. My goal is to make the header fixed when scrolling down 300px on the page, and remove the fixed position if less than 300px. Additionally, I would like to animate the header by sliding it down whe ...

I'm encountering an issue where I receive the error `Cannot read property 'map' of undefined` while attempting to integrate the backend with React. What could be causing this error and how

I'm currently learning React and I've been using a tutorial here to connect my database to the front end of my React application. Unfortunately, every time I try running 'npm start' at 'localhost:3000' in express-react/backend ...

How can I create a clickable <div> element containing multiple links and trigger only one action?

Within my code, there is a <div> element that has been made clickable. Upon clicking this <div>, the height and text expand using the jQuery function $(div).animate();. While this functionality works as intended, I am encountering a slight issu ...

Position the Google Map to center itself around its markers

Is there a way to automatically center my Google Map based on dynamically loaded markers? I have tried using 'bounds' and implementing Fit to bounds, but have been unsuccessful in getting it to work. Below is the code snippet I am currently worki ...

Transform the string with binary hexadecimal characters in ASCII into a Buffer

Currently, I am utilizing node.js for my project. Within my code, there is a string variable called msg_str that contains the value "0102ab00aabb00". My goal is to convert this ASCII binary hex representation into a Buffer and have it displayed as <01 ...

Playing Sound Instantly in JavaScript without delay

I have successfully implemented playing sound with keys using HTML and .play. However, there is a delay as it waits for the track to finish playing before allowing me to play it again instantly upon each click. I am seeking a solution to trigger the sound ...

Tips for utilizing the getJson method to pass a variable to a PHP file

I need help with my JavaScript code, as I am trying to pass a datastring containing the value "no" to data.php using getJson in order to receive JSON as a response. However, my JavaScript code is not functioning correctly. Below is the code that I have: J ...

Is there a way to execute WebGL and JavaScript on the server side?

In the midst of my current project involving Three.js based WebGL, I find myself in need of quickly capturing a screenshot of a specific model. My approach so far has been to write some JavaScript code that renders the 3D model and then provides me with an ...

Notification will be triggered if the search query falls below x characters in length

Thank you for taking the time to read my query. I am currently working on creating a fancybox search page for a website project. While I have successfully implemented the search results in fancybox, I am facing an issue where clicking on the search button ...

Attempting to dynamically add an image to a template snippet

Struggling with inserting images dynamically from database paths in templates. How can I display them when a user clicks the Show More button on an expense page? New to templates and unsure about syntax. Show More Button displayed in the HTML template sho ...

Troubleshooting cross-origin resource sharing problem with Express NodeJS server running on localhost

Utilizing the fetch web API to send a POST request from ReactJS to an Express NodeJS server running on localhost with different ports. Using Client Fetch API fetch("http://localhost:8081/test", { method: "post", mode:"no-cors", headers: { ...

Improved method for categorizing items within an Array

Currently working on developing a CRUD API for a post-processing tool that deals with data structured like: { _date: '3/19/2021', monitor: 'metric1', project: 'bluejays', id1: 'test-pmon-2', voltageConditio ...

Showing the Datepicker from jQuery right in the middle of the screen

Here's the generated code as default: <div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper- clearfix ui-corner-all ui-datepicker-multi ui-datepicker-multi-2" style="width: 34em; position: absolute; left: ...

Issue with AxisHelper not displaying colors as expected

To incorporate an AxisHelper into my three.js project, I used the following code snippet: axes = new THREE.AxisHelper(100); scene.add(axes); After adding it, I noticed that the helper was displaying in solid white color, which made it difficult to see. I ...

JavaScript's $(window).on('resize') function allows for dynamic resizing of elements based on the browser window

Is the code below in JavaScript equivalent to each other? window.onresize = function() { // Do something. } $(window).on('resize', function () { // Do something. }); Do both code snippets offer the same functionality? Are there any min ...