Creating a mesmerizing glass effect in Three.js using a PNG image mask on a video texture

The other day, I revisited activetheory.net and was captivated by the beautiful glass effect on the Homescreen logo border. I tried to replicate it by examining the minified code and discovered they were using a PNG as a mask.

I successfully loaded a PNG inside the shader and displayed it, as well as managed to get a mesh with video texture to work. However, I'm now facing difficulties in combining the PNG with the video inside the shaders.

If anyone has experience with this and can offer some help, I would greatly appreciate it!

Thank you and have a wonderful day!

Here is the shader-material segment:

var g = new THREE.PlaneGeometry(128.0, 72.0);
var outline = THREE.ImageUtils
    .loadTexture('outline.png');
outline.magFilter = THREE.NearestFilter;
var mat = new THREE.ShaderMaterial({
    uniforms: {
            map: {type: "t", value: movieScreen.texture},
            outline: {type: "t", outline},
            aspect: {type: "fv1", value: []},
            res: {type: "v2", value: new THREE.Vector2(window.innerWidth, window.innerHeight)}
        },
    vertexShader: document.
    getElementById('vertShader').text,
    fragmentShader: document.
    getElementById('fragShader').text,
    transparent: true,
});

And here are the shaders:

<script id="vertShader" type="shader">
    varying vec2 vUv;
    varying vec2 nUv;

    void main() {
        vUv = uv;
        nUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
    }
</script>
<script id="fragShader" type="shader">

    varying vec2 vUv;
    varying vec2 nUv;

    uniform float color;
    uniform sampler2D outline;
    uniform sampler2D map;


    void main(void) {

        float alpha = step(0.9, texture2D(outline, vUv).a);

        gl_FragColor = texture2D(outline, nUv);
        gl_FragColor *= alpha;
    }
</script>

Answer №1

At last, I managed to get a shader that functions in a similar way. For those who are curious.

Here are the shader details:

<script id="vertShader" type="shader">
    varying vec2 vUv;
    varying vec2 nUv;

    void main() {
        vUv = uv;
        nUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.05);
    }
</script>
<script id="fragShader" type="shader">

    varying vec2 vUv;
    varying vec2 nUv;

    uniform float color;
    uniform sampler2D outline;
    uniform sampler2D map;


    void main(void) {

        float alpha = step(0.9, texture2D(outline, vUv).a);

        gl_FragColor = texture2D(map, nUv);
        gl_FragColor *= alpha;
        gl_FragColor += 0.08 * alpha;
    }
</script>

Enjoy experimenting with it!

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

Tips on displaying a confirmation message upon a user clicking a checkbox

I am encountering an issue with displaying a confirmation message when a checkbox is clicked. The confirmation box pops up but does not carry out any action, like showing the text within the textbox after the user clicks OK. Any guidance on this matter wou ...

Having trouble importing my function component into a router in reactjs. Need some guidance on how to properly set it up

