0031279: Visualization, TKOpenGl - environment background is misplaced within Ray...
[occt.git] / src / Shaders / Shaders_RaytraceBase_fs.pxx
index 63f44e1..942d9f6 100644 (file)
@@ -1026,6 +1026,7 @@ static const char Shaders_RaytraceBase_fs[] =
   "  int aTrsfId;\n"
   "\n"
   "  float aRaytraceDepth = MAXFLOAT;\n"
+  "  float aRefractionIdx = 0.0;\n"
   "\n"
   "  for (int aDepth = 0; aDepth < NB_BOUNCES; ++aDepth)\n"
   "  {\n"
@@ -1037,11 +1038,30 @@ static const char Shaders_RaytraceBase_fs[] =
   "    {\n"
   "      vec4 aColor = vec4 (0.0);\n"
   "\n"
-  "      if (bool(uEnvMapForBack) || aWeight.w == 0.0f /* reflection */)\n"
+  "      if (bool(uEnvMapForBack) || aWeight.w == 0.0 /* reflection */)\n"
   "      {\n"
-  "        float aTime = IntersectSphere (theRay, uSceneRadius);\n"
+  "        float aRadius = uSceneRadius;\n"
+  "        vec3 aTexCoord = vec3 (0.0);\n"
   "\n"
-  "        aColor = FetchEnvironment (theRay.Direct * aTime + theRay.Origin, uSceneRadius, aWeight.w != 0.0);\n"
+  "        if (aDepth == 0 || (aRefractionIdx == 1.0 && aWeight.w != 0.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"
+  "          \n"
+  "          aTexCoord = aDirect * uSceneRadius;\n"
+  "          aRadius = length (aTexCoord);\n"
+  "        }\n"
+  "        else\n"
+  "        {\n"
+  "          float aTime = IntersectSphere (theRay, uSceneRadius);\n"
+  "          aTexCoord = theRay.Direct * aTime + theRay.Origin;\n"
+  "        }\n"
+  "\n"
+  "        aColor = FetchEnvironment (aTexCoord, aRadius, aWeight.w != 0.0);\n"
   "      }\n"
   "      else\n"
   "      {\n"
@@ -1170,6 +1190,7 @@ static const char Shaders_RaytraceBase_fs[] =
   "    if (aOpacity.x != 1.0f)\n"
   "    {\n"
   "      aWeight *= aOpacity.y;\n"
+  "      aRefractionIdx = aOpacity.z;\n"
   "\n"
   "      if (aOpacity.z != 1.0f)\n"
   "      {\n"