//vec3 lightPos = {x: 20, y: 8, z: -32}; vec3 lightPos = {x: 0, y: 2, z: 0}; vec3 lightCol = {r: 1.0, g: 0.8, b: 0.9}; /+vec3 light2Pos = {x: 0, y: 2, z: 0.2}; vec3 light2Col = {r: 1, g: 0.8, b: 0};+/ vec4 vertexShader( in attr!(vec3, `positions`) inPos, in attr!(vec3, `normals`) inNorm, in attr!(vec3, `texCoords`) inTC, out vec3 toLight, out vec3 norm, out vec3 toEye, out vec2 outTC) { static if (compute) { inNorm = modelMat.rotate(inNorm); norm = inNorm; toLight = lightPos - modelMat.xform(inPos); toLight.normalize(); toEye = viewerPosition - modelMat.xform(inPos); toEye.normalize(); outTC = vec2(inTC.x, inTC.y);//vec2(inPos.x, inPos.y); return comboMat.xform(vec4(inPos.x, inPos.y, inPos.z, 1)); } else return vec4.zero; } void pixelShader( //in vec3 col, in vec3 toLight, in vec3 inNorm, in vec3 toEye, in vec2 texCoord, out Color output) { static if (compute) { inNorm.normalize(); toLight.normalize(); toEye.normalize(); float normDotLight = inNorm.dot(toLight); vec3 refl = 2 * (normDotLight) * inNorm - toLight; float specular = refl.dot(toEye); if (specular < 0) specular = 0; // poor man's power function specular = specular * specular; specular = specular * specular; specular -= specular * cbrt(cbrt(cbrt(specular))) * 0.995; specular *= 22.5f; float fresnel = 1 + toEye.dot(inNorm); fresnel *= fresnel; fresnel = .25f / (fresnel * fresnel); if (fresnel > .25f) fresnel = .25f; float diffuse = normDotLight; if (diffuse < 0) diffuse = 0; vec3ub tex = tex2Dlinear(0, texCoord); vec3 diffCol = vec3( lightCol.r * tex.r * (1.f/255.f), lightCol.g * tex.g * (1.f/255.f), lightCol.b * tex.b * (1.f/255.f)); output = vec3ToColor(diffCol * 1.5f * (diffuse * 0.08 + specular + fresnel)); }}