【发布时间】:2021-04-24 01:33:09
【问题描述】:
所以我设法提出了一个着色器,它将根据某些线段的位置来阻挡图像的某些部分(总结像素着色器,它只是检查从灯光中心到任何给定的像素与任何“墙”线段相交,因此如果是这样就不会绘制图像)。
但是,我的问题是光线的截止非常尖锐,我想稍微模糊一下,不要模糊光线与墙段相交的硬边。什么是实现这一目标的好方法?我附上了正在运行的着色器的 gif 图像和相关代码。
Stuff circled in red should be blurry, green should remain sharp
float4 MainPS(VertexShaderOutput input) : COLOR
{
float4 color = tex2D(s0, input.TextureCoordinates);
float2 centerPos = float2(150.0f + mX, 150.0f + mY);
float2 coords = float2((input.TextureCoordinates.x * 300) + mX, (input.TextureCoordinates.y * 300) + mY);
//change alpha based on distance
color.w = map(distance(centerPos, coords), 0, 150, .5, .1f);
//If the line segment from the center to this pixel intersects any given line segment (hardcoded for now, don't draw it)
if (intersect(centerPos, coords, float2(160.0f, 200.0f), float2(200.0f, 140.0f)) ||
intersect(centerPos, coords, float2(160.0f, 200.0f), float2(250.0f, 200.0f)) || intersect(centerPos, coords, float2(200.0f, 140.0f), float2(250.0f, 200.0f)))
color = float4(0, 0, 0, 0);
return color;
}
任何帮助/提示将不胜感激。
【问题讨论】: