]> OCCT Git - occt-copy.git/commitdiff
0027256: Visualization, Path Tracing - add support of alpha-channel of texture
authordbp <dbp@opencascade.com>
Thu, 17 Nov 2016 15:51:38 +0000 (18:51 +0300)
committerapn <apn@opencascade.com>
Fri, 18 Nov 2016 12:17:36 +0000 (15:17 +0300)
Regenerate resource files.

src/Graphic3d/Graphic3d_NameOfTexture2D.hxx
src/Graphic3d/Graphic3d_Texture2D.cxx
src/Shaders/PathtraceBase.fs
src/Shaders/RaytraceBase.fs
src/Shaders/Shaders_PathtraceBase_fs.pxx
src/Shaders/Shaders_RaytraceBase_fs.pxx
src/Textures/2d_chess.rgba [new file with mode: 0644]
src/Textures/FILES
tests/v3d/raytrace/sample_ball_alpha [new file with mode: 0644]

index 44448b43d8c4f7cb8b2fa03398b4ce9708a10090..d3ec9340c6319784a9715bb70e3655a7c9ea7b26 100644 (file)
@@ -41,6 +41,7 @@ Graphic3d_NOT_2D_MAPLE,
 Graphic3d_NOT_2D_MARBLE,
 Graphic3d_NOT_2D_MOTTLED,
 Graphic3d_NOT_2D_RAIN,
+Graphic3d_NOT_2D_CHESS,
 Graphic3d_NOT_2D_UNKNOWN
 };
 
index 37e7308682c3c14e0b2150684c96665ac1fdee5e..ca8ac556a7c1ade048a820c6c94a452a55b6d7a0 100644 (file)
@@ -42,7 +42,8 @@ static const char *NameOfTexture_to_FileName[] =
   "2d_maple.rgb",
   "2d_marble.rgb",
   "2d_mottled.rgb",
-  "2d_rain.rgb"
+  "2d_rain.rgb",
+  "2d_chess.rgba"
 };
 
 // =======================================================================
index 98400ccc49a217a60cb3e2853ff73ea4fa9ff4fb..916ac69b8e688a4ff303ad5fd43852414a78ab1d 100644 (file)
@@ -759,10 +759,16 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse)
       aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),
                            dot (aTrsfRow2, aTexCoord));
 
-      vec3 aTexColor = textureLod (
-        sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f).rgb;
+      vec4 aTexColor = textureLod (
+        sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f);
 
-      aMaterial.Kd.rgb *= aTexColor * aTexColor; // de-gamma correction (for gamma = 2)
+      aMaterial.Kd.rgb *= (aTexColor.rgb, aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)
+
+      if (aTexColor.w != 1.0f)
+      {
+        // mix transparency BTDF with texture alpha-channel
+        aMaterial.Kt = (UNIT - aTexColor.www) + aTexColor.w * aMaterial.Kt;
+      }
     }
 #endif
 
index 31520ad1960247602de727ee58d869fb82449d0b..a7f7be191c5f0bc6c027012b52faa5db1613f6b6 100644 (file)
@@ -969,11 +969,14 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
       aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),
                            dot (aTrsfRow2, aTexCoord));
 
-      vec3 aTexColor = textureLod (
-        sampler2D (uTextureSamplers[int(aDiffuse.w)]), aTexCoord.st, 0.f).rgb;
+      vec4 aTexColor = textureLod (
+        sampler2D (uTextureSamplers[int(aDiffuse.w)]), aTexCoord.st, 0.f);
 
-      aDiffuse.rgb *= aTexColor;
-      aAmbient.rgb *= aTexColor;
+      aDiffuse.rgb *= aTexColor.rgb;
+      aAmbient.rgb *= aTexColor.rgb;
+
+      // keep refractive index untouched (Z component)
+      aOpacity.xy = vec2 (aTexColor.w * aOpacity.x, 1.0f - aTexColor.w * aOpacity.x);
     }
 #endif
 
