在着色器中从DataTextures读取不正确

时间:2017-05-04 15:20:55

标签: three.js textures webgl shader

当我的POT DataTextures的纹素尺寸为1:1(宽度:高度)时,我有一个很好的程序,但是当纹素尺寸为2:1或1:2时,看起来纹素不正确阅读并申请。我使用连续索引(1,2,3,4,5 ......)使用以下两个函数访问纹素。

我想知道我是如何访问texel数据有什么问题,或者如果我对整数索引使用Float32Array需要切换到Uint8Array或其他东西?提前谢谢!

此函数在我的可视化中找到每个粒子云有一个纹素的纹理的uv:

float pTexelSizeX = 1.0 / uPerParticleBufferWidth;
float pTexelSizeY = 1.0 / uPerParticleBufferHeight;
vec2 perParticleUV = vec2( 
    mod(aParticleIndex, uPerParticleBufferWidth)*pTexelSizeX, 
    floor(aParticleIndex / uPerParticleBufferHeight)*pTexelSizeY );
perParticleUV += vec2(0.5*pTexelSizeX, 0.5*pTexelSizeY);

此函数为包含在所有云中的每个粒子包含一个纹素的纹理找到uv:

.money

1 个答案:

答案 0 :(得分:0)

不应该

vec2 perMotifUV = vec2( 
    mod(cellIndex, uPerCloudBufferWidth)*texelSizeX, 
    floor(cellIndex / uPerCloudBufferHeight)*texelSizeY );
是吗?

vec2 perMotifUV = vec2( 
    mod(cellIndex, uPerCloudBufferWidth)*texelSizeX, 
    floor(cellIndex / uPerCloudBufferWidth)*texelSizeY );  // <=- use width

另一个相同吗?除以宽度而不是高度