erebus
diff liberebus/src/brdf.cc @ 2:474a0244f57d
fixed specialization mistake
fixed line endings
added makefiles
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Apr 2014 06:31:10 +0300 |
parents | 4abdce1361b9 |
children | 93894c232d65 |
line diff
1.1 --- a/liberebus/src/brdf.cc Mon Apr 28 05:58:22 2014 +0300 1.2 +++ b/liberebus/src/brdf.cc Mon Apr 28 06:31:10 2014 +0300 1.3 @@ -1,130 +1,130 @@ 1.4 -#include "brdf.h" 1.5 -#include "erebus_impl.h" 1.6 - 1.7 -ReflAttrib::ReflAttrib() 1.8 - : value(1), color(1, 1, 1), map(0) 1.9 -{ 1.10 -} 1.11 - 1.12 -ReflAttrib::ReflAttrib(const Color &col, Texture *tex) 1.13 -{ 1.14 - set_color(col); 1.15 - map = tex; 1.16 -} 1.17 - 1.18 -void ReflAttrib::set_value(float val) 1.19 -{ 1.20 - value = val; 1.21 - color = Color{val, val, val}; 1.22 -} 1.23 - 1.24 -void ReflAttrib::set_color(const Color &col) 1.25 -{ 1.26 - color = col; 1.27 - value = color_luminance(col); 1.28 -} 1.29 - 1.30 -void ReflAttrib::set_map(Texture *tex) 1.31 -{ 1.32 - map = tex; 1.33 -} 1.34 - 1.35 -Texture *ReflAttrib::get_map() const 1.36 -{ 1.37 - return map; 1.38 -} 1.39 - 1.40 -float ReflAttrib::get_value() const 1.41 -{ 1.42 - return value; 1.43 -} 1.44 - 1.45 -float ReflAttrib::get_value(float u, float v) const 1.46 -{ 1.47 - return map ? value * color_luminance(map->lookup(u, v)) : value; 1.48 -} 1.49 - 1.50 -const Color &ReflAttrib::get_color() const 1.51 -{ 1.52 - return color; 1.53 -} 1.54 - 1.55 -Color ReflAttrib::get_color(float u, float v) const 1.56 -{ 1.57 - return map ? color * map->lookup(u, v) : color; 1.58 -} 1.59 - 1.60 -// ---- class Reflectance ---- 1.61 -ReflAttrib Reflectance::def_attrib; 1.62 - 1.63 -Reflectance::Reflectance() 1.64 -{ 1.65 - set_default_attribs(); 1.66 -} 1.67 - 1.68 -void Reflectance::set_attrib(const char *name, const Color &color, Texture *tex) 1.69 -{ 1.70 - attrib[name] = ReflAttrib{color, tex}; 1.71 -} 1.72 - 1.73 -ReflAttrib &Reflectance::get_attrib(const char *name) 1.74 -{ 1.75 - auto it = attrib.find(name); 1.76 - if(it == attrib.end()) { 1.77 - return def_attrib; 1.78 - } 1.79 - return it->second; 1.80 -} 1.81 - 1.82 -const ReflAttrib &Reflectance::get_attrib(const char *name) const 1.83 -{ 1.84 - auto it = attrib.find(name); 1.85 - if(it == attrib.end()) { 1.86 - return def_attrib; 1.87 - } 1.88 - return it->second; 1.89 -} 1.90 - 1.91 -float Reflectance::get_attrib_value(const char *name) const 1.92 -{ 1.93 - return get_attrib(name).get_value(); 1.94 -} 1.95 - 1.96 -float Reflectance::get_attrib_value(const char *name, float u, float v) const 1.97 -{ 1.98 - return get_attrib(name).get_value(u, v); 1.99 -} 1.100 - 1.101 -Color Reflectance::get_attrib_color(const char *name) const 1.102 -{ 1.103 - return get_attrib(name).get_color(); 1.104 -} 1.105 - 1.106 -Color Reflectance::get_attrib_color(const char *name, float u, float v) const 1.107 -{ 1.108 - return get_attrib(name).get_color(u, v); 1.109 -} 1.110 - 1.111 -float Reflectance::sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const 1.112 -{ 1.113 - *indir = sample_dir(norm, outdir); 1.114 - return eval(norm, outdir, *indir); 1.115 -} 1.116 - 1.117 -// --- class LambertRefl --- 1.118 - 1.119 -void LambertRefl::set_default_attribs() 1.120 -{ 1.121 - set_attrib("color", Color(1, 1, 1)); 1.122 -} 1.123 - 1.124 -Vector3 LambertRefl::sample_dir(const Vector3 &norm, const Vector3 &outdir) const 1.125 -{ 1.126 - Vector3 dir = Vector3{randf(-1, 1), randf(-1, 1), randf(-1, 1)}.normalized(); 1.127 - return dot_product(dir, norm) < 0.0 ? -dir : dir; 1.128 -} 1.129 - 1.130 -float LambertRefl::eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const 1.131 -{ 1.132 - return dot_product(norm, outdir); 1.133 -} 1.134 \ No newline at end of file 1.135 +#include "brdf.h" 1.136 +#include "erebus_impl.h" 1.137 + 1.138 +ReflAttrib::ReflAttrib() 1.139 + : value(1), color(1, 1, 1), map(0) 1.140 +{ 1.141 +} 1.142 + 1.143 +ReflAttrib::ReflAttrib(const Color &col, Texture *tex) 1.144 +{ 1.145 + set_color(col); 1.146 + map = tex; 1.147 +} 1.148 + 1.149 +void ReflAttrib::set_value(float val) 1.150 +{ 1.151 + value = val; 1.152 + color = Color{val, val, val}; 1.153 +} 1.154 + 1.155 +void ReflAttrib::set_color(const Color &col) 1.156 +{ 1.157 + color = col; 1.158 + value = color_luminance(col); 1.159 +} 1.160 + 1.161 +void ReflAttrib::set_map(Texture *tex) 1.162 +{ 1.163 + map = tex; 1.164 +} 1.165 + 1.166 +Texture *ReflAttrib::get_map() const 1.167 +{ 1.168 + return map; 1.169 +} 1.170 + 1.171 +float ReflAttrib::get_value() const 1.172 +{ 1.173 + return value; 1.174 +} 1.175 + 1.176 +float ReflAttrib::get_value(float u, float v) const 1.177 +{ 1.178 + return map ? value * color_luminance(map->lookup(u, v)) : value; 1.179 +} 1.180 + 1.181 +const Color &ReflAttrib::get_color() const 1.182 +{ 1.183 + return color; 1.184 +} 1.185 + 1.186 +Color ReflAttrib::get_color(float u, float v) const 1.187 +{ 1.188 + return map ? color * map->lookup(u, v) : color; 1.189 +} 1.190 + 1.191 +// ---- class Reflectance ---- 1.192 +ReflAttrib Reflectance::def_attrib; 1.193 + 1.194 +Reflectance::Reflectance() 1.195 +{ 1.196 + set_default_attribs(); 1.197 +} 1.198 + 1.199 +void Reflectance::set_attrib(const char *name, const Color &color, Texture *tex) 1.200 +{ 1.201 + attrib[name] = ReflAttrib{color, tex}; 1.202 +} 1.203 + 1.204 +ReflAttrib &Reflectance::get_attrib(const char *name) 1.205 +{ 1.206 + auto it = attrib.find(name); 1.207 + if(it == attrib.end()) { 1.208 + return def_attrib; 1.209 + } 1.210 + return it->second; 1.211 +} 1.212 + 1.213 +const ReflAttrib &Reflectance::get_attrib(const char *name) const 1.214 +{ 1.215 + auto it = attrib.find(name); 1.216 + if(it == attrib.end()) { 1.217 + return def_attrib; 1.218 + } 1.219 + return it->second; 1.220 +} 1.221 + 1.222 +float Reflectance::get_attrib_value(const char *name) const 1.223 +{ 1.224 + return get_attrib(name).get_value(); 1.225 +} 1.226 + 1.227 +float Reflectance::get_attrib_value(const char *name, float u, float v) const 1.228 +{ 1.229 + return get_attrib(name).get_value(u, v); 1.230 +} 1.231 + 1.232 +Color Reflectance::get_attrib_color(const char *name) const 1.233 +{ 1.234 + return get_attrib(name).get_color(); 1.235 +} 1.236 + 1.237 +Color Reflectance::get_attrib_color(const char *name, float u, float v) const 1.238 +{ 1.239 + return get_attrib(name).get_color(u, v); 1.240 +} 1.241 + 1.242 +float Reflectance::sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const 1.243 +{ 1.244 + *indir = sample_dir(norm, outdir); 1.245 + return eval(norm, outdir, *indir); 1.246 +} 1.247 + 1.248 +// --- class LambertRefl --- 1.249 + 1.250 +void LambertRefl::set_default_attribs() 1.251 +{ 1.252 + set_attrib("color", Color(1, 1, 1)); 1.253 +} 1.254 + 1.255 +Vector3 LambertRefl::sample_dir(const Vector3 &norm, const Vector3 &outdir) const 1.256 +{ 1.257 + Vector3 dir = Vector3{randf(-1, 1), randf(-1, 1), randf(-1, 1)}.normalized(); 1.258 + return dot_product(dir, norm) < 0.0 ? -dir : dir; 1.259 +} 1.260 + 1.261 +float LambertRefl::eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const 1.262 +{ 1.263 + return dot_product(norm, outdir); 1.264 +}