opengl 2数正规化差

5jdjgkvh  于 2023-04-29  发布在  其他
关注(0)|答案(1)|浏览(112)

我正在做一个简单的图形绘制着色器,但遇到了一个问题,使线的厚度相等无处不在。
当我不正常化它原来有点厚的地区差异较小。当我把它正常化时,它变得非常不安。

#version 460 core

layout(location = 0) out vec4 color;

in vec4 gl_FragCoord;

uniform vec2 Screen_Size;
uniform vec2 zoom;
uniform vec2 offset;
#define GRAPHCOLOR vec3(0.176, 0.439, 0.701)

float leftside(vec2 pos) {
    return(pos.y);
}
float rightside(vec2 pos) {
    return(pos.x);
}
vec2 cameramat(vec2 pos) {
    return((pos - offset) * zoom);
}
void main() {
    float eps = (50.0*sqrt(zoom.x*zoom.y)) / 2000.0;
    vec2 pos = cameramat(2.0 * (gl_FragCoord.xy / Screen_Size) - vec2(1, 1));
    vec3 _color = vec3(0.9, 0.9, 0.9);
    vec2 sides = (vec2(leftside(pos), rightside(pos)));

    _color = mix(_color, vec3(0.70), step(abs(pos.x - float(int(pos.x))), 0.002 * zoom.x));
    _color = mix(_color, vec3(0.70), step(abs(pos.y - float(int(pos.y))), 0.002 * zoom.y));

    _color = mix(_color, vec3(0.4), step(abs(pos.x), 0.002 * zoom.x));
    _color = mix(_color, vec3(0.4), step(abs(pos.y), 0.0025 * zoom.y));

    _color = mix(_color, mix(_color, GRAPHCOLOR, step(abs((sides.x - sides.y)), eps / 2)),smoothstep(eps, 0, abs((sides.x - sides.y))));

    color = vec4(_color, 0.9);
}

下面是一些示例图:
| 非归一化x = y|非归一化50 x = 50 y|非归一化x = y|归一化50 x = 50 y|
| --------------|--------------|--------------|--------------|
|

|

|

|

|
以下是完整的项目:

hkmswyz6

hkmswyz61#

所以显然我不得不乘以eps的大小梯度,我会离开这个开放以防有人遇到一个类似的问题

相关问题