THREE.JS Anti-Alias not working in multi-scene set-up - three.js

What's the trick for getting anti-aliasing to work properly on smaller scenes - which are overlaid on top of big scenes?
Check out this fiddle here:
https://jsfiddle.net/gilomer88/j974zmq0/6/
When you tap on any of the cubes you see there a new smaller "detailsScene" opens up on top of the main scene - and the cube in that "detailsScene" is not looking good. (It may not look all that bad here, but trust me, in my real project I'm loading a ".glb" model and it looks really terrible there. And it's not the model that's off. I know that because when I load it into my main scene it looks 100% perfect. Unless I have to re-load it for some reason into this smaller scene...?)
Otherwise I'm pretty sure I set the renderer for this smaller scene the right way, using:
detailsRenderer.setPixelRatio( window.devicePixelRatio );
(You'll find that bit on line 192 in the JS of the fiddle code.)
Any thoughts?

Anti-aliasing is working fine. The scene is just a bit blurred, because the canvas is scaled up while the renderer renders on a smaller size. You should always set the size of the renderer, such that it matches the canvas size. Just passing the canvas element to the renderer is obviously not enough in order to let the renderer know on which size it should render the scene.
detailsRenderer.setSize(detailsCanvas.offsetWidth, detailsCanvas.offsetHeight);
https://jsfiddle.net/sg3fn0tk/

Related

What is responsible for refraction flickering and how can it be improved?

My refracted objects flicker as the object rotates. When zoomed in, the effect is rarer, but still present.
My refraction is achieved with a simple transmission:1, thickness:0.2.
Is there some sort of a setting/map I can increase that would help it?
Edit: Here's a live example & full screen (please close the error pop-up, it's from loading GLTF) I forked a tutorial so there are other glass primitives and a control panel. If we reduce the roughness close to 0, the flickering becomes visible in the sphere primitive as well.
Indeed there is a setting. Do you have antialias set on your renderer?
let renderer = new THREE.WebGLRenderer({antialias: true});
A solution that worked for me was setting .setPixelRatio(2) to 2 or higher on my renderer. Flickering stopped and refracted objects look really good.

Three.js: Trouble combining stencil clipping with EffectComposer

NOTE: It appears I oversimplified my initial question. See below for the edit.
I'm trying to combine the technique shown in the clipping/stencil example of Three.js, which uses the stencil buffer to render 'caps' when clipping geometry, with an EffectComposer-based rendering pipeline, but I am running into some difficulties. A fiddle demonstrating the problem can be found at https://jsfiddle.net/2vc76ajd/1/.
The EffectComposer has two passes: a RenderPass and a ShaderPass using CopyShader (see code below).
composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
var shaderPass = new ShaderPass(CopyShader);
shaderPass.enabled = false;
composer.addPass(shaderPass);
The first renders the scene as usual, the latter merely copies the rendertarget onto a fullscreen quad. If I disable the ShaderPass everything works as intended: the geometry is clipped, and cutting planes are drawn in a different color:
When the ShaderPass is enabled by clicking the 'copy pass' checkbox in the upper right, however, the entire cutting plane gets rendered, rather than just the 'caps':
Presumably there is some interaction here between offscreen render targets and stencil buffers. However, I have so far been unable to find a way to have subsequent render passes look the same as the initial render. Can anyone tell me what I am missing?
EDIT: While WestLangley's answer solved my initial problem, it unfortunately doesn't work when you're using an SSAOPass, which is what I was doing before trying to simplify the problem for the question. I have posted an updated fiddle at https://jsfiddle.net/bavL98hf/1/, which includes the proposed fix and now toggles between a RenderPass or an SSAOPass. With SSAO turned on, the result is this:
I have tried setting stencilBuffer to true on all the render targets used in SSAOPass in addition to the ones in EffectComposer, but sadly that doesn't work this time. Can anyone tell me what else I am overlooking?

Paper.JS raster artefacts

there is a task to spread some raster cubes (PNG, with transparent background) along
the canvas based on Paper.JS platform.
I did it, however, there is a bug – canvas is bigger than browser window and when you are scrolling it to the right, animated cubes go glitchy, see attached screenshot. It seems that
the renderer doesn't clear previous frames. The same bug occurs in all browsers.
Is anyone knows how to overcome it? When I am trying to resize window and call onResize, everything becomes good unless I am not trying to scroll it again.
artefact image
Try using symbols instead of recreating the same rasters over and over:
In you 'building cubes' setup:
sprites[s] = new Symbol(new Raster(urls[s]));
and in hive():
var tmpRaster = sprites[selector].place();
Also, I believe paper.js tries to not animate off-screen elements to save on processing time. Instead of having the canvas be larger than the viewport, you may be better off using view.scrollBy(point)

Reset depth buffers destroyed by EffectComposer

I'm trying to render two different scenes and cameras on top of each other, like a HUD. Both render correctly when alone. Also this works as intended, so you can see mainscene under the helpscene:
renderer.render(mainscene, maincamera);
renderer.render(helpscene, helpcamera);
When I'm using EffectComposer to render the main scene, I can not see helpscene at all, I only see the results of composer rendering:
renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat, stencilBuffer: false };
renderTarget = new THREE.WebGLRenderTarget( width, height, renderTargetParameters );
composer = new THREE.EffectComposer(renderer, renderTarget);
---- cut out for brevity ---
composer.render(delta);
renderer.render(helpscene, helpcamera); // has no effect whatsoever on the screen, why?
What is happening here? Again if I comment either render call out, they work correctly. But both enabled, I only see the composer scene/rendering. I would expect the helpscene to overlay (or at least overwrite) whatever is rendered before that.
I have quite complex code before renderer.render(helpscene, helpcamera);, it might take various different render paths and use effectcomposer or not based on different settings. But I want the helpscene to always take the simple route with no effects or anything, that's why I'm using a separate render call and not incorporating it as an effectcomposer pass.
EDIT: Turns out it is because some funny business with depth buffers (?). If I set material.depthTest = false to everything in the helper scene, it will show kind of correctly. It looks like the depth is set to zero or very low by some composer pass or by the composer itself, and rather unexpectedly, it will have the effect of hiding anything rendered with subsequent render calls.
Because I'm only using LineMaterial in the helper scene it will do for now, but I expect some problems further down the road with the depthTest = false workaround (might have some real shaded objects there later, which would need depth test against other objects inside the same helper scene).
So I guess the REAL QUESTION IS: how do I reset the depth buffers (or something) after EffectComposer, so that further render calls are not affected by it? I can also do the helper scene rendering as the last composer pass, does not make much difference.
I should maybe mention that one of my composer setups main RenderPass renders as a texture to a distorted plane geometry near a perspective camera created for that purpose (like the ortographic camera & quad setup found in many postprocessing examples, but with distortion). Other setup has a "normal" RenderPass with the actual scene camera, where I would expect the depth information to be such that I should see the helper scene anyway (that's probably some seriously f****ed up english, sorry, non-native speaker here and I could not come up with better words). I am having the same problem with both alternatives.
...and answering my self. After finding the real cause, it's quite simple.
renderer.clear(false, true, false); will clear the depth buffers so the overlay render works as expected :)

