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

0028762: Visualization, Ray tracing - Implement depth-of-field effect

Graphic3d_RenderingParams - introduced new parameters CameraFocalPlaneDist and CameraApertureRadius managing DOF effect.
TKOpenGl - added new ray generation logic to RaytraceBase.fs.
vrenderparams command - added -focal and -aperture parameters.
OpenGl_View.hxx - function for ray generating was split into two functions (ray tracing and path tracing).
OpenGl_View_Raytrace.cxx - fixed interaction between adaptive sampling and stereo camera
This commit is contained in:
duv
2017-06-27 11:22:31 +03:00
committed by bugmaster
parent 475c2302d4
commit b27ab03d09
9 changed files with 588 additions and 45 deletions

View File

@@ -108,6 +108,27 @@ uniform vec4 uBackColorTop = vec4 (0.0);
//! Bottom color of gradient background.
uniform vec4 uBackColorBot = vec4 (0.0);
//! Aperture radius of camera used for depth-of-field
uniform float uApertureRadius = 0.f;
//! Focal distance of camera used for depth-of field
uniform float uFocalPlaneDist = 10.f;
//! Camera position used for projective mode
uniform vec3 uEyeOrig;
//! Camera view direction used for projective mode
uniform vec3 uEyeView;
//! Camera's screen vertical direction used for projective mode
uniform vec3 uEyeVert;
//! Camera's screen horizontal direction used for projective mode
uniform vec3 uEyeSide;
//! Camera's screen size used for projective mode
uniform vec2 uEyeSize;
/////////////////////////////////////////////////////////////////////////////////////////
// Specific data types
@@ -271,12 +292,43 @@ vec4 BackgroundColor()
/////////////////////////////////////////////////////////////////////////////////////////
// Functions for compute ray-object intersection
//=======================================================================
// function : sampleUniformDisk
// purpose :
//=======================================================================
vec2 sampleUniformDisk ()
{
vec2 aPoint;
float aKsi1 = 2.f * RandFloat () - 1.f;
float aKsi2 = 2.f * RandFloat () - 1.f;
if (aKsi1 > -aKsi2)
{
if (aKsi1 > aKsi2)
aPoint = vec2 (aKsi1, (M_PI / 4.f) * (0.f + aKsi2 / aKsi1));
else
aPoint = vec2 (aKsi2, (M_PI / 4.f) * (2.f - aKsi1 / aKsi2));
}
else
{
if (aKsi1 < aKsi2)
aPoint = vec2 (-aKsi1, (M_PI / 4.f) * (4.f + aKsi2 / aKsi1));
else
aPoint = vec2 (-aKsi2, (M_PI / 4.f) * (6.f - aKsi1 / aKsi2));
}
return vec2 (sin (aPoint.y), cos (aPoint.y)) * aPoint.x;
}
// =======================================================================
// function : GenerateRay
// purpose :
// =======================================================================
SRay GenerateRay (in vec2 thePixel)
{
#ifndef DEPTH_OF_FIELD
vec3 aP0 = mix (uOriginLB, uOriginRB, thePixel.x);
vec3 aP1 = mix (uOriginLT, uOriginRT, thePixel.x);
@@ -286,6 +338,27 @@ SRay GenerateRay (in vec2 thePixel)
vec3 aDirection = normalize (mix (aD0, aD1, thePixel.y));
return SRay (mix (aP0, aP1, thePixel.y), aDirection);
#else
vec2 aPixel = uEyeSize * (thePixel - vec2 (0.5f)) * 2.f;
vec2 aAperturePnt = sampleUniformDisk () * uApertureRadius;
vec3 aLocalDir = normalize (vec3 (
aPixel * uFocalPlaneDist - aAperturePnt, uFocalPlaneDist));
vec3 aOrigin = uEyeOrig +
uEyeSide * aAperturePnt.x +
uEyeVert * aAperturePnt.y;
vec3 aDirect = uEyeView * aLocalDir.z +
uEyeSide * aLocalDir.x +
uEyeVert * aLocalDir.y;
return SRay (aOrigin, aDirect);
#endif
}
// =======================================================================

View File

