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-based gradients #677

Merged
merged 25 commits into from
May 2, 2022
Merged

Shader-based gradients #677

merged 25 commits into from
May 2, 2022

Conversation

OverloadedOrama
Copy link
Member

@OverloadedOrama OverloadedOrama commented Apr 24, 2022

Gradient generation is now shader based. This results in much faster speeds compared to the previous GDScript generation algorithm.

Apart from the significant performance increase, the new gradient generation system offers 6 types of gradients. Linear, Radial, Step, Radial Step, Dithering & Radial Dithering. The previous gradient system only generated Step gradients. A lot more freedom is given to the users as well. Now, they can tweak the angle of the gradient, the size, position, radius and center for the radial gradients, and the dithering matrix for the dithering gradients.

Textures of the bayer matrices taken from https://github.com/tromero/BayerMatrix

2022-04-24.21-14-18.mp4

Fixes #645, implements the first part of #628.

@OverloadedOrama
Copy link
Member Author

I managed to rewrite the Step & Dithering shaders (with their radial versions as well) without a for loop. This makes them work in the Web version with GLES2 and they should be a little more optimized now. I also rewrote the dithering textures loading logic, so that in the future we could allow the users to load their own dithering patterns, but that feature is outside the scope of this PR. I suppose some more UI/UX improvements are needed before merging.

Having a selection, applying a dithering gradient, removing the selection and then going to the gradient dialog again causes the dithering shaders to "remember" the previous selection, even if there is no selection currently. This only happens with the two dithering shaders and only with the GLES2 renderer. Removing `uniform sampler2D dither_texture;` from the shader code seems to fix the issue, but that's obviously isn't what we want so a "proper" fix is included in this commit.
More optimized and works on the Web version with GLES2
Now all shaders work on the Web version and have been optimized.
@AlphinAlbukhari
Copy link
Contributor

AlphinAlbukhari commented Apr 28, 2022

I think the UV should be pixelated first because the preview is too perfect and it will look different with the output
Preview:
Screenshot (295)
Almost not pixelated

Output:
Screenshot (296)
Output is pixelated, looks different with the preview

By adding

vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE;

vec2 uv = floor(UV * tex_size) / (tex_size - 1.0);
uv = uv * 2.0 - 1.0;

we'll get this

gradient.pixel.mp4

Didn't change the dithering shaders because they seemed to give different results.
@OverloadedOrama
Copy link
Member Author

That's a good point. I changed how the preview looks in all shaders except the two dithering ones, because they seemed to give different results than they do now. Although I am a bit worried that the other gradients may give different results as well, but so far I haven't noticed anything. Ideally, making the preview look the same as the output should happen outside of shader code, but I'm not sure how that would work.

@AlphinAlbukhari
Copy link
Contributor

AlphinAlbukhari commented Apr 28, 2022

Maybe using viewport with same size as canvas size? Place the preview inside there so we can see it being naturally pixelated

@OverloadedOrama
Copy link
Member Author

Should be good to merge now, if we want we can always make improvements later.

@OverloadedOrama OverloadedOrama merged commit cf92694 into master May 2, 2022
@OverloadedOrama OverloadedOrama deleted the shader-gradients branch May 2, 2022 13:12
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.

Gradient color picker insanely slow
2 participants