Texture2D.GetPixel().grayscale always returns 0

I am procedurally generating a mesh (representing terrain) and that part is working fine. However, I need to manually put terrain features at certain points, so I have resorted to ‘painting’ the new terrain onto the mesh (see code sample below). Basically, I am using Photoshop to generate a grayscale height map and modifying my internal representation of the terrain before I actually generate the mesh. I have implemented this method:

class TerrainGenerator
   Texture2D terrainFeature;
   //a bunch of stuff, not relevant
	public void Paint(Texture2D template, int x = 0, int y = 0){
		for(int i = 0; i < template.width; i++){
			for(int j = 0; j < template.height; j++){
				print(i + " " + j + " " + template.GetPixel(x, y).grayscale);
				elevations[i + x, j + y] += -128 + template.GetPixel(x, y).grayscale;
			}
		}
	}
}

This method is incomplete because I am hung up on my issue and I won’t proceed until it is fixed. My problem is that everything printed there indicates that the value is 0, and the actual modification of the terrain happening on the next line reflects that. I am using the height map so that 0-127 moves that part of the terrain down, and 129-255 moves it up, and right now it is all moving down, as expected from getting 0 for every point in the image.

The image itself is a .png file made in Photoshop. It is 100x100 pixels (a 1:1 correspondence to the underlying mesh). It is being imported as an advanced texture type, non power of 2 is none. It is read/write enabled, import type is default, bypass sRGB sample is checked, and sprite mode is none. Generate mip maps is unchecked wrap mode is repeat, filter mode is bilinear, and ansio level is 1. Please help me understand why it isn’t reading my image correctly :slight_smile:

The terrain I am attempting to paint onto the mesh.

35273-debugvolcanopainttemplate.png

Event though it isn’t mentioned on the Color.grayscale documentation page, since Color uses values between 0 and 1, grayscale also returns a value between 0 and 1. It looks like you’d expected a value between 0 and 255, however it returns a float, not a byte.