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

[3.x] Added material blit #65103

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Draft

Conversation

ghsoares
Copy link

@ghsoares ghsoares commented Aug 30, 2022

This is a WIP pull request, the goal of this feature is to make it easier to use shaders to perform instant compute operations in the GPU, without the need to support compute shaders, that can be used on lower-end devices ("instant" means that the shader runs in sync with the caller thread, so it can freeze the thread for some time if the shader performs expensive calculations). The idea is to blit a source texture into a output texture, using any user-defined shader, being Spatial or Canvas Item shader.

The feature is available as a single VisualServer method call:
VisualServer.material_blit(RID material, RID source_texture, RID output_texture)
The source_texture can be read in a CanvasItem shader as TEXTURE input.

I had some issues to write the code, as I don't understand much of rendering back-end, so the code is a bit messy and I may need some help to complete this feature if relevant. I'm targetting 3.x as it is OpenGL only for now, and I don't have Vulkan support in my machine to write a 4.x version.

Here is a demo run of a simple paint program using this feature:

Demo.mp4

Don't mind my drawing skills 😅

Here is the paint demo project:
Paint.zip

Bugsquad edit: This partially addresses godotengine/godot-proposals#1010.

@ghsoares
Copy link
Author

Some other use cases could be procedural texture generation, visual simulations (in my case, a fluid flow simulation) and custom post processing based on previous frames (old-school frame-stacking motion blur, for example).

@Calinou Calinou added this to the 3.x milestone Aug 30, 2022
@ghsoares ghsoares force-pushed the material_blit branch 2 times, most recently from d6135d7 to 19c3a93 Compare August 31, 2022 14:37
@ghsoares
Copy link
Author

ghsoares commented Aug 31, 2022

I added the ability to provide a source and output rectangle, the source rectangle is used to create a custom projection matrix to read from a specific area of the source texture, and the output rectangle is used in glViewport and glScissor to write to a specific area of the output texture.

There is a demo of it in action:

Demo2.mp4

There is the updated demo project:
Paint.zip

@ghsoares ghsoares force-pushed the material_blit branch 2 times, most recently from 6ccb59d to 8432fc5 Compare August 31, 2022 23:14
@akien-mga akien-mga changed the title Added material blit [3.x] Added material blit Apr 25, 2024
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.

2 participants