我尝试根据本教程渲染分形:http: //blog.hvidtfeldts.net/index.php/2011/08/distance-estimated-3d-fractals-iii-folding-space/comment-page-1/# comment-20302在“A REAL Fractal”下的那个。问题是,我的光线缺少分形,我得到的只是黑色图像。我认为我的光线错过了分形。我的问题是:
我应该为“Scale”和“Iteration”使用哪些合理的默认值?
生成分形的代码:
distanceFromPoint(vec3 z) {
vec3 a1 = vec3(1,1,1);
vec3 a2 = vec3(-1,-1,1);
vec3 a3 = vec3(1,-1,-1);
vec3 a4 = vec3(-1,1,-1);
vec3 c;
int n = 0;
float dist, d;
while (n < Iterations) {
c = a1; dist = length(z-a1);
d = length(z-a2); if (d < dist) { c = a2; dist=d; }
d = length(z-a3); if (d < dist) { c = a3; dist=d; }
d = length(z-a4); if (d < dist) { c = a4; dist=d; }
z = Scale*z-c*(Scale-1.0);
n++;
}
return (length(z) ) * pow(Scale, -float(n));
光线的构造是否正确?我的“主要”方法的代码:
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_ws.xy;
p.x *= u_aspect;
vec3 ro = 1.1*vec3(2.5*sin(0.25*ctime),1.0+1.0*cos(ctime*.13),2.5*cos(0.25*ctime));
vec3 ww = normalize(vec3(0.0) - ro);
vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww ));
vec3 vv = normalize(cross(ww,uu));
vec3 rd = normalize( p.x*uu + p.y*vv + 2.5*ww );
float totalDistance = 0.0;
vec4 color = vec4(trace(ro, rd));