#ifndef RC_FX_SHADERS_H_INCLUDED
#define RC_FX_SHADERS_H_INCLUDED

std::string refraction1_vert =
"varying vec3  Normal; \n"
"varying vec3  EyeDir; \n"
"varying vec4  EyePos; \n"
"varying float LightIntensity; \n"
"\n"
"void main(void) \n"
"{ \n"
"    gl_Position    = ftransform(); \n"
"    Normal         = normalize(gl_NormalMatrix * gl_Normal); \n"
"    vec4 pos       = gl_ModelViewMatrix * gl_Vertex; \n"
"    EyeDir         = pos.xyz; \n"
"    EyePos         = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
"    LightIntensity = max(dot(normalize(gl_LightSource[0].position.xyz - EyeDir), Normal), 0.0); \n"
"}";

std::string refraction1_frag =
"const vec3 Xunitvec = vec3 (1.0, 0.0, 0.0); \n"
"const vec3 Yunitvec = vec3 (0.0, 1.0, 0.0); \n"
" \n"
"uniform vec3  BaseColor; \n"
"uniform float Depth; \n"
"uniform float MixRatio; \n"
" \n"
"// need to scale our framebuffer - it has a fixed width/height of 2048 \n"
"uniform float FrameWidth; \n"
"uniform float FrameHeight; \n"
" \n"
"uniform sampler2D EnvMap; \n"
"uniform sampler2D RefractionMap; \n"
" \n"
"varying vec3  Normal; \n"
"varying vec3  EyeDir; \n"
"varying vec4  EyePos; \n"
"varying float LightIntensity; \n"
" \n"
"void main (void) \n"
"{ \n"
"    // Compute reflection vector \n"
"    vec3 reflectDir = reflect(EyeDir, Normal); \n"
" \n"
"    // Compute altitude and azimuth angles \n"
" \n"
"    vec2 index; \n"
" \n"
"    index.y = dot(normalize(reflectDir), Yunitvec); \n"
"    reflectDir.y = 0.0; \n"
"    index.x = dot(normalize(reflectDir), Xunitvec) * 0.5; \n"
" \n"
"    // Translate index values into proper range \n"
" \n"
"    if (reflectDir.z >= 0.0) \n"
"        index = (index + 1.0) * 0.5; \n"
"    else \n"
"    { \n"
"        index.t = (index.t + 1.0) * 0.5; \n"
"        index.s = (-index.s) * 0.5 + 1.0; \n"
"    } \n"
"    \n"
"    // if reflectDir.z >= 0.0, s will go from 0.25 to 0.75 \n"
"    // if reflectDir.z <  0.0, s will go from 0.75 to 1.25, and \n"
"    // that's OK, because we've set the texture to wrap. \n"
"  \n"
"    // Do a lookup into the environment map. \n"
" \n"
"    vec3 envColor = vec3 (texture2D(EnvMap, index)); \n"
"    \n"
"    // calc fresnels term.  This allows a view dependant blend of reflection/refraction \n"
"    float fresnel = abs(dot(normalize(EyeDir), Normal)); \n"
"    fresnel *= MixRatio; \n"
"    fresnel = clamp(fresnel, 0.1, 0.9); \n"
" \n"
"   // calc refraction \n"
"   vec3 refractionDir = normalize(EyeDir) - normalize(Normal); \n"
" \n"
"   // Scale the refraction so the z element is equal to depth \n"
"   float depthVal = Depth / -refractionDir.z; \n"
"    \n"
"   // perform the div by w \n"
"   float recipW = 1.0 / EyePos.w; \n"
"   vec2 eye = EyePos.xy * vec2(recipW); \n"
" \n"
"   // calc the refraction lookup \n"
"   index.s = (eye.x + refractionDir.x * depthVal); \n"
"   index.t = (eye.y + refractionDir.y * depthVal); \n"
"    \n"
"   // scale and shift so we're in the range 0-1 \n"
"   index.s = index.s / 2.0 + 0.5; \n"
"   index.t = index.t / 2.0 + 0.5; \n"
"    \n"
"   // as we're looking at the framebuffer, we want it clamping at the edge of the rendered scene, not the edge of the texture, \n"
"   // so we clamp before scaling to fit \n"
"   float recip1k = 1.0 / 255.0; \n"
"   index.s = clamp(index.s, 0.0, 1.0 - recip1k); \n"
"   index.t = clamp(index.t, 0.0, 1.0 - recip1k); \n"
"    \n"
"   // scale the texture so we just see the rendered framebuffer \n"
"   index.s = index.s * FrameWidth * recip1k; \n"
"   index.t = index.t * FrameHeight * recip1k; \n"
"    \n"
"    vec3 RefractionColor = vec3 (texture2D(RefractionMap, index)); \n"
"    \n"
"    // Add lighting to base color and mix \n"
"    vec3 base = LightIntensity * BaseColor; \n"
"    envColor = mix(envColor, RefractionColor, fresnel); \n"
"    envColor = mix(envColor, base, 0.2); \n"
" \n"
"    gl_FragColor = vec4 (envColor, 1.0); \n"
"}";



