0 votes

I have a light and a sprite, and I only want the parts of the sprite that itersect my light source to be visible. How can I do that? When I try to use a masking blend mode, the sprite is colorless.

Edit: Sorry for the bad question, I thought this was simpler than it now seems to be. @eons solution works great for basic sprites/textures, but I want my sprites to use their normal map. When I set "Shading Mode" to "Light Only" only the normal map is visible, the rest of the sprite is black.

enter image description here

It still looks that way if the Light2D is Mix or Mask. However, if the material of the regular sprite (on right in the picture) is set to "Light Only" it is hidden just fine as described in the example project.

Normal mapping is achieved by pasting this code into the "Fragment" section of the CanvasItemShader and linking the proper normal map as a shader param. Since the masking stuff is not working for normal mapped sprites, is there something wrong with my shader? I don't know much about shaders unfortunately.

uniform texture normal;
//normal maps expect Y-up, but 2D is Y-down, so must mirror this.
NORMAL = tex(normal,UV).rgb * vec3(2.0,-2.0,1.0) - vec3(1.0,-1.0,0.0);
asked Apr 30, 2017 in Engine by jarlowrey (611 points)
retagged May 1, 2017 by jarlowrey

Check the "using lights as masks" demo, it adds a CanvasItemMaterial to the node that needs to be hidden, set to be affected by lights only to make the mask effect.

EDIT: turned this into a comment to leave it unanswered

Hey @eons, thanks for responding. I updated the question with more relevant info.

I guess this may need some light shader trick but I don't know how that works, maybe the best could be to talk about this on IRC, there you may find more people used to Godot shader language.

Maybe I'm misunderstanding something, but the shader seems to work fine (both the texture and normal mapping effect are visible when lit, otherwise dark) when the shading mode is set to 'Light Only' when I try it on the '2D Normal Mapping' demo. What does your normal map look like?

Yeah I put my sprite in the demo project and it works. I think my light and sprite are exactly the same across the Godot projects, and the normal map definitely is. Not sure what the heck is going on. Here's the images enter image description here

enter image description here

Strange. The normal map looks alright. You could of course try rebuilding your scene from scratch and checking at which point it goes wrong, if you haven't already.

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.