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

DestinationUV uniform doesn't scale with scene on render #1013

Closed
HikariIsChillin opened this issue Mar 27, 2024 · 5 comments · Fixed by #1026
Closed

DestinationUV uniform doesn't scale with scene on render #1013

HikariIsChillin opened this issue Mar 27, 2024 · 5 comments · Fixed by #1026
Assignees
Labels
b-bug Something isn't working

Comments

@HikariIsChillin
Copy link

Describe the bug
If a shader uses destinationUV and you try to render it in a scale different from 1.0x, the uniform doesn't scale with the scene

To Reproduce
Just add a shader that uses destinationUV to anything and render with a different scale, this is the simplest example:

import { makeScene2D } from '@motion-canvas/2d'

import destinationUVbug from '../shaders/destinationUVbug.glsl'

export default makeScene2D(function* (view) {
	view.shaders(destinationUVbug)
})
// destinationUVbug.glsl
#version 300 es
precision highp float;

#include "@motion-canvas/core/shaders/common.glsl"

void main() {
    outColor = vec4(floor(destinationUV * 10.) / 10., 0., 1.);
}

Expected behavior
The UV should scale with the render

Package versions:
Click on the version in the bottom right corner to copy the versions

  • core: ^3.15.1
  • ui: ^3.15.1
@HikariIsChillin HikariIsChillin added the b-bug Something isn't working label Mar 27, 2024
@HikariIsChillin
Copy link
Author

Same frame rendered in 0.25x, 0.5x, 1.0x and 2.0x scale:
004639_0 25x
004639_0 5x
004639_1 0x
004639_2 0x

aarthificial added a commit to aarthificial/motion-canvas that referenced this issue Apr 6, 2024
@aarthificial
Copy link
Contributor

Can you take a look at #1026 to see if it fixes the issue completly?

@HikariIsChillin
Copy link
Author

HikariIsChillin commented Apr 12, 2024

From my tests it fixed everything except inside of cached nodes.

If you use the same shader as before but like this it will still have the issue, the destinationUV is resized to the size of the cached node, but when you change the scale is stays at the size the node had before scaling.

import { Node, Rect, makeScene2D } from '@motion-canvas/2d'

import destinationUVbug from '../shaders/destinationUVbug.glsl'

export default makeScene2D(function* (view) {
	// view.shaders(destinationUVbug)

	view.add(
		<Node cache>
			<Rect size={view.size().sub(200)} shaders={destinationUVbug} />
		</Node>
	)
})

One funny interaction I noticed is that if you set the size of the rect with numbers or by subtracting from the view.size() like in the code above, the shader destinationUV will fit the Node properly at the normal scale, but if you do:

<Node cache>
	<Rect size={view.size().mul(0.5)} shaders={destinationUVbug} />
</Node>

Multiplying or dividing, the scale is broken just like when changing the scale of the scene. But this only happens if the scale of the scene isn't 1,0x. So my guess is both of these are the same issue.

@aarthificial
Copy link
Contributor

@HikariIsChillin Thanks for checking this out!
I added a fixup to #1026 now everything should work

@HikariIsChillin
Copy link
Author

@aarthificial Everything is working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b-bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants