title: how to return the mask of sampled pixels
body: <p>I am using a program, which is available on GitHub (<a href="https://github.com/ulikk/panoviewer" rel="nofollow noreferrer">here</a>), to convert an equirectangular image (360-degree images) to a perspective view (viewport) using OpenGL. For that, the ray-tracing approach is used to find the intersection of fragment points on the unit sphere and later this information will be used to sample required pixels from equirectangular images and project them on perspective view. Everything works fine, but now along the projection result, I need the program to return to me also a mask image (of type unsigned byte and same size of the equirectangular image) which represents pixels which are sampled from the equirectangular images. </p>
  
  <p>How can I change the fragment shader to return to me this unsigned byte mask (0 represents non-samples and 255 represents sampled pixels) at the same time that it is rendering the view on frame buffer? </p>
  
  <p>To be more specific, my current fragment shader looks as follows:</p>
  
  <pre><code>const float pi = 3.141592653589793;
  varying vec3 planePoints;
  uniform sampler2D tex;
  void main()
  {
          vec2 equirectangularTexturePos;
          vec3 spherepos = normalize(planePoints);
          equirectangularTexturePos.x = (atan(spherepos.y, -spherepos.x)+pi)/(2.0*pi);
          equirectangularTexturePos.y = acos(spherepos.z)/(pi);
          gl_FragColor = texture2D(tex, equirectangularTexturePos);
  }
  </code></pre>
  
  <p>and what I want is something similar as follows be added to my fragment shader:</p>
  
  <pre><code>texture2D(mask, equirectangularTexturePos) = 255;
  </code></pre>