std::string refraction2_frag =
"varying vec3 vertex_light_position; \n"
"varying vec3 vertex_normal; \n"
"\n"
"void main() { \n"
"   // Set the diffuse value (darkness). This is done with a dot product between the normal and the light \n"
"   // and the maths behind it is explained in the maths section of the site. \n"
"   float diffuse_value = max(dot(vertex_normal, vertex_light_position), 0.0); \n"
"\n"
"   // Set the output color of our current pixel \n"
"   gl_FragColor = gl_Color * diffuse_value; \n"
"}";

std::string refraction2_vert =
"varying vec3 vertex_light_position; \n"
"varying vec3 vertex_normal; \n"
"\n"
"void main() {         \n"
"   // Calculate the normal value for this vertex, in world coordinates (multiply by gl_NormalMatrix) \n"
"   vertex_normal = normalize(gl_NormalMatrix * gl_Normal); \n"
"   // Calculate the light position for this vertex \n"
"   vertex_light_position = normalize(gl_LightSource[0].position.xyz); \n"
"\n"
"   // Set the front color to the color passed through with glColor*f \n"
"   gl_FrontColor = gl_Color; \n"
"   // Set the position of the current vertex \n"
"   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
"}";



std::string gooch_vert =
"varying float NdotL; \n"
"varying vec3  ReflectVec; \n"
"varying vec3  ViewVec; \n"
"\n"
"void main(void) \n"
"{ \n"
"    vec3 ecPos      = vec3 (gl_ModelViewMatrix * gl_Vertex); \n"
"    vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal); \n"
"    vec3 lightVec   = normalize(gl_LightSource[0].position.xyz - ecPos); \n"
"    ReflectVec      = normalize(reflect(-lightVec, tnorm)); \n"
"    ViewVec         = normalize(-ecPos); \n"
"    NdotL           = (dot(lightVec, tnorm) + 1.0) * 0.5; \n"
"    gl_Position     = ftransform(); \n"
"}";

std::string gooch_frag =
"uniform vec3  SurfaceColor; // (0.75, 0.75, 0.75) \n"
"uniform vec3  WarmColor;    // (0.6, 0.6, 0.0) \n"
"uniform vec3  CoolColor;    // (0.0, 0.0, 0.6) \n"
"uniform float DiffuseWarm;  // 0.45 \n"
"uniform float DiffuseCool;  // 0.45 \n"
"\n"
"varying float NdotL; \n"
"varying vec3  ReflectVec; \n"
"varying vec3  ViewVec; \n"
"\n"
"void main (void) \n"
"{ \n"
"    vec3 kcool    = min(CoolColor + DiffuseCool * SurfaceColor, 1.0); \n"
"    vec3 kwarm    = min(WarmColor + DiffuseWarm * SurfaceColor, 1.0); \n"
"    vec3 kfinal   = mix(kcool, kwarm, NdotL); \n"
"\n"
"    vec3 nreflect = normalize(ReflectVec); \n"
"    vec3 nview    = normalize(ViewVec); \n"
"\n"
"    float spec    = max(dot(nreflect, nview), 0.0); \n"
"    spec          = pow(spec, 32.0); \n"
"\n"
"    gl_FragColor = vec4 (min(kfinal + spec, 1.0), 1.0); \n"
"}";



