1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +03:00

0030640: Visualization, Graphic3d_Camera - add option creating Projection matrix with [0,1] depth range

Added new property Graphic3d_Camera::IsZeroToOneDepth() and OpenGl_Caps::useZeroToOneDepth
for activating [0,1] depth range instead of [-1,1] range using glClipControl() within OpenGL 4.5+.
This commit is contained in:
kgv
2021-03-03 14:58:46 +03:00
committed by bugmaster
parent 395d00e058
commit e70625d6b1
25 changed files with 226 additions and 71 deletions

View File

@@ -16,7 +16,12 @@ float occDirectionalLightShadow (in sampler2D theShadow,
{
vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];
vec3 aLightDir = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 0.0));
vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w) * 0.5 + vec3 (0.5);
vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);
#ifdef THE_ZERO_TO_ONE_DEPTH
aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);
#else
aProjCoords = aProjCoords * 0.5 + vec3 (0.5);
#endif
float aCurrentDepth = aProjCoords.z;
if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0
|| aProjCoords.y < 0.0 || aProjCoords.y > 1.0

View File

@@ -820,7 +820,11 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);
float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);
#ifdef THE_ZERO_TO_ONE_DEPTH
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);
#else
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;
#endif
}
SBSDF aBSDF;

View File

@@ -1082,7 +1082,11 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);
float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);
#ifdef THE_ZERO_TO_ONE_DEPTH
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);
#else
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;
#endif
}
vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);

View File

@@ -19,7 +19,12 @@ static const char Shaders_DirectionalLightShadow_glsl[] =
"{\n"
" vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];\n"
" vec3 aLightDir = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 0.0));\n"
" vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w) * 0.5 + vec3 (0.5);\n"
" vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);\n"
"#ifdef THE_ZERO_TO_ONE_DEPTH\n"
" aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);\n"
"#else\n"
" aProjCoords = aProjCoords * 0.5 + vec3 (0.5);\n"
"#endif\n"
" float aCurrentDepth = aProjCoords.z;\n"
" if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0\n"
" || aProjCoords.y < 0.0 || aProjCoords.y > 1.0\n"

View File

@@ -823,7 +823,11 @@ static const char Shaders_PathtraceBase_fs[] =
" vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);\n"
"\n"
" float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);\n"
" #ifdef THE_ZERO_TO_ONE_DEPTH\n"
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);\n"
" #else\n"
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;\n"
" #endif\n"
" }\n"
"\n"
" SBSDF aBSDF;\n"

View File

@@ -1085,7 +1085,11 @@ static const char Shaders_RaytraceBase_fs[] =
" vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);\n"
"\n"
" float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);\n"
" #ifdef THE_ZERO_TO_ONE_DEPTH\n"
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);\n"
" #else\n"
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;\n"
" #endif\n"
" }\n"
"\n"
" vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);\n"