Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The reflection of Reflector is stretched when the camera has view offset #30587

Open
ProgramEverything opened this issue Feb 22, 2025 · 4 comments
Labels

Comments

@ProgramEverything
Copy link

ProgramEverything commented Feb 22, 2025

Description

I am using the Reflector to render the reflection on a mesh. When the camera isn't set with the view offset, everything's ok. But when the camera is set with a quite large view offset, as the object being reflected is on the edge of the view, the reflection is stretched.

Reproduction steps

  1. setup a scene with a perspective camera
  2. set the view offset of the perspective camera with
camera.setViewOffset(
    window.innerWidth,
    window.innerHeight,
    offset.x,
    offset.y,
    window.innerWidth,
    window.innerHeight
  );
  1. when the offset.x is quite large, the object being reflected is on the edge of the view, the reflection is stretched

Code

please see the codes in the live example

Live example

the following example uses the original reflector, you can see the strech when the offset x is set around 500


I think the problem is related to the view offset of the reflector camera. I comment the

virtualCamera.projectionMatrix.copy( camera.projectionMatrix );

in the source code of Reflector.js. Then the stretch is disappeared in some cases. When the camera is dollyed in , it appeared again. I don't know if this is helpful.

Screenshots

the original reflector
Image

my reflector, solves the stretch only in some certain cases, as below
Image
when the camera is dollyed in , it appeared again, even without the view offset.
Image

Version

r172

Device

No response

Browser

No response

OS

No response

another guy also notices the same problem, link is here: Using Camera.setViewOffset with Reflector stretches the reflected texture in three.js

@Mugen87 Mugen87 added the Addons label Feb 22, 2025
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 24, 2025

The reflector uses a technique called "projective texture mapping" and not every camera modification is compatible to that. We have a similar issue in #28954 (comment). This is a more fundamental limitation and only fixable with a partial rewrite.

Unfortunately, you can't use the same workaround like #28954 since the node version of Reflector does not handle this use case correctly, too. The view offset seems to be inverted: https://jsfiddle.net/ajsdx5yt/

@ProgramEverything
Copy link
Author

ProgramEverything commented Feb 25, 2025

The reflector uses a technique called "projective texture mapping" and not every camera modification is compatible to that. We have a similar issue in #28954 (comment). This is a more fundamental limitation and only fixable with a partial rewrite.

Unfortunately, you can't use the same workaround like #28954 since the node version of Reflector does not handle this use case correctly, too. The view offset seems to be inverted: https://jsfiddle.net/ajsdx5yt/

So if I use the WebGLRenderer, there will be the problem that the reflection is stretched, if I use the WebGPURenderer, there will be the problem that the reflection is offset to the opposite direction. Are these two problems both caused by the texture2DProj? If so, it's quite tricky.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 25, 2025

Are these two problems both caused by the texture2DProj?

WebGPURenderer does not use texture2DProj(). It seems to be a different problem.

@ProgramEverything
Copy link
Author

I see, let me have a look if I can solve the opposite offset problem in WebGPURenderer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants