Fixed problem with misplacing background texture in Ray-Tracing.
An environment background is always drawn using a perspective matrix.
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
{
int aTrsfId;
float aRaytraceDepth = MAXFLOAT;
+ float aRefractionIdx = 0.0;
for (int aDepth = 0; aDepth < NB_BOUNCES; ++aDepth)
{
{
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
{
if (aOpacity.x != 1.0f)
{
aWeight *= aOpacity.y;
+ aRefractionIdx = aOpacity.z;
if (aOpacity.z != 1.0f)
{
" int aTrsfId;\n"
"\n"
" float aRaytraceDepth = MAXFLOAT;\n"
+ " float aRefractionIdx = 0.0;\n"
"\n"
" for (int aDepth = 0; aDepth < NB_BOUNCES; ++aDepth)\n"
" {\n"
" {\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"
" if (aOpacity.x != 1.0f)\n"
" {\n"
" aWeight *= aOpacity.y;\n"
+ " aRefractionIdx = aOpacity.z;\n"
"\n"
" if (aOpacity.z != 1.0f)\n"
" {\n"
--- /dev/null
+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