Anaglyph stereoscopic viewport methods issue

I have been trying to change the default anaglyph red-cyan mode when you look through the camera and have stereoscopy on from its default “colored anaglyph” to a “grayscale anaglyph” where the stereoL and stereoR images are converted to greyscale with luma in order to reduce eye strain with certain colors like reds. I was also trying to add other common anaglyph viewing methods such as half color and dubois.

In GPU_viewport_stereo_composite i can make the texture “color_stereo” greyscale using a luma function but can only affect the GB channels since I am using a mask, GPU_color_mask(false, true, true, true) to create the anaglyph effect. I cannot find out how to use shaders on the first pass which i believe is in wm_draw_window offscreen

  for (int view = 0; view < 2; view++) {
    eStereoViews sview;
    if (view == 0) {
      sview = STEREO_LEFT_ID;
    else {
      sview = STEREO_RIGHT_ID;
      wm_draw_region_stereo_set(bmain, area, region, sview);

    wm_draw_region_bind(region, view);
    ED_region_do_draw(C, region);
  if (use_viewport) {
    GPUViewport *viewport = region->draw_buffer->viewport;
    GPU_viewport_stereo_composite(viewport, win->stereo3d_format, win->scene->camera->data);

Below is the modified datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl shader when I call GPU_viewport_stereo_composite. In this function I bind the texture “color_stereo” and with the masking enabled can affect the GB channels. I do not know how to affect the R channel and maintain the red-cyan anaglyph effect. How do I get the separate L/R stereo textures and pass them into the composite shader in order to do operations on them and then do a manual overlay instead of using masking and not being able to affect all the stages? Below is my modified stereo merge shader and it shows what I am trying to do.

const char datatoc_gpu_shader_image_overlays_stereo_merge_frag_glsl[] = {
    "#define S3D_DISPLAY_ANAGLYPH 0      \n"

    "/* Composite stereo textures */   \n"
    "uniform sampler2D imageTexture;    \n"
    "uniform sampler2D overlayTexture;   \n"
    //"uniform sampler2D stereoL;   \n"
    //"uniform sampler2D stereoR;   \n"
    "uniform int stereoDisplaySettings;   \n"

    "uniform int anaglyphMethod; \n"
    "layout(location = 0) out vec4 imageColor;   \n"
    "layout(location = 1) out vec4 overlayColor;  \n"

    "float blendScreen(float base, float blend)	\n"
    "{	\n"
    "	return 1.f - ((1.f - base) * (1.f - blend));	\n"
    "}	\n"

    "vec3 blendScreen2(vec3 base, vec3 blend)	\n"
    "{	\n"
    "	return vec3(blendScreen(base.r, blend.r), blendScreen(base.g, blend.g), blendScreen(base.b, "
    "blend.b));	\n"
    "}	\n"

	"void main() //what I HAVE  \n"
	"{                     \n"
	"  ivec2 texel = ivec2(gl_FragCoord.xy);    \n"
	  "//vec4 stereoR = already in buffer...?;     \n"
	  "vec4 stereoGB = texelFetch(imageTexture, texel, 0);     \n"
	 "float grayGB = dot(stereoGB.rgb, vec3(.299f, .587f, .114f)); \n"

	"if (anaglyphMethod == 0) //color    \n"
	  "imageColor = stereoGB; \n"

	"else if (anaglyphMethod == 1) //grayscale    \n"
	  "imageColor = vec4(vec3(grayGB), stereoGB.a); \n"

	  "overlayColor = vec4(0.f); \n"
	"}   \n"

   "void main() //what i WANT - individual stereoL/R texture access, no masking, manual blending  \n"
    "{                     \n"
    "  ivec2 texel = ivec2(gl_FragCoord.xy);    \n"
    "vec4 stereoL = texelFetch(stereoL, texel, 0);     \n"
    "vec4 stereoR = texelFetch(stereoR, texel, 0);     \n"

    "if (anaglyphMethod == 0) //color    \n"
    "{      \n"
      "myRed = vec4(stereoL.r, 0.f, 0,f); \n"
      "myCyan = vec4(0.f, stereoR.g, stereoR.b); \n"
    "}      \n"

    "else if (anaglyphMethod == 1) //grayscale  \n"
    "{    \n"
      "float grayL = dot(stereoL.rgb, vec3(.299f, .587f, .114f)); \n"
      "myRed = vec4(vec3(grayL, 0.f, 0.f), stereoL.a); \n"

      "float grayR = dot(stereoR.rgb, vec3(.299f, .587f, .114f)); \n"
      "myCyan = vec4(0.f, grayR, grayR, stereoR.a); \n"
    "}    \n"

	  "imageColor = blendScreen2(myRed, myCyan); \n"
    "overlayColor = vec4(0.f); \n"

    "}   \n"