脚踏实地

心 勿噪

please please please, make it smaller!

http://www.iquilezles.org/blog/?p=2828

I think size matters. However, unlike in real life, when programming the smaller the better. Generally. Also, the less branches the better, at least when programming for parallel systems. And also, the more compact and regular, the prettier (but this is my personal opinion only).
Related to this, in the last 6 months I have pointed out / proposed this same optimization to at least five different people. Basically, it seems most people make this same “mistake” over and over again, which is to write this horrifying thing
vec3 color = vec3(0.0);
if (theta < 1.0) {
color.r = 1.0;
color.g = theta;
}
else if (theta < 2.0) {
color.r = 2.0 - theta;
color.g = 1.0;
}
else if (theta < 3.0) {
color.g = 1.0;
color.b = theta - 2.0;
}
else if (theta < 4.0) {
color.g = 4.0 - theta;
color.b = 1.0;
}
else if (theta < 5.0) {
color.r = theta - 4.0;
color.b = 1.0;
}
else {
color.r = 1.0;
color.b = 6.0 - theta;
}
return color;
instead of this equivalent line:
vec3 color = clamp( abs(mod(theta+vec3(0.,4.,2.),6.)-3.)-1., 0., 1. );

posted on 2015-01-05 14:22 LSH 阅读(280) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理