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

Add support for custom shaders on AnimatedSprite3D #3266

Open
NitroPlum opened this issue Sep 8, 2021 · 2 comments
Open

Add support for custom shaders on AnimatedSprite3D #3266

NitroPlum opened this issue Sep 8, 2021 · 2 comments

Comments

@NitroPlum
Copy link

Describe the project you are working on

A 3D Zelda-style adventure game focused on fishing mechanics. Characters are 2D pixel art sprites on AnimatedSprite3Ds in a 3D world.

Describe the problem or limitation you are having in your project

I am unable to use Pixel Art on an AnimatedSprite3D because of the scaling of the art. A solution exists in the form of a SmoothPixel3D shader. However, I can not apply this shader to an AnimatedSprite3D without overriding the base material, therefore, undoing most of the node's functionality.
The shader in question :
https://github.com/CptPotato/GodotThings/blob/master/SmoothPixelFiltering/SmoothPixel3D.shader

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add the ability to apply custom shaders to AniamtedSprite3Ds while maintaining all features of AnimatedSprite3D. Or, simply add a toggleable Pixel Smoothing feature.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I simply want the ability to add a custom shader to an AnimatedSprite3D like other nodes.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I am currently unaware of a solution to this. I've asked as many other people as I could find and everyone was stumped.

Is there a reason why this should be core and not an add-on in the asset library?

From what I can tell, it seems like the AnimatedSprite3D literally doesn't support this in any way at the moment. I see no way to make this work without modifying AnimatedSprite3D's source code.

@clayjohn
Copy link
Member

clayjohn commented Sep 8, 2021

For interested contributors, the core of the problem here is that the AnimatedSprite3D handles its own texture logic in the _draw function. Each frame that the animation changes it requests a texture (or portion of a texture) for that frame and assigns it to the internal material. However, when a user uses a material override, the logic doesn't carry over to the material override.

In a regular Sprite3D this is not a big problem as you can assign the same texture to the "albedo_texture" parameter and it works fine. However, the AnimatedSprite3D loses the ability to nicely update frames (you would have to do it manually which defeats the purpose of having an Animated Sprite3D.

The solution will be to see if we can override the override materials texture in the _draw() function here:
https://github.com/godotengine/godot/blob/76693aa364b553d96682a564bc695bfa715e40d7/scene/3d/sprite_3d.cpp#L925-L928

I am not sure if it is possible though.

@prominentdetail
Copy link

I need this feature.
I want to apply a hit effect to my animatedsprite3d nodes that will color them a solid color instead of the modulate multiply method. It seems like I would need a shader for this, but there doesn't appear any way to attach one.

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

No branches or pull requests

4 participants