// OpenGL Vertex Program 1.1
std::string style_vert =
"//The vertex shader\n"
"varying vec3 normalVec;\n"
"varying vec3 vertVec;\n"
"void main()\n"
"{\n"
"	vertVec = gl_Vertex.xyz; \n"
"	normalVec = gl_Normal;\n"
"	gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"}";

// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string style_frag =
"// Pixel shader\n"
"// based on http://www.clockworkcoders.com/oglsl/tutorial10.htm\n"
"\n"
"uniform sampler2D tex;\n"
"uniform vec3 lightPos;\n "
"varying vec3 normalVec; \n"
"varying vec3 vertVec;\n"
"\n"
"void main() \n"
"{ \n"
"   vec4 colorTex = texture2D(tex, vec2(gl_TexCoord[0].st)); \n"
"   vec3 eyePos = lightPos; //second light \n "
"\n"
"   eyePos.y += 1.0; // shifting second light up \n"
"\n"
"   vec3 eyeVec = normalize(eyePos - vertVec); \n"
"	vec3 lightVec = normalize(lightPos - vertVec); \n "
"\n"
"	// Silhouette / outline color: \n"
"	vec4 black = vec4(0.0, 0.0, 0.0, 1.0); \n"
"\n "
"	// Angle for silhouette \n"
"	float s = max(dot(normalVec, eyeVec),0.0); \n"
"	// angle for diffuse light \n"
"	float diffuse = max(dot(normalVec, lightVec), 0.0); \n "
"\n"
"	//Ambient color \n"
"	gl_FragColor = (colorTex)*1.4; \n"
"\n"
"	if (s < 0.25) { \n"
"		gl_FragColor = black; \n"
"	} else { \n"
"	 	// Diffuse part \n"
"	   	if (diffuse < 0.5) { \n"
"	   		gl_FragColor *= 0.4; \n"
"		} \n"
"	    // Specular part \n"
"	   	if (s < 0.9) {\n"
"	   		gl_FragColor *= 0.8;\n"
"		} else { // light is directly above the vertex \n"
"	   		gl_FragColor *= 1.4; // make it very bright \n"
"		} \n"
"   } \n"
"}";



std::string glass_vert =
"varying vec3 fvNormal;\n"
"varying vec3 fvViewVec;\n"
"void main( void )\n"
"{\n"
"	float dist = 0.00087; \n" //maybe this value must be changed depending on the world size
"   gl_Position = ftransform();\n"
"   fvNormal    = gl_NormalMatrix * gl_Normal;\n"
"   fvViewVec = vec3(dist * gl_ModelViewMatrix * gl_Vertex);\n"
"}\n"
;
// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string glass_frag =
"uniform float Alpha; \n"
"varying vec3 fvNormal; \n"
"varying vec3 fvViewVec; \n"
"\n"
"void main( void ) \n"
"{\n"
"  vec4 color; \n"
"  vec4 temp; \n"
"  temp.xyz=-normalize(fvNormal); \n"
"  color.r=temp.r+0.5; \n"
"  color.g=temp.g+0.5; \n"
"  color.b=temp.b+0.5; \n"
"  color.a=Alpha; \n"
"  float t=(1.0-fvViewVec.z)/2.0; \n"
"  if(t<0.0){t=0.0;} \n"
"  gl_FragColor = color; \n"
"}\n"
;




