WebGL的渲染与RGL 0.93.935ṛ包 [英] WebGL rendering with rgl 0.93.935 R package

查看:221
本文介绍了WebGL的渲染与RGL 0.93.935ṛ包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下述R code生成一个HTML文件,并在浏览器中打开它:

The following R code generates an HTML file and opens it in the browser:

library(rgl)
M <- rbind(
  c(0,0,0),
  c(-1,4,0),
  c(4,9,0),
  c(6,3,0)
  )
  quads3d(M,col='red')
browseURL(paste("file://", writeWebGL(dir=file.path(tempdir(), "webGL"), 
          width=500), sep=""))

渲染是在三维空间中一个交互式平面多面体

The rendering is an interactive planar polyhedron in the 3D space.

随着 RGL 包的最新版本( 0.93.935 ),HTML呈现做的没有的工作对于Windows用户(以及iOS用户,我认为)使用默认配置的浏览器。与旧版本的 0.93.928 ,它的工作原理。

With the latest version of the rgl package (0.93.935), the HTML rendering does not work for Windows users (as well as iOS users, I think) with default configuration browser. With the older version 0.93.928, it works.

我已经发布了 HTML的RGL 0.93.928 和的 //pagist.github.io/ 5884523相对=nofollow> HTML输出。

I have posted the html output of rgl 0.93.928 and the html output of rgl 0.93.935.

我报道这个问题邓肯·默多克(作者 RGL ),他给了我的火狐的以下解决方案:类型和运行about:config中。的在地址栏中,然后转动参数<$​​ C $ C> WebGL的preFER本地-GL 和 webgl.force启用真的。然后,HTML渲染工作。

I have reported this issue to Duncan Murdoch (author of rgl) and he has given me the following solution for Firefox: type and run "about: config" in the address bar, and turn the parameters webgl.prefer-native-gl and webgl.force-enabled to true. Then the HTML rendering works.

我的问题:

  • 如何做谷歌浏览器?

  • How to do with Google Chrome?

是否有可能改变的东西在HTML code,以便使HTML渲染工作原理与默认配置? (作为0.93.928版本)。

Is it possible to change something in the HTML code in order that the HTML rendering works with the default configuration? (as for the 0.93.928 version).

推荐答案

由于困难,因为得到的问题是那么容易的解决之道。

As difficult as the getting to the problem was as easy is the solution to it.

由于RGL的最新版本,我可以收购问题所在的HTML输出的片段着色器里:

As of latest version of rgl I could acquire the problem resides inside the fragment shader of the html output:

varying vec4 vCol; // carries alpha
varying vec4 vPosition;
varying vec3 vNormal;

vec3 eye = normalize(-vPosition.xyz);
const vec3 emission = vec3(0., 0., 0.);
const vec3 ambient1 = vec3(0., 0., 0.);
const vec3 specular1 = vec3(1., 1., 1.);// light*material
const float shininess1 = 50.;
vec4 colDiff1 = vec4(vCol.rgb * vec3(1., 1., 1.), vCol.a);
const vec3 lightDir1 = vec3(0., 0., 1.);
vec3 halfVec1 = normalize(lightDir1 + eye);

void main(void) {
    vec4 lighteffect = vec4(emission, 0.);
    vec3 n = normalize(vNormal);
    n = -faceforward(n, n, eye);
    vec3 col1 = ambient1;
    float nDotL1 = dot(n, lightDir1);
    col1 = col1 + max(nDotL1, 0.) * colDiff1.rgb;
    col1 = col1 + pow(max(dot(halfVec1, n), 0.), shininess1) * specular1;
    lighteffect = lighteffect + vec4(col1, colDiff1.a);
    gl_FragColor = lighteffect;
}

它定义之外的主要功能,跳过赋值的变量,因而无法编译师被零故障。该解决方案是将不同的值后直接将定义块以上的主要功能的启动:

it defines variables outside on the main function which skips value assignments and thus fails to compile with division-by-zero failures. The solution is to move the start of the main function above the definition block directly after the varying values:

varying vec4 vCol; // carries alpha
varying vec4 vPosition;
varying vec3 vNormal;

void main(void) {
    vec3 eye = normalize(-vPosition.xyz);
    const vec3 emission = vec3(0., 0., 0.);
    const vec3 ambient1 = vec3(0., 0., 0.);
    const vec3 specular1 = vec3(1., 1., 1.);// light*material
    const float shininess1 = 50.;
    vec4 colDiff1 = vec4(vCol.rgb * vec3(1., 1., 1.), vCol.a);
    const vec3 lightDir1 = vec3(0., 0., 1.);
    vec3 halfVec1 = normalize(lightDir1 + eye);

    vec4 lighteffect = vec4(emission, 0.);
    vec3 n = normalize(vNormal);
    n = -faceforward(n, n, eye);
    vec3 col1 = ambient1;
    float nDotL1 = dot(n, lightDir1);
    col1 = col1 + max(nDotL1, 0.) * colDiff1.rgb;
    col1 = col1 + pow(max(dot(halfVec1, n), 0.), shininess1) * specular1;
    lighteffect = lighteffect + vec4(col1, colDiff1.a);
    gl_FragColor = lighteffect;
}

根据需要这将显示的对象。

This will show the object as desired.

您可能需要再次联系邓肯·默多克并送他一个链接到这个职位,如果像你说的你是不是在HTML和WebGL的熟悉。

You may want to contact Duncan Murdoch again and send him a link to this post if as you said you're not versed in html and webgl.

这篇关于WebGL的渲染与RGL 0.93.935ṛ包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