}
// temp
- if (__pLight == null)
+ if (__pMesh->IsNormalEnabled())
{
- __pLight = new (std::nothrow) _Light();
+ if (__pLight == null)
+ {
+ __pLight = new (std::nothrow) _Light();
- __objectColor.SetRGBAColor(0.0f, 0.0f, 1.0f, 1.0f);
+ __objectColor.SetRGBAColor(0.0f, 0.0f, 1.0f, 1.0f);
- __pLight->__type = _Light::LIGHT_TYPE_DIRECTIONAL;
+ __pLight->__type = _Light::LIGHT_TYPE_SPOT;
- __pLight->__ambient[0] = 0.2f;
- __pLight->__ambient[1] = 0.2f;
- __pLight->__ambient[2] = 0.2f;
- __pLight->__ambient[3] = 1.0f;
+ __pLight->__ambient[0] = 0.0f;
+ __pLight->__ambient[1] = 0.0f;
+ __pLight->__ambient[2] = 0.0f;
+ __pLight->__ambient[3] = 1.0f;
- __pLight->__diffuse[0] = 0.8f;
- __pLight->__diffuse[1] = 0.0f;
- __pLight->__diffuse[2] = 0.0f;
- __pLight->__diffuse[3] = 1.0f;
+ __pLight->__diffuse[0] = 1.0f;
+ __pLight->__diffuse[1] = 1.0f;
+ __pLight->__diffuse[2] = 1.0f;
+ __pLight->__diffuse[3] = 1.0f;
- __pLight->__specular[0] = 0.0f;
- __pLight->__specular[1] = 0.0f;
- __pLight->__specular[2] = 1.0f;
- __pLight->__specular[3] = 1.0f;
+ __pLight->__specular[0] = 1.0f;
+ __pLight->__specular[1] = 1.0f;
+ __pLight->__specular[2] = 1.0f;
+ __pLight->__specular[3] = 1.0f;
- __pLight->__position[0] = 1.0f;
- __pLight->__position[1] = -1.0f;
- __pLight->__position[2] = 1.0f;
- __pLight->__position[3] = 0.0f;
- }
+ __pLight->__position[0] = 360.0f; //0.0f;
+ __pLight->__position[1] = 400.0f; //0.0f;
+ __pLight->__position[2] = 1000.0f; //1.0f;
+ __pLight->__position[3] = 0.0f;
- if (__pMaterial == null)
- {
- __pMaterial = new (std::nothrow) _Material();
+ __pLight->__direction[0] = 0.0f;
+ __pLight->__direction[1] = 0.0f;
+ __pLight->__direction[2] = -1.0f;
- __pMaterial->__ambient[0] = 1.0f;
- __pMaterial->__ambient[1] = 1.0f;
- __pMaterial->__ambient[2] = 1.0f;
- __pMaterial->__ambient[3] = 1.0f;
+ __pLight->__exponent = 5.0f; //0.0f;
+ __pLight->__cutOff = 150.0f; //180.0f;
- __pMaterial->__diffuse[0] = 1.0f;
- __pMaterial->__diffuse[1] = 1.0f;
- __pMaterial->__diffuse[2] = 1.0f;
- __pMaterial->__diffuse[3] = 1.0f;
+ __pLight->__attenuation[0] = 1.0f;
+ __pLight->__attenuation[1] = 0.0f;
+ __pLight->__attenuation[2] = 0.0f;
+ }
- __pMaterial->__specular[0] = 1.0f;
- __pMaterial->__specular[1] = 1.0f;
- __pMaterial->__specular[2] = 1.0f;
- __pMaterial->__specular[3] = 1.0f;
+ if (__pMaterial == null)
+ {
+ __pMaterial = new (std::nothrow) _Material();
- __pMaterial->__emissive[0] = 0.0f;
- __pMaterial->__emissive[1] = 0.0f;
- __pMaterial->__emissive[2] = 0.0f;
- __pMaterial->__emissive[3] = 0.0f;
+ __pMaterial->__ambient[0] = 0.2f;
+ __pMaterial->__ambient[1] = 0.2f;
+ __pMaterial->__ambient[2] = 0.2f;
+ __pMaterial->__ambient[3] = 1.0f;
- __pMaterial->__shiness = 10.0f;
+ __pMaterial->__diffuse[0] = 0.8f;
+ __pMaterial->__diffuse[1] = 0.8f;
+ __pMaterial->__diffuse[2] = 0.8f;
+ __pMaterial->__diffuse[3] = 1.0f;
+
+ __pMaterial->__specular[0] = 1.0f; //0.0f;
+ __pMaterial->__specular[1] = 1.0f; //0.0f;
+ __pMaterial->__specular[2] = 1.0f; //0.0f;
+ __pMaterial->__specular[3] = 1.0f;
+
+ __pMaterial->__emissive[0] = 0.0f;
+ __pMaterial->__emissive[1] = 0.0f;
+ __pMaterial->__emissive[2] = 0.0f;
+ __pMaterial->__emissive[3] = 1.0f;
+
+ __pMaterial->__shiness = 0.0f;
+ }
+ }
+ else
+ {
+ if (__pLight)
+ {
+ delete __pLight;
+ __pLight = null;
+ }
+
+ if (__pMaterial)
+ {
+ delete __pMaterial;
+ __pMaterial = null;
+ }
}
}
else
"{\n"
" vec3 lightdir, n, h;\n"
" vec4 color = vec4(c_zero, c_zero, c_zero, c_zero);\n"
- " float ndotl, ndoth;\n"
+ " float ndotl, ndoth, attenuation;\n"
"\n"
" n = normalize((u_inv_modelview * vec4(a_normal, 1.0)).xyz);\n"
"\n"
" if (u_light.type < 2)\n"
" {\n"
- " vec3 att_dist;\n"
+ " vec3 distance;\n"
+ " float spot_factor;\n"
"\n"
" // point or spot case\n"
" lightdir = u_light.position.xyz - (u_modelview * a_position).xyz;\n"
"\n"
" // compute distance attenuation\n"
- " // TODO\n"
+ " distance.x = c_one;\n"
+ " distance.z = dot(lightdir, lightdir);\n"
+ " distance.y = sqrt(distance.z);\n"
+ "\n"
+ " attenuation = c_one / dot(distance, u_light.attenuation);"
"\n"
" lightdir = normalize(lightdir);\n"
"\n"
" if (u_light.cutoff < 180.0)\n"
" {\n"
" // compute spot factor\n"
- " // TODO\n"
+ " spot_factor = dot(-lightdir, normalize(u_light.direction));\n"
+ "\n"
+ " if (spot_factor >= cos(radians(u_light.cutoff)))\n"
+ " spot_factor = pow(spot_factor, u_light.exponent);\n"
+ " else\n"
+ " spot_factor = c_zero;\n"
+ "\n"
+ " attenuation *= spot_factor;\n"
" }\n"
" }\n"
" else\n"
" {\n"
- " lightdir = u_light.position.xyz;\n"
+ " // directional light\n"
+ " lightdir = normalize(u_light.position.xyz);\n"
+ " attenuation = c_one;\n"
" }\n"
"\n"
- "// if (attenuation > c_zero) // TODO: enable\n"
+ " if (attenuation > c_zero)\n"
" {\n"
" color = u_light.ambient * u_material.ambient;\n"
"\n"
" color += pow(ndoth, u_material.shiness) * u_material.specular * u_light.specular;\n"
" }\n"
"\n"
- "// color *= att_factor; // TODO: enable\n"
+ " color *= attenuation;\n"
" }\n"
"\n"
" color += u_material.emissive;\n"
"varying vec4 v_color;\n"
"void main()\n"
"{\n"
- " gl_FragColor.rgba = v_color;\n"
- "// gl_FragColor.rgba = texture2D(u_tex2d, v_texcoord).bgra * v_color;\n"
+ " gl_FragColor.rgba = texture2D(u_tex2d, v_texcoord).bgra * v_color;\n"
"}\n";
// CHECK