How do I make an Inverted (Negative) Crosshiar?

f24816f24816 Posts: 3Member

Minecraft has a crosshiar that applies the opposite texture of what you are looking at to the crosshair to make it more visible.
Could you do this with a negative shader and a BackBufferCopy and what is the structure?


Tags :

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 4,000Admin

    Welcome to the forum @f24816!

    I have not tested it myself, but I think a shader like this should work:

    shader_type canvas_item
    
    void fragment() {
        vec4 texture_color = texture(TEXTURE, UV);
        if (texture_color.a > 0) {
            COLOR = 1.0 - texture(SCREEN_TEXTURE, SCREEN_UV);
        } else {
            COLOR = vec4(0.0, 0.0, 0.0, 0.0)l
        }
    }
    

    Then you just need to use a TextureRect (or similar) node with a crosshair that has pixels where you want the inverted effect to be, and then it should work. :smile:

  • cyberealitycybereality Posts: 1,232Moderator

    Yes, a negative shader like @TwistedTwigleg says should work. One thing to keep in mind is that it will look correct in GLES2 but that same shader will look strange in GLES3 (due to different color spaces, I still haven't totally figured it out). For something simple like this it probably won't matter but if you are getting weird results that might be the problem.

  • f24816f24816 Posts: 3Member


    It make sense but I also tried to use visual shader and this is as far as I got.

  • f24816f24816 Posts: 3Member

    This is how I did it eventually.

        shader_type canvas_item;
    
        void fragment() {
            // Get rgb values from screen.
            vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
            // Invert them.
            c.rgb = 1.0 - c.rgb;
            // Asign them to the cursor.
            COLOR.rgb = c;
            // Asign the original alpha value.
            COLOR.a = texture(TEXTURE, UV).a;
        }
    

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file