0 votes

Hi ,

I am building a small FPS game and followed a tutorial to prevent weapons clipping through geometry. This involves having a ViewportContainer, Viewport and secondary Camera setup where the camera renders a different layer than the main camera. Weapons are then put in the layer the secondary camera renders.

However, the viewport does not mix well with the main rendering, causing all sorts of artefacts. It's as if the colour mixing was totally wrong.

Do you know what could possibly be wrong ? I have attached a lot of info about the issue and project in case that helps.

Thanks .

Video of the issue: https://www.loom.com/share/e01f70c123a1484c9e5e95cdc15ceaac
Node setup walkthrough: https://www.loom.com/share/f3f1de193d7a4ad09ca063dcbbcc132d
Project files: https://github.com/dsaltares/100-days-gamedev/tree/issue/weapon-clipping-fix

Godot version 3.3.3
in Engine by (21 points)

1 Answer

0 votes
Best answer


the reason you're having this problem is because you have several directional lights.
It was reported as a bug already.

If you really want two suns you can work around that by using the method described (and explained) in the bug report.
Here is it step-by-step in case you need it:

  1. Create a new ShaderMaterial for the material property of the ViewportContainer (CanvasItem > Material > material)
  2. Create a new Shader in this material
  3. Open it and put the following code in it:

    shader_type canvas_item;
    void fragment() {
        COLOR = texture(TEXTURE, UV);
        COLOR.a = clamp(COLOR.a, 0.0, 1.0);
  4. That's it!

by (732 points)
selected by

That did it, thank you so much. I implemented your suggestion here https://github.com/dsaltares/100-days-gamedev/commit/ad54fd1a3cd242bec4b36168cbc06e9ee3f0134e and it works like a charm.

It looked like an Engine bug to me, but did not think to check GH issues ‍♂️.

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.