Is the definition of uniforms present in the THREE.js RawShaderMaterial?

The suggested reading regarding THREE.Js RawShaderMaterial states:

Default uniforms and attributes are not automatically included in the GLSL shader code.

Nevertheless, I have successfully executed the following shader using a rawShaderMaterial:

    <script type="x-shader/x-vertex" id="vertexShader">                                                                                                                                                                             
     precision mediump float;                                                                                                                                                                                                       
     precision mediump int;                                                                                                                                                                                                         

     uniform mat4 modelViewMatrix;                                                                                                                                                                                                  
     uniform mat4 projectionMatrix;                                                                                                                                                                                                 

     attribute vec3 position;                                                                                                                                                                                                       
     attribute vec4 color;                                                                                                                                                                                                          

     varying vec3 vPosition;                                                                                                                                                                                                        
     varying vec4 vColor;                                                                                                                                                                                                           


      void main() {                                                                                                                                                                                                                 
        vPosition = position;                                                                                                                                                                                                       
        vColor = color;                                                                                                                                                                                                             

        gl_Position = projectionMatrix *                                                                                                                                                                                            
                      modelViewMatrix *                                                                                                                                                                                             
                      vec4(position.x, position.y, position.z, 1.0);                                                                                                                                                                
        } 

Even though the modelViewMatrix or projectionMatrix are not explicitly defined anywhere. Could it be that certain uniforms are indeed being transmitted to the rawshader material?

Answer №1

Absolutely,

These variables are ready for use:
uniform mat4 modelViewMatrix;  
uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;
uniform vec3 cameraPosition;

When utilizing RawShaderMaterial, remember that you need to explicitly declare these variables in your shader to access them. They will not be automatically added.

Version of three.js mentioned: r.73

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

Invoking a function containing an await statement does not pause the execution flow until the corresponding promise is fulfilled

Imagine a situation like this: function process1(): Promise<string> { return new Promise((resolve, reject) => { // do something const response = true; setTimeout(() => { if (response) { resolve("success"); ...

What is the best way to combine two arrays of objects in AngularJS?

How can I merge the existing object array with another one in AngularJS to implement the "load more" feature? Specifically, I want to add the AJAX response to the existing data each time. Currently, I have a variable called $scope.actions that holds the ...

If the JSON file exists, load it and add new data without recreating the file or overwriting existing data

Currently, I am in the process of developing a function called createOrLoadJSON(). This function is responsible for checking whether an existing JSON file exists within the application. If the file does not exist, it should create a new file named "userDat ...

Three.js: Assisting in the creation of a dynamic FlowMap

Currently working on creating a flowmap using Three.js: I've referenced some of the code from this source: https://github.com/mrdoob/three.js/blob/master/examples/webgl_water_flowmap.html however, nothing seems to be displaying on my page: If anyone ...

Issue: Module 'xml2json' not found

Encountered an error while running my project package. When I tried to install the necessary packages using npm install xml2json I still encountered another error below. Can anyone provide suggestions or ideas on how to resolve this issue? D:\xa ...

Encountering a cannot POST / error while using Express

I am encountering an issue with my RESTful API while using Postman to call the route /websites. Despite my efforts, I keep receiving the error message "Cannot POST /websites". In addition, I am exploring the implementation of a job queue utilizing Express, ...

Building a dynamic and fast Vite project using "lit-ts" to create a visually appealing static website

I recently put together a project using Vite Lit Element Typescript and everything seemed to be running smoothly on the development server. However, when I tried running npm run build, only the compiled JS file was outputted to the /dist folder without any ...

Here is a unique rewrite:"Adjusting the prop of a Material UI Button component depending on screen size breakpoints can be achieved by utilizing

While using the Material UI Button component, I encountered an issue with conditionally determining the variant of the button based on screen size. Specifically, I want the variant to be 'outlined' on medium and larger screens, and no variant at ...

Implementing the use of a partial view in ASP.NET MVC with the help of JavaScript

I am faced with a challenge of displaying 15 different partial views based on the user's selection from a menu tab. Essentially, I have these 15 menu tabs on one side of the page, and when a user clicks on a tab, the content related to that tab should ...

Creating a VSCode extension using Vue: Step-by-step guide

I'm looking to develop a VSCode extension with Vue utilizing the VSCode webview. However, when attempting to import the compiled index.html into my extension, I consistently receive a prompt to enable JavaScript. Is there a solution for integrating Vu ...

The request body is not showing up as a key-value pair, while the request headers and other parameters are visible

Example of 'Advanced REST Client' Request I am currently using Postman and Advanced REST client to create a simple POST request based on the code below: 'use strict'; var express = require('express'); var bodyParser = requir ...

Looking for a method to incorporate an onclick function into a column for renderCell within the MUI Datagrid. Any suggestions?

I'm currently developing a react application and utilizing the MUI Datagrid to present some data. I have incorporated a rendercell to insert an edit icon which should trigger a pop-up modal when clicked. Below is the column setup. export const specifi ...

A guide to verifying a user's age using JavaScript by collecting information from 3 separate input fields

On page load, only the year input is required for users to fill in. The user can enter their birth year first without providing the month and day. Currently, I have a function that checks if a person is over 16 years old by comparing their birth year with ...

Streamline your processes by automating jQuery AJAX forms

I am looking to automate a click function using the code snippet below in order to directly submit form votes. Is there a method to develop a standalone script that can submit the votes without requiring a webpage refresh: <input type="submit" id="edit ...

React and Lottie Animation seamlessly synchronized with scrolling movements

I utilized Bodymovin to create various animations and I am hoping to trigger the animation when the scroll reaches that specific point. I have been attempting to find a solution, but unfortunately, I have not been successful. Currently, I am using Gatsby ...

Confirmation checkbox that retains original value if canceled

Imagine a scenario where there is a checkbox value. When the checkbox value changes, the user is asked, "Do you want to SHOW this item on the website?" or "Do you want to HIDE this item on the website?" Everything seems to be working fine, except for one ...

The VUE project I'm working on seems to be having compatibility issues with the Bootstrap modal in V

I added bootstrap using npm and inserted the code from bootstrap into my project, but it's not functioning correctly. I've spent an hour trying to troubleshoot, but still no luck. Here is the code snippet: <template> <div> <! ...

The click event triggered by the onclick clone/function may not always activate the click handler

As a newcomer in the JavaScript domain, I am encountering an issue where the first clone created after clicking 'add more' does not trigger my click me function. However, every subsequent clone works perfectly fine with it. What could be causing ...

Is it possible to send information via the URL while using jQuery Mobile?

My mobile application utilizes an in-app browser to send information, such as deviceID, to my server via a URL. For instance, the browser opens a web-page (jquery Mobile): www.myserver.com/doWork.html#deviceID Within the doWork.html file on the server si ...

Increase the height of an element based on the content of the text within

Today I am facing a challenge: I need the text below to change when I click on one of these icons: https://i.sstatic.net/28xEF.png Luckily, it works with the following code: CSS .games-text { background-color: $color-primary; & p { m ...