ShaderMaterial encountering incorrect texture in Three.js

I am experimenting with a shaderMaterial to adjust the brightness and contrast on a specific object, in this case, a sphere designed for VR video.

Here is my implementation of the ShaderMaterial:

var geometry = new THREE.SphereGeometry( 500, 60, 40 );

var panoTexture = new THREE.VideoTexture( video );
panoTexture.minFilter = THREE.LinearFilter;
panoTexture.magFilter = THREE.LinearFilter;
panoTexture.format = THREE.RGBFormat;

// var material   = new THREE.MeshLambertMaterial( { map : texture } );

var shader = THREE.BrightnessContrastShader;
shader.uniforms[ "contrast" ].value = 0.0;
shader.uniforms[ "brightness" ].value = 0.0;
shader.uniforms[ "texture" ].texture = panoTexture;

var panoMaterial   = new THREE.ShaderMaterial(shader);


panoVideoMesh = new THREE.Mesh( geometry, panoMaterial );

Below is my code for the shader:

THREE.BrightnessContrastShader = {

    uniforms: {

        "tDiffuse":   { type: "t", value: null },
        "brightness": { type: "f", value: 0 },
        "contrast":   { type: "f", value: 0 },
        "texture":   { type: "t", value: 0 }

    },

    vertexShader: [

        "varying vec2 vUv;",

        "void main() {",

            "vUv = uv;",

            "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",

        "}"

    ].join("\n"),

    fragmentShader: [

        "uniform sampler2D tDiffuse;",
        "uniform float brightness;",
        "uniform float contrast;",

        "varying vec2 vUv;",

        "void main() {",

            "gl_FragColor = texture2D( tDiffuse, vUv );",

            "gl_FragColor.rgb += brightness;",

            "if (contrast > 0.0) {",
                "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
            "} else {",
                "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
            "}",

        "}"

    ].join("\n")

};

After rendering, the sphere displays another texture from a different part of the scene. How can I ensure that the video texture remains on the panoTexture? Is this achievable, and am I taking the right approach?

Answer №1

Success!

shader.uniforms[ "tDiffuse" ].value = panoTexture;

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

Merging arrays of objects in JavaScript to create a fresh one

I am struggling to combine two sets of data into a single array by matching them based on the day. I want to create a new array of objects that include the relevant information from both sets. The first set includes the following: [ { date: '9/30/2 ...

Creating Input Fields on the Fly in VueJS

My goal is to dynamically manipulate input fields in real-time. I found a helpful solution at , which successfully adds and removes fields as needed. However, when attempting to save the input values to the database, the functionality breaks. Here is the ...

Accessing data through AJAX without the need for a proxy, JSONP, or

This particular script found at https://github.com/shutterstock/api/blob/master/examples/javascript-jquery/v2.html is a front-end solution that directly interacts with the ShutterStock api. It does not utilize a proxy server, and JSONP or CORS are also n ...

What is the best way to access the Nodejs response object from outside the routing function?

Having an issue with obtaining a response object from outside the router function in Nodejs back-end. I can successfully log the response object in the first routing function, however, I am unable to access the values in the console of the second routing f ...

In Javascript, the difference between defining a variable using "this.varName" and "var varName" lies in the scope of the variable

Excuse my JS ignorance, but here's a question: In JS, I've noticed functions that define variables inside them like this: function functionName(){ this.something = ""; }; I'm wondering if something is considered a local variable. W ...

Utilize the Set data structure to eliminate duplicates from an array while retaining the item with

Looking for help with this array: array = [{id: 1, name: 'apple'}, {id: 2, name: 'banana'}, {id: 3, name: 'apple'}] I want to eliminate objects with duplicated "name" property while retaining the highest id for each unique ...

The behavior of the jQuery click function seems to be quirky and not functioning as expected. Additionally, the

It seems that instead of triggering a POST request, somehow a GET request is being triggered. Additionally, the ajax call is not being made as expected. I have attempted this many times before, but none of my attempts seem to be working. It could potenti ...

The onhashchange function is limited in its ability to completely track changes in the hash

I set up an onhashchange event listener on the page in the following way: window.addEventListener('hashchange', () => console.log('hash change!')) This listener can detect hash changes that I manually enter: However, I am not see ...

Retrieve information from a database in JSON format using AngularJS, then showcase it within the textbox

As a beginner in AngularJS, I am trying to retrieve data from my database and display it in a textbox. This is my code snippet: $scope.getData = function(){ $http.post('query?action=get',{ }) .then(function(response){ $sc ...

Separating text for tooltips from the element itself

I'm looking to enhance my website by adding tooltip descriptions to elements based on their CSS classes. While tooltips are usually added using the element's title attribute, I have numerous elements with the same lengthy description and want to ...

Update the DIV element's class to reflect whether the quiz answer provided is correct or incorrect

I am facing a challenge while attempting to assign a CSS class to a dynamically created element in JavaScript. The error I'm encountering pertains to the reference issue with the trackerMarker element within the event listener functionality. Although ...

I encountered a problem while trying to incorporate the solution that prompts another button click event

Interesting topic: JQuery / JavaScript - triggering button click event from another button <input type="submit" name="savebutton" id="uniqueOne" /> <input type="submit" name="savebutton" id="uniqueTwo" /> I have implemented a feature on my si ...

What is the best way to transform an array of key–value objects into an array of objects containing just one property?

I am working with an array of objects that looks like this: [ { "key": "fruit", "value": "apple" }, { "key": "color", "value": "red" }, { "key": "location& ...

What is the best way to integrate PHP code into my countdown JavaScript code to automatically insert data into a MySQL column once the countdown has reached

I have created a countdown JavaScript code that resets every day at 23:00 of local time. I am wondering if it is possible to incorporate PHP code into this script so that after the countdown finishes each day, it automatically adds "5" to my "Credit" col ...

Retrieve the assigned value of a textbox using a JavaScript function

I'm currently using the script below: <script type="text/javascript"> $(document).ready(function () { $("#<%=txtEnd.ClientID %>").dynDateTime({ showsTime: true, ifFormat: "%Y/%m/%d %H:%M", ...

Ensure that the alert for an Ajax JSON record count remains active when the count is

Trying out Ajax JSON for the first time has been a bit tricky. Even though I hard coded "Record: 1" on the server side, it keeps alerting me with a total record of 0. I'm not sure where I went wrong. Could it be an issue with how I passed the array da ...

A pair of HTTP GET requests

How can I ensure that data is retrieved from a.json before moving on to b.json and then running the init function, given 2 JSON urls? var urlA = "a.json"; var urlB = "b.json"; This is my approach: var app = angular.module('calendarApp', []); a ...

What are the best methods for implementing runtime type checking in JavaScript?

Utilizing either TypeScript or Facebook's Flow (type), I am empowered to statically assign types to variables like this: function add (x: integer, y: integer) { ... } Both TypeScript and Flow are able to identify and prevent incorrect invocations su ...

To set up MongoDB on your system, execute the following command: `npm install --

I've encountered a problem while attempting to install MongoDB on my personal computer for a Node project. I used the command line and ran npm install --save mongodb. Even though MongoDB appears in the dependencies section of my package.json file with ...

How to send a JSON Object and a CSV file using FormData

I need to send a JSON Object and a CSV file in a fetch request from my frontend to my backend. The JSON object is stored in the headerIngestion variable, while the CSV file is saved in the csv state. let formData = new FormData(); formData.append('h ...