Skip to content

Conversation

@donmccurdy
Copy link
Member

@donmccurdy donmccurdy commented Mar 9, 2018

Resolves #666.

<a-scene renderer="antialias: true;
                   sortObjects: true;
                   gammaOutput: true;">

* Determines state of various renderer properties.
* This could be done by a component, but it's important
* to know the values when the renderer is created, so
* that materials don't need to be recompiled.
Copy link
Member Author

Choose a reason for hiding this comment

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

Correction: we only need to know antialias up front.

@ngokevin
Copy link
Member

ngokevin commented Mar 9, 2018

I would try using renderer="foo: bar" syntax, but not thru the component flow? Perhaps just parse it with AFRAME.utils.styleParser.parse.

@donmccurdy
Copy link
Member Author

Would you want to roll antialias into that, or leave it as-is? Other than that a “real” component would be fine.

@ngokevin
Copy link
Member

Yeah, we can roll anti-alias into that, and deprecate the current antialias="true".

@donmccurdy
Copy link
Member Author

Ok, implemented renderer="antialias: true; gammaOutput: true" here. Will add docs + test if the gist looks good.

@donmccurdy donmccurdy added this to the 0.8.X milestone Mar 21, 2018
@ngokevin
Copy link
Member

Looks good. There's no problem with the component setting up too late?

Copy link
Member

@ngokevin ngokevin left a comment

Choose a reason for hiding this comment

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

noice


// Default not AA for mobile.
// NOTE: This default is also applied in a-scene.js.
var attrString = HTMLElement.prototype.getAttribute.call(el, this.name);
Copy link
Member

Choose a reason for hiding this comment

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

We've been doing vars-on-top (declarations only). Though tempted to just adopt prettier :P

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if (needsShaderUpdate) {
warn('Modifying renderer properties at runtime requires shader update and may drop frames.');
sceneEl.object3D.traverse(function (node) {
if (node.isMesh) {
Copy link
Member

Choose a reason for hiding this comment

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

can do an early return and keep an indent if (!node.isMesh) { return; }

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

renderer.physicallyCorrectLights = data.physicallyCorrectLights;
},
update: function (prevData) {
if (!Object.keys(prevData).length) { return; }
Copy link
Member

Choose a reason for hiding this comment

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

I guess this check isn't even really needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's needed, update() is called during initialization and we don't want to set .needsUpdate=true unnecessarily.

// NOTE: This default is also applied in a-scene.js.
var attrString = HTMLElement.prototype.getAttribute.call(el, this.name);
if (attrString && !attrString.match(/($|\W)antialias\W/)) {
el.setAttribute(this.name, {antialias: !el.isMobile});
Copy link
Member

Choose a reason for hiding this comment

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

Can do setAttribute('renderer', 'antialias', !el.isMobile);

Don't need this.name above either, can just be renderer

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@dmarcos
Copy link
Member

dmarcos commented Mar 24, 2018

Default components are gone on #3490. We need to adapt this PR

@donmccurdy
Copy link
Member Author

There's no problem with the component setting up too late?

Well, the renderer.antialias handling is a bit of a hack because init() runs too late. Otherwise it's fine, we can set the other properties before any shaders have compiled.

Having trouble doing a git push from the cafe, so the last commit is still missing and my "Done" comments were premature.

@dmarcos — without default components, the only issue I see is that I can't detect whether the renderer component has been added before or after scene initialization. sceneEl.hasLoaded seems to be true when init() runs either way. I don't want to set .needsUpdate on all of the materials if the renderer hasn't compiled them yet... is there another way to see if the first render has already happened?

@donmccurdy
Copy link
Member Author

Resolved the initialization issue by checking sceneEl.time > 0. Added tests and docs. I think this is ready to go except one thing — are we OK deprecating antialias="true" on an 0.8.X release? I've kept it functional here but the warning is still logged.

@dmarcos
Copy link
Member

dmarcos commented Mar 24, 2018

Besides the warning messages. Should we reflect in the docs that antialias cannot be changed after initialization?

@donmccurdy
Copy link
Member Author

Done (and rebased).

@donmccurdy donmccurdy changed the title [a-scene] Expose additional renderer properties as scene components. [renderer] Add scene component for renderer config. Mar 24, 2018
@dmarcos
Copy link
Member

dmarcos commented Mar 25, 2018

Better not to introduce API changes on a minor version. We can deprecate <a-scene antialias="true"> later

@dmarcos dmarcos merged commit bb16c01 into aframevr:master Mar 25, 2018
@dmarcos
Copy link
Member

dmarcos commented Mar 25, 2018

Thank you!

@donmccurdy
Copy link
Member Author

Better not to introduce API changes on a minor version. We can deprecate later

Ok, note this PR does log a warning about antialias (but keeps it working). We'll want to remove that before 0.8.2 then?

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.

3 participants