From: mzernova Date: Mon, 13 Jan 2020 07:21:10 +0000 (+0300) Subject: 0031279: Visualization, TKOpenGl - environment background is misplaced within Ray... X-Git-Tag: V7_5_0_beta~166 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=832a6f4412321ca784bbb36916dc740d04a05c0c 0031279: Visualization, TKOpenGl - environment background is misplaced within Ray-Tracing Fixed problem with misplacing background texture in Ray-Tracing. An environment background is always drawn using a perspective matrix. --- diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 73eb9a3b5b..c42998f373 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -2545,6 +2545,20 @@ Standard_Boolean OpenGl_View::setUniformState (const Standard_Integer the aDirects, aViewPrjMat, anUnviewMat); + + if (myRenderParams.UseEnvironmentMapBackground + || myRaytraceParameters.CubemapForBack) + { + OpenGl_Mat4 aTempMat; + OpenGl_Mat4 aTempInvMat; + updatePerspCameraPT (myCamera->OrientationMatrixF(), + aCntxProjectionState.Current(), + theProjection, + aTempMat, + aTempInvMat, + theWinSizeX, + theWinSizeY); + } } else { diff --git a/src/Shaders/RaytraceBase.fs b/src/Shaders/RaytraceBase.fs index 0c7ead83ca..c2b6ca4e70 100644 --- a/src/Shaders/RaytraceBase.fs +++ b/src/Shaders/RaytraceBase.fs @@ -1023,6 +1023,7 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse) int aTrsfId; float aRaytraceDepth = MAXFLOAT; + float aRefractionIdx = 0.0; for (int aDepth = 0; aDepth < NB_BOUNCES; ++aDepth) { @@ -1034,11 +1035,30 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse) { vec4 aColor = vec4 (0.0); - if (bool(uEnvMapForBack) || aWeight.w == 0.0f /* reflection */) + if (bool(uEnvMapForBack) || aWeight.w == 0.0 /* reflection */) { - float aTime = IntersectSphere (theRay, uSceneRadius); + float aRadius = uSceneRadius; + vec3 aTexCoord = vec3 (0.0); - aColor = FetchEnvironment (theRay.Direct * aTime + theRay.Origin, uSceneRadius, aWeight.w != 0.0); + if (aDepth == 0 || (aRefractionIdx == 1.0 && aWeight.w != 0.0)) + { + vec2 aPixel = uEyeSize * (vPixel - vec2 (0.5)) * 2.0; + vec2 anAperturePnt = sampleUniformDisk() * uApertureRadius; + vec3 aLocalDir = normalize (vec3 (aPixel * uFocalPlaneDist - anAperturePnt, uFocalPlaneDist)); + vec3 aDirect = uEyeView * aLocalDir.z + + uEyeSide * aLocalDir.x + + uEyeVert * aLocalDir.y; + + aTexCoord = aDirect * uSceneRadius; + aRadius = length (aTexCoord); + } + else + { + float aTime = IntersectSphere (theRay, uSceneRadius); + aTexCoord = theRay.Direct * aTime + theRay.Origin; + } + + aColor = FetchEnvironment (aTexCoord, aRadius, aWeight.w != 0.0); } else { @@ -1167,6 +1187,7 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse) if (aOpacity.x != 1.0f) { aWeight *= aOpacity.y; + aRefractionIdx = aOpacity.z; if (aOpacity.z != 1.0f) { diff --git a/src/Shaders/Shaders_RaytraceBase_fs.pxx b/src/Shaders/Shaders_RaytraceBase_fs.pxx index 63f44e1a69..942d9f64e5 100644 --- a/src/Shaders/Shaders_RaytraceBase_fs.pxx +++ b/src/Shaders/Shaders_RaytraceBase_fs.pxx @@ -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" diff --git a/tests/v3d/raytrace/bug31279 b/tests/v3d/raytrace/bug31279 new file mode 100644 index 0000000000..8bf7a934e5 --- /dev/null +++ b/tests/v3d/raytrace/bug31279 @@ -0,0 +1,18 @@ +puts "============" +puts "0031279: Visualization, TKOpenGl - environment background is misplaced within Ray-Tracing" +puts "============" +puts "" + +source $env(CSF_OCCTSamplesPath)/tcl/raytrace.tcl +vrenderparams -env +vcamera -persp +vviewparams -scale 1.3 -proj 0.57 -0.57 0.57 -up -0.4 0.4 0.8 -at -62 -111 -15 +vtextureenv on 1 + +if { [vreadpixel 100 100 rgb name] == "BLACK" } { puts "ERROR: background is misplaced" } + +vcamera -persp +vdump $imagedir/${casename}_persp.png + +vcamera -ortho +vdump $imagedir/${casename}_ortho.png \ No newline at end of file