Nietzsche mocked German idealists at length, but I think calling him a materialist is a bridge too far, same as for all his anti-Christianity it is not clear that he was an atheist. He inherited his metaphysics from Schopenhauer, transforming his World Will into will to power, who can be seen as irrationalizing Hegel's Absolute Geist with a side of that "intellectual intuition" that Kant kept rejecting but couldn't let go of. Nietzsche's is a highly personalized and individualistic philosophy focused on human condition and action, like existentialism, barely a realism but hardly materialism, and with panpsychic overtones perhaps.
He explicitly rejected and mocked the dominant version of materialism of his day, atomism. As Nietzsche writes in Beyond Good and Evil:"As regards materialistic atomism, it is one of the best-refuted theories that have been advanced, and in Europe there is now perhaps no one in the learned world so unscholarly as to attach serious signification to it, except for convenient everyday use (as an abbreviation of the means of expression)". Moreover, he joined Hume in deflating the categories of substance and causality, along with the logical laws of identity and contradiction, all of which he saw as crutches of intellect clinging to the ephemeral stability of Being, and inadequate for capturing the Becoming of life, which only truly manifests itself in willings and urges:"Psychologists should bethink themselves before putting down the instinct of self-preservation as the cardinal instinct of an organic being. A living thing seeks above all to DISCHARGE its strength — life itself is WILL TO POWER".
Marx passed away in 1883 and Nietzsche started writing about philosophy only in 1878. He probably did not gain enough prominence for Marx to notice in his waning years. As for the influence the other way, Clark and Leiter write in Nietzsche: Daybreak, "there is no evidence, however, that Nietzsche ever read Marx". He was aware of socialists and Young Hegelians more broadly, like Strauss, Stirner and Feuerbach, and yes, his individualism and emphasis on the historical role of "exceptional individuals", was antithetical to socialism and historical materialism, and his philosophy of life was antithetical to everything rationalism, especially Hegel. This said, he did embrace the Heraclitean aspects of Hegel, the becoming, the flux of life, irrationalized and vitalized by Schopenhauer. So there is one point of contact between Nietzsche, and especially early Marx of Young Hegelian days and alienation from Economic and Philosophic Manuscripts of 1844 (Stirner wrote in a similar spirit), — the Hegelian dialectic.
See also online discussions concerning Nietzsche on Marx, and Marx on Schopenhauer.