1

我正在寻找一种在 GLSL 中沿屏幕四边形(内发光)创建发光效果的方法。我知道如何在片段着色器中创建矩形程序以及如何将其模糊以使其向外发光。但我无法弄清楚我是如何沿着屏幕四边形设置一个发光的,它面向内,具有可配置的发光距离和模糊级别。任何相关示例或文档的链接?这是我需要的: 在此处输入图像描述

大码:

const vec2 resolution = vec2(800,600);
float rect( vec2 p, vec2 b, float smooth )
{
vec2 v = abs(p) - b;
float d = length(max(v,0.0));
return 1.0-pow(d, smooth);
}

void main( void ) {

vec2 unipos = (gl_FragCoord.xy / resolution);
vec2 pos = unipos*2.0-1.0;
pos.x *= resolution.x / resolution.y;


float d1 = rect(pos - vec2(-1.0,0.0), vec2(1,1), 0.1); 
vec3 clr1 = vec3(0.2,0.6,1.0) *d1; 



gl_FragColor = vec4( clr1 , 1.0 );

}

此代码使用外部发光创建全屏矩形,而我只需要发光并且它应该是内部的。

4

0 回答 0