tcbrindle / raytracer.hpp Goto Github PK
View Code? Open in Web Editor NEWSimple compile-time raytracer using C++17
Simple compile-time raytracer using C++17
ERROR :
/home/abhi/raytracer.hpp/raytracer.hpp:432:62: in constexpr expansion of 'rt::cmath::pow(((float)specular), ((int)surf.rt::surface::roughness))'
/home/abhi/raytracer.hpp/raytracer.hpp:79:20: in constexpr expansion of 'std::pow<float, int>(base, iexp)'
/usr/include/c++/7/cmath:418:17: error: 'pow(2.2191121242940426e-3, 2.5e+2)' is not a constant expression
return pow(__type(__x), __type(__y));
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
How do I fix this?
I get the following error:
Scanning dependencies of target raytracer-ct
[ 16%] Building CXX object CMakeFiles/raytracer-ct.dir/compile_time.cpp.o
/home/v/compile/raytracer.hpp/compile_time.cpp:78:20: error: constexpr variable 'image' must be initialized by a constant expression
constexpr auto image = [] {
^ ~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/cmath:464:12: note: subexpression not valid in a constant expression
{ return __builtin_sqrtf(__x); }
^
/home/v/compile/raytracer.hpp/raytracer.hpp:52:12: note: in call to 'sqrt(3.425000e+01)'
return std::sqrt(val);
^
/home/v/compile/raytracer.hpp/raytracer.hpp:117:12: note: in call to 'sqrt(3.425000e+01)'
return cmath::sqrt(dot(v, v));
^
/home/v/compile/raytracer.hpp/raytracer.hpp:122:27: note: in call to 'mag(look_at - pos)'
return (real_t{1.0} / mag(v)) * v;
^
/home/v/compile/raytracer.hpp/raytracer.hpp:167:23: note: in call to 'norm(look_at - pos)'
forward{norm(look_at - pos)},
^
/home/v/compile/raytracer.hpp/compile_time.cpp:33:16: note: in call to 'camera(rt::vec3{3., 2., 4.}, rt::vec3{-1., 0.5, 0.})'
camera cam_{vec3{ 3.0, 2.0, 4.0 }, vec3{ -1.0, 0.5, 0.0 }};
^
/home/v/compile/raytracer.hpp/compile_time.cpp:81:18: note: in call to 'static_scene()'
r.render(static_scene{}, c, c.width, c.height);
^
/home/v/compile/raytracer.hpp/compile_time.cpp:78:28: note: in call to '&[] {
rt::ray_tracer r{};
static_canvas<32, 32> c{};
r.render((anonymous namespace)::static_scene{}, c, c.width, c.height);
return c;
}
->operator()()'
constexpr auto image = [] {
^
1 error generated.
In rt::sqrt
when NaN is passed to val
, it will be in an infinite loop.
Right way is to use CMAKE_CXX_STANDARD
and not an option -std=c++1z
directly.
If there are too many ray bounces, the color result is an average of the albedo and grey, which does not look right in my opinion. I tried setting reflection to the current albedo, if there were too many bounces.
You can compare pow(2, 3) and std::pow(2, 3) for instance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.