Transmitting a feature identifier: darkened display

My goal is to pass an attribute variable with three.js to the vertex shader, which then should transfer it to the fragment shader using a varying variable.

Here's the Vertex Shader:

attribute vec4 color;
varying vec4 outColor;

void main() 
{
    outColor= color;
    gl_Position= projectionMatrix * modelViewMatrix * vec4(position,1.0);
}

And the Fragment Shader:

varying vec4 outColor;

void main() {
    gl_FragColor = outColor;
}

If there are different colors assigned to each of the 8 vertices of a cube, as it is interpolated between those colors on the faces, creating a blended effect. The initialization of attributes in JavaScript looks like this:

var colors= [];
for(var i=0; i<geometry.vertices.length; i++) {
    colors.push(new THREE.Vector4(0.0,1.0,0.0,1.0));
}

var attributes = {
    color: {type:"v4", value: colors}
};

var material= new THREE.ShaderMaterial({
    uniforms: uniforms,
    attributes: {},
    vertexShader: document.getElementById("vertexShader").textContent,
    fragmentShader: document.getElementById("fragmentShader").textContent
});

The current setup should render a green cube, however, there seems to be an issue with the instruction outColor=color; in the vertex shader causing the screen to display black instead. When changed to outColor=vec4(0.0,1.0,0.0,1.0);, the cube renders correctly in green.

To view the complete source code, click here.

Answer №1

Consider using attributes instead of an empty object when initializing the THREE.ShaderMaterial.

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

Deliver an intentionally bogus HTTP response using Express

I'm currently working on creating test cases for a web application and I am interested in testing how well the client can handle invalid HTTP responses. Can you provide some suggestions on how to purposely mess up a response so that it is no longer va ...

Is it possible to create a WebXR using the ARCore API specifically for IOS devices?

I'm experiencing an issue with my code that seems to be working flawlessly on Android devices, but when attempting to run it on an iOS device, clicking the button to start the AR session yields no results. I reached out to ChatGPT for assistance, and ...

What methods does Enzyme have for determining the visibility of components?

I am facing an issue with a Checkbox component in my project. I have implemented a simple functionality to hide the checkbox by setting its opacity : 0 based on certain conditions within the containing component (MyCheckbox) MyCheckBox.js import React fr ...

After deploying to Vercel, the Next.js URL is updated but the page remains blank

When I deploy my app to Vercel, it seems to break as the pages become blank white after clicking on any link. However, everything works fine when tested locally. This issue arises only on Vercel, while the app functions smoothly in the local environment. ...

The three.js V71 file that I exported from Blender 2.75 does not have any animations included

Working with the latest three.js exporter for three.js v71 integrated into Blender 2.75, I encountered an issue. My Blender file consists of a cube, armature, and a single bone, but upon exporting to three.js, the bone and animation data are not included. ...

The Facebook Canvas feature is currently experiencing difficulties with logging in through mobile devices

I am encountering an issue with my canvas Facebook application that has both a web page and a designated mobile page. The web page functions properly, and when I simulate the browser to mobile using the console, everything works fine. However, when I atte ...

Guide to rotating a cube by using one of its edges as the axis

Just dipping my toes into React Three Fiber and Three.js, I have a question about rotating a cube using an edge as the axis. Specifically, I'd like to rotate it around the bottom-front edge. Any suggestions or advice would be greatly appreciated. I a ...

javascript Submit username in React Form and save it upon submission

I'm facing an issue with a React component that contains a form. My task is to capture the username and save it using sessionstorage. Although I've attempted a solution, it seems like the data isn't getting saved. Here's my current cod ...

Switching individual items created by a v-for loop in Nuxt.js

I am struggling to create a simple accordion-like structure with the ability to toggle individual elements: <div v-for="qa, j in group.questions_answers" :key="j"> <div class="question" @click="toggle()" & ...

The basic node API request is not showing any information

There is a request in my server.js file var Post = require('./../models/post'); //GET ALL POSTS app.get('/api/posts', function (req, res) { Post.getPosts(function (err, posts) { if(err) { throw err; } ...

Updating token using an Ajax request in a PHP webpage

Currently, I am encountering an issue with my token system for requesting PHP pages via Ajax. The problem arises when attempting to make multiple Ajax requests from the same page as I am unable to refresh the token on the initial page. To elaborate furthe ...

Ways to monitor the status of a server request using jQuery (ajax)?

I am currently working on a PHP application that involves users submitting forms to the server via ajax (jQuery). The server needs to insert a large number of records into a MySQL database, which may take some time due to various calculations. My question ...

Obtain date and currency formatting preferences

How can I retrieve the user's preferences for date and currency formats using JavaScript? ...

Update the current value in array.prototype

Recently, I've noticed that the built-in JavaScript sort function can be unreliable at times. To address this issue, I decided to create my own sorting function. Consider the following scenario: Array.prototype.customSort = function(sortFunction, upd ...

Solving an issue with conflicting Javascript code

I'm experiencing an issue with JavaScript. I have implemented two scripts for a select element on my website. One script handles submitting it without a submit button, and the other script is responsible for custom styling the select. Here are the two ...

Differences between POST and GET in relation to submitting a form to an action page and retrieving the results

I am currently exploring a new website and came across a form with an action that redirects to a different page upon submission. Upon submitting the form using the post method on the website itself, it successfully sends the data and loads information fro ...

Rotating Images from an Amazon S3 Bucket within a React Application

My app allows users to take photos and store them in an AWS S3 bucket. The URL for each image is saved so that it can be viewed later. Oddly, when viewing the image directly in the S3 bucket, it appears correctly oriented. However, when accessed via the ap ...

Tips for combining multiple textures in a single mesh using react-three-fiber

Currently, with React-three-fiber, I am in the process of constructing a carousel using plane geometries that I plan to animate. My main challenge right now is determining how to input multiple textures into my basic mesh material so that each of the three ...

Implementing additional states in an AngularJS app configuration with Ui-Router

Currently tackling a major application with numerous routes for its different components, my team and I have decided to break down the routes into separate files instead of cramming everything into one large file. In attempting to create a variable and im ...

Adjust the code to enhance the functionality of web components in Sharepoint

I recently came across some code online that I'm trying to modify in order to add an expanding button next to a web part on my Sharepoint site. However, the problem is that by default, all web parts are already expanded and require a click to collapse ...