It's not a question of grammar, that is, not a question of syntax.
It's a question of semantics, that is, a question of meaning.
If you refer to an object or objects, it's countable.
If you refer to the substance, it's not countable.
I wrote several papers for a course in art history. (paper means written report.)
I need more paper so I can wrap this gift. (paper refers to a substance)
CJ