我对 Cg 着色器有疑问。
我正在使用着色器来显示热图,因此它会根据屏幕与中心的距离来修改屏幕区域的颜色。问题是如果我需要为很多区域着色,比如通过 300 个点,片段需要循环遍历所有可见屏幕太多次,在这种情况下 1920x1080x300,这显然是一个瓶颈,有没有办法只告诉我的着色器在不使其循环的情况下对区域进行着色?
half4 frag(vertOutput output) : COLOR
{
half h = 0;
for (int i = 0; i < _Points_Length; i ++)
{
half dist = distance(output.worldPos, _Points[i].xyz);//_Points[i].xyz is the point I'm passing to my shader
half radi = _Properties[i].x; //this is the radius of the area around the actual point
half hi = 1 - saturate(dist / radi);
h += hi * _Properties[i].y; //Properties[i].y is just an intensity modifier
}
h = saturate(h);
half4 color = tex2D(_HeatTex, fixed2(h, 0.5));
return color;
}