/* uniform int base_texture_ID; uniform int detail_texture_ID; uniform int normal_texture_ID; */ uniform sampler2D base_texture; uniform sampler2D detail_texture; uniform sampler2D normal_texture; uniform sampler2DShadow shadow_texture; uniform int NumEnabledLights; varying vec3 light_dir; /* void main(void) { vec3 normal, texture, detail; normal = texture2D(normal_texture, vec2(gl_TexCoord[3])).rgb; normal = gl_NormalMatrix * normalize(normal * 2.0f - 1.0f); texture = vec3(texture2D(base_texture, vec2(gl_TexCoord[0]))); detail = vec3(texture2D(detail_texture, vec2(gl_TexCoord[1]))); // shadow = vec3(texture2D(base_texture, vec2(gl_TexCoord[1]))); gl_FragColor.rgb = max(dot(normal, normalize(light_dir)), 0.0f)*texture*detail; // gl_FragColor.rgb = texture*detail; // gl_FragColor.rgb = normal; // gl_FragColor.rgb = light_dir; } */ varying vec3 eyepos; void DirectionalLight(in int i, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) { float nDotVP; float nDotHV; float pf; nDotVP = max(0.0, dot(normal, normalize(vec3(gl_LightSource[i].position)))); nDotHV = max(0.0, dot(normal, normalize(vec3(gl_LightSource[i].halfVector)))); if (nDotVP == 0.0) pf = 0.0; else pf = pow(nDotHV, gl_FrontMaterial.shininess); ambient += gl_LightSource[i].ambient; diffuse += gl_LightSource[i].diffuse * nDotVP; specular += gl_LightSource[i].specular * pf; } void PointLight(in int i, in vec3 eye, in vec3 ecPosition3, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) { float nDotVP; float nDotHV; float pf; float attenuation; float d; vec3 VP; vec3 halfVector; VP = vec3(gl_LightSource[i].position - ecPosition3); d = length(VP); VP = normalize(VP); attenuation = 1.0 / max( gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d, 0); halfVector = normalize(VP + eye); nDotVP = max(0.0, dot(normal, VP)); nDotHV = max(0.0, dot(normal, halfVector)); if (nDotVP == 0.0) pf = 0.0; else pf = pow(nDotHV, gl_FrontMaterial.shininess); ambient += gl_LightSource[i].ambient; diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; specular += gl_LightSource[i].specular * pf * attenuation; } void SpotLight(in int i, in vec3 eye, in vec3 ecPosition3, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) { float nDotVP; float nDotHV; float pf; float spotDot; float spotAttenuation; float attenuation; float d; vec3 VP; vec3 halfVector; VP = vec3(gl_LightSource[i].position - ecPosition3); d = length(VP); VP = normalize(VP); attenuation = 1.0 / ( gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d); spotDot = dot(-VP, gl_LightSource[i].spotDirection); if (spotDot < gl_LightSource[i].spotCosCutoff) spotAttenuation = 0.0; else spotAttenuation = pow(spotDot, gl_LightSource[i].spotExponent); attenuation *= spotAttenuation; halfVector = normalize(VP + eye); nDotVP = max(0.0, dot(normal, VP)); nDotHV = max(0.0, dot(normal, halfVector)); if (nDotVP == 0.0) pf = 0.0; else pf = pow(nDotHV, gl_FrontMaterial.shininess); ambient += gl_LightSource[i].ambient; diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; specular += gl_LightSource[i].specular * pf * attenuation; } void PointLight_2(in int i, in vec3 ecPosition3, in vec3 normal, inout vec4 diffuse) { float nDotVP; float attenuation; float d; vec3 VP; vec3 halfVector; VP = vec3(gl_LightSource[i].position - ecPosition3); d = length(VP); VP = normalize(VP); d = max(min(d, 5), 0.01); attenuation = 1.0 / ( //gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d); nDotVP = max(0.0, dot(normal, VP)); diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation; } varying vec4 light; void main(void) { vec3 normal; vec4 texture, base, detail; normal = texture2D(normal_texture, vec2(gl_TexCoord[3])).rgb; normal = gl_NormalMatrix * normalize(normal * 2.0f - 1.0f); base = vec4(texture2D(base_texture, vec2(gl_TexCoord[0]))); detail = vec4(texture2D(detail_texture, vec2(gl_TexCoord[1]))); // base = vec4(texture2D(base_texture, vec2(gl_TexCoord[1]))); // if ( texture = base;//*0.75+detail*0.25; vec3 eye; bool LocalViewer; LocalViewer = false; if (LocalViewer) eye = -normalize(eyepos); else eye = vec3(0.0, 0.0, 1.0); vec4 amb, diff, spec; int i; amb = vec4(0.0); diff = vec4(0.0); spec = vec4(0.0); amb = gl_LightSource[7].ambient; if (NumEnabledLights >= 0) PointLight_2(0, eyepos, normal, diff); if (NumEnabledLights >= 1) PointLight_2(1, eyepos, normal, diff); if (NumEnabledLights >= 2) PointLight_2(2, eyepos, normal, diff); if (NumEnabledLights >= 3) PointLight_2(3, eyepos, normal, diff); if (NumEnabledLights >= 4) PointLight_2(4, eyepos, normal, diff); if (NumEnabledLights >= 5) PointLight_2(5, eyepos, normal, diff); if (NumEnabledLights >= 6) PointLight_2(6, eyepos, normal, diff); // gl_FragColor.rgb = texture*light;//texture*(diff+amb);//texture*diff*6;//*gl_FrontMaterial.ambient+diff*gl_FrontMaterial.diffuse+spec*gl_FrontMaterial.specular+gl_FrontLightModelProduct.sceneColor); gl_FragColor = texture*light; // if (NumEnabledLights >= 1) amb.r = 0.5; /* if (NumEnabledLights == 2) amb.g = 0.5; if (NumEnabledLights == 3) amb.b = 0.5; if (NumEnabledLights == 4) amb.r = 1.0; if (NumEnabledLights == 5) amb.g = 1.0; if (NumEnabledLights == 6) amb.b = 1.0; */ // gl_FragColor.rgb = amb; // gl_FragColor.rgb = vec3((NumEnabledLights+1)/8.0);//max(dot(normal, normalize(light_dir)), 0.0f)*texture; }