Having trouble incorporating GLSL shaders into Three.js

I have reproduced the code here at using Three.js version r50. However, I am looking to adapt this technique for the latest version of Three.js. My specific question pertains to the shaders.

The error message that I am encountering reads as follows:

THREE.WebGLProgram: gl.getProgramInfoLog() WARNING: Output of vertex shader 'vNormal' not read by fragment shader

Below is my revised code - could you please assist me? I have also made changes to the way in which shaders are loaded (the warning message appeared before this modification). I attempted to follow similar patterns found in other examples. Here is my updated code:

THREE.DisplacementShader = {

vertexShader: [
    'uniform float time;',
    'uniform vec2 scale;',
    'uniform float uTwist;',
    'varying vec2 vUv;',
    'varying vec3 vNormal;',
    'uniform vec2 uShapeBias;',
    'uniform float uTurbulence;',

    '#ifdef VERTEX_TEXTURES',
        'uniform sampler2D tHeightMap;',
        'uniform float uDisplacementScale;',
        'uniform float uDisplacementBias;',
    '#endif',

    'vec4 DoTwist( vec4 pos, float t )',
    '{',
        'float st = sin(t);',
        'float ct = cos(t);',
        'vec4 new_pos;',

        'new_pos.x = pos.x*ct - pos.z*st;',
        'new_pos.z = pos.x*st + pos.z*ct;',

        'new_pos.y = pos.y;',
        'new_pos.w = pos.w;',

        'return( new_pos );',
    '}',

    'void main( void ) {',

        'vUv = uv;',
        'vNormal = normalize( normalMatrix * normal );',

        //change matrix
        'vec4 mPosition = modelMatrix *  vec4( position, 1.0 );',

        'mPosition.x *= 1.0 - uShapeBias.x*(vUv.y);',
        'mPosition.y *= 10.0;',
        'mPosition.z *= 1.0 - uShapeBias.y*(vUv.y);',

        'float height = -500.0;',

        //twist
        'float angle_rad = uTwist * 3.14159 / 180.0;',

        'float ang = (position.y-height*1.0)/height * angle_rad;',

        'vec4 twistedPosition = DoTwist(mPosition, ang);',
        'vec4 twistedNormal = DoTwist(vec4(vNormal,1.0), ang);',

        //change matrix
        'vec4 mvPosition = viewMatrix * twistedPosition;',

        '#ifdef VERTEX_TEXTURES',
            'vec3 dv = texture2D( tHeightMap, vUv ).xyz;',
            'float df = uDisplacementScale * dv.x + uDisplacementBias;',
            'vec4 displacedPosition = vec4( twistedNormal.xyz * df, 0.0 ) + mvPosition;',
            'gl_Position = projectionMatrix * displacedPosition;',
        '#else',
            'gl_Position = projectionMatrix * mvPosition;',
        '#endif',

    '}',
].join( "\n" ),

fragmentShader: [
    'varying vec2 vUv;',

    'uniform sampler2D tHeightMap;',
    'uniform float uSmoke;',
    'uniform float uOpacity;',
    'uniform vec3 uColor1;',
    'uniform vec3 uColor2;',
    'uniform float uScreenHeight;',


    'void main( void ) {',

        'vec4 heightColor = texture2D( tHeightMap, vUv);',

        'vec3 gradient1 = uColor1;',
        'vec3 gradient2 = uColor2;',
        'vec3 fireSumColor = (gradient1+gradient2)*heightColor.r;',

        //smoke
        'gl_FragColor = vec4(mix( fireSumColor, vec3(0.0), uSmoke ),1.0);',

        'float depth = ( gl_FragCoord.z / gl_FragCoord.w );',
        'float fogFactor = smoothstep( 1000.0, 6000.0, depth );',

        'gl_FragColor = mix( gl_FragColor, vec4( vec3(1.0), gl_FragColor.w ), fogFactor ) * uOpacity;',

    '}'
].join( "\n" )

};

This may be a specialized inquiry, but any guidance would be greatly appreciated. I suspect the issue lies with the varying variable type and potentially how it is being handled.

Answer №1

The main point of this message is quite obvious - you define a varying in your vertex shader and assign it a value, but fail to utilize it in the fragment shader. There are two potential solutions:

  • If you do not require the vNormal in the fragment shader, simply remove it from the vertex shader.
  • If the vNormal is necessary in the fragment shader, include a varying vec3 vNormal declaration in your fragment shader and then incorporate vNormal into the calculations.

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

Receiving a data response from AJAX in Node.js is easy with these steps

Right now, I am in the process of learning express, ajax, and nodejs. My current focus is on making ajax and nodejs communicate with each other. I have been sending a client request using ajax to a nodejs server. Everything seems to be working fine up unti ...

Updating PHP query with JavaScript or jQuery: yea or nay?

