1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

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.
This commit is contained in:
mzernova
2020-01-13 10:21:10 +03:00
committed by bugmaster
parent 4e8371cb1f
commit 832a6f4412
4 changed files with 80 additions and 6 deletions

View File

@@ -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
{

View File

@@ -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)
{

View 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"