I was using RawShaderMaterial instead of ShaderMaterial. That was the problem. I removed the duplicate variables declared in the shader and it worked.
RawShaderMaterial
ShaderMaterial