I am currently working on a project where I need specific text fields to update periodically with information from a database. To achieve this, I am experimenting with using PHP within JavaScript (or JS in PHP?). My goal is to have these fields update with ...

Guide to opening all href links in a new window

When loading HTML content parsed from an email to a frame, the issue arises when there is an href link that tries to open in the same frame. I want to modify it so that it opens in a new tab instead. Usually, setting the target to _blank in the href would ...

Is there a more efficient method for streamlining the Express-Validator middleware in a separate file

In my current project, there is a lot of validation required using Express-Validator. In each file, I find myself repeating the same validation code: //Validation and Sanitizing Rules const validationRules = [ param('tab').isString().isLength({ ...

Custom JSON filtering

I have a JSON object called Menu which contains various menu items for my system that I am developing using VueJS + Vuetify. I need to filter these menu items based on the "text" field, regardless of position in the text and without differentiating between ...

Obtaining Distinct Values in AngularJS Using ng-option

My table contains the following data: info = [ {id: 1, name: 'Manchester United', type: 'Soccer', featured: true, country: 'England'}, {id: 2, name: 'Manchester City', type: 'Soccer', featured: false, ...

Sneaky spam and ads embedded within Joomla template

Today, while examining the source code of a Joomla site I am developing, I stumbled upon some hidden links that seem to be spam. I have spent an hour searching through various template files but have been unable to locate them. The hidden links in questio ...

Angular foreach method encounters a syntax issue

When I use the getTotal.getValues() function to make a server call that returns values like "one", "two", "three" up to "nine", I am able to print them using console.log(res). However, I am facing an issue where I cannot push these returned values into t ...

Interactive multiple draggable items using Jquery

I have implemented basic JavaScript code in my project. One of the functionalities I created is a drag-and-drop system with an inventory feature. However, I encountered an issue where the current drag-and-drop system only works for one item at a time. M ...

Beware, search for DomNode!

I attempted to create a select menu using material-ui and React const SelectLevelButton = forwardRef((props, ref) => { const [stateLevel, setStateLevel] = useState({ level: "Easy" }); const [stateMenu, setStateMenu] = useState({ isOpen ...

What is causing my grayscale function to only impact part of the canvas?

As a beginner programmer, I have been experimenting with creating a grayscale function in JavaScript for practice. This is the code I have come up with: <canvas width='400' height='400'></canvas> <script> var can ...

Using TypeScript generics to add constraints to function parameters within an object

My Goal: Imagine a configuration with types structured like this: type ExmapleConfig = { A: { Component: (props: { type: "a"; a: number; b: number }) => null }; B: { Component: (props: { type: "b"; a: string; c: number }) =& ...

Encountering an issue with importing external JavaScript files in the App.js file during React development

Currently, I am embarking on the development of a basic starter app that deals with SMTP anonymously in React. This project is primarily for educational purposes. Prior to diving into actual development work, I have decided to keep things simple and focus ...

extract personalized label from data endpoint

I am encountering an issue with the MyComponent.vue component: <template> <div v-html="content"></div> </template> <script> import Vue from 'vue' import CustomComponent from 'CustomComponent.vue' ...

An Aframe animation being initiated by an unexpected event

Two animations are set on a <a-sky>. The first activates on click, while the second is triggered by a custom 'close' event in another JavaScript file. The sky is defined as shown: <a-sky mixin="sky" id="thesky" src="puydesancy.jpg" sca ...

Issues with incorrect source path in Typescript, Gulp, and Sourcemaps configuration

In my nodejs app, the folder structure is as follows: project |-- src/ | |-- controllers/ | | |`-- authorize-controller.ts | |`-- index.ts |--dist/ | |--controllers/ | | |`-- authorize-controller.js | | |`-- authorize-controller.js.map | ...

Positioning of SVG text along the y-axis

https://i.sstatic.net/FkBRo.png In my project, I am creating a population pyramid using d3 in combination with react. While d3 handles the calculations, react is responsible for rendering the DOM elements. Everything is going smoothly so far, except for p ...

I am having trouble locating the lightbox and bootstrap js file in Django. Any suggestions on how to resolve this issue would

[11/Nov/2020 20:13:11] "GET /about HTTP/1.1" 200 3615 [11/Nov/2020 20:13:12] "GET /static/js/lighbox.min.js HTTP/1.1" 404 1677 [11/Nov/2020 20:13:12] "GET /static/js/bootstrap.bundle.min.js.map HTTP/1.1" 404 1716 A snippet fr ...

Filter an array in React based on the value selected in an HTML select

I'm having trouble filtering my array based on a select value and getting the desired result. Essentially, I want to be able to choose an option from a select dropdown and have the data re-render with content related to that option. However, the data ...

Express and Webpack Error: "SyntaxError: Unexpected token <"

I am facing difficulties while testing my React webpage that I built using Webpack. When trying to run an Express server, the localhost page appears blank with a console message saying Uncaught SyntaxError: Unexpected token <. It seems like the webpage ...