最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting uniforms in webgl - Stack Overflow

programmeradmin1浏览0评论

Can anyone explain or point me in the right direction of a good explaination of the different functions used to set uniform values. In the cheat sheet here we get this:

void uniform[1234][fi](uint location, ...) void uniform[1234][fi]v(uint location, Array value) void uniformMatrix[234]fv(uint location, bool transpose, Array)

but i'd like to know what each of these is doing and what the f's and i's are for.

Can anyone explain or point me in the right direction of a good explaination of the different functions used to set uniform values. In the cheat sheet here we get this:

void uniform[1234][fi](uint location, ...) void uniform[1234][fi]v(uint location, Array value) void uniformMatrix[234]fv(uint location, bool transpose, Array)

but i'd like to know what each of these is doing and what the f's and i's are for.

Share Improve this question edited Jun 25, 2015 at 15:39 genpfault 52.1k12 gold badges91 silver badges148 bronze badges asked Jun 25, 2015 at 12:05 adamdalyadamdaly 1991 gold badge4 silver badges11 bronze badges 3
  • Of course. As a lowly javascript developer floats and integers aren't at the forefront of my mind. I would guess that the v is referring to vectors then, but why would there be a v on the uniformMatrix and why would you be able to create a uniform1fv with only one dimension. Wouldn't that be the same as uniform1f? – adamdaly Commented Jun 25, 2015 at 13:33
  • I've merged my comments into an answer – LJᛃ Commented Jun 25, 2015 at 14:03
  • Is this helpful? webglfundamentals.org/webgl/lessons/webgl-shaders-and-glsl.html – user128511 Commented Jun 26, 2015 at 17:10
Add a comment  | 

2 Answers 2

Reset to default 12

1234 = dimensions

f = float

i = integer

v The final character, if present, is v, indicating that the command takes an array (a vector) of values rather than a series of individual arguments

For a non array uniform the only difference between v and non v versions of the uniform functions is just how you provide the data to it:

uniform1fv(loc,[3.14159]) vs uniform1f(loc,3.14159).

uniform3fv(loc,[.5,1.,.5]) vs uniform3f(loc,.5,1.,.5)

but for an array uniform you can set the entire array using the v functions

in shader

uniform float someArray[10];

in js

// at init time
var location = gl.getUniformLocation(prg, "someArray");

// at render time
var arrayWith10Values = [5, 4, 1, 3, 4, 5, 12, 0.1, 2, -1];
gl.uniform1fv(location, arrayWith10Values);

To do that with the non v functions you'd have to look up every location

var location0 = gl.getUniformLocation(prg, "someArray[0]");
var location1 = gl.getUniformLocation(prg, "someArray[1]");
var location2 = gl.getUniformLocation(prg, "someArray[2]");
var location3 = gl.getUniformLocation(prg, "someArray[3]");
var location4 = gl.getUniformLocation(prg, "someArray[4]");
...etc...

gl.uniform1f(location0, value0);
gl.uniform1f(location1, value1);
gl.uniform1f(location2, value2);
gl.uniform1f(location3, value3);
gl.uniform1f(location4, value4);
...etc...

The values within the square brackets refer to the dimension and the datatype of your variable. So you have the following list

  • 1 - one value
  • 2 - two values
  • 3 - three values
  • 4 - four values
  • f - your data is a float
  • i - your data is an integer
  • v - your data refers to an array

In the WebGL Specification are more infromation about that.

发布评论

评论列表(0)

  1. 暂无评论