jez*_*ien 2 javascript firefox glsl webgl webgl2
我正在尝试使用WebGL 2.0在浏览器中渲染3D医疗数据.
WebGL 2.0现在支持AFAIK 3D纹理.
texImage3D()是一个公认的函数调用.
我正在编写一个片段着色器并声明一个统一的采样器:
uniform sampler3D samp;
Run Code Online (Sandbox Code Playgroud)
当我在Firefox上运行它时,我收到一个错误:
未捕获异常:着色器编译错误:错误:0:19:'sampler3D':非法使用保留字错误:0:19:'sampler3D':语法错误
当我使用sampler2D时工作得很好(虽然不能解决我的目的).
请问有谁可以指出我在这里做错了什么?
sampler3D还不支持吗?但在这种情况下,如何使用texImage3D()加载任何纹理?
您是否更改了需要更改的所有内容以使用WebGL 2.0功能sampler3D
?
要使用sampler3D
你需要添加
#version 300 es
Run Code Online (Sandbox Code Playgroud)
到着色器的顶部.它必须是第一线,前面没有白色的空间
请注意,GLSL 1.0中的GLSL 3.00还有许多其他更改
在这里测试
"use strict";
const vs = `#version 300 es
in vec4 position;
void main() {
gl_Position = position;
}
`;
const fs = `#version 300 es
precision mediump float;
precision lowp sampler3D;
uniform sampler3D u_someTexture;
out vec4 theColor;
void main() {
theColor = texture(u_someTexture, vec3(0,0,0));
}
`;
function main() {
var m4 = twgl.m4;
var gl = twgl.getContext(document.createElement("canvas"));
log("using: " + gl.getParameter(gl.VERSION));
if (!twgl.isWebGL2(gl)) {
log("Sorry, this example requires WebGL 2.0");
return;
}
var programInfo = twgl.createProgramInfo(gl, [vs, fs], (err) => {
log("could not compile shader: " + err);
});
if (programInfo) {
log("compiled shader with sampler3D");
}
}
main();
function log() {
var elem = document.createElement("pre");
elem.appendChild(document.createTextNode(Array.prototype.join.call(arguments, " ")));
document.body.appendChild(elem);
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://twgljs.org/dist/twgl-full.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1767 次 |
最近记录: |