Encountering a compilation error when attempting to import a shader from a file in a project using THREE.js, Vue.js

I've encountered an error and spent hours searching for a solution, but unfortunately found nothing. The correct way to import shader code from a file is:

import {ColourShader} from '../shaders/ColourShader.js'

Here is the content of my 'ColourShader.js' file:

export var ColourShader = {
  vertexShader: [
    'void main() {',
      'gl_Position = vec4( position, 1.0 );',
    '}'
  ].join(),

  fragmentShader: [
    'uniform vec2 u_resolution;',
    'uniform float u_time;',
    'const int octaves = 6;',
    'const float seed = 43758.5453123;',
    // more shader code...
  ].join('\n')
}

When I import this shader using a script tag, it works fine. However, when trying to import it into my Vue.js single file component, I encounter multiple errors such as:

THREE.WebGLShader: Shader couldn't compile.

THREE.WebGLProgram: shader error: 0 35715 false gl.getProgramInfoLog invalid shaders

Answer №1

Your issue stems from the lack of clarity in your code, which led to the following error:

'colour += vec3(',
'(q.x + q.y) + QR * 30.,',
'QR * 15.', //// <------ Missing comma here
'r.x * r.y + QR * 5.',
');',

Utilizing template literals can simplify your work, as shown in the revised example below:

let fragmentShader = `
uniform vec2 u_resolution;
uniform float u_time;
const int octaves = 6;
const float seed = 43758.5453123;
const float seed2 = 73156.8473192;

// Code snippet continues...
`

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

Ways to halt a CSS animation when it reaches the screen boundary

I put together this demo: By clicking, a red box falls down. The issue arises when trying to determine the screen size using only CSS. In my demo, I set the box to fall for 1000px regardless of the actual screen height. Here is the keyframe code snippet ...

Can three.js be executed in Jupyter's ijavascript kernel?

Seeking assistance in integrating my library built with three.js into an ijavascript (jupyter + ijavascript) notebook environment. Any insights on whether this is achievable? It seems like three.js is compatible when using require('three'), but ...

Navigate the JSON object at predetermined intervals, such as in the case of movie subtitles

Apologies if the title is not specific enough, open to any suggestions for improvement. Here's my issue: I have a JSON file (presented here as a JavaScript object) that contains subtitles for a movie. My goal is to display the text exactly as it appea ...

The conversion of the input (ImageButton) to jQuery is not possible

Within my gridview, I have ImageButtons that open an edit form. To determine the ID, I need to access the surrounding element (Row). The issue arises when I try to pass 'this' as a parameter in the onClientClick event which triggers a JavaScript ...

Utilizing HTML templates in Express instead of Jade

Currently in the process of setting up a new MEAN stack project, with Angular as my chosen front-end framework. I am aiming to utilize HTML files for my views in order to incorporate Angular within them. However, I am facing challenges when attempting to s ...

How can I make my Background change on click using hexadecimal color codes?

I am struggling with changing the background color of an html document using a button click. While colors like "yellow, "blue", and "red" work perfectly, I encounter an issue when trying to use hexadecimal colors such as "#000000". The if-condition doesn ...

Tips on removing previously selected files from a Bootstrap 4 input file

I am currently facing an issue with a form that includes an input file implemented using Bootstrap 4. The functionality of this input file depends on Javascript: when the user clicks on the "browse files" button, a window opens for file selection, and upon ...

Highlighting of Vue directives in HTML within WebStorm

Can the Vue attributes and directives be highlighted? Including those in quotes. https://i.sstatic.net/NOGn7.jpg ...

How can I deactivate the today button in the angular-ui bootstrap datepicker popup?

Currently, I am working with two dates: StartDate and EndDate which are being managed using the angular-ui-bootstrap datepicker. When a user selects a StartDate (which must be greater than today's date), I want to ensure that the min-date of the EndD ...

Executing search bar capability through the use of AJAX and HTTP requests in JavaScript

I am currently working on implementing a search feature that will locate data based on the user's query. Specifically, I want to create a search bar in my HTML that can search for book titles stored in my database accessible through GET requests. Alth ...

Transform User's Regex Output into Uppercase

My nodejs program allows users to input text and apply their own regular expressions for editing. I want users to have the option to capitalize or lowercase text as well. For example, if a user enters "StackOverflow is great!" with the regex (.) set to be ...

Is there a way to conceal the loading screen until the website has completely loaded?

I've been working on my personal portfolio/website and encountered a bug that I can't seem to fix on my own. The issue is with the logo (aa) and text under it showing even after the content page has fully loaded, taking around 3 seconds to hide. ...

Is there a way to prompt WebAPI to receive a complicated object as its argument for a DELETE HTTP request without relying on C# attributes?

Currently, my server is utilizing C#/WebAPI while the client side is using AngularJS. I am faced with a dilemma when it comes to formatting an HTTP DELETE request without specifying attributes in C#. Specifically, I am struggling with how to handle a meth ...

Navigating the issue of "Experiencing additional hooks rendered compared to the previous render"

I'm currently in the process of developing a small application where certain elements will be nested within one another. My approach involves segmenting each component into its own file (children), returning a function with two components in each Rend ...

Notification does not appear once the full content of all iframes on the page has been loaded

<!DOCTYPE html> <html lang="en"> <head> <title> </title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="css/custom.css" /> </head> <bo ...

Issue with Angular 2 NgFor Pattern Error Message Display Absence

I am attempting to incorporate inputs with a regex requirement within an ngFor loop, but I am not receiving the expected error message when entering something that does not match the required pattern. Even when I input an incorrect pattern, "Test" remains ...

Trouble with a basic array duplication function

function duplicateArray(arr) { var len = arr.length; var dup = new Array(); var j; for (j = 0; j < len; j++) { dup[j] = arr[j]; } console.log(dup); } return; duplicateArray([2, 3, 5]); I appreciate your assistance, There are no errors ...

Elasticsearch refusing to acknowledge specified size limit

I've encountered an issue with my Elasticsearch search request in Vuejs. Everything runs smoothly until I try to add size/from parameters into the query, which results in the error message "Options contains invalid key: size". I'm struggling to p ...

How can I utilize an external file in Node js to output as a response?

I came across a similar inquiry, but I am interested in exploring manual methods. My goal is to achieve this without relying on express or any other external library. var http = require('http'); var server = http.createServer(function(req, res) ...

Attempting to grasp the concept of memory leakage in a more thorough manner

As I dive into the world of frontend development and start learning Vue.js, I came across a paragraph in the tutorial that caught my attention: Vue.js makes rendering a template seem simple, but under the hood it does a lot of work. The data and DOM are ...