当前位置: 首页>>代码示例>>C++>>正文


C++ LocalFrame::buildFromNormal方法代码示例

本文整理汇总了C++中LocalFrame::buildFromNormal方法的典型用法代码示例。如果您正苦于以下问题:C++ LocalFrame::buildFromNormal方法的具体用法?C++ LocalFrame::buildFromNormal怎么用?C++ LocalFrame::buildFromNormal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LocalFrame的用法示例。


在下文中一共展示了LocalFrame::buildFromNormal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getAutoGenWorldLocalFrame

LocalFrame SceneObject::getAutoGenWorldLocalFrame(unsigned fi, const vec3f& position, bool flat) const
{
	LocalFrame lf;
	lf.buildFromNormal(getWorldNormal(fi, position, flat));
	/*
	lf.n = getWorldNormal(fi, position, flat);
	vec3f tmpT;
	tmpT = (std::abs(lf.n.z) > 0.99f) ? vec3f(1,0,0) : vec3f(0,0,1);
	lf.s = lf.n.cross(tmpT);
	lf.s.normalize();
	lf.t = lf.s.cross(lf.n);
	lf.t.normalize();
	*/
	/*
	vec3f axis = up.cross(lf.n);
	float angle = acos(clampf(up.dot(lf.n), -1, 1));
	
	if (!(axis.length() >= 1e-6f || (axis.length() < 1e-6f && n.dot(lf.n) == 1.f)))
	{
		printf("error , %.8f\n" , n.dot(lf.n));
	}
	axis.normalize();
	//if (axis.length() < 1e-6f)
	//{
	//	lf.s = vec3f(1,0,0);
	//	lf.t = vec3f(0,0,1);
	//}
	//else
	{
		lf.s = vec3f(rotMat(axis, angle)*vec4<float>(vec3f(1,0,0), 0));
		lf.t = vec3f(rotMat(axis, angle)*vec4<float>(vec3f(0,0,1), 0));
	}
	*/
	return lf;
}
开发者ID:winmad,项目名称:Renderer,代码行数:35,代码来源:SceneObject.cpp

示例2: getDirectionSampleProbDensity

float GlossyMaterial::getDirectionSampleProbDensity(const Ray& inRay, const Ray& outRay) const
{
	if(!outRay.contactObject)
		return 0;
	LocalFrame lf;
	vec3f normal = outRay.getContactNormal();
	vec3f reflDir = -normal.dot(inRay.direction)*normal*2 + inRay.direction;
	lf.buildFromNormal(reflDir);
	vec3f coeff = coeffTex.getColor(outRay.contactObject->getTexCoord(outRay.contactObjectTriangleID, outRay.origin));
	return cosineSphericalSampler.getProbDensity(lf, outRay.direction, coeff.x);
}
开发者ID:winmad,项目名称:RenderX,代码行数:11,代码来源:GlossyMaterial.cpp

示例3: getDirectionSampleProbDensity

float SceneVPMObject::getDirectionSampleProbDensity(const Ray &inRay, const Ray &outRay) const{
	if(outRay.directionSampleType == Ray::DEFINITE)
		return 0;
	if(outRay.contactObject)
		return outRay.contactObject->getDirectionSampleProbDensity(inRay, outRay);
	HGPhaseSampler hgPhaseSampler(g);
	LocalFrame lf;	lf.buildFromNormal(inRay.direction);
	float albedo = y(ds) / y(dt);
	float oPdfW = hgPhaseSampler.getProbDensity(lf, outRay.direction);
	return albedo*oPdfW;
}
开发者ID:winmad,项目名称:RenderX,代码行数:11,代码来源:SceneVPMObject.cpp

示例4: scatter

