klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

webgl 着色器获取贴图一个像素的宽度 #711

Open klren0312 opened 1 year ago

klren0312 commented 1 year ago

webgl1

uniform vec2 u_ImageSize;
void main () {
  vec2 onePixel = vec2(1.0) / u_ImageSize;
}
const u_ImageSize = gl.setUniformLocation(program, 'u_ImageSize')
gl.uniform2f(u_ImageSize, image.width, image.height)

webgl2

uniform sampler2D u_Sampler;
void main () {
  vec2 onePixel = vec2(1.0) / vec2(textureSize(u_Sampler, 0));
}

参考资料

webgl2使用textureSize获取贴图大小

https://registry.khronos.org/OpenGL-Refpages/gl4/html/textureSize.xhtml