QGraphicsView / QGraphicsScene image size

I want to display an image in a QGraphicsView with a QGraphicsScene. My code is very basic :
QGraphicsScene* scene = new QGraphicsScene(this);
scene->addPixmap(QPixmap(qApp->applicationDirPath() +"/france.gif"));
ui->myGraphicsView->setScene(scene);
ui->myGraphicsView->fitInView(scene->sceneRect());
My problem is that my picture has a wrong size. It is very small, with wrong proportions and on the center of my GraphicsView. With qDebug i kwow that my picture is load successfully and it has a size of about 100x800px. My graphicsView is smaller so i want to resize my picture to adjust it with my GraphicsView size.
The graphicsView is set in the mainwindow Form and the scene is declared in the header : "QGraphicsScene scene;"
I try everything is possible in the world (i think) but the graphicsView is alaways blank or contains the small version of the picture. When I copy/paste some codes of internet i always get this problem. I also try with this example : Qt GUI Development - Displaying a 2D grid using QGraphicsView , same problem...
Maybe i'm very very very tired but i really don't understand what is wrong. Help me please :)
sceneRect() may not be what you think it is unless you specifically set it. Also you are missing aspectRatioMode in fitInview call which can distort it image, sometimes resulting in "small" appearance.
QGraphicsScene* scene = new QGraphicsScene(this);
QGraphicsPixmapItem p = scene->addPixmap(QPixmap(qApp->applicationDirPath() +"/france.gif"));
ui->myGraphicsView->setScene(scene);
ui->myGraphicsView->fitInView(p, Qt::KeepAspectRatio);
From my experience, a shown image is very small if we try to fitInView before the scene window is displayed. Technically, the sceneRect size is not set in the way we want until it is actually shown. Therefore, we need to let the scene window shows up before we can properly use fitInView.
Well, I think the solution is available here
Qt5 C++ QGraphicsView: Images don't fit view frame

Resources