admin管理员组文章数量:1193749
I'm trying to understand how to simulate console.log in webgl shaders which are written in GLSL. It's easy to get error messages but I can't get how to print custom messages.
Basically I want to print stuff in the browser's console:
<script id="shader-fs1" type="x-shader/x-fragment">
void main(void)
{
//console.log doesn't work here since it's GLSL not javascript
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
</script>
Any suggestions?
I'm trying to understand how to simulate console.log in webgl shaders which are written in GLSL. It's easy to get error messages but I can't get how to print custom messages.
Basically I want to print stuff in the browser's console:
<script id="shader-fs1" type="x-shader/x-fragment">
void main(void)
{
//console.log doesn't work here since it's GLSL not javascript
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
</script>
Any suggestions?
Share Improve this question edited Jul 1, 2013 at 3:41 genpfault 52.1k12 gold badges91 silver badges148 bronze badges asked Jul 1, 2013 at 3:07 user1796666user17966663 Answers
Reset to default 10After compiling shader you can do something like:
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
alert(gl.getShaderInfoLog(shader));
}
And it will show you any error messages during compiling. GLSL cannot send data back to program in any other form but framebuffer/texture, so you can only check what's happening by inspecting output colors. WebGL inspector might me useful, as pointed by Michael, but not that much for shaders, but for general debugging of webGL apps
Not sure if that is possible, but you may want to check out the WebGL Inspector library for debugging purposes.
Currently there is no known way to output data from GLSL in WebGL except via it's purposed result (screen/image color). Unless you already do I would suggest you check out Learning WebGL, also kick.js might be useful to you.
本文标签: javascriptHow to consolelog in webgl shadersStack Overflow
版权声明:本文标题:javascript - How to console.log in webgl shaders? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738439948a2086899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论