 }
 #endif
 
-#if defined MASK && !defined ROTATE_SCANLINES
-	// Shadow mask.
-	vec4 Mask(vec2 pos)
-	{
-		vec3 mask = vec3(maskDark, maskDark, maskDark);
-
-		// Very compressed TV style shadow mask.
-		if (shadowMask == 1.0)
-		{
-			float line = maskLight;
-			float odd = 0.0;
-
-			if (fract(pos.x*0.166666666) < 0.5) odd = 1.0;
-			if (fract((pos.y + odd) * 0.5) < 0.5) line = maskDark;
-
-			pos.x = fract(pos.x*0.333333333);
-
-			if      (pos.x < 0.333) mask.r = maskLight;
-			else if (pos.x < 0.666) mask.g = maskLight;
-			else                    mask.b = maskLight;
-			mask*=line;
-		}
-
-		// Aperture-grille.
-		else if (shadowMask == 2.0)
-		{
-			pos.x = fract(pos.x*0.333333333);
-
-			if      (pos.x < 0.333) mask.r = maskLight;
-			else if (pos.x < 0.666) mask.g = maskLight;
-			else                    mask.b = maskLight;
-		}
-	#ifdef EXTRA_MASKS
-		// These can cause moire with curvature and scanlines
-		// so they're an easy target for freeing up registers
-
-		// Stretched VGA style shadow mask (same as prior shaders).
-		else if (shadowMask == 3.0)
-		{
-			pos.x += pos.y*3.0;
-			pos.x  = fract(pos.x*0.166666666);
-
-			if      (pos.x < 0.333) mask.r = maskLight;
-			else if (pos.x < 0.666) mask.g = maskLight;
-			else                    mask.b = maskLight;
-		}
-
-		// VGA style shadow mask.
-		else if (shadowMask == 4.0)
-		{
-			pos.xy  = floor(pos.xy*vec2(1.0, 0.5));
-			pos.x  += pos.y*3.0;
-			pos.x   = fract(pos.x*0.166666666);
-
-			if      (pos.x < 0.333) mask.r = maskLight;
-			else if (pos.x < 0.666) mask.g = maskLight;
-			else                    mask.b = maskLight;
-		}
-	#endif
-
-		else mask = vec3(1.,1.,1.);
-
-		return vec4(mask, 1.0);
-	}
-#endif
-
 void main()
 {
 #ifdef CURVATURE
-  vec2 posNorm=v_texCoord.xy*(rubyTextureSize.xy/rubyInputSize.xy);
+	vec2 posNorm=v_texCoord.xy*(rubyTextureSize.xy/rubyInputSize.xy);
 	vec2 pos = Warp(posNorm)*(rubyInputSize.xy/rubyTextureSize.xy);
 #else
 	vec2 pos = v_texCoord.xy;
 #endif
 
-#if defined MASK && !defined ROTATE_SCANLINES
-	// mask effects look bad unless applied in linear gamma space
-	vec4 in_gamma = vec4(monitor_gamma, monitor_gamma, monitor_gamma, 1.0);
-	vec4 out_gamma = vec4(1.0 / crt_gamma, 1.0 / crt_gamma, 1.0 / crt_gamma, 1.0);
-	vec4 res = pow(BL_TEXTURE(Source, pos), in_gamma);
-#else
 	vec4 res = BL_TEXTURE(Source, pos);
-#endif
-
-#if defined MASK && !defined ROTATE_SCANLINES
-	// apply the mask; looks bad with vert scanlines so make them mutually exclusive
-	res *= Mask(gl_FragCoord.xy * 1.0001);
-#endif
-
-#if defined CURVATURE && defined GL_ES
-	// hacky clamp fix for GLES
-	vec2 bordertest = (pos);
-	if ( bordertest.x > 0.0001 && bordertest.x < 0.9999 && bordertest.y > 0.0001 && bordertest.y < 0.9999)
-		res = res;
-	else
-		res = vec4(0.,0.,0.,0.);
-#endif
-
-#if defined MASK && !defined ROTATE_SCANLINES
-	// re-apply the gamma curve for the mask path
-	FragColor = pow(scanline(pos, res), out_gamma);
-#else
-	FragColor = scanline(pos, res);
-#endif
+  FragColor=res;
 
 //Remove garbled display around
 #if defined CURVATURE

}
#endif

vec4 scanline(vec2 coord, vec4 frame)
{
#if defined SCANLINES
	vec2 omega = vec2(3.1415 * rubyOutputSize.x, 2.0 * 3.1415 * rubyTextureSize.y);
	vec2 sine_comp = vec2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
	vec3 res = frame.xyz;
	#ifdef ROTATE_SCANLINES
		sine_comp = sine_comp.yx;
		omega = omega.yx;
	#endif
	vec3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(coord * omega), vec2(1.0, 1.0)));

	return vec4(scanline.x, scanline.y, scanline.z, 1.0);
#else
	return frame;
#endif
}

#ifdef CURVATURE
// Distortion of scanlines, and end of screen alpha.
vec2 Warp(vec2 pos)

  float right=Warp(vec2(0, posNorm.y)).x+0.999;
  float top=Warp(vec2(posNorm.x,1)).y-1;
  float bottom=Warp(vec2(posNorm.x,0)).y+0.999;
  float alpha=max(max(
	smoothstep(-CURVATURE_SMOOTH,0,left-posNorm.x),
	smoothstep(0,CURVATURE_SMOOTH,posNorm.x-right)
  ),max(
	smoothstep(-CURVATURE_SMOOTH,0,top-posNorm.y),
	smoothstep(0,CURVATURE_SMOOTH,posNorm.y-bottom)
  ));
  res=mix(res,vec4(0,0,0,1),alpha);
  FragColor=res;
#else
  if(v_texCoord.x <= 0 || v_texCoord.x >= (rubyInputSize.x/rubyTextureSize.x)
    || v_texCoord.y <= 0 || v_texCoord.y >= (rubyInputSize.y/rubyTextureSize.y)){
