Exemplo n.º 1
0
s_res		heart_dst(s_geo sp, s_cam cam, s_res prev)
{
	vec4	p;
	s_res	ret;
	int		i;
	float	step;

	step = 0.2 / 5;
	ret.dst = length(cam.pos - sp.pos) <= sp.bounds ?
		0 : sphere_dst(sp, cam, prev).dst;
	if (ret.dst == prev.dst)
		return (prev);
	p.xyz = cam.pos + ret.dst * cam.ray;
	p.w = heart((p.xyz - sp.pos) * 5 / sp.bounds);
	i = -1;
	while (++i < INT(30 * sp.bounds) && p.w <= 0)
	{
		p.w = heart((p.xyz - sp.pos) * 5 / sp.bounds);
		ret.dst += 0.2 / 5;
		p.xyz = cam.pos + ret.dst * cam.ray;
	}
	if (p.w < 0)
		return (prev);
	ret = end_heart(geo_cam(sp, cam), step, ret, p);
	if (prev.dst > 0 && ret.dst > prev.dst)
		return (prev);
	return (ret);
}
Exemplo n.º 2
0
s_res		goursat_dst(s_geo sp, s_cam cam, s_res prev)
{
	vec4	p;
	s_res	ret;
	int		i;
	float	step;
	int		tmp;

	step = 0.2 / 5;
	ret.dst = length(cam.pos - sp.pos) <=
		sp.bounds ? 0.1 : sphere_dst(sp, cam, prev).dst;
	if (ret.dst < 0)
		return (prev);
	p.xyz = cam.pos + ret.dst * cam.ray;
	i = -1;
	while (++i < INT(sp.bounds) * 30)
	{
		if ((p.w = goursat((p.xyz - sp.pos) * 5 / sp.bounds, sp.a.xyz)) > 0)
			break ;
		ret.dst += step;
		p.xyz = cam.pos + ret.dst * cam.ray;
	}
	if (p.w < 0)
		return (prev);
	return (end_goursat(geo_cam(sp, cam), step, ret, p));
}
Exemplo n.º 3
0
__kernel void		shader(
		__global const int* input,
		__global int* output,
		const size_t count,		//max des ids (ne pas toucher)
		const double2 res,		//resolution de l'ecran
		const double2 rot,		//rotation (fleches)
		const double3 pos,		//position (x: ad; y: ws, z: qe)
		const double4 mouse,	//position souris: xy, dernier click: zw
		const double zoom,		//zoom +- (pas pave numerique)
		const double time,		//temps
		const size_t frame,		//frame (nombe d'iterations passe, utile pour montecarlo)
		const size_t mode)		//incrementer avec barre d'espace: il faut le modulo.
{
	int		id;
	double2				coord;
	double2				uv;
	t_cam				cam;
	t_geo				sphere;

	id = get_global_id(0);
	if (((size_t)id) >= count)
		return ;
	coord = (double2)((id % (int)(res.x)), id / ((int)(res.x)));
	uv = ((coord / res) - 0.5) * 2 * (double2)(1, -1) * normalize(res) * zoom;
	cam.ray = normalize((double3)(uv, 1));
	cam.pos = pos + (double3)(0, 0, -3);
	sphere.pos = (double3)(0, 0, 0);
	sphere.dim.x = 1;
	t_ret tmp;
	tmp.t = -1;
	double t = sphere_dst(cam, sphere, tmp).t;
	output[id] = encode((double3)(1 / t));
}