GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


Phong Fragment_program by ARB_program
!!ARBfp1.0

#OPTION ARB_precision_hint_fastest;

OUTPUT output = result.color;
TEMP base, bump, lVect, viewV, atten;
TEMP diffuse, specular, temp, invLen;

PARAM amb    = program.local[0];
PARAM lCol  = program.local[1];

#PARAM attParams = { 0.5, 0.0, 0.100005, 0.0 };
PARAM attParams = { 0.9, 0.0, 0.000000, 1.0 };

TEX        base,  fragment.texcoord[0], texture[0], 2D;
TEX        bump,  fragment.texcoord[0], texture[1], 2D;

MAD        bump, bump, 2.0, -1.0;                                 # Scale and bias

DP3        temp,   bump, bump;                                  # Post-filter normalisation of bumpmap
RSQ        invLen, temp.x;
MUL        bump,   bump, invLen;

DP3        temp,   fragment.texcoord[1], fragment.texcoord[1];  # Normalize light vector
RSQ        invLen, temp.x;
MUL        lVect,  fragment.texcoord[1], invLen;

DST        atten, temp,  invLen;                                # Attenuation
DP3        atten, atten, attParams;
RCP        atten, atten.x;

DP3_SAT    diffuse, lVect, bump;                                # Diffuse

DP3        temp,   fragment.texcoord[2], fragment.texcoord[2];  # Normalize view vector
RSQ        invLen, temp.x;
MUL        viewV,  fragment.texcoord[2], invLen;

DP3        temp,  lVect, bump;                                  # Reflection vector
MUL        temp,  temp,  bump;
MAD        lVect,  temp,  2.0, -lVect;

MUL        diffuse, diffuse, base;                                 # Ambient * Base + (Diffuse * Base) * Attenuation
MUL        temp, base, amb;
MUL        diffuse, diffuse, lCol;    

MAD        output, diffuse, atten, temp;
  
END