std::string outline_vert =
"#version 330 \n"
"\n"
"layout (location = 0) in vec3 position; \n"
"layout (location = 1) in vec4 normal; \n"
"layout (location = 2) in vec2 uv; \n"
"\n"
"out vec2 vsUV; \n"
"\n"
"void main() \n"
"{ \n"
"   gl_Position = vec4(position, 1.0); \n"
"   vsUV        = (position.xy * 0.5) + 0.5; \n"
"}"
;
// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string outline_frag =
"#version 330 \n"
" \n"
"out vec4 fsColor; \n"
" \n"
"in vec2 vsUV; \n"
" \n"
"uniform vec2 viewportSize; \n"
" \n"
"#define LINE_WEIGHT 4.0 \n"
" \n"
"uniform sampler2D gbufferNormals; \n"
"uniform sampler2D gbufferAlbedo; \n"
"uniform sampler2D gbufferMask; \n"
" \n"
"void main() \n"
"{ \n"
"   float dx = (1.0 / viewportSize.x) * LINE_WEIGHT; \n"
"   float dy = (1.0 / viewportSize.y) * LINE_WEIGHT; \n"
" \n"
"   vec2 uvCenter   = vsUV; \n"
"   vec2 uvRight    = vec2(uvCenter.x + dx, uvCenter.y); \n"
"   vec2 uvTop      = vec2(uvCenter.x,      uvCenter.y - dx); \n"
"   vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx); \n"
" \n"
"   vec3 mCenter   = texture(gbufferNormals, uvCenter).rgb; \n"
"   vec3 mTop      = texture(gbufferNormals, uvTop).rgb; \n"
"   vec3 mRight    = texture(gbufferNormals, uvRight).rgb; \n"
"   vec3 mTopRight = texture(gbufferNormals, uvTopRight).rgb; \n"
" \n"
"   vec3 dT  = abs(mCenter - mTop); \n"
"   vec3 dR  = abs(mCenter - mRight); \n"
"   vec3 dTR = abs(mCenter - mTopRight); \n"
" \n"
"   float dTmax  = max(dT.x, max(dT.y, dT.z)); \n"
"   float dRmax  = max(dR.x, max(dR.y, dR.z)); \n"
"   float dTRmax = max(dTR.x, max(dTR.y, dTR.z)); \n"
"    \n"
"   float deltaRaw = 0.0; \n"
"   deltaRaw = max(deltaRaw, dTmax); \n"
"   deltaRaw = max(deltaRaw, dRmax); \n"
"   deltaRaw = max(deltaRaw, dTRmax); \n"
" \n"
"   // Lower threshold values will discard fewer samples \n"
"   // and give darker/thicker lines. \n"
"   float threshold    = 0.8; \n"
"   float deltaClipped = clamp((deltaRaw * 2.0) - threshold, 0.0, 1.0); \n"
" \n"
"   float oI = deltaClipped; \n"
"   vec4 outline = vec4(oI, oI, oI, 1.0); \n"
"   vec4 albedo  = texture(gbufferAlbedo, vsUV); \n"
"   fsColor = albedo - outline; \n"
"} \n"
;



std::string plastic_vert =
"varying vec3 tnorm; \n"
"varying vec3 lightVec; \n"
"void main(void) \n"
"{ \n"
"   vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex); \n"
"   tnorm = normalize(gl_NormalMatrix * gl_Normal); \n"
"   lightVec = normalize(vec3(gl_ModelViewMatrix * gl_LightSource[0].position) - ecPosition); \n"
"   gl_Position = ftransform(); \n"
"}";

std::string plastic_frag =
"uniform vec4 Color; \n"
"uniform float intensity; \n"
"varying vec3 tnorm; \n"
"varying vec3 lightVec; \n"
"void main(void) \n"
"{ \n"
"   float v = 0.5 * (1.0 + dot(normalize(lightVec), tnorm)); \n"
"   v = pow(v,intensity); \n"
"   gl_FragColor = v * Color; \n"
"}";



