Facing a Challenge with Textures in ThreeJS ShaderMaterial

I seem to be having trouble with my texture not being displayed properly in three.js r71. The plane is just showing up black and I can't figure out what's wrong with my ShaderMaterial. I could really use another set of eyes to help me identify the issue.

Any assistance would be greatly appreciated!

Below is the HTML code snippet:

<!DOCTYPE html>

<html>
  <head>
    
    <script src="jquery.min.js"></script>
    <script src="three.min.js"></script>
    <script src="testshdr.js"></script>
    
  </head>
  
  <body>
   
    <!-- Shaders -->
    <script id="vertexShader" 
            type="x-shader/x-vertex" >

    varying vec2 vUv;

    void main(){
      vUv = uv;
      gl_Position = projectionMatrix * 
                    modelViewMatrix * 
                    vec4(position, 1.0);

    }

    </script>

    <script name="no_effect"
            id="fragmentShader_0"
            type="x-shader/x-fragment" >

    varying vec2 vUv;

    uniform sampler2D editImg;

    void main(){
      vec4 myTexture = texture2D(editImg, vUv);
      gl_FragColor = vec4 (myTexture.r, 
                           myTexture.g, 
                           myTexture.b, 
                           1.0);

    }

    </script>
   
    <script type="text/javascript">
      var tst = new TestShdr();
    </script>

  </body>
  
</html>

And here's the JavaScript code snippet:

var TestShdr = function () {
  'use strict';
  
  var
    SCENE,
    RENDERER,
    CAMERA,
    GEO,
    MAT,
    OBJ,
    TEX,
    UNIFS,
    VS,
    FS;
  
  SCENE = new THREE.Scene();
  RENDERER = new THREE.WebGLRenderer();
  RENDERER.setSize(256, 256);
  
  CAMERA = new THREE.PerspectiveCamera(56, 1, 0.1, 1000);
  
  SCENE.add(CAMERA);
  CAMERA.position.z = 5;
  
  TEX = THREE.ImageUtils.loadTexture('1107.jpg');
  
  UNIFS = {
    editImg: { type: 't', value: TEX}
  };
  VS = $('#vertexShader').html();
  FS = $('#fragmentShader_0').html();
  
  GEO = new THREE.PlaneBufferGeometry(1, 1, 1, 1);
  MAT = new THREE.ShaderMaterial({uniforms: UNIFS,
                                  vertexShader: VS,
                                  fragmentShader: FS
                                 });
  OBJ = new THREE.Mesh(GEO, MAT);
  SCENE.add(OBJ);
  
  document.body.appendChild(RENDERER.domElement);
  
  RENDERER.render(SCENE, CAMERA);
  
};

Answer №1

It is recommended that you perform the following action:

tex = THREE.ImageLoader.loadTexture('1107.jpg', {}, function() {
    renderer.render(scene, camera);
});

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

Changing properties of JavaScript arrays

Currently using Express and dealing with an array of objects that I need to adjust the created property for better presentation, utilizing the dateFormat package. The array originates from a mongo query and is stored in a variable called stories. A sample ...

Ruby on Rails: clearing the asset pipeline cache by hand

While Rails usually clears the asset pipeline cache automatically when files are modified, I am facing a unique situation. I am providing my application as an HTML response to an Ajax request, cross-domain using rack-cors to bypass CORS. The issue arises ...

Is there a way to showcase my information on flash cards using JavaScript?

Currently, I am developing a full stack application that utilizes JavaScript on both the front and back end. This application allows users to create their own flashcards set. Upon clicking "View Cards," the data is fetched and the question-answer pair is d ...

Capturing jQuery ajax requests in Angular

Within my Angular application, I am utilizing the integrated $.couch API from CouchDB. My goal is to intercept every ajax request, regardless of whether it originates from Angular's $http service or jQuery's $.ajax (which is utilized by $.couch). ...

Adjusting the color of a specific part of a text within a string using

I am trying to update the color of specific keywords within a post. For example: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor lacinia urna eget gravida. Quisque magna nulla, fermentum fermentum od #keyword1 #keyword2 #keyword3 ...