index 527a49e7f20c559915b6f37d706c5ca5e9091d7c..187e127cbbc220825b95f06a334c40c1050de4cf 100644 (file)
@@ -762,10 +762,16 @@ static const char Shaders_PathtraceBase_fs[] =
   "      aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),\n"
   "                           dot (aTrsfRow2, aTexCoord));\n"
   "\n"
-  "      vec3 aTexColor = textureLod (\n"
-  "        sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f).rgb;\n"
+  "      vec4 aTexColor = textureLod (\n"
+  "        sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f);\n"
   "\n"
-  "      aMaterial.Kd.rgb *= aTexColor * aTexColor; // de-gamma correction (for gamma = 2)\n"
+  "      aMaterial.Kd.rgb *= (aTexColor.rgb, aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)\n"
+  "\n"
+  "      if (aTexColor.w != 1.0f)\n"
+  "      {\n"
+  "        // mix transparency BTDF with texture alpha-channel\n"
+  "        aMaterial.Kt = (UNIT - aTexColor.www) + aTexColor.w * aMaterial.Kt;\n"
+  "      }\n"
   "    }\n"
   "#endif\n"
   "\n"
index 63c7309eaf2da684acfdf8ef317b30b186a02d33..2df52815a12229069d9ca8be007589d8830a5623 100644 (file)
@@ -972,11 +972,14 @@ static const char Shaders_RaytraceBase_fs[] =
   "      aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),\n"
   "                           dot (aTrsfRow2, aTexCoord));\n"
   "\n"
-  "      vec3 aTexColor = textureLod (\n"
-  "        sampler2D (uTextureSamplers[int(aDiffuse.w)]), aTexCoord.st, 0.f).rgb;\n"
+  "      vec4 aTexColor = textureLod (\n"
+  "        sampler2D (uTextureSamplers[int(aDiffuse.w)]), aTexCoord.st, 0.f);\n"
   "\n"
-  "      aDiffuse.rgb *= aTexColor;\n"
-  "      aAmbient.rgb *= aTexColor;\n"
+  "      aDiffuse.rgb *= aTexColor.rgb;\n"
+  "      aAmbient.rgb *= aTexColor.rgb;\n"
+  "\n"
+  "      // keep refractive index untouched (Z component)\n"
+  "      aOpacity.xy = vec2 (aTexColor.w * aOpacity.x, 1.0f - aTexColor.w * aOpacity.x);\n"
   "    }\n"
   "#endif\n"
   "\n"
diff --git a/src/Textures/2d_chess.rgba b/src/Textures/2d_chess.rgba
new file mode 100644 (file)
index 0000000..ce455d4
Binary files /dev/null and b/src/Textures/2d_chess.rgba differ
index c71f1d23768b9338156754687bd50559a2cdf124..40b9c5579affc53a9652d08621563cbe8a971916 100755 (executable)
@@ -20,6 +20,7 @@ icon:::2d_MatraDatavision.rgb
 icon:::2d_mottled.rgb
 icon:::2d_rain.rgb
 icon:::2d_rock.rgb
+icon:::2d_chess.rgba
 icon:::env_clouds.rgb
 icon:::env_cv.rgb
 icon:::env_lines.rgb
diff --git a/tests/v3d/raytrace/sample_ball_alpha b/tests/v3d/raytrace/sample_ball_alpha
new file mode 100644 (file)
index 0000000..df43214
--- /dev/null
@@ -0,0 +1,13 @@
+puts "============"
+puts "Visualization - Path Tracing, Ball sample"
+puts "============"
+puts ""
+
+source $env(CSF_OCCTSamplesPath)/tcl/pathtrace_ball.tcl
+
+vtexture ball 21 -scale 0.1 0.1
+vsetmaterial ball plaster
+vbsdf ball -fresnel Constant 0.0
+
+vfps 100
+vdump $imagedir/${casename}_zoom.png