std::string tangent_vert =
"uniform mat4 matView; \n"
"uniform float bViewSpace; \n"
" \n"
"varying vec2 TexCoord; \n"
"varying vec3 Normal; \n"
"varying vec3 Binormal; \n"
"varying vec3 Tangent; \n"
" \n"
"//attribute vec3 rm_Binormal; \n"
"//attribute vec3 rm_Tangent; \n"
" \n"
"void main( void ) \n"
"{ \n"
"   mat4 matTransform = mat4( 1.0, 0.0, 0.0, 0.0, \n"
"                             0.0, 1.0, 0.0, 0.0, \n"
"                             0.0, 0.0, 1.0, 0.0, \n"
"                             0.0, 0.0, 0.0, 1.0 ); \n"
" \n"
"   vec3 rm_Tangent = gl_MultiTexCoord1.xyz; \n"
"   vec3 rm_Binormal = -gl_MultiTexCoord2.xyz; \n"
" \n"
"    \n"
"   if( bViewSpace != 0.0 ) \n"
"   { \n"
"      matTransform = matView; \n"
"   } // end if ( bViewSpace ) \n"
" \n"
"   gl_Position = ftransform(); \n"
"   TexCoord    = gl_MultiTexCoord0.xy; \n"
"   Normal      = ( ( matTransform * vec4( gl_Normal.xyz, 1.0 ) ).xyz + 1.0 ) / 2.0; \n"
"   Binormal    = ( ( matTransform * vec4( rm_Binormal.xyz, 1.0 ) ).xyz + 1.0 ) / 2.0; \n"
"   Tangent     = ( ( matTransform * vec4( rm_Tangent.xyz, 1.0 ) ).xyz + 1.0 ) / 2.0; \n"
"    \n"
"} \n"
;

std::string tangent_frag =
"varying vec2 TexCoord; \n"
"varying vec3 Normal; \n"
"varying vec3 Binormal; \n"
"varying vec3 Tangent; \n"
" \n"
"void main( void ) \n"
"{ \n"
"   vec4 color = vec4( 0.0, 0.0, 0.0, 1.0 ); \n"
"    \n"
"   //color.xy  = TexCoord; \n"
"   //color.xyz = Normal; \n"
"   //color.xyz = Binormal; \n"
"   color.xyz = Tangent;    \n"
"    \n"
"   gl_FragColor = color; \n"
"    \n"
"} \n"
;


std::string speaker_vert =
"uniform mat4 view_proj_matrix; \n"
"uniform mat4 view_matrix; \n"
"uniform float time_0_X; \n"
"uniform float pulseSharpness; \n"
"uniform float bassFrequency; \n"
"uniform float amplitude; \n"
"uniform float beat; \n"
" \n"
"varying vec2 vTexCoord; \n"
"varying vec3 vNormalES; \n"
"varying vec3 vViewVec; \n"
"varying vec3 vLightDir; \n"
" \n"
"// Sample offsets to generate the normal \n"
"const vec2 offY = vec2(0.0, 0.1); \n"
"const vec2 offZ = vec2(0.1, 0.0); \n"
" \n"
"// 2 * pi \n"
"const float PI2 = 6.2831853; \n"
" \n"
" \n"
"float getX(vec2 pos, float pulse) \n"
"{ \n"
"   // Speaker shape \n"
"   float d = length(pos); \n"
"   float x = 15.0 * smoothstep(20.0, 25.0, d)  \n"
"            - 0.4 * smoothstep(30.0, 62.0, d) * d; \n"
" \n"
"   // Add the pulse making it stronger towards the center of the speaker \n"
"   return x + pulse * sqrt(80.0 - d); \n"
"} \n"
" \n"
"void main(void) \n"
"{ \n"
"   vec4 Pos = gl_Vertex; \n"
" \n"
"   // Our model isn't centered around origin, so we'll move it \n"
"   // there before doing anything. \n"
"   //Pos.y += 3.0; \n"
"   //Pos.z -= 6.4; \n"
" \n"
"   float t = fract(beat * time_0_X); \n"
" \n"
"   // Create a pulse function, that is. starts from 0, does a \n"
"   // sharp rise to 1 and a less sharp decline back to 0 again, \n"
"   // Using f(t) = t * (1 - t)^p will suit us for this. \n"
"   // We want this curve to reach a value of 1 at its maximum in \n"
"   // the 0 < r < 1 interval. So we'll need to find the maximum \n"
"   // value in this interval, invert and multiply with the curve. \n"
"   // Those interested in math might want to derive the invMax \n"
"   // calculation below themselves by solving for f'(t) = 0 \n"
"   // and inserting into the function. \n"
"   float invMax = (pulseSharpness + 1.0) * pow(1.0 + 1.0 / pulseSharpness, pulseSharpness); \n"
"   float pulse = amplitude * invMax * t * pow(1.0 - t, pulseSharpness); \n"
" \n"
"   // Swing the pulse at a certain frequency \n"
"   pulse *= sin(bassFrequency * PI2 * time_0_X); \n"
" \n"
"   // Sample at three positions ... \n"
"   float x0 = getX(Pos.yz, pulse); \n"
"//#define BOMB \n"
"#ifdef BOMB \n"
"   //float x1 = getX(Pos.yz + offY, pulse); \n"
"   //float x2 = getX(Pos.yz + offZ, pulse); \n"
"    \n"
"#else \n"
"   float d = length(Pos.yz + offY); \n"
"   float x = 15.0 * smoothstep(20.0, 25.0, d) - 0.4 * smoothstep(30.0, 62.0, d) * d; \n"
" \n"
"   // Add the pulse making it stronger towards the center of the speaker \n"
"   float x1 = x + pulse * sqrt(80.0 - d); \n"
"    \n"
"   d = length(Pos.yz + offZ); \n"
"   x = 15.0 * smoothstep(20.0, 25.0, d) - 0.4 * smoothstep(30.0, 62.0, d) * d; \n"
" \n"
"   // Add the pulse making it stronger towards the center of the speaker \n"
"   float x2 = x + pulse * sqrt(80.0 - d); \n"
"#endif \n"
"   //Pos.x = x0; \n"
" \n"
"   // .. then form the tangent and binormal vectors \n"
"   vec3 tangent  = vec3(x1 - x0, offY); \n"
"   vec3 binormal = vec3(x2 - x0, offZ); \n"
" \n"
"   // ... which will give us our normal \n"
"   vec3 normal; \n"
"   //normal = tangent; \n"
"   normal = normalize(cross(tangent, binormal)); \n"
" \n"
"   gl_Position = gl_ModelViewProjectionMatrix * Pos; \n"
"    \n"
"   vTexCoord = 1.0-gl_MultiTexCoord0.yx; \n"
"   // Eye-space lighting \n"
"   vNormalES = gl_NormalMatrix * normal; \n"
"    \n"
"   vViewVec  = -vec3(gl_ModelViewMatrix * Pos); \n"
" \n"
"   vLightDir = vec3(gl_ModelViewMatrix * gl_LightSource[0].position); \n"
"  \n"
"    \n"
" \n"
" \n"
"} \n"
;

std::string speaker_frag =
"//uniform vec4 lightDir; \n"
"uniform sampler2D Base; \n"
" \n"
"varying vec2 vTexCoord; \n"
"varying vec3 vNormalES; \n"
"varying vec3 vViewVec; \n"
"varying vec3 vLightDir; \n"
" \n"
"void main(void) \n"
"{ \n"
" \n"
"   vec4 base = texture2D(Base, vTexCoord); \n"
"   // Make our base texture a little brighter ... \n"
"   // Yes, you're right, this should be done in photoshop rather \n"
"   // than in the shader, but I'm too lazy to make a brighter version \n"
"   // of this texture or even look for a better one. \n"
"   base = sqrt(base); \n"
" \n"
"   // Make the speaker more glossy in the middle \n"
"   vec2 l = vTexCoord - 0.5; \n"
"   float gloss = clamp(1.0 - 6.0 * dot(l, l), 0.0, 1.0); \n"
" \n"
"   vec3 normal = normalize(vNormalES); \n"
"   // Soft diffuse \n"
"   vec3 lightDir = normalize(vLightDir); \n"
"   float diffuse = 0.5 + 0.5 * dot(lightDir, normal); \n"
"   // Standard Phong specular \n"
"   float specular = pow(clamp(dot(reflect(-normalize(vViewVec), normal), lightDir.xyz), 0.0, 1.0), 64.0); \n"
" \n"
"   gl_FragColor = 0.8 * diffuse * base + gloss * specular ; \n"
" \n"
" \n"
"} \n"
;



