Skip to content

Commit

Permalink
Merge pull request #410 from dmurdoch/alphatexture
Browse files Browse the repository at this point in the history
Use luminance to retrieve value for `textype="alpha"`
  • Loading branch information
dmurdoch committed Feb 18, 2024
2 parents 09462bd + 99df7cd commit 0d31d58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# rgl 1.2.13
# rgl 1.2.14

## Major changes

Expand Down Expand Up @@ -28,6 +28,7 @@ run in a Shiny session.
* Fixed issue with `warning()` call reported by CRAN.
* Smooth shapes were not rendered correctly by `rglwidget()`.
This was especially noticeable for spheres with `fov = 0`, but was present in other cases as well (issue #401).
* `textype = "alpha"` was not rendered correctly by `rglwidget()` (issue #408).

# rgl 1.2.1

Expand Down
8 changes: 5 additions & 3 deletions inst/htmlwidgets/lib/rglClass/shaders/rgl_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ void main(void) {
#endif //TEXTURE_rgba

#ifdef TEXTURE_alpha
float luminance = dot(vec3(1.,1.,1.),textureColor.rgb)/3.;

#if defined(TEXMODE_replace) || defined(TEXMODE_decal)
textureColor = vec4(lighteffect.rgb, textureColor.a);
textureColor = vec4(lighteffect.rgb, luminance);
#endif

#if defined(TEXMODE_modulate) || defined(TEXMODE_blend) || defined(TEXMODE_add)
textureColor = vec4(lighteffect.rgb, lighteffect.a*textureColor.a);
textureColor = vec4(lighteffect.rgb, lighteffect.a*luminance);
#endif

#endif
#endif // TEXTURE_alpha

// The TEXTURE_luminance values are not from that reference
#ifdef TEXTURE_luminance
Expand Down
7 changes: 7 additions & 0 deletions man/material.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ of objects in an \pkg{rgl} scene.
\item{"rgb"}{color}
\item{"rgba"}{color and alpha texture}
}
Note that support for these modes is slightly different
in the display within R versus the WebGL display using
\code{rglwidget()}. In particular, in WebGL
\code{textype = "alpha"} will always take the alpha value from
the luminance (i.e. the average of the R, G and B channels)
of the texture, whereas the R display bases
the choice on the internal format of the texture file.
}
\item{texmode}{
specifies how the texture interacts with the existing
Expand Down

0 comments on commit 0d31d58

Please sign in to comment.