I am very new to blender and would like to understand the mistake I am doing with the color ramp node. I am currently using color ramp to assign different textures to each object in my scene. The complete surface should have the same RGB value. I then use this rendered image and filter out objects based on the pixel values. I have created a simple scene with 2 default cubes(pass index for the bottom cube in 0 and for the upper cube is 1) and added the color ramp settings as shown in the image. But, when I render with this settings, the RGB values on the surface are not uniform. Can someone please help me with this issue. I am using Blender 2.8.
If you over expose your render you can see patern.
Render saved as PNG 8-bit. Nothing is pluged into Surface socket of Material Output node. Tested with Eevee, Cycles, Samples ... all same result. Even if compression is set to zero.
The only difference did PNG saved as 16-bit. Completely black. So I guess OpenEXR will work as well. So the issue comes from output file format.
... and just for lovers of generic graphics - JPEG
And as mentioned already - Cryptomatte seems to me as a better friend, especially for material. With this ColorRamp 0/1 option I can't imagine to work on more complex object.
The first thing I noticed is that you're plugging the Color Ramp directly into the material output without running that first through a shader node like "diffuse" or "Principled BSDF". Not sure if that would fix your problem. Although, Considering your end goal of filtering out objects by the color value, you should look into the Cryptomatte feature. That is basically its purpose and it's a super-powerful feature that many 3d apps and compositing programs support. You might give it a try instead of your current method.
edit: Just a little info also on why you're seeing different colors across the object. The color your pushing is still being effected the lighting in the scene. If you add the color ramp to an emission shader the color should be even across the object. As a side hint, you don't need to open your render in another image editor to check the color values. Just right-click hold on the image in the rendered window and you'll see a black footer show up with all the color info an more.