/*---------------------------------------------------------------------------* Copyright 2010-2011 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ varying vec2 v_texCoord; uniform vec3 u_ambientColor; uniform vec4 u_lightColor; uniform vec3 u_lightPosition; uniform vec3 u_cameraPosition; uniform sampler2D s_diffuse; uniform sampler2D s_normal; uniform sampler2D s_position; void main() { vec4 diffuse = texture2D(s_diffuse, v_texCoord); vec4 norm = texture2D(s_normal, v_texCoord); vec3 pos = texture2D(s_position, v_texCoord).xyz; if(norm.w == 0.0) { discard; } vec3 normal = normalize(norm.xyz); vec3 lightDir = normalize(u_lightPosition - pos); vec3 ambientCol = u_ambientColor * diffuse.rgb; float strength = u_lightColor.a * 255.0 / distance(pos, u_lightPosition); vec3 diffuseCol = u_lightColor.rgb * strength * diffuse.rgb; vec3 specularCol = diffuse.a * u_lightColor.rgb; vec3 refl = reflect(lightDir, normal); vec3 toViewer = normalize(pos - u_cameraPosition); float shininess = diffuse.a * 255.0; gl_FragColor = vec4(ambientCol + diffuseCol * max(0.0, dot(normal, lightDir)) + specularCol * pow(max(0.0, dot(refl, toViewer)), shininess), 1.0); }