I am working on a Slider component function called export default Slider. In my App.js file, I have the following code: function App() { return ( <Router> <Routes> <Route exact path='/' element={<Home />} /> ...

What is preventing the input box from shrinking further?

I created a search box using CSS grid that is supposed to shrink when the page is resized. However, it doesn't seem to shrink as much as I expected it to. Here is how it appears when fully extended: https://i.stack.imgur.com/tPuCg.png And here is how ...

Using ESLint to enforce snake_case naming conventions within TypeScript Type properties

When working with TypeScript, I prefer to use snake_case for properties within my Interfaces or Types. To enforce this rule, I have configured the ESLint rule camelcase as follows: 'camelcase': ["error", {properties: "never"}], Even though the E ...

Trouble with image click event in jQuery/JavaScript

I am having trouble with my HTML and JS code. I have added images to my HTML page and want to make it so that when the image is clicked, an alert box pops up. However, for some reason, my JavaScript isn't working as expected. Here is a snippet of my ...

PowerShell is having trouble detecting the Application during the packaging process

After completing the coding for a beginner Desktop Application in electron, I encountered an issue when trying to package it into an executable .exe file. The error message displayed was: Command failed: powershell.exe -nologo -noprofile -command "& { ...

Issues with displaying or hiding a DIV using javascript - popup box unresponsive

I am working with this ASPX code: <div id="IsAccountingOk" class="modalDialog"> <div> <a href="#close" title="Close" class="close">X</a><br /> <asp:Label ID="lblIsAccountingOkHeader" runat="server" Text ...

The Battle: AJAX FormData vs encodeURI

When utilizing jQuery's encodeURI(), the data transmitted through AJAX appears in this format: key1=true & key2=34 & ... In order to send an image via AJAX, I employ the FormData() method, resulting in the AJAX data without an image looking ...

Strange Node.js Issue

I don't have much experience with node.js, but I had to use it for launching on Heroku. Everything was going smoothly until a few days ago when suddenly these errors started appearing. Error: /app/index.jade:9 7| meta(name='viewport', co ...

What methods can be used to continuously send data to another web page within my website using XMLHttpRequest()?

As I delve into working with node.js and express.js, my primary goal is to efficiently tackle a specific issue. One of the pages on my website is tasked with receiving location data in latitude var lat and longitude var long. The challenge at hand is to c ...

Issue encountered while constructing my application (utilizing the "yarn run build" command and in Vercel)

Encountered an error during the build process, whether on the server or locally. This issue arises when using package managers like yarn, npm, and others. The error specifically points to a problem in the CSS file, but it only occurs in the production bu ...

`Adding data to Rails database and displaying without the need for reloading using AngularJS`

When working on my Rails project, I encountered an issue with adding data to the database using `http.post` from an AngularJS controller. Below is the code snippet demonstrating this: RestaurantIndexCtrl.js.coffee: restauranteur.controller 'Restaura ...

How to Implement Drupal.behaviors for Specific Pages?

Currently, I have a module that showcases an alert to users within a block. For those interested, you can find my code on GitHub here: https://github.com/kevinquillen/User-Alerts If you would like more information about the module and its functionality, ...

Javascript code fails to execute properly on IE8

I have a scenario where I am working with two drop-down menus. When the user selects an option from one menu, it should dynamically change the options in the other menu. However, I'm facing an issue with Internet Explorer where the second drop-down me ...

When it comes to using the text() function, the statement encounters difficulty

let person = $(".tekst").text(); if (person=="XxX") { $("#discu").css("display", "none"); } alert(person); When I access my element with class .tekst and get its text using the text() function, it correctly displays as XxX, which is what I expected. ...

Style the div element with CSS

Is there a way to style a div element within an HTML document using Sencha framework? I have specific CSS properties that I would like to apply to my div. #logo{ position:absolute; top:20%; left:0%; } Below is a snippet of my Sencha code: Ex ...

Why is my npm installation generating an ERESOLVE error specifically linked to karma-jasmine-html-reporter?

Could someone help me understand this dependency error I encountered while running npm install and provide guidance on how to resolve such errors? View Error Screenshot I am currently using Angular 16, the latest stable version. npm ERR! code ERESOLVE ...

AngularJS encountered an error: [$injector:modulerr] problem occurred during code execution

Hey there! I've been trying to set up a pop-up feature in Angular, but unfortunately, I keep encountering an error: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/$injector/modulerr?p0=PopupDemo&p1=Error%…ogleapis.com%2Fa ...

Retrieve data from a list using an API

I am currently working on creating a dynamic list by fetching data from an API. The goal is to display detailed information in a modal when a user clicks on a specific item in the list. While the list itself is functioning properly, I am encountering an i ...

Exploring a collection of objects housed in a json document

Currently, I'm looking to retrieve a collection of objects using JavaScript from a JSON file that resides on my website. While I could easily embed the array of objects directly into my JavaScript code, I am interested in understanding how to work wit ...