将数组传递给着色器 [英] Pass array to shader

查看:500
本文介绍了将数组传递给着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了我的数组this.kernel:它有48个元素,我想把它传递给我的片段着色器。



当我打电话的时候

  gl.uniform3fv(gl.getUniformLocation this.program,kernel),16,this.kernel); 

在我的着色器中定义了内核:

  uniform vec3 kernel [16]; 

我得到一个没有足够参数的错误。
我已经查找了规范等,但没有找到我的问题-.-

  void glUniform3fv(GLint位置,GLsizei计数,const GLfloat *值); 

感谢您的帮助

€:转换this.kernel为float32array,但我仍然有这个错误。



2:Chrome中的错误:没有足够的参数


$ b $在Firefox中的b

:NS_ERROR_XPC_BAD_CONVERT_JS:无法转换JavaScript参数

解决方案您的 this.kernel 需要是长度为48(= 3 * 16)的Float32Array。你不能使用vec3s数组。



另外,WebGL中不使用计数。该功能(来自 WebGL规范

  void uniform3fv(WebGLUniformLocation?location,Float32Array v); 

示例用法:

 gl.uniform3fv(gl.getUniformLocation(shaderProgram,colors),new Float32Array([0,1,2,3,4,5])); 

查看完整的示例:
http://jsfiddle.net/mortennobel/URvtx/


I create my array this.kernel: it hast 48 elements and I want to pass it to my fragment shader.

When i call

 gl.uniform3fv(gl.getUniformLocation(this.program, "kernel"), 16, this.kernel);

kernel is defined in my shader:

uniform vec3 kernel[16]; 

I get an error for not enough arguments. I already looked up the specification etc, but don't find my problem -.-

void glUniform3fv(  GLint  location, GLsizei  count, const GLfloat * value);

Thanks for help

€: I converted this.kernel to a float32array but I still have this error.

€2: error in Chrome: not enough arguments

in Firefox: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument

解决方案

Your this.kernel needs to be a Float32Array of length 48 (=3*16). You cannot use an array of vec3s.

Also the count is not used in WebGL. The function is (from WebGL Specification)

void uniform3fv(WebGLUniformLocation? location, Float32Array v);

Example usage:

gl.uniform3fv(gl.getUniformLocation(shaderProgram, "colors"), new Float32Array([0,1,2,3,4,5]));

See a complete example here: http://jsfiddle.net/mortennobel/URvtx/

这篇关于将数组传递给着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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