gpt4 book ai didi

opengl - GLSL 纹理大小

转载 作者:行者123 更新时间:2023-12-04 20:41:23 27 4
gpt4 key购买 nike

我的片段着色器有问题。
我想获取纹理的大小(从图像加载)。

我知道可以使用 textureSize(sampler) 来获取包含纹理大小的 ivec2。但我不知道为什么这不起作用(它不能编译):

#version 120

uniform sampler2D tex;

float textureSize;
float texelSize;


void main()
{
textureSize = textureSize(tex).x;//first line
//textureSize = 512.0;//if i set the above line as comment and use this one the shader compiles.
texelSize = 1.0 / textureSize;

vec4 color = texture2D(tex,gl_TexCoord[0].st);
gl_FragColor = color * gl_Color;
}

最佳答案

问题是我的 GLSL 版本太低(在 1.30 中实现)并且我缺少一个参数。

这里的工作版本:

#version 130

uniform sampler2D tex;

float textureSize;
float texelSize;


void main()
{
ivec2 textureSize2d = textureSize(tex,0);
textureSize = float(textureSize2d.x);
texelSize = 1.0 / textureSize;

vec4 color = texture2D(tex,gl_TexCoord[0].st);
gl_FragColor = color * gl_Color;
}

关于opengl - GLSL 纹理大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25803909/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com