首页 > 解决方案 > 有什么方法可以根据我绘制的二维数据更改 GLSL 中的背景颜色

问题描述

我想改变我的二维图的背景,使其强度根据数据增加或减少。我在下面编写的程序的工作方式是改变线条的颜色,但我希望同样的事情发生在我的背景上。

这是我从下面的代码中得到的结果:

图像

VS = """
#version 450
// Attribute variable that contains coordinates of the vertices.
layout(location = 0) in vec2 position;
out vec2 p;
uniform float count;

// Main function, which needs to set `gl_Position`.
in vec3 vertex_position;
void main() {
  p = position;

  gl_Position = vec4(position.x, position.y, 0., 1.);
}
"""
FS = """
#version 450
// Output variable of the fragment shader, which is a 4D vector containing the
// RGBA components of the pixel color.
in vec2 p;
out vec4 out_color;
uniform vec2 u_resolution;


// Main fragment shader function.

void main()
{
    // We simply set the pixel color to yellow.
    vec2 st = gl_FragCoord.xy/u_resolution;

    vec3 color = vec3(p.y);

    float pct = smoothstep( p.y-0.9, p.y, st.y) -
          smoothstep( p.y, p.y+0.9, st.y);

    color = (1.0-pct)*color+pct*vec3(0.0,0.0,0.0);
    out_color = vec4(color,1.0);


}


"""

这就是我想要的结果:

图像

标签: python-3.xglsl

解决方案


推荐阅读