I'm making a voxel engine dividing the world in chunks with 32 x 32 x 32 blocks each. I've been implementing many rendering optimizations such as not rendering faces covered by solid voxels or face merging for same looking neighbour voxels.
The thing is that I want to implement a per-vertex ambient occlusion, calculating the occlussion from the CPU and passing it to the shaders, just like that image. It works almost fine but the face merging makes bigger gradients on larger faces because of the linear interpolation OpenGL makes to the final color of the fragment.
I would like to now if there is a way to fix that problem, by telling the fragment shader how far is a fragment from the vertex or something like that.