calculating

I’m new. try to do some calculations using shaders.

I want to count the red pixels in a texture with a shader or do I have to use a computer shader?

I don’t think a shader can count the number of pixels in a texture, they don’t really work that way. What you can do is write a script to do that for you.

public class CountRedPixels : MonoBehaviour {

	// Texture needs Read/Write enabled from the Advanced Texture import settings
	public Texture2D _Texture;

	[Range(0, 1)]
	public float _MinRedColorValue = 0.5f;

	// Update is called once per frame
	void Update () {
		PerformRedPixelCount();
	}
	
	void PerformRedPixelCount () {
		int numOfRedPixels = 0;

		for (int y = 0; y < _Texture.height; y++)
		{
			for (int x = 0; x < _Texture.width; x++)
			{
				Color pixelColor = _Texture.GetPixel(x, y);
				if (pixelColor.r >= _MinRedColorValue)
				{
					numOfRedPixels++;
				}
			}
		}

		string debugMessage = string.Format("Found {0} pixels in {1} with a minimun R value of {2} ({3})", 
		                                    numOfRedPixels, 
		                                    _Texture.name, 
		                                    _MinRedColorValue, 
		                                    (int)(_MinRedColorValue * 255));
		Debug.Log(debugMessage);
	}
}