@@ -111,6 +111,27 @@ static const char Shaders_RaytraceBase_fs[] =
"//! Bottom color of gradient background.\n"
"uniform vec4 uBackColorBot = vec4 (0.0);\n"
"\n"
"//! Aperture radius of camera used for depth-of-field\n"
"uniform float uApertureRadius = 0.f;\n"
"\n"
"//! Focal distance of camera used for depth-of field\n"
"uniform float uFocalPlaneDist = 10.f;\n"
"\n"
"//! Camera position used for projective mode\n"
"uniform vec3 uEyeOrig;\n"
"\n"
"//! Camera view direction used for projective mode\n"
"uniform vec3 uEyeView;\n"
"\n"
"//! Camera's screen vertical direction used for projective mode\n"
"uniform vec3 uEyeVert;\n"
"\n"
"//! Camera's screen horizontal direction used for projective mode\n"
"uniform vec3 uEyeSide;\n"
"\n"
"//! Camera's screen size used for projective mode\n"
"uniform vec2 uEyeSize;\n"
"\n"
"/////////////////////////////////////////////////////////////////////////////////////////\n"
"// Specific data types\n"
"\n"
@@ -274,12 +295,43 @@ static const char Shaders_RaytraceBase_fs[] =
"/////////////////////////////////////////////////////////////////////////////////////////\n"
"// Functions for compute ray-object intersection\n"
"\n"
"//=======================================================================\n"
"// function : sampleUniformDisk\n"
"// purpose :\n"
"//=======================================================================\n"
"vec2 sampleUniformDisk ()\n"
"{\n"
" vec2 aPoint;\n"
"\n"
" float aKsi1 = 2.f * RandFloat () - 1.f;\n"
" float aKsi2 = 2.f * RandFloat () - 1.f;\n"
"\n"
" if (aKsi1 > -aKsi2)\n"
" {\n"
" if (aKsi1 > aKsi2)\n"
" aPoint = vec2 (aKsi1, (M_PI / 4.f) * (0.f + aKsi2 / aKsi1));\n"
" else\n"
" aPoint = vec2 (aKsi2, (M_PI / 4.f) * (2.f - aKsi1 / aKsi2));\n"
" }\n"
" else\n"
" {\n"
" if (aKsi1 < aKsi2)\n"
" aPoint = vec2 (-aKsi1, (M_PI / 4.f) * (4.f + aKsi2 / aKsi1));\n"
" else\n"
" aPoint = vec2 (-aKsi2, (M_PI / 4.f) * (6.f - aKsi1 / aKsi2));\n"
" }\n"
"\n"
" return vec2 (sin (aPoint.y), cos (aPoint.y)) * aPoint.x;\n"
"}\n"
"\n"
"// =======================================================================\n"
"// function : GenerateRay\n"
"// purpose :\n"
"// =======================================================================\n"
"SRay GenerateRay (in vec2 thePixel)\n"
"{\n"
"#ifndef DEPTH_OF_FIELD\n"
"\n"
" vec3 aP0 = mix (uOriginLB, uOriginRB, thePixel.x);\n"
" vec3 aP1 = mix (uOriginLT, uOriginRT, thePixel.x);\n"
"\n"
@@ -289,6 +341,27 @@ static const char Shaders_RaytraceBase_fs[] =
" vec3 aDirection = normalize (mix (aD0, aD1, thePixel.y));\n"
"\n"
" return SRay (mix (aP0, aP1, thePixel.y), aDirection);\n"
"\n"
"#else\n"
"\n"
" vec2 aPixel = uEyeSize * (thePixel - vec2 (0.5f)) * 2.f;\n"
"\n"
" vec2 aAperturePnt = sampleUniformDisk () * uApertureRadius;\n"
"\n"
" vec3 aLocalDir = normalize (vec3 (\n"
" aPixel * uFocalPlaneDist - aAperturePnt, uFocalPlaneDist));\n"
"\n"
" vec3 aOrigin = uEyeOrig +\n"
" uEyeSide * aAperturePnt.x +\n"
" uEyeVert * aAperturePnt.y;\n"
"\n"
" vec3 aDirect = uEyeView * aLocalDir.z +\n"
" uEyeSide * aLocalDir.x +\n"
" uEyeVert * aLocalDir.y;\n"
"\n"
" return SRay (aOrigin, aDirect);\n"
"\n"
"#endif\n"
"}\n"
"\n"
"// =======================================================================\n"