vec3 lightPos = {x: 0, y: 2, z: 0}; vec3 lightCol = {r: 1.0, g: 0.8, b: 0.9}; 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); return comboMat.xform(vec4(inPos.x, inPos.y, inPos.z, 1)); } else return vec4.zero; } void pixelShader( 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 = 2f * (normDotLight) * inNorm - toLight; float specular = refl.dot(toEye); if (specular < 0) specular = 0; // poor man's power function specular *= specular; specular *= specular; specular *= 2.5f; float fresnel = 1f + toEye.dot(inNorm); fresnel *= fresnel; fresnel = 0.9f / (fresnel * fresnel); if (fresnel > 0.9) fresnel = 0.9; float diffuse = normDotLight; if (diffuse < 0f) diffuse = 0f; 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 * (diffuse + specular + fresnel)); }}