コード例 #1
0
ファイル: lighting.c プロジェクト: Kikoman90/RTv1
float			*ft_lambert(t_th *mlx, t_obj *tmp, t_obj *light, float *tab)
{
	t_vec	pos;
	t_vec	dist;
	float	d;

	pos = (t_vec){mlx->cam_pos.x + mlx->t * mlx->ray_dir.x, mlx->cam_pos.y +
		mlx->t * mlx->ray_dir.y, mlx->cam_pos.z + mlx->t * mlx->ray_dir.z};
	mlx->norm = ft_norm(mlx, tmp, pos);
	while (light != NULL)
	{
		LAMBERT = 0.15;
		dist = ft_vectorsub(&light->pos, &pos);
		d = ft_clamp((1.0 / sqrtf(sqrtf(ft_vectordot(&dist, &dist)))), 0., 1.);
		ft_vectornorm(&dist);
		if (ft_shadow(mlx, tmp, light, pos) == 0)
			LAMBERT += ft_clamp(ft_vectordot(&dist, &mlx->norm), 0.0, 1.0);
		tab = ft_endlight(tmp, light, tab, d);
		tab[0] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		tab[1] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		tab[2] += (COND2) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		light = light->next;
	}
	mlx->refpos = (t_vec){mlx->ray_dir.x, mlx->ray_dir.y, mlx->ray_dir.z};
	return ((PREF2) ? tab : ft_reflect(mlx, tmp, &pos, tab));
}
コード例 #2
0
ファイル: lighting.c プロジェクト: Kikoman90/RTv1
static float	*ft_reflect(t_th *mlx, t_obj *tmp, t_vec *pos, float *tab)
{
	t_obj	*tmp2;
	t_obj	*light;
	t_vec	dist;
	double	d;

	if (mlx->cpt >= mlx->maxref || (light = mlx->light) == NULL)
		return (tab);
	if ((tmp2 = ft_ref_init(mlx, tmp, pos)) == NULL || (mlx->cpt++) < 0)
		return (tab);
	while (light != NULL)
	{
		LAMBERT = 0.14;
		dist = ft_vectorsub(&light->pos, pos);
		d = ft_clamp(1.0 / sqrtf(sqrtf(ft_vectordot(&dist, &dist))), 0.0, 1.0);
		ft_vectornorm(&dist);
		if (ft_shadow(mlx, tmp2, light, *pos) == 0)
			LAMBERT += ft_clamp(ft_vectordot(&dist, &mlx->norm), 0.0, 1.0);
		tab = ft_endlight(tmp2, light, tab, d);
		tab[0] += (COND1) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		tab[1] += (COND1) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		tab[2] += (COND1) ? ft_spec(mlx, dist, d, tab[3]) : 0.0;
		light = light->next;
	}
	return ((PREF1) ? tab : ft_reflect(mlx, tmp2, pos, tab));
}
コード例 #3
0
ファイル: add.c プロジェクト: jfortin42/tamer
float		*ft_endlight(t_obj *tmp, t_obj *light, float *tab, float d)
{
	LAMBERT = ft_clamp(LAMBERT * 4.0 * d, 0.0, 1.0);
	tab[0] += LAMBERT * (tmp->col.red / 255) * (light->col.red / 255);
	tab[1] += LAMBERT * (tmp->col.green / 255) * (light->col.green / 255);
	tab[2] += LAMBERT * (tmp->col.blue / 255) * (light->col.blue / 255);
	return (tab);
}
コード例 #4
0
ファイル: ft_vec2.c プロジェクト: emjmeiring/wolf3d
void	vecclamp(t_vec3 *vec, double a, double b)
{
	vec->x = ft_clamp(vec->x, a, b);
	vec->y = ft_clamp(vec->y, a, b);
	vec->z = ft_clamp(vec->z, a, b);
}