Skip to content

WIP: transparent rendering - #268

Closed
forresto wants to merge 6 commits into
google:masterfrom
forresto:transparent-attribute
Closed

forresto wants to merge 6 commits into
google:masterfrom
forresto:transparent-attribute

Conversation

@forresto

@forresto forresto commented Dec 7, 2018 •

Copy link
Copy Markdown

Reference Issue

Conversation in #182

TODO:

  • Fix trails
  • Wire up background-color="transparent"
  • Decide if/how to get transparent attribute into shared renderer
  • Add docs

@forresto

forresto commented Dec 7, 2018 •

Copy link
Copy Markdown
Author

With this.renderer.autoClear = false; other models on the page jump in, and trails:

image

With this.renderer.autoClear = true; gets rid of the other models, but still leaves these trails... any hints?

image

Comment thread src/three-components/ModelScene.js Outdated
this.skysphere.renderOrder = 1;

// TODO: hook to transparent attribute
this.skysphere.visible = false;

@forresto forresto Dec 7, 2018 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... would there need to be more logic around that? There are a few places that expect the skysphere to exist.

@cdata

cdata commented Dec 7, 2018

Copy link
Copy Markdown
Contributor

Thanks for the PR! We will take a look.

I wonder if there is a connection to #239

@cdata

cdata commented Dec 7, 2018

Copy link
Copy Markdown
Contributor

@forresto can you confirm which browsers/platforms you are experiencing this in as we go to test for ourselves?

Comment thread src/three-components/Renderer.js Resolved
@jsantell

jsantell commented Dec 7, 2018

Copy link
Copy Markdown
Contributor

Quick comments:

  • the folding you're seeing is from changing when the canvas is cleared due to using one WebGLRenderingContext for all elements on the page -- the skysphere does not render to the depth buffer -- this is different than Banding artifacts #239
  • three r99 added the ability for scene.background to accept cube maps, which will make a lot of the skysphere logic throughout the codebase much nicer. (WIP) PMREM+HDR+r99 #237 has some of that implemented that still needs a few other things to shake out.
  • This will of course add overhead for all elements and possibly require recreating the WebGLRenderingContext
  • What would happen if both background-color and transparent are defined? Should transparent be an option of background-color?
  • What's the expected way to style this background with CSS? Something like model-viewer { background-color: var(--some-gradient); }?

@forresto

forresto commented Dec 7, 2018

Copy link
Copy Markdown
Author

Safari, Chrome, and Firefox on Mac.

Should transparent be an option of background-color?

I think that would make sense. I wasn't sure if there might be a rendering feature that could use both background-color and transparent.

What's the expected way to style this background with CSS?

style on the model-viewer element seems to work. Also, the general case of a parent background showing through.

@forresto

forresto commented Dec 7, 2018

Copy link
Copy Markdown
Author

using one WebGLRenderingContext for all elements on the page

Would that prevent having transparent and non-transparent elements on the same page?

@jsantell

jsantell commented Dec 7, 2018 •

Copy link
Copy Markdown
Contributor

Would that prevent having transparent and non-transparent elements on the same page?

If using alpha is optional and only applied if necessary, and then an element adds a transparent background, then we'd have to recreate the context since we can't change attributes used outside of creation.

That being said, I don't have any actual numbers of using alpha vs not in terms of performance. There are plans (#216) of using different strategies of rendering based off of usage (one element on desktop? it gets their own webgl context. multiple elements on mobile? they reuse the same webgl context) which can investigate this a bit more.

I'll look today in breaking out the scene.background changes in #237 which would make this a bit easier as well. Previously that change couldn't stand alone, but I think that's no longer the case (or my original assumptions were wrong!)

@forresto

forresto commented Dec 7, 2018 •

Copy link
Copy Markdown
Author

Now I see how clearing works :) Demo: https://3d-model-viewer-component.webflow.io/transparent-hack

image

const webGlOptions = {antialias: true};

// TODO: hook to transparent attribute
const isTransparent = true;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Renderer is a singleton we don't have a way to get an attribute in here. TBD how that should work. Ideas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renderer is responsible for all elements/scenes, currently, so a renderer can be responsible for both a transparent and non-transparent scene -- ModelScene is unique per element, however

});
this.renderer.autoClear = false;
// TODO: hook to transparent attribute
this.renderer.autoClear = isTransparent;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A handful of components use the renderer outside of elements -- composing environment maps or shadows, or any WebGLRenderTargets -- autoClear should not change as they affect all of those framebuffers

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I keep it false and avoid other scenes bleeding in?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@forresto we do per-scene (in other words, per-element) renderer configuration in the render loop itself. See https://github.com/GoogleWebComponents/model-viewer/blob/master/src/three-components/Renderer.js#L135-L171.

However, this may not be suitable for all kinds of renderer configuration, and autoClear is probably not going to be suitable as it clears the whole context.

In the future, we intend to support additional rendering modes (Jordan already referenced this, but I'll ping it again as an example: #216). As we start to get into that, we should be able to layer on configurations like this.

@forresto forresto Dec 17, 2018 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you recommending that I hold more work on this PR for #216? I can use my branch for now, since it seems to work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks @forresto yeah I think it would be best to pin this PR for now and come back to it soon as we start to upgrade our approaches to rendering.

@pushmatrix

Copy link
Copy Markdown
Contributor

Adding a big 👍 to this feature. Super looking forward to it being possible.

@mrdoob

mrdoob commented Mar 13, 2019

Copy link
Copy Markdown
Collaborator

@pushmatrix we were considering creating 2 internal webgl contexts (when needed) one for alpha: false, and another one for alpha: true.

@tijmenvangurp

Copy link
Copy Markdown

Hey, I am really looking forward to use background-color="transparent"are there any workarounds in the meantime? Basically, I want my full page to have a certain background with gradient where my object is just floating on, which is not possible with the current implementation.

@forresto

forresto commented Jul 4, 2019

Copy link
Copy Markdown
Author

Here's a build of my branch: https://uploads-ssl.webflow.com/5c013e2442f37ff004567ee6/5c17c0247910f0e6fe21dde9_model-viewer.min.js.txt (you can rename to .js)

Demo: https://3d-model-viewer-component.webflow.io/transparent-hack

Note that the build is a few months behind the official version.

@tijmenvangurp

Copy link
Copy Markdown

@forresto Thanks for your reply :) will try to incorporate your build, hope that background transparent can be incorporated in the official build soon.

@cdata

cdata commented Jul 10, 2019

Copy link
Copy Markdown
Contributor

I spent a little bit of time poking at this problem. The main roadblock that I ran into is that we need to set alpha: true when creating the GL context in order to support transparency, but this causes incorrect rendering in some alpha blending scenarios (see #381).

So, we should not force alpha: true on the context. Perhaps we can add an attribute to let folks opt-in or out to background transparency? What would be the right default?

Relatedly, it seems desirable for us to generally move away from background-color and background-image as attributes, because they conflate <model-viewer>'s responsibilities with those of CSS (see #661 ).

@elalish

elalish commented Feb 3, 2020

Copy link
Copy Markdown
Contributor

Closing in favor of #975. @forresto Thanks for working on this and sorry it took us so long to come to a solution. Hope the current state solves your needs!

@elalish elalish closed this Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants