/******************************************************************************* * * Simple GLSL FX file * *******************************************************************************/ #pragma language GLSL // un-tweakables // structures and shaders ///////////////////// uniform float sparkScale = 16.0; varying vec3 eyeNormal; varying vec3 eyeView; varying vec2 texCoord; void mainVS() { // Must write gl_Position for rasterization to be defined.... // gl_Position = ftransform(); // Transform to shading space (we are going to shade in eyespace) // // eyeNormal = gl_NormalMatrix * gl_Normal; eyeView = -vec3(gl_ModelViewMatrix * gl_Vertex); texCoord = gl_MultiTexCoord0.st * sparkScale; } //sparkles texture to perturb the normals uniform sampler2D sparkleTex; //cubic environment map uniform samplerCube envMap; //parameter to control the reflection falloff, 0.33 typically looks pretty good uniform float reflFalloff = 0.33; //how strong the spaks are at bending the normals, 0.0625 looks fairly good uniform float sparkStrength = 0.625; //ambient lighting uniform vec3 ambient = vec3( 0.2, 0.2, 0.2); uniform vec3 lightDir = vec3( 0.57735, 0.57735, 0.57735); uniform vec3 lightColor = vec3( 1.0, 1.0, 1.0); uniform vec3 carColor = vec3(0.0, 0.5, -0.70); /* //candy apple green uniform vec3 carColor0 = vec3(0.0, 0.2, 0.70); uniform vec3 carColor1 = vec3(0.0, 0.5, -0.70); uniform vec3 carColor2 = vec3(0.1, 0.0, -0.1); uniform vec3 sparkleColor = vec3(0.7, 0.2, 0.0); */ /* //orange to red const vec3 carColor0 = vec3(0.40, 0.4, -0.40); const vec3 carColor1 = vec3(0.0, -0.43, 0.40); const vec3 carColor2 = vec3(1.0, 0.05, 0.18); const vec3 sparkleColor = vec3(-0.4, 0.5, -0.70); */ /* // cool gold const vec3 carColor0 = vec3(0.70, -0.09, 0.00); const vec3 carColor1 = vec3(0.20, 0.23, 0.00); const vec3 carColor2 = vec3(0.20, 0.75, 0.08); const vec3 sparkleColor = vec3(-0.2, 0.2, 0.20); */ /* //intense copper const vec3 carColor0 = vec3(0.40, 0.0, 0.00); const vec3 carColor1 = vec3(0.60, 0.1, 0.00); const vec3 carColor2 = vec3(-0.5, 0.15, -0.35); const vec3 sparkleColor = vec3(0.2, 0.3, 0.5); */ uniform float clearCoatShininess = 32.0; uniform float paintShininess = 2.0; void mainPS() { vec3 light = normalize( lightDir); vec3 normal = normalize(eyeNormal); //fetch the sparkle texture vec4 sparkle1 = texture2D(sparkleTex, texCoord); //normalize the view vector vec3 view=normalize(eyeView); //compute the reflection vector vec3 reflection = -reflect( view, normal); float nDotV = clamp(dot(view,normal), 0.0, 1.0); vec3 sparkNorm = normalize( normal + vec3( sparkle1*2.0 - 1.0) * sparkStrength); vec3 sparkRefl = -reflect( view, sparkNorm); //compute the illumination, this is a sumation of two specular lobes vec3 color = vec3(pow(max(0.0,dot(sparkRefl,light)), clearCoatShininess))*lightColor.rgb; color += carColor * (vec3(pow(max(0.0,dot(sparkRefl,light)), paintShininess)*pow(nDotV,reflFalloff))*lightColor.rgb+ambient.rgb); //apply the clearcoat with a fresnel term color = vec3(textureCube(envMap,reflection))*(1.0-pow(nDotV,reflFalloff))+color;//*nDotV; gl_FragColor = vec4(color,1.0); } //////// techniques //////////////////////////// technique blinn { pass p0 { VertexShader = compile vs_2_0 mainVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LEqual; CullMode = Back; PixelShader = compile ps_2_0 mainPS(); } }