+2 votes

https://godotengine.org/qa/36024/if-there-is-a-group-of-sprites-to-be-cut-off-how-to-do-it

I can cut off a sprite or a texture by shader, but if there is a sprite with several children to be cut off, how to do it?

ps: https://github.com/godotengine/godot/issues/23763

in Engine by (26 points)

Why are you making a duplicate of your question?

sorry but I just think that no one will answer the former question....

Wouldn't help if you made the exact same question.

Check out the answer to my question about getting your questions answered.

Hi, @zhagsenkk have you managed to solve the problem?

1 Answer

0 votes

I can cut off a sprite or a texture by shader, but if there is a sprite with several children to be cut off, how to do it?

This makes more sense. There is two basic ways to do it.

1.) If every sprite has it's own material, it will need to set the values per-material. So you will need to have a code that looks like this:

extends Node2D

func _ready():
    for EachChild  in self.get_children() :
        var TheMaterial = EachChild.material as ShaderMaterial
        TheMaterial.set_shader_param("Clip", 0.1)

2.) Actually there is a more efficient way to do it.
What you need to know is that every material will have a set of it's own material properties.

What this means is that if the material is shared between sprites, like in a sprite sheet or texture atlas, they will all be effected at the same time.

Here is a example of sprites sharing a material:
enter image description here

A Zip file, with a Godot example. I use Godot 3.1 Alpha2
https://drive.google.com/open?id=129cKrKHbt3p3s3qI6K_sVERnQ4oCu53E

by (1,482 points)

Thx. The effect i want to make is:
https://drive.google.com/open?id=1jwir3mfqR74ObfUn7uZ1yvdmfT4YcPBB
The sprite with several children is influenced as a whole. Like they are one sprite.
this question may be the same issue:
https://godotengine.org/qa/36255/how-to-apply-a-shader-to-a-group-of-nodes

OK, what you need is 2 UV channels. 1 for the sprite image and 1 for the mask. The mask will probably work in Global space and tile. I will make an example for you.

Hi, I was just making the shader when I realized you wanted a UI-Mask.Talk about miss communication.
In Godot the Light 2D is used for masks like this:
enter image description here

The way it works is you set the light2D node to Mask. It uses the Alpha channel of the image to make the mask, so use PNG images.
When using more than One you will want to use the layer settings.
enter image description here

tanks! can you supply your project?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.