Skip to content

Commit

Permalink
add sepia effect
Browse files Browse the repository at this point in the history
  • Loading branch information
MNasybullin committed Oct 7, 2020
1 parent dc69032 commit 4957d95
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: sdiego <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 14:12:41 by sdiego #+# #+# */
/* Updated: 2020/10/07 19:20:33 by sdiego ### ########.fr */
/* Updated: 2020/10/07 19:50:13 by sdiego ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -126,6 +126,7 @@ typedef struct s_camera
double half_height;
double pixel_size;
int aliasing;
int sepia;
} t_camera;
/*
typedef struct s_x
Expand Down
17 changes: 16 additions & 1 deletion src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: sdiego <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/08 18:08:48 by sdiego #+# #+# */
/* Updated: 2020/10/07 18:41:12 by sdiego ### ########.fr */
/* Updated: 2020/10/07 19:51:11 by sdiego ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -21,6 +21,7 @@ t_camera camera(double hsize, double vsize, double fov)
c.hsize = hsize;
c.vsize = vsize;
c.aliasing = 0;
c.sepia = 0;
c.fov = fov;
c.transform = identity_matrix();
half_view = tanf(c.fov / 2);
Expand Down Expand Up @@ -80,6 +81,16 @@ typedef struct s_treads
int finish;
} t_treads;

t_color sepia(t_color color)
{
t_color sepia;

sepia.r = (0.396 * color.r) + (0.769 * color.g) + (0.189 * color.b);
sepia.g = (0.349 * color.r) + (0.686 * color.g) + (0.168 * color.b);
sepia.b = (0.272 * color.r) + (0.534 * color.g) + (0.131 * color.b);
return (sepia);
}

void aliasing(t_treads *treads, int x, int y, int remaining)
{
t_ray r;
Expand All @@ -99,6 +110,8 @@ void aliasing(t_treads *treads, int x, int y, int remaining)
i++;
}
col = divide_col(col, 10);
if (treads->camera->sepia == 1)
col = sepia(col);
treads->sdl->img[y * treads->camera->hsize + x] = col_to_int(col);
}

Expand All @@ -120,6 +133,8 @@ void draw(t_treads *treads)
{
r = ray_for_pixel(treads->camera, x, y);
col = color_at(treads->world, r, remaining);
if (treads->camera->sepia == 1)
col = sepia(col);
treads->sdl->img[y * treads->camera->hsize + x] = col_to_int(col);
}
else
Expand Down
7 changes: 6 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: sdiego <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 14:12:33 by sdiego #+# #+# */
/* Updated: 2020/10/07 19:18:40 by sdiego ### ########.fr */
/* Updated: 2020/10/07 19:50:36 by sdiego ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,6 +37,11 @@ int key_press(t_sdl *sdl, t_camera *camera)
camera->aliasing = camera->aliasing == 0 ? 1 : 0;
sdl->progress = 0;
}
else if (sdl->e.key.keysym.sym == SDLK_2)
{
camera->sepia = camera->sepia == 0 ? 1 : 0;
sdl->progress = 0;
}
return (0);
}

Expand Down

0 comments on commit 4957d95

Please sign in to comment.