# Bloom shader
# By Øyvind "Elg" Strømme
# Based mostly off Blur Shader by John Rittenhouse
# Which in turn is based partially off of humus's blur filter from his glow application http://esprit.campus.luth.se/~humus/

!!ARBvp1.0 OPTION ARB_position_invariant ;
# input:
# 
# local[0]	Magnitude of blur
#
# output:
#
# texCoord[0]	Will contain the magnitude of blur adjusted
#
# Set so a magnitude of 1 is approximately 1 pixel with 640x480
PARAM size = 0.0016;
TEMP R0;

MUL	R0, size, program.local[0];
MUL	R0.y, R0.y,  1.33333;
MOV	result.texcoord[0], R0;


END

# This shader corrects the texture coordinates for use with _currentRender
!!ARBfp1.0 
OPTION ARB_precision_hint_nicest;

# texture 0 is _currentRender
#
# env[0] is the 1.0 to _currentRender conversion
# env[1] is the fragment.position to 0.0 - 1.0 conversion

TEMP	R0,R1, SUM, AUM;

PARAM inv13 = 0.006923077;


# calculate the screen texcoord in the 0.0 to 1.0 range
MUL		R0, fragment.position, program.env[1];
MUL		R1, fragment.position, program.env[1];

# scale by the screen non-power-of-two-adjust to give us normal screen coords in R0
MUL		R0, R0, program.env[0];
MUL		R1, R1, program.env[0];

# load the screen render
TEX		SUM, R0, texture[0], 2D;
TEX		AUM, R1, texture[0], 2D;

# Now scale it and output it
MUL		SUM, SUM, AUM;
MUL             SUM, SUM, 1.5;

ADD		result.color.xyz, SUM, inv13;

END

