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

Shader Animations w/ Dynamic Types for Shaders and Effects #314

Merged
merged 16 commits into from
Jul 5, 2024

Conversation

jfboeve
Copy link
Collaborator

@jfboeve jfboeve commented Jun 27, 2024

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.

@jfboeve jfboeve changed the title Feat/shader controller dyn ShaderController functionalities Jun 27, 2024

await snapshot({ name: 'animation2 finished' });
Copy link
Collaborator

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

@frank-weindel frank-weindel changed the base branch from feat/shader-anim-dev to dev July 5, 2024 17:20
@frank-weindel frank-weindel changed the title ShaderController functionalities Shader Animations w/ Dynamic Types for Shaders and Effects Jul 5, 2024
@frank-weindel frank-weindel merged commit 09f8d0f into dev Jul 5, 2024
1 check passed
@frank-weindel frank-weindel linked an issue Jul 6, 2024 that may be closed by this pull request
@@ -1079,7 +1062,7 @@ export class CoreNode extends EventEmitter {
return false;
}

if (this._shader) {
if (this.props.shader === this.stage.defShaderCtr) {
Copy link
Contributor

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand

Copy link
Collaborator

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: () => () => {
Copy link
Contributor

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,
Copy link
Contributor

@elsassph elsassph Jul 7, 2024

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 for shader, parent, texture, etc. (though it has src: null),
  • this.props has a spread of props but overrides shader with stage.defShaderCtr,
  • a few lines below this.shader = props.shader, which sets this.props.shader using the setter.

Copy link
Collaborator

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) {
Copy link
Contributor

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?

Copy link
Collaborator

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++) {
Copy link
Contributor

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);
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

Issue with handling floating-point precision in node property animation Animating Shader properties
3 participants