-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcolor.cc
More file actions
89 lines (76 loc) · 2.8 KB
/
getcolor.cc
File metadata and controls
89 lines (76 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
This file is part of the Mandelbox program developed for the course
CS/SE Distributed Computer Systems taught by N. Nedialkov in the
Winter of 2015 at McMaster University.
Copyright (C) 2015 T. Gwosdz and N. Nedialkov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "color.h"
#include "renderer.h"
#include "vector3d.h"
#include <cmath>
#include <algorithm>
using namespace std;
//---lightning and colouring---------
static vec3 CamLight(1.0,1.0,1.0);
static double CamLightW = 1.8;// 1.27536;
static double CamLightMin = 0.3;// 0.48193;
//-----------------------------------
static const vec3 baseColor(1.0, 1.0, 1.0);
static const vec3 backColor(0.4,0.4,0.4);
static const vec3 offsetColor(0.25, 0.3, .6666667);
//-----------------------------------
inline void lighting(const vec3 &n, const vec3 &color, const vec3 &pos, const vec3 &direction, vec3 &outV)
{
//vec3 nn = n -1.0;
//double ambient = max( CamLightMin, direction.Dot() )*CamLightW;
outV = CamLight*max( CamLightMin, direction.Dot(n -1.0) )*CamLightW*color;
}
vec3 getColour(const pixelData &pixData, const RenderParams &render_params,
const vec3 &from, const vec3 &direction)
{
//colouring and lightning
vec3 hitColor = baseColor;
if (pixData.escaped == false)
{
//apply lighting
lighting(pixData.normal, hitColor, pixData.hit, direction, hitColor);
//add normal based colouring
if(render_params.colourType == 0 || render_params.colourType == 1)
{
hitColor = hitColor * pixData.normal;
hitColor = (hitColor + 1.0)/2.0;
hitColor = hitColor*render_params.brightness;
hitColor += offsetColor;
if ( hitColor.x > 1 ) hitColor.x -= 1;
if ( hitColor.y > 1 ) hitColor.y -= 1;
if ( hitColor.z > 1 ) hitColor.z -= 1;
hitColor.z = .5*hitColor.z + .3*hitColor.x + .2*hitColor.y;
hitColor.x = fabs(-1*hitColor.x);
hitColor.y = fabs(-1*hitColor.y);
//gamma correction
clamp(hitColor, 0.0, 1.0);
hitColor = hitColor*hitColor;
}
if(render_params.colourType == 1)
{
//"swap" colors
double t = hitColor.x;
hitColor.x = hitColor.z;
hitColor.z = t;
}
}
else
//we have the background colour
hitColor = backColor;
return hitColor;
}