at the begining of your code, outside of any function, just put this line:
var d3d_automaterial = 1;

if you set it to greater than 0 it's on, 0 means its off.
if this doesnt work, its because you are using the wrong version of gamestudio.