updated for hardware stencil support