-
Notifications
You must be signed in to change notification settings - Fork 22
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
Shader Animations w/ Dynamic Types for Shaders and Effects #314
Conversation
- Still need to add comments and maybe refactor a bit
examples/tests/shader-animation.ts
Outdated
|
||
await snapshot({ name: 'animation2 finished' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the space? This goes into the file name
566e662
to
b2a2cf9
Compare
@@ -1079,7 +1062,7 @@ export class CoreNode extends EventEmitter { | |||
return false; | |||
} | |||
|
|||
if (this._shader) { | |||
if (this.props.shader === this.stage.defShaderCtr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be the opposite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes I see it now.
type: 'DefaultShader', | ||
props: {}, | ||
shader: new UnsupportedShader('DefaultShader'), | ||
getResolvedProps: () => () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks incorrect, and wasteful as it creates garbage on every invocation.
super(); | ||
|
||
this.props = { | ||
...props, | ||
parent: null, | ||
texture: null, | ||
shader: null, | ||
shader: stage.defShaderCtr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something odd around shaders initialisation:
props
are supposed to already have default values forshader
,parent
,texture
, etc. (though it hassrc: null
),this.props
has a spread ofprops
but overridesshader
withstage.defShaderCtr
,- a few lines below
this.shader = props.shader
, which setsthis.props.shader
using the setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props
do already have default values assigned prior to CoreNode construction. The things happening in the constructor that you are calling out are to ensure that the setters are run for those particular properties. If the props weren't overridden in the spread then the setters would not actually run because of the "change check" at the top of each one.
But there is actually no reason at this point to do this for shader
so I will remove it.
|
||
set shaderProps(value: Record<string, unknown> | null) { | ||
this.props.shaderProps = value; | ||
if (value === this.stage.defShaderCtr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting a custom shader doesn't change update type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep not sure what I was thinking there.
const shaderPropKeys = Object.keys(props.shaderProps!); | ||
const spLength = shaderPropKeys.length; | ||
let j = 0; | ||
for (; j < spLength; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not for (let j = 0;
?
this.progress, | ||
startValue, | ||
endValue, | ||
const dynEntries = Object.keys(this.dynPropValuesMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how rare the shader animations are going to be, it might have been more efficient to skip entirely this kind of code by having for instance this.dynPropValuesMap
be undefined
by default.
Added a new implementation for animating shaderProps.
Added ShaderController & DynamicShaderController functionalities. This allows us to change properties of shaders during runtime.
Optimised DynamicShader prop calculations, by having the DynamicShaderController do the calculations, which previously was done every time a node+dynamic shader where used in a renderOp.