I use a shader to toggle on and off the roof of a house.

if (is_roof_pixel) {
     ALPHA = 0.0;
}

The problem is this lets sunlight in.
Is there a way to hide the roof without letting in directional light?
Maybe there's some way to hide the mesh after it draws its shadow?

I also tried discardas well but no luck.

Blender has a visibility option that allows you to hide meshes for specific cameras, maybe theres a similar feature in godot?

Easiest solution might be to use a second/extra shadow casting object, that is a mesh instance object with the shadow casting property set to shadow only. It wouldn't visibly render, but it's shadow would.

    Megalomaniak
    Unfortunately mesh is the entire world (this is a minecraft clone), duplicating the mesh would be really hard on performance I think? Im open to harder solutions though

    You could procedurally produce the shadowcaster mesh via the SurfaceTool and modify further via the MeshDataTool classes perhaps.