
uniform sampler2D texGlow;
uniform sampler2D texNoise;

uniform highp vec2 noiseTexCoordScale;

vec3 applyGlow(vec3 color)
{
	float fluidAmount = min(dot(color, vec3(1.0)), 1.0);
	//float weight = length(color);
	//color = (1.0 - weight) * texture2D(texGlow, varyTexCoord).rgb + weight * color;
	vec3 c0 = color;
    vec4 glowShadow = texture2D(texGlow, varyTexCoord);
	vec3 c1 = glowShadow.rgb;

	vec3 noise = texture2D(texNoise, varyTexCoord * noiseTexCoordScale).rgb;
	
	const float noiseStr = 0.05; // this is tuned to remove most of the color banding on Nexus7, and not introduce too much grain at the same time.
	c1 = max(c1 - noise * noiseStr, 0.0);
	c1 *= 1.0 / (1.0 - noiseStr); // scale the values back to 0-1, so that the glow can saturate at whites

	color = c0 + c1;
	return color;
}
