计算机图形:如何使用计算机程序绘制这种效果?

时间:2015-06-19 18:11:28

标签: opengl graphics

我想知道如何使用计算机程序(CPU或GPU)来绘制这种效果?

enter image description here

1 个答案:

答案 0 :(得分:1)

你有两条线。您要做的是为每个像素选择更近的线,并计算到它的距离。这将是你在给定点的强度。当你接近图像的底部时,做淡化为黑色(使用像素的y位置来做到这一点)

你的线在x轴上看起来恰好是25%和75%,因此伪码看起来像这样:

for each pixel p: //p.x and p.y is normalized to the 0-1 range!
  intensity = ( 0.25 - min( abs(p.x-0.25) , abs(p.x-0.75) ) ) / 0.25; //intensity is normalized to 0-1 range
  intensity *= intensity; //distance squared
  intensity *= (1.0 - p.y); //Top of image is 0, bottom is 1
  display_intensity();
end

根据您的使用方式,您可以在CPU上创建纹理,或使用着色器并在GPU上的GLSL中进行计算。