Intricate form of a character's silhouette

Imagine I have a unique character that users can select, and when it's selected, I want to display an outline around it.

The character is represented as an object3D with multiple meshes. I attempted cloning the character and applying a backside material for the outline, but this approach was ineffective because each cube in the shape rendered its backside separately, resulting in an incorrect outline display.

Is it necessary to create a new mesh specifically for the outline, or is there a simpler solution available?

Answer №1

What @spassvolgel mentioned is absolutely spot on;

I believe the necessary steps involve: 1. Initially rendering the background 2. Subsequently, creating a character model with a plain color on a separate transparent layer, slightly larger than the original 3. Adding the character with its regular material or texture on another transparent layer 4. Lastly, placing the character layer over the outline layer and then combining them within the background

You can achieve this by generating multiple scenes and merging them through sequential render passes:

renderer.autoClear = false;
. . . 

renderer.render(scene, camera); // rendering the complete scene
renderer.clearDepth();
renderer.render(scene2, camera); // displaying only the selected item in a larger size and flat color
renderer.render(scene3, camera); // showing the selected item again

Version three.js.r.129

Answer №2

To address geometries of varying complexities, a versatile solution involves applying a fragment shader using the ShaderMaterial class in three.js. If you are unfamiliar with shaders, you can find an introduction here.

An illuminating example showcasing the use of shaders to accentuate geometries can be explored here. The vertex shader computes the normal for a vertex and a parameter representing the intensity of a glow effect:

uniform vec3 viewVector;
uniform float c;
uniform float p;
varying float intensity;
void main() 
{
    vec3 vNormal = normalize( normalMatrix * normal );
    vec3 vNormel = normalize( normalMatrix * viewVector );
    intensity = pow( c - dot(vNormal, vNormel), p );

    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}

These parameters are then transmitted to the fragment shader where they manipulate color values of pixels surrounding the geometry:

uniform vec3 glowColor;
varying float intensity;
void main() 
{
    vec3 glow = glowColor * intensity;
    gl_FragColor = vec4( glow, 1.0 );
}

Answer №3

While browsing through gamedev.stackexchange.com/, I stumbled upon an interesting discussion about using a stencil buffer. Implementing this in THREE.js is a bit of a mystery to me, though.

Check out the thread here for more insights.

Answer №4

For optimal results, consider rendering your outlined object(s) onto a texture that matches the size of your destination framebuffer. Subsequently, render a quad of the same size using that texture and apply effects such as blurring or image transformations in the fragment shader. An illustrative example can be found here, utilizing raw WebGL. Alternatively, you could create a custom ShaderMaterial with relative ease.

Answer №5

I'm still searching for the solution, but I wanted to showcase what happens when I generate multiple meshes and place another mesh behind each of them using

side: THREE.BackSide  

http://jsfiddle.net/GwS9c/8/

As you can see, the effect is not as intended. I am aiming for a distinct outline behind ALL three meshes without any overlap. While my knowledge in programming shaders is limited, many online sources suggest cloning the meshes as a possible solution.

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

What exactly is the function of the NextPage feature in Next.js?

Recently, I began incorporating TypeScript into my Next project. Could someone clarify the purpose of the following code snippets for me? import { NextPage } from 'next'; export const Page: NextPage = () => {} After reviewing the documentation ...

Different Ways to Retrieve JSON Data from AWS S3 Bucket Using Node.js

I am facing a challenge with downloading a .json file stored in an S3 Bucket using Node.js. Here is the code snippet I have written: const bucket = "s3bucketname"; const AWS = require('aws-sdk'); const S3= new AWS.S3(); exports.handler = async ...

What are some ways to modify attributes in a jQuery datatable?

