Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

362
Views
How to project only part of a texture to a face threejs?

I want to make portals with threejs by drawing an ellipse and then texture mapping a WebGlRenderTarget to its face. I have that function sort of working, but it tries to stretch the large rectangular buffer from the render target to the ellipse. What I want is to project the texture in its original dimensions onto the ellipse and just cut out anything that doesn't hit the ellipse like so:

Before Projection:

After projection:

enter image description here

How can this be done with threejs? I've looked into texture coordinates, but don't understand how to use them, and even saw a projection light PR in threejs that might work?

Edit: I also watched a Sebastian Lague video on portals and saw he does this with “screen space coordinates”. Any advice on using those?

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Made a codepen available here:
https://codepen.io/cdeep/pen/JjyjOqY

UV mapping lets us specify which parts of the texture correspond to which vertices of the geometry. More details here: https://www.spiria.com/en/blog/desktop-software/understanding-uv-mapping-and-textures/

You could loop through the vertices and set the corresponding UV value.

const vertices = ellipseGeometry.attributes.position.array;
for(let i = 0; i < numPoints; i++) {
  const [x, y] = [vertices[3*i], vertices[3*i + 1]];
  uvPositions.push(0.5 + x * imageHeight / ((2 * yRadius) * imageWidth));
  uvPositions.push(0.5 + y / (2 * yRadius));
}
ellipseGeometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvPositions, 2 ));

UV coordinates increase from (0, 0) to (1, 1) from bottom left to top right. The above code works because the ellipse is on the x-y plane. Or else, you'll need to get the x,y values in the plane of the ellipse.

More info on texture mapping in three.js here:
https://discoverthreejs.com/book/first-steps/textures-intro/

Edit: Do note that the demo doesn't really look like a portal. For that, you'll need to move the texture based on the camera view which isn't that simple

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!