Frontend utilizing the Next-auth Github Provider for Profile Consumption

After following the official documentation for implementing SSO with the Next-auth Github provider in my App, I encountered an issue where the Client API documentation suggested using useSession() to retrieve session information, but it was not returning t ...

What could be causing my JavaScript function to produce repeated letters with just one key press?

After implementing a code that generates different variables based on the 'truth' variable, I encountered an issue. Everything works flawlessly when 'truth' is set to "name," but as soon as I switch it to "email," any keystroke results ...

ng serve issue persists even after resolving vulnerabilities

Can anyone assist me in resolving why I am unable to start my project after fixing 3 high vulnerabilities? I ran npm audit to identify the vulnerabilities and then used npm install --save-dev @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_em ...

Utilize prop-types inheritance when a component is rendered via props

Is it possible to inherit prop-types when a component is rendered via the parents prop, without direct access to 'ChildProps' and 'Props' interface? Parent Component interface ChildProps { counter: number; setCounter: React.Dispat ...

Is it possible to alter the background color once the content of an input field has been modified?

I am working with an angular reactive form and I want to dynamically change the background color of all input fields when their value is changed. Some of these input fields are pre-populated and not required. I came across a potential solution on Stack Ove ...

The onInvoke hook in Zone.js is receiving an inaccurate currentZone value

Greetings. In the comments for the ZoneSpec interface (found in zone.ts file), it states that the onInvoke hook must receive currentZone as the second parameter. If creating an interceptor zone, the reference to that zone should be passed as the second pa ...

What is the process for importing module functions in Svelte when utilizing npm?

I'm having trouble understanding how to properly use imports in Svelte with npm. I have a Svelte component that I can't seem to get working. Uncommenting "//import { Configuration, OpenAIApi } from "openai";" leads to the error message: [!] (plug ...

Increase the date by one day in the minimum date field using the date picker

I've been struggling with adding one day to the minDate in my code. Despite trying multiple solutions from Stackoverflow, none of them have worked successfully. Here is the code I currently have: $('#cal_mulamhn').datepicker({ minDate ...

invoking a function in javascript from react

Currently, I am grappling with the task of invoking a JavaScript function from within React while adapting a "React" based "Menu" onto some existing jQuery functions. Below you can find my code for the menu: class Menus extends React.Component{ co ...

Tips for minimizing unnecessary rerenders in child components that rely on cached information from the parent component

check out the sandbox here Application maintains state to compute a memoized value, which is then passed as props to the Options. When a change occurs in the state triggered by a callback function in Option, it causes a rerender of the main Application, r ...

Save user information to initialize rootScope upon refreshing the page

I'm looking for a way to retain a User Json Object in such a manner that I can use it to initialize my $rootScope.user Json Object with the saved information even after refreshing the page. The storage should persist as long as the browser window rem ...

Using Angular to pass parameters to a function

When passing a parameter to the getActiveId function in the ng-click <span class="col ion-ios7-heart-outline center" ng- click="getActiveId({{activeSlide.selected}})"> The value turns to zero in the controller, but it is passed correctly after tes ...

utilizing the JavaScript SDK to send alerts to a user's friends on Facebook

I am attempting to send a notification to a user's friend using the JS SDK on a Facebook canvas app, but I'm encountering this error in the console: POST https://graph.facebook.com/16542203957691/notifications? 400 (OK) jquery.min.js:140 c.exten ...

Stop the reoccurring action for a jQuery plugin by using the clearInterval function

Having a difficulty with clearing the interval inside a jQuery plugin. Below is a simplified code snippet. When attempting to run the following in the Firefox console: $('.banner').pluginName().stop() the console keeps logging `console.log(1)`. ...

Reactively created menu using JQuery

Looking to implement a dynamic JQuery menu using React (ES6). Utilizing the JQuery menu examples (https://jqueryui.com/menu/) as a guide, however, those examples only cover static menus. It doesn't clarify how to modify menu items like updating labels ...