Ray SceneVPMObject::scatter(const Ray& inRay, const bool fixIsLight, const bool russian) const
{
	Ray outRay;
	outRay.directionSampleType = Ray::RANDOM;
	HomoMediaDistSampler logDistSampler(dt);
	float sampDist = logDistSampler.sampleDist();

	bool go_in_vol  = (inRay.intersectObject == this) && (inRay.insideObject != this);
	bool be_in_vol  = (inRay.insideObject == this);
	bool out_of_vol = (sampDist >= inRay.intersectDist); // hit a surface

	// go in volume
	if(go_in_vol){
		vec3f position = inRay.origin + inRay.direction*inRay.intersectDist;
		LocalFrame lf = inRay.intersectObject->getAutoGenWorldLocalFrame(inRay.intersectObjectTriangleID, position, flatNormals);
		vec3f normal = lf.n;
		outRay.origin = position;
		outRay.direction = inRay.direction;
		
		vec3f reflDir = -normal.dot(inRay.direction)*normal*2 + inRay.direction;
		reflDir.normalize();
		float theta = acos(inRay.direction.dot(normal));
		
		SceneObject* currentInsideObject = inRay.insideObject;
		SceneObject* outSideObject = (SceneObject*)this;

		float current_n = currentInsideObject ? currentInsideObject->getRefrCoeff() : 1;
		float next_n = outSideObject ? outSideObject->getRefrCoeff() : 1;
		float sin_phi = current_n / next_n * sin(theta);

		outRay.intersectObject = NULL;
		outRay.color = vec3f(1, 1, 1);
		outRay.directionProb = 1;
		outRay.contactObject = (SceneObject*)this;
		outRay.contactObjectTriangleID = inRay.intersectObjectTriangleID;

		if(sin_phi >= 1){ // no total internal reflection
			outRay.direction = vec3f(0.f);
			outRay.contactObject = NULL;
			outRay.contactObjectTriangleID = -1;
			outRay.directionSampleType = Ray::DEFINITE;
			return outRay;

// 			outRay.direction = reflDir;
// 			outRay.insideObject = inRay.insideObject;
// 			outRay.directionProb = 1;
// 			outRay.directionSampleType = Ray::DEFINITE;
// 			outRay.photonType = Ray::NOUSE;
// 			outRay.color /= outRay.getCosineTerm();

			//if (abs(outRay.getCosineTerm() - 1.f) > 1e-6f)
			//	printf("exception1: %.6f\n" , outRay.getCosineTerm());
		}
		else{
			float phi = asin(sin_phi);
			if(theta > M_PI/2)
				phi = M_PI - phi;
			vec3f axis = normal.cross(inRay.direction);
			axis.normalize();
			outRay.direction = vec3f(rotMat(axis, phi) * vec4<float>(normal, 0));
			outRay.direction.normalize();

			float cos_theta = abs(cos(theta));
			float cos_phi = abs(cos(phi));
			float esr = powf(abs(current_n*cos_theta-next_n*cos_phi)/(current_n*cos_theta+next_n*cos_phi),2);
			float epr = powf(abs(next_n*cos_theta-current_n*cos_phi)/(next_n*cos_theta+current_n*cos_phi),2);
			float er = (esr+epr)*0.5f;
			float p = clampf(er , 0.f , 1.f);

			if(RandGenerator::genFloat() < p)
			{
				outRay.direction = reflDir;
				outRay.color *= er / outRay.getCosineTerm();
				outRay.directionProb = p;
				outRay.insideObject = inRay.insideObject;
				outRay.directionSampleType = Ray::DEFINITE;
				outRay.photonType = Ray::NOUSE;
			}
			else
			{
				if (!fixIsLight) outRay.color *= (current_n * current_n) / (next_n * next_n);
				//printf("go in: %.6f/%.6f\n" , current_n , next_n);
				outRay.color *= (1-er) / outRay.getCosineTerm();
				outRay.directionProb = 1-p;
				outRay.contactObject = outRay.insideObject = (SceneObject*)this;
				outRay.directionSampleType = Ray::DEFINITE;
				outRay.photonType = Ray::HITVOL;
			
			}
			outRay.direction.normalize();
		}

		return outRay;
	}
	// in volume
	if(be_in_vol && !out_of_vol){
		HGPhaseSampler hgPhaseSampler(g);
		//IsotropicPhaseSampler sp;
		LocalFrame lf;		lf.buildFromNormal(inRay.direction);

//.........这里部分代码省略.........
开发者ID:winmad,项目名称:RenderX,代码行数:101,代码来源:SceneVPMObject.cpp


注:本文中的LocalFrame::buildFromNormal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。