GithubHelp home page GithubHelp logo

andromeda's People

Contributors

moranzcw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

andromeda's Issues

关于triangle::hit中的计算对渲染结果影响的问题

你好github主,我注意到在你的项目中triangle::hit中,有关于判断det为负的情况,并将他取反尝试矫正成正确的情况。起初我也参考了你的triangle::hit实现,但我发现当我在加载小球模型的时候,边缘出现了不正确的情况,以及在地板上也出现了不正确的情况。不知你是否也遇到或者知晓这种情况?
以下是跟github主相同逻辑判断triangle::hit生成的效果图:
test-ball

以下是我修改triangle::hit中部分代码后生成的效果图:
test-ball-temp

很明显,修改之后的效果更符合我预期的样子:
以下是我在我的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;
	}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.