moranzcw / andromeda Goto Github PK
View Code? Open in Web Editor NEWA simple ray tracing renderer written in C++.
License: MIT License
A simple ray tracing renderer written in C++.
License: MIT License
你好github主,我注意到在你的项目中triangle::hit
中,有关于判断det为负的情况,并将他取反尝试矫正成正确的情况。起初我也参考了你的triangle::hit
实现,但我发现当我在加载小球模型的时候,边缘出现了不正确的情况,以及在地板上也出现了不正确的情况。不知你是否也遇到或者知晓这种情况?
以下是跟github主相同逻辑判断triangle::hit
生成的效果图:
以下是我修改triangle::hit
中部分代码后生成的效果图:
很明显,修改之后的效果更符合我预期的样子:
以下是我在我的OfflineRTLab中关于triangle::hit
修改之后的代码
bool triangle::hit(const ray &r_in, double t_min, double t_max, hit_record &rec) const
{
double u, v;
vec3 pvec = cross(r_in.direction(), e2);
// determinant
double det = dot(e1, pvec);
if (det == 0 || det < 0)
return false;
vec3 tvec = r_in.origin() - vertices[0].pos;
// 0.0 <= u <= 1
u = dot(tvec, pvec);
if (u < 0.0 || u > det)
return false;
vec3 qvec = cross(tvec, e1);
// u + v <= 1
v = dot(r_in.direction(), qvec);
if (v < 0.0 || u + v > det)
return false;
double invDet = 1.0 / det;
rec.t = dot(e2, qvec) * invDet;
if (rec.t < t_min || rec.t > t_max)
return false;
rec.p = r_in.at(rec.t);
u = u * invDet;
v = v * invDet;
rec.u = vertices[0].tex_coord.x() * (1 - u - v) + vertices[1].tex_coord.x() * u + vertices[2].tex_coord.x() * v;
rec.v = vertices[0].tex_coord.y() * (1 - u - v) + vertices[1].tex_coord.y() * u + vertices[2].tex_coord.y() * v;
rec.normal = vertices[0].normal * (1 - u - v) + vertices[1].normal * u + vertices[2].normal * v;
rec.mat_ptr = mat_ptr;
return true;
}
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.