-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetcolor_para.cc
91 lines (76 loc) · 2.66 KB
/
getcolor_para.cc
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
90
91
/*
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_para.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.15,0.15,0.15);
//-----------------------------------
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, nn.Dot(direction) )*CamLightW;
outV = CamLight*ambient*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.5;
hitColor = hitColor*render_params.brightness;
//gamma correction
clamp(hitColor, 0.0, 1.0);
hitColor = hitColor*hitColor;
double r, g, b;
//BRIGHT GREEN
r = 0;//0.94118 - 0.78431;
g = 0.58824 - 1.0;
b = 0; //.58824 - 0.23529;
hitColor.x = (hitColor.x * r) + 0;
hitColor.y = (hitColor.y * g) + 0.95;
hitColor.z = (hitColor.z * b) + 0;
}
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;
}