"// Handlers and samplers for light sources\n"
"//////////////////////////////////////////////////////////////////////////////////////////////\n"
"\n"
- "// =======================================================================\n"
- "// function : Latlong\n"
- "// purpose : Converts world direction to environment texture coordinates\n"
- "// =======================================================================\n"
- "vec2 Latlong (in vec3 thePoint)\n"
- "{\n"
- " float aPsi = acos (-thePoint.z);\n"
- "\n"
- " float aPhi = atan (thePoint.y, thePoint.x) + M_PI;\n"
- "\n"
- " return vec2 (aPhi * 0.1591549f,\n"
- " aPsi * 0.3183098f);\n"
- "}\n"
- "\n"
"//=======================================================================\n"
"// function : SampleLight\n"
"// purpose : General sampling function for directional and point lights\n"
"\n"
" if (thePDF == 0.f && theHitDistance == MAXFLOAT) // light source not found\n"
" {\n"
- " if (theDepth + uSphereMapForBack == 0) // view ray and map is hidden\n"
+ " if (theDepth + uEnvMapForBack == 0) // view ray and map is hidden\n"
" {\n"
" aTotalRadiance = BackgroundColor().rgb;\n"
" }\n"
" else\n"
" {\n"
- " aTotalRadiance = FetchEnvironment (Latlong (theRay.Direct)).rgb;\n"
+ " #ifdef BACKGROUND_CUBEMAP\n"
+ " if (theDepth == 0)\n"
+ " {\n"
+ " vec2 aPixel = uEyeSize * (vPixel - vec2 (0.5)) * 2.0;\n"
+ " vec2 anAperturePnt = sampleUniformDisk() * uApertureRadius;\n"
+ " vec3 aLocalDir = normalize (vec3 (aPixel * uFocalPlaneDist - anAperturePnt, uFocalPlaneDist));\n"
+ " vec3 aDirect = uEyeView * aLocalDir.z +\n"
+ " uEyeSide * aLocalDir.x +\n"
+ " uEyeVert * aLocalDir.y;\n"
+ " aTotalRadiance = FetchEnvironment (aDirect, 1.0, true).rgb;\n"
+ " }\n"
+ " else\n"
+ " {\n"
+ " aTotalRadiance = FetchEnvironment (theRay.Direct, 1.0, false).rgb;\n"
+ " }\n"
+ " #else\n"
+ " aTotalRadiance = FetchEnvironment (theRay.Direct, 1.0, theDepth == 0).rgb;\n"
+ " #endif\n"
" }\n"
" #ifdef THE_SHIFT_sRGB\n"
" aTotalRadiance = pow (aTotalRadiance, vec3 (2.f));\n"