【问题标题】:Incorrect reading from DataTextures in shader从着色器中的 DataTextures 读取不正确
【发布时间】:2017-10-02 20:57:28
【问题描述】:

当我的 POT DataTexture 的纹素尺寸为 1:1(宽度:高度)时,我有一个运行良好的程序,但是当它们的纹素尺寸为 2:1 或 1:2 时,纹素似乎不正确阅读并应用。我正在使用连续索引 (1,2,3,4,5...) 来使用以下两个函数访问纹素。

我想知道我访问纹素数据的方式是否有问题,或者我对整数索引的 Float32Array 使用是否需要切换到 Uint8Array 或其他什么?提前致谢!

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

float texelSizeX = 1.0 / uPerCloudBufferWidth;
float texelSizeY = 1.0 / uPerCloudBufferHeight;
vec2 perMotifUV = vec2( 
    mod(cellIndex, uPerCloudBufferWidth)*texelSizeX, 
    floor(cellIndex / uPerCloudBufferHeight)*texelSizeY );
perCloudUV += vec2(0.5*texelSizeX, 0.5*texelSizeY);

此函数为所有云中包含的每个粒子找到一个纹理像素的 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);

【问题讨论】:

    标签: three.js textures webgl shader


    【解决方案1】:

    不应该这样

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

    是这个吗?

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

    另一个也一样?除以宽度而不是高度

    【讨论】:

    • 天哪!谢谢!!!你完全正确。我一直在到处寻找这个错误!你能解释为什么除以宽度而不是高度有效吗?我想既然它是y 维度,我应该除以缓冲区的“垂直”维度。
    猜你喜欢
    • 2014-05-21
    • 2021-08-01
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多