diff --git a/src/Graphic3d/Graphic3d_NameOfTexture2D.hxx b/src/Graphic3d/Graphic3d_NameOfTexture2D.hxx index 44448b43d8..d3ec9340c6 100644 --- a/src/Graphic3d/Graphic3d_NameOfTexture2D.hxx +++ b/src/Graphic3d/Graphic3d_NameOfTexture2D.hxx @@ -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 }; diff --git a/src/Graphic3d/Graphic3d_Texture2D.cxx b/src/Graphic3d/Graphic3d_Texture2D.cxx index 37e7308682..ca8ac556a7 100644 --- a/src/Graphic3d/Graphic3d_Texture2D.cxx +++ b/src/Graphic3d/Graphic3d_Texture2D.cxx @@ -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" }; // ======================================================================= diff --git a/src/Shaders/PathtraceBase.fs b/src/Shaders/PathtraceBase.fs index 98400ccc49..916ac69b8e 100644 --- a/src/Shaders/PathtraceBase.fs +++ b/src/Shaders/PathtraceBase.fs @@ -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 diff --git a/src/Shaders/RaytraceBase.fs b/src/Shaders/RaytraceBase.fs index 31520ad196..a7f7be191c 100644 --- a/src/Shaders/RaytraceBase.fs +++ b/src/Shaders/RaytraceBase.fs @@ -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 diff --git a/src/Shaders/Shaders_PathtraceBase_fs.pxx b/src/Shaders/Shaders_PathtraceBase_fs.pxx index 527a49e7f2..187e127cbb 100644 --- a/src/Shaders/Shaders_PathtraceBase_fs.pxx +++ b/src/Shaders/Shaders_PathtraceBase_fs.pxx @@ -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" diff --git a/src/Shaders/Shaders_RaytraceBase_fs.pxx b/src/Shaders/Shaders_RaytraceBase_fs.pxx index 63c7309eaf..2df52815a1 100644 --- a/src/Shaders/Shaders_RaytraceBase_fs.pxx +++ b/src/Shaders/Shaders_RaytraceBase_fs.pxx @@ -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 index 0000000000..ce455d4e25 Binary files /dev/null and b/src/Textures/2d_chess.rgba differ diff --git a/src/Textures/FILES b/src/Textures/FILES index c71f1d2376..40b9c5579a 100755 --- a/src/Textures/FILES +++ b/src/Textures/FILES @@ -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 index 0000000000..df43214efd --- /dev/null +++ b/tests/v3d/raytrace/sample_ball_alpha @@ -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