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

0026571: Visualization, TKOpenGl - write depth values within RayTracing program

View-projection matrix was added to raytrace shaders (as uniform) in order to compute correct depth values for OpenGL.
For path tracing the additional depth buffer sampler was added to Display.fs program. It allows propagation of depth values from internal FBO to resulting FBO.
The old approach of mixing of OpenGL and ray-tracing graphics was kept in order to keep correct blending of transparent ray-traced objects with non-transparent OpenGL objects.
This commit is contained in:
duv
2016-02-29 17:11:34 +03:00
committed by abv
parent 251a79847b
commit 1d8656890c
5 changed files with 83 additions and 15 deletions

View File

@@ -1,6 +1,9 @@
//! Input image.
uniform sampler2D uInputTexture;
//! Ray tracing depth image.
uniform sampler2D uDepthTexture;
//! Output pixel color.
out vec4 OutColor;
@@ -8,6 +11,9 @@ void main (void)
{
vec4 aColor = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);
float aDepth = texelFetch (uDepthTexture, ivec2 (gl_FragCoord.xy), 0).r;
gl_FragDepth = aDepth;
// apply gamma correction (we use gamma = 2)
OutColor = vec4 (sqrt (aColor.rgb), aColor.a);
}

View File

@@ -614,6 +614,7 @@ vec3 intersectLight (in SRay theRay, in bool isViewRay, in int theBounce, in flo
vec4 PathTrace (in SRay theRay, in vec3 theInverse)
{
float anOpenGlDepth = ComputeOpenGlDepth (theRay);
float aRaytraceDepth = MAXFLOAT;
vec3 aRadiance = ZERO;
vec3 aThroughput = UNIT;
@@ -659,11 +660,22 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse)
vec4 aSrcColorRGBA = ComputeOpenGlColor();
aRadiance += aThroughput.xyz * aSrcColorRGBA.xyz;
aThroughput *= aSrcColorRGBA.w;
aDepth = INVALID_BOUNCES; // terminate path
}
theRay.Origin += theRay.Direct * aHit.Time; // get new intersection point
// Evaluate depth
if (aDepth == 0)
{
// Hit point in NDC-space [-1,1] (the polygon offset is applied in the world space)
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin + theRay.Direct * aPolygonOffset, 1.f);
aNDCPoint.xyz *= 1.f / aNDCPoint.w;
aRaytraceDepth = aNDCPoint.z * 0.5f + 0.5f;
}
// fetch material (BSDF)
SMaterial aMaterial = SMaterial (
vec4 (texelFetch (uRaytraceMaterialTexture, MATERIAL_KD (aTriIndex.w))),
@@ -779,6 +791,8 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse)
anOpenGlDepth = MAXFLOAT; // disable combining image with OpenGL output
}
gl_FragDepth = aRaytraceDepth;
return vec4 (aRadiance, 0.f);
}

View File

@@ -36,6 +36,9 @@ uniform vec3 uDirectRB;
//! Inverse model-view-projection matrix.
uniform mat4 uUnviewMat;
//! Model-view-projection matrix.
uniform mat4 uViewMat;
//! Texture buffer of data records of bottom-level BVH nodes.
uniform isamplerBuffer uSceneNodeInfoTexture;
//! Texture buffer of minimum points of bottom-level BVH nodes.
@@ -777,6 +780,7 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
int aTrsfId;
float anOpenGlDepth = ComputeOpenGlDepth (theRay);
float aRaytraceDepth = MAXFLOAT;
for (int aDepth = 0; aDepth < NB_BOUNCES; ++aDepth)
{
@@ -831,6 +835,16 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
theRay.Origin += theRay.Direct * aHit.Time; // intersection point
// Evaluate depth
if (aDepth == 0)
{
// Hit point in NDC-space [-1,1] (the polygon offset is applied in the world space)
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin + theRay.Direct * aPolygonOffset, 1.f);
aNDCPoint.xyz *= 1.f / aNDCPoint.w;
aRaytraceDepth = aNDCPoint.z * 0.5f + 0.5f;
}
vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);
aNormal = normalize (vec3 (dot (aInvTransf0, aNormal),
@@ -970,6 +984,8 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
theRay.Origin += theRay.Direct * uSceneEpsilon;
}
gl_FragDepth = aRaytraceDepth;
return vec4 (aResult.x,
aResult.y,
aResult.z,