//Vertex shader
o.baseWorldPos = unity_ObjectToWorld._m03_m13_m23;

//Frag shader
fixed4 col = fixed4(1,0,0,1);

if (i.baseWorldPos.x >= 0.5 && i.baseWorldPos.y >= 0.5 && i.baseWorldPos.z >= 0.5) {

    col = fixed4(i.baseWorldPos.x,i.baseWorldPos.y,i.baseWorldPos.z,1);


so in my vertex shader, i grab the meshes world position, and based on tests using the if statement in this code i can confirm that the value matches the position of the model in world space in the game/editor. If the objects xyz are all below 0.5, it draws in a full red color, if not then it becomes a color based on the positions as it should. So we know that the position being passed in is correct.

The problem is, the color that is generated based of this position, is something entirely different. When I set the positions so that each xyz = 0.51, you would expect to get a color of rgb = 0.51, but instead i get rgb = 0.7411.

color taken from the render

does anyone have any idea why this is the case?

  • \$\begingroup\$ Hint: 0.741^2.2 ≈ 0.51 (plus some wiggle room due to 8-bit quantization) \$\endgroup\$
    – DMGregory
    Apr 22, 2022 at 12:18

1 Answer 1


It turns out the displayed color is different than the actual data in the texture, which has the correct values, and I had just neglected to check that.

By rendering the object to a render texture, and copying that render texture to a regular texture using Texture2D.ReadPixels, I can then use GetPixel to get the literal RGB data of each color rendered, which match up to the object's position.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .