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

Modify newly generated custom shaders on AnimatedSprite3D to preserve built-in spritesheet animation #4607

Open
Raiguri opened this issue May 31, 2022 · 13 comments

Comments

@Raiguri
Copy link

Raiguri commented May 31, 2022

Describe the project you are working on

I'm creating 2.5D game with 3Danimatedsprites and I need some shaders like swaying grass and distortion effect on the Player.

Describe the problem or limitation you are having in your project

Shaders do not provide for working with 3Danimatedsprite. Information about SpriteFrames disappears and 3DAnimatedSprite becomes blank

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

The only idea I have is that when you create a shader, it will be overlap the existing 3Danimatedsprite texture like 2Danimatedsprite.
OR
Just copy existing shader of 3Danimated sprite and then modify it.

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

Shader will work with 3D sprite like 2D sprite

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

If you do it through code, it will be very long and very inconvenient

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

This feature should have been there from the beginning

@Raiguri Raiguri changed the title Shaders on 3DAn Shaders on 3DAnimatedSprite May 31, 2022
@Raiguri Raiguri changed the title Shaders on 3DAnimatedSprite Shaders on Animated Sprite 3D May 31, 2022
@KoBeWi
Copy link
Member

KoBeWi commented May 31, 2022

This sounds like a bug.

@Calinou
Copy link
Member

Calinou commented Jun 1, 2022

Related to godotengine/godot#61563.

@and3rson
Copy link

and3rson commented Jul 1, 2022

+1 for this. Godot currently seems to lack an option of adding a shader on a Sprite3D or AnimatedSprite3D, and overriding the material breaks sprite sheet animations since there's no way to access and modify current frame's texture.

@and3rson
Copy link

and3rson commented Jul 1, 2022

UPDATE: I've found a workaround to modify AnimatedSprite3D:

  1. Create a new viewport, set usage to 2D, enable Y Flip, enable Transparent BG, and set size to your sprite's size.
  2. Create an AnimatedSprite (NOT 3D) inside your new viewport.
  3. Create a MeshInstance, add uniform sampler2D and assign ViewportTexture to it.
  4. You can now modify the rendered frames of AnimatedSprite in your shader.

Alternatively, you can apply canvas_item shader to your AnimatedSprite and simply use it as albedo inside SpatialMaterial of MeshInstance.

@lewiji
Copy link

lewiji commented Jul 5, 2022

I use shaders on AnimatedSprite3D nodes and have done for a while. Is there a specific use case it doesn't work for?

I have 1 image texture as a spritesheet for a given SpriteFrames resource. I use the same image texture as the albedo texture of the shader. The AnimatedSprite3D now displays the frames of the animation as normal, but they are rendered via the shader. Now I can do what I like to the image in the shader and its applied to the current frame of the animation.

I guess this doesn't work if you have more than one spritesheet texture in a single SpriteFrames resource.

@Raiguri
Copy link
Author

Raiguri commented Jul 16, 2022

UPDATE: I've found a workaround to modify AnimatedSprite3D:

  1. Create a new viewport, set usage to 2D, enable Y Flip, enable Transparent BG, and set size to your sprite's size.
  2. Create an AnimatedSprite (NOT 3D) inside your new viewport.
  3. Create a MeshInstance, add uniform sampler2D and assign ViewportTexture to it.
  4. You can now modify the rendered frames of AnimatedSprite in your shader.

Alternatively, you can apply canvas_item shader to your AnimatedSprite and simply use it as albedo inside SpatialMaterial of MeshInstance.

3D shadows are working?

@Zain-A-Abbas

This comment was marked as off-topic.

@Glukozavr
Copy link

I use shaders on AnimatedSprite3D nodes and have done for a while. Is there a specific use case it doesn't work for?

I have 1 image texture as a spritesheet for a given SpriteFrames resource. I use the same image texture as the albedo texture of the shader. The AnimatedSprite3D now displays the frames of the animation as normal, but they are rendered via the shader. Now I can do what I like to the image in the shader and its applied to the current frame of the animation.

I guess this doesn't work if you have more than one spritesheet texture in a single SpriteFrames resource.

Actually this works, thanks! If you have the same texture in AnimatedSprite3D and in your shader, so you have a shader like one below - it works with animation. I am still figuring out why the colors are dull though

shader_type spatial;

uniform sampler2D tex;

void fragment() {
	vec4 col = texture(tex, UV);
	ALBEDO = vec3(col.r * 2.0, col.g * 2.0, col.b * 2.0);
	ALPHA = col.a;
}

@Calinou
Copy link
Member

Calinou commented May 31, 2023

I am still figuring out why the colors are dull though

Add : source_color hint to your tex uniform (hint_color in 3.x).

@Glukozavr
Copy link

I am still figuring out why the colors are dull though

Add : source_color hint to your tex uniform (hint_color in 3.x).

Thanks! I found it out the other way, but that's exactly what was missing

@nakano15

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Sep 19, 2023

@nakano15 Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@Sithoid
Copy link

Sithoid commented Dec 14, 2023

In a recent Reddit discussion about Sprite3D shaders, I've been encouraged to post the solution I'm currently using that doesn't involve viewports. Here is the class that tracks animation changes. I'm a bit wary about making proposals, being quite new to Godot, but I hope posting this will help those who search for solutions in the future, even if it turns out to be a backwards approach. Still, I do wish accessing Sprite3D's textures didn't require workarounds, so I hope this issue gets traction.

@Calinou Calinou changed the title Shaders on Animated Sprite 3D Modify newly generated custom shaders on AnimatedSprite3D to preserve built-in spritesheet animation Dec 14, 2023
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

9 participants