std::string tx_phong_vert =
"uniform vec3 fvEyePosition; \n"
" \n"
"varying vec2 Texcoord; \n"
"varying vec3 ViewDirection; \n"
"varying vec3 LightDirection; \n"
"varying vec3 Normal; \n"
"    \n"
"void main( void ) \n"
"{ \n"
"   gl_Position = ftransform(); \n"
"   Texcoord    = gl_MultiTexCoord0.xy; \n"
"     \n"
"   vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex; \n"
"    \n"
"   ViewDirection  = fvEyePosition - fvObjectPosition.xyz; \n"
"   LightDirection = (gl_LightSource[0].position).xyz - fvObjectPosition.xyz; \n"
"   Normal         = gl_NormalMatrix * gl_Normal; \n"
"    \n"
"} \n"
;

std::string tx_phong_frag =
"uniform vec4 fvAmbient; \n"
"uniform vec4 fvSpecular; \n"
"uniform vec4 fvDiffuse; \n"
"uniform float fSpecularPower; \n"
" \n"
"uniform sampler2D baseMap; \n"
" \n"
"varying vec2 Texcoord; \n"
"varying vec3 ViewDirection; \n"
"varying vec3 LightDirection; \n"
"varying vec3 Normal; \n"
" \n"
"void main( void ) \n"
"{ \n"
"   vec3  fvLightDirection = normalize( LightDirection ); \n"
"   vec3  fvNormal         = normalize( Normal ); \n"
"   float fNDotL           = dot( fvNormal, fvLightDirection );  \n"
"    \n"
"   vec3  fvReflection     = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection );  \n"
"   vec3  fvViewDirection  = normalize( ViewDirection ); \n"
"   float fRDotV           = max( 0.0, dot( fvReflection, fvViewDirection ) ); \n"
"    \n"
"   vec4  fvBaseColor      = texture2D( baseMap, Texcoord ); \n"
"    \n"
"    \n"
"   vec4  fvTotalAmbient   = gl_LightSource[0].ambient * fvBaseColor;  \n"
"   vec4  fvTotalDiffuse   = gl_LightSource[0].diffuse * fNDotL * fvBaseColor;  \n"
"   vec4  fvTotalSpecular  = gl_LightSource[0].specular * ( pow( fRDotV, fSpecularPower ) ); \n"
" \n"
"   gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular ); \n"
"        \n"
"} \n"
;



// OpenGL Vertex Program 1.1
std::string style2_vert =
"varying vec3 normal;"
"varying vec2 Texcoord;"
"void main()"
"{"
"   Texcoord = gl_MultiTexCoord0.xy;"
"	normal = gl_NormalMatrix * gl_Normal;"
"	gl_Position = ftransform();"
"}";

// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string style2_frag =
"uniform sampler2D baseMap;"
"varying vec3 normal;"
"varying vec2 Texcoord;"
"void main()"
"{"
"   vec4  fvBaseColor = texture2D( baseMap, Texcoord ); "
"	float intensity;"
"	vec4 color;"
"	vec3 n = normalize(normal);"
""
"	intensity = dot(vec3(gl_LightSource[0].position),n);"
""
"	if (intensity > 0.95)"
"		color = vec4(1.0,0.5,0.5,1.0);"
"	else if (intensity > 0.5)"
"		color = vec4(0.6,0.3,0.3,1.0);"
"	else if (intensity > 0.25)"
"		color = vec4(0.4,0.2,0.2,1.0);"
"	else"
"		color = vec4(0.2,0.1,0.1,1.0);"
"	color = color * fvBaseColor; \n"
"	color = normalize(color); \n"
"	gl_FragColor = color;"
"}";