Upon loading the page, I initially set serverside to false. However, under certain conditions, I need to change serverside to true without altering any other attributes. For example: $(tableID).DataTable({ serverSide : false; }); Changing it to: $(t ...

React frontend communicating without backend server

Is it possible to send a message between two frontend users on web applications built with React? ...

Utilizing AJAX and PHP POST to dynamically refresh innerHTML content with MySQL data updates

I've been trying to solve this problem for a long time now, and I've reached a point where I can't seem to figure it out. On a page, there are several forms where users input different information that gets submitted to a mySQL database usin ...

Utilizing JavaScript to Retrieve Selected Parameter in SSRS Report

Currently, I am incorporating an SSRS report into my website using Iframe. I aim to share a link to the specific filtered report, which is why I require knowledge of the report's parameters. My query pertains to how I can identify these parameters (e ...

What about creating desktop applications with JavaScript?

Can Windows desktop applications be developed using JavaScript? I know about HTA (HTML Application) programs, but I'm curious if there is a more recent .NET or different solution that allows for integrating the DLL libraries from Visual Studio. ...

Issue with res.redirect not functioning as expected

I am having some difficulty with the use of res.redirect() in my express application. After searching through other questions, I haven't found a solution that directly addresses my specific issue or is detailed enough to be useful. app.get(/\d& ...

Sending data from a Node.js backend to a React.js frontend using res.send

How can I pass a string from my nodejs backend using res.send? app.post("/user", (req,res) => { console.log(req.body.email); res.send('haha'); }); I need to perform certain operations on the front end based on the value of the string retriev ...

Fade In/Out Scroll Effect

As the user scrolls down the page, I have a slider that smoothly slides from right to left. What I'm trying to achieve is for the slider to fade out when the last slide is no longer in view during downward scrolling, and fade back in as the last slid ...

Calculating the Boundary Box Post Vertex Relocation Using Shader

Is it possible to update the bounding box or sphere in ThreeJS after modifying vertex positions in a shader? Update: Just to clarify, I am utilizing a particle buffer geometry and adjusting the vertex positions within the shader. I am not using geometry.a ...

Adjust columns sizes on ExtJS 6 dashboards in real-time

Is it possible to adjust the column widths within an Ext.dashboard.Dashboard once it has been displayed? The initial configuration sets the column widths as follows: columnWidths: [ 0.35, 0.40, 0.25 ] I would like to dynamically modify them ...

Creating a click-away listener feature in your Next js application

I have a reusable component called DropDown and a custom hook called useClickOutside. I am utilizing the context API to manage multiple dropdowns with unique ids. Code for useClickOutside import { useEffect, useRef } from "react"; import { toUSV ...

Step-by-step guide on running two JavaScript codes sequentially to ensure accurate results

I am currently working on an MVC project where I need to display the user's current location city in the top right corner of a webpage. The first javascript code fetches the city name, and the second one retrieves the weather conditions of that city. ...

Exploring the implementation of the meta robots tag within Joomla 2.5's global settings

Encountering a peculiar issue with Joomla 2.5 and the Meta robots tag. Joomla seems to have a flaw where regardless of the URL, as long as there is a valid article id, it will generate a page. For instance: The id '61' is valid but leads to a ...

What steps should I take to ensure my sanity studio updates are reflected in my nextjs app?

Upon configuring my sanity studio with the initial data, everything seemed to be working well. However, when I try to make changes and publish them, the next app still displays the previous data. Even after deleting some information in the studio, the upda ...

Swap two pairs of elements in an array in a random order

I have a list of team members and also 2 substitute players: team = Samson, Max, Rowan, Flynn, Jack subs = Struan, Harry I am facing a challenge in randomly swapping the 2 subs into the team. The difficulty lies in ensuring that only these 2 elements are ...

Divide a string into various text boxes

Is there a way to allow users to edit the value of a field that is Vertex 3D? The stored value is in string format, but I want to present it to the user as three separate input fields for easier editing. I am looking for a method to split the string by sp ...

From ThreeJS to Unity: Converting Matrix Transformations

Upon receiving a Json from ThreeJs, the structure appears as follows: { "scene": { "metadata": { .. }, "geometries": [ .. "materials": [ ... ...

Constructing hierarchical objects in JavaScript

I am looking to create a complex nested object in JavaScript that follows a specific structure. const data = { name: 'Context 1', children: [ { name: 'Option 1', children: [ { name: 'Context&ap ...