用函数描绘群山+地形+长城+金字塔+雾气
Posted | archive
代码一共924个字,相当于一篇稍长的高考作文。
float map(float x, float z)
{
// terrain
float f;
f = 0.50000000f*noise2f( 1.0f*x, 1.0f*z);
f += 0.25000000f*noise2f( 2.0f*x, 2.0f*z);
f += 0.12500000f*noise2f( 4.0f*x, 4.0f*z);
f += 0.06250000f*noise2f( 8.0f*x, 8.0f*z);
f += 0.03125000f*noise2f( 16.0f*x, 16.0f*z);
f += 0.01562500f*noise2f( 32.0f*x, 32.0f*z);
f += 0.00781250f*noise2f( 64.0f*x, 64.0f*z);
f += 0.00390625f*noise2f(128.0f*x, 128.0f*z);
f = 0.5f+0.5f*f;
f = f*f*(3.0f-2.0f*f);
f = f*f*(3.0f-2.0f*f);
f = -2.5f + 1.5f*f;
// chinese wall
float cx = x-1.5f*noise2f( 2.0f*x, 2.0f*z);
float cz = z+1.5f*noise2f( 2.0f*x, 2.0f*z);
float di = fabsf(cx+cz);
if( di<0.1f )
f += 0.1f-di;
// pyramid
float g;
z -= 2.0f;
float rx = x*0.9f-z*0.2f;
float rz = x*0.2f+z*0.9f;
g = 0.25f - fabsf(rx*1.65f) - fabsf(rz*1.65f);
g = ((int)(g*10.0f))/10.0f; // stairs
if( fabsf(rx+rz)<0.1f || fabsf(rx-rz)<0.1f ) // path
g += 0.1f;
// select terrain or pyramid
if( g>f ) f=g;
return f;
}
void fog(float *rgb, float t, const float *rayDir)
{
float fog = (1.0f-m2xf(-2.5f*rayDir[1]*t) ) / rayDir[1];
collerp(rgb, fog*0.01f, rgb, fogColor);
}
同样的场景用自然语言精确描述又需要多少字呢?
来源:4k intro常见技巧讲述pdf。作者是rgba的iq。做demoscene的大神。。。
Comments