// OpenGL Vertex Program 1.1
std::string style3_vert =
"varying vec3 normal;"
"varying vec2 Texcoord;"
"void main()"
"{"
"   Texcoord = gl_MultiTexCoord0.xy;"
"	normal = gl_NormalMatrix * gl_Normal;"
"	gl_Position = ftransform();"
"}";

// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string style3_frag =
"varying vec3 normal;"
"varying vec2 Texcoord;"
"void main()"
"{"
"	float intensity;"
"	vec4 color;"
"	vec3 n = normalize(normal);"
""
"	intensity = dot(vec3(gl_LightSource[0].position),n);"
""
"	if (intensity > 0.95)"
"		color = vec4(1.0,0.5,0.5,1.0);"
"	else if (intensity > 0.5)"
"		color = vec4(0.6,0.3,0.3,1.0);"
"	else if (intensity > 0.25)"
"		color = vec4(0.4,0.2,0.2,1.0);"
"	else"
"		color = vec4(0.2,0.1,0.1,1.0);"
"	gl_FragColor = color;"
"}";



// OpenGL Vertex Program 1.1
std::string style4_vert =
"varying vec3 vNormal; \n"
"varying vec3 vVertex; \n"
" \n"
"void main(void) \n"
"{ \n"
"   gl_Position = ftransform(); \n"
"   gl_TexCoord[0] = gl_MultiTexCoord0; \n"
"   vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); \n"
"   vNormal = normalize(gl_NormalMatrix * gl_Normal); \n"
"} \n"
;

// --------------------------------------------------------------------------

// OpenGL Fragment Program 1.1
std::string style4_frag =
"varying vec3 vNormal; \n"
"varying vec3 vVertex; \n"
" \n"
"uniform float silhouetteThreshold; \n"
"uniform vec4 silhouetteColor; \n"
"uniform float enableLighting; \n"
" \n"
"uniform sampler2D tex; \n"
" \n"
"void main (void) \n"
"{ \n"
" \n"
"vec4 materialColor = gl_FrontMaterial.diffuse; \n"
" \n"
"    //vec4 silhouetteColor = vec4(1.0, 1.0, 1.0, 1.0); \n"
" \n"
"vec4 specularColor = gl_FrontMaterial.specular; \n"
"    if(enableLighting == 0.0) \n"
"		specularColor = vec4(1.0, 1.0, 1.0, 1.0); \n"
" \n"
"vec3 eyePos = normalize(-vVertex); \n"
"vec3 lightPos = gl_LightSource[0].position.xyz; \n"
" \n"
"vec3 Normal = vNormal; //normalize(vNormal); \n"
"vec3 EyeVert = normalize(eyePos - vVertex); \n"
"vec3 LightVert = normalize(lightPos - vVertex); \n"
"vec3 EyeLight = normalize(LightVert+EyeVert); \n"
"vec4 texture = texture2D(tex,gl_TexCoord[0].st); \n"
" \n"
"   float sil = max(dot(Normal,EyeVert), 0.0); \n"
"   if( sil < silhouetteThreshold ) \n"
"      gl_FragColor = silhouetteColor; \n"
"   else \n"
"   { \n"
"      gl_FragColor = materialColor*texture; \n"
" \n"
"      float spec = pow(max(dot(Normal,EyeLight),0.0), 5.0); \n"
"      if( spec < 0.05 ) \n"
"         gl_FragColor *= 0.9; \n"
"      else \n"
"         gl_FragColor = specularColor*texture; \n"
" \n"
"      float diffuse = max(dot(Normal,LightVert),0.0); \n"
"      if( diffuse < 0.3 && enableLighting != 0.0 ) \n"
"         gl_FragColor *=0.8; \n"
" \n"
"   } \n"
"} \n"
;






#endif // RC_FX_SHADERS_H_INCLUDED
