I'm looking to add extra textures to the CanvasTexture class. I'm finding it difficult in finding the definition of it in the game engine. I can only find 2 references to CanvasTexture and they are both for the UI text.

I want to know how to either create my own class by extending the CanvasTexture class, or by extending the Texture2D class. I then want to be able to copy paste the existing shader code useD to draw these textures and modify the logic (so that I can incorporate the new textures).

Use case:
I want to use the built in CanvasTexture with diffuse, normal and specular, 2d shadows but I want to add an extra 1 - 2 texture inputs for to update damage masks dynamically at runtime with a shader.

Env:

  • Godot 4
  • C#

Any help would be appreciated thanks!

  • Add a new Shader Material

    Add a new Shader

    Mode should be Canvas Item

    Type can be Shader or Visual Shader

    Even with the Shader "empty", the sprite will be rendering just fine

    From there, if you're doing a visual shader, add a texture Input for the main texture and two Texture2DParameters named whatever you like.

    The regular shader way is very similar. I just don't remember the naming convention off the top of my head.

    Then build it out with whatever you want to do. Random example:

Have you tried making a canvas shader? Should be the easiest way to accomplish what you're after

    award
    1.a) How do I get any of these to use a custom shader?

    1.b) How can I add my own option to this list if 1.a is not possible?

    2) Where do I get the default shader code for the CanvasTexture so that I don't start from scratch?

    3) Will a custom shader require me not using Sprite2D? Because I don't want to have to re-implement atlas textures, or sprite sheet animation, canvas groups, instancing, lights/shadows etc. I'm hoping whatever shader is used by Sprite2D with CanvasTexture deals with all of those features. If so just point to me the complete shader code, and I'll just copy paste and make modifications. If it's not in the GitHub repo but is autogenerated, how do I get that auto-generated shader code?

    4) How do I use the new custom shader with Sprite2D? Do I make a new material and assign it to the Sprite2D material and then assign the new shader to this material? Because that doesn't seem to work, the original texture is still rendered, not my new material.

    Add a new Shader Material

    Add a new Shader

    Mode should be Canvas Item

    Type can be Shader or Visual Shader

    Even with the Shader "empty", the sprite will be rendering just fine

    From there, if you're doing a visual shader, add a texture Input for the main texture and two Texture2DParameters named whatever you like.

    The regular shader way is very similar. I just don't remember the naming convention off the top of my head.

    Then build it out with whatever you want to do. Random example:

    Oh, that's exactly what I needed, thank you so much 🙏 .

    I didn't know the resulting shader would be a combination of whatever comes from the Sprite2D inputs and the custom shader, I thought it was either one or the other.