本文整理汇总了C++中Point3::Dot方法的典型用法代码示例。如果您正苦于以下问题:C++ Point3::Dot方法的具体用法?C++ Point3::Dot怎么用?C++ Point3::Dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point3
的用法示例。
在下文中一共展示了Point3::Dot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getRefractionVector
Point3 getRefractionVector(Point3 view, Point3 normal, float n1, float n2)
{
Point3 Vnormal = normal;
float cosThetaOne = view.Dot(normal) / view.Length();
float sinThetaTwo = (n1 / n2) * sqrt(1 - pow(cosThetaOne, 2));
float cosThetaTwo = sqrt(1 - pow(sinThetaTwo, 2));
Point3 Vt = (view - (view.Dot(normal)*normal)).GetNormalized();
/******************Total Internal Reflection **************************/
//if (sinThetaTwo > 1 || sinThetaTwo < -1) //Checking total interanl reflection
// return(getReflectionVector(-view, normal)); //If happened returning a reflection vector
/*************************End Total Internal Reflection***************/
return ((cosThetaTwo * -1 * Vnormal) + (sinThetaTwo * -1 * Vt));
}
示例2: getOrthoNormalBasisVector
void getOrthoNormalBasisVector(Point3 i_up, Point3 &o_out_vector /*U*/, Point3& o_vector_right /*v*/)
{
Point3 randomVectorW;
//bool foundRandomVector = false;
while (true)
{
randomVectorW = getRandomVector();
if ( fabs(i_up.Dot(randomVectorW)) < RANDOMCOSINEANGLE)
{
o_out_vector = i_up.Cross(randomVectorW);
o_vector_right = i_up.Cross(o_out_vector).GetNormalized();
o_out_vector.Normalize();
break;
}
}
}
示例3: Shade
Color MtlBlinn::Shade(const Ray &ray, const HitInfo &hInfo, const LightList &lights, int reflection_bounceCount, int gi_bounceCount) const
{
Color ambientComp, diffuseComp, specularComp, reflectiveComp, refractiveComp, reflectionTotal, refractionTotal, noColor, diffuseReflection;
diffuseReflection = ambientComp = diffuseComp = specularComp = reflectiveComp = refractiveComp = noColor = reflectionTotal = refractionTotal = Color(0.0f, 0.0f, 0.0f);
Color fromReflection = Color(0.0f, 0.0f, 0.0f);
Color fromRefraction = Color(0.0f, 0.0f, 0.0f);
Point3 viewDirection = -ray.dir;
float schlicksConstant, ratioOfRefraction;
Color kd = diffuse.Sample(hInfo.uvw);
int hitside = HIT_FRONT;
float n1 = 1;
float n2 = ior;
for (int i = 0; i < lights.size(); i++)
{
Color lightColor = lights[i]->Illuminate(hInfo.p, hInfo.N);
/*if (lightColor != noColor)
{*/
if (lights[i]->IsAmbient())
{
ambientComp = ambientComponent(lights[i], lightColor, hInfo, diffuse.Sample(hInfo.uvw));
}
else
{
//lightColor.ClampMinMax();
Point3 rayDir = ray.dir;
globalPhotonMap.EstimateIrradiance<50>(lightColor, rayDir, 2.0f, hInfo.p, &hInfo.N);
diffuseComp = diffuseComponent(lights[i], lightColor, hInfo, diffuse.Sample(hInfo.uvw));
specularComp = specularComponent(lights[i], lightColor, viewDirection, hInfo, specular.Sample(hInfo.uvw), glossiness);
}
//}
}
/************************Refraction************************************************************/
if(refraction.Sample(hInfo.uvw) != noColor && reflection_bounceCount > 0)
{
Ray refractionRay;
HitInfo refractionRayHit;
refractionRayHit.Init();
refractionRay.p = hInfo.p;
if (hInfo.front == HIT_FRONT)
{
refractionRay.dir = getRefractionVector(viewDirection, getPerturbedNormal(hInfo.N, hInfo.p, refractionGlossiness), n1, n2);
}
else
{
refractionRay.dir = getRefractionVector(viewDirection, getPerturbedNormal( -hInfo.N, hInfo.p, refractionGlossiness), n2, n1);
}
if(TraceRay(&rootNode, refractionRay, refractionRayHit, hitside))
{
Point3 refractionDir = refractionRay.dir;
refractiveComp += refractionRayHit.node->GetMaterial()->Shade(refractionRay, refractionRayHit,
lights, --reflection_bounceCount);
refractiveComp *= refraction.Sample(hInfo.uvw);
}
else
{
refractiveComp = environment.SampleEnvironment(refractionRay.dir);
}
}
/********************Schlick's Approximation - Fresnel Reflection***************************/
schlicksConstant = pow(((n1 - n2) / (n1 + n2)), 2);
ratioOfRefraction = schlicksConstant + (1 - schlicksConstant) * pow((1 - viewDirection.Dot(hInfo.N)), 5);
reflectionTotal = ratioOfRefraction*refraction.Sample(hInfo.uvw);
refractionTotal = (1 - ratioOfRefraction)*refraction.Sample(hInfo.uvw);
///*******************************************************************************************/
//refractiv eComp *= refractionTotal; //It = (1-R) * KT'
reflectionTotal += reflection.Sample(hInfo.uvw); //Doing outside in case refraction didn't occured at all
/*********************************************************************************************/
/**********************Reflection*************************************************************/
if(reflectionTotal != noColor && reflection_bounceCount > 0)
{
Ray reflectionViewVector;
reflectionViewVector.dir = getReflectionVector(viewDirection,
getPerturbedNormal(hInfo.N, hInfo.p, reflectionGlossiness));
reflectionViewVector.p = hInfo.p;
HitInfo reflectionRayHit;
reflectionRayHit.Init();
//--reflection_bounceCount;
if (TraceRay(&rootNode, reflectionViewVector, reflectionRayHit, HIT_FRONT))
{
fromReflection += reflectionRayHit.node->GetMaterial()->Shade(reflectionViewVector,
reflectionRayHit, lights, --reflection_bounceCount);
reflectiveComp = reflectionTotal * fromReflection;
}
else
{
reflectiveComp = environment.SampleEnvironment(reflectionViewVector.dir);
}
}
/****************************************************************************************************/
if(GI_ALGO)
{
if (kd != noColor && gi_bounceCount > 0)
{
HemiSphereSampler giHemiSampler = HemiSphereSampler(__gi_sampleCount, __gi_sampleCount, 1);
//.........这里部分代码省略.........
示例4: getReflectionVector
Point3 getReflectionVector(Point3 view, Point3 normal)
{
return((2 * normal * (view.Dot(normal))) - view); //Using Reflection Vector for formulae
}
示例5: Shade
Color MtlBlinn::Shade(const Cone &ray, const HitInfo &hInfo, const LightList &lights, int bounceCount) const{
float bias = BIAS_SHADING;
Color shade;
Color rShade = Color(0,0,0);
Color tShade = Color(0,0,0);
const Material *mat;
mat = hInfo.node->GetMaterial();
const MtlBlinn* mb =static_cast<const MtlBlinn*>(mat);
// cout<<"HInfo front: "<<hInfo.front<<endl;
/* local copy */
Point3 P;
P.Set(hInfo.p.x,hInfo.p.y,hInfo.p.z);
Cone iRay = ray;
Color ambInt = mb->diffuse.Sample(hInfo.uvw, hInfo.duvw);
Color allOther = Color(0,0,0);
Color diffuse = mb->diffuse.Sample(hInfo.uvw, hInfo.duvw);
Color ambComponent = Color(0,0,0);
Point3 newN = hInfo.N;
for ( unsigned int i=0; i<lights.size(); i++ ) {
if(lights[i]->IsAmbient()){
// cout<<"ambient "<<endl;
Color intensity = lights[i]->Illuminate(hInfo.p);
ambComponent += (ambInt * intensity);
continue;
}
else{
// cout<<"other lighting "<<endl;
Point3 L = -lights[i]->Direction(P);
L.Normalize();
Point3 V = ray.p - P;
V.Normalize();
Point3 LplusV = L + V;
Point3 H = (L+V)/LplusV.Length();
H.Normalize();
float alpha = mb->glossiness;
// Point3 N = hInfo.N;
Point3 N = newN;
float S = H.Dot(N);
S = pow(S,alpha);
float costheta = L.Dot(N)/(L.Length() * N.Length());
Color intensity = lights[i]->Illuminate(P);
// cout<<"costheta "<<endl;
allOther += intensity * (costheta>0?costheta:0) * (diffuse + S * (mb->specular.Sample(hInfo.uvw, hInfo.duvw))) ;
}
/* finally add inta*cola + intall*costheta*(cold + s* colS)*/
shade = ambComponent + allOther;
}
/* Calculate refraction */
if(refraction.GetColor().r>0 && bounceCount>0){
//compute new jittered normal
float gloss = refractionGlossiness;
if(gloss){
float random = rand()/(float)RAND_MAX;
float rRadius = sqrtf(random) * gloss;
random = rand()/(float)RAND_MAX;
float rAngle = random * 2.0 * M_PI;
float x = rRadius * cos(rAngle);
float y = rRadius * sin(rAngle);
Point3 xAxis(1,0,0), yAxis(0,1,0), v1, v2, normalDir;
normalDir = hInfo.N;
// normalDir.Normalize();
if(normalDir.Dot(xAxis) > 0.7) v1 = normalDir.Cross(yAxis);
else v1 = normalDir.Cross(xAxis);
v2 = v1.Cross(normalDir);
v1.Normalize(); v2.Normalize();
v1 *= x;
v2 *= y;
newN = hInfo.N + v1.Length() + v2.Length();
newN.Normalize();
}
else{
newN = hInfo.N;
}
//-------------------------------------
Color reflShade = Color(0,0,0);
float R0, Refl = 0.0f, Trans = 0.0f;
HitInfo temp;
temp.Init();
// Point3 N = hInfo.N;
Point3 N = newN;
// Point3 V = Point3(iRay.p.x - hInfo.p.x, iRay.p.y - hInfo.p.y, iRay.p.z - hInfo.p.z);
Point3 V = Point3(hInfo.p.x - iRay.p.x, hInfo.p.y - iRay.p.y, hInfo.p.z - iRay.p.z);
V.Normalize();
float n1 = 1, n2 = 1;
if(hInfo.front){ /* Hitting from outside */
// temp.front = false;
n2 = ior;
// cout<<"outside "<<endl;
}
else if(!hInfo.front){ /* Transmission from the inside */
//.........这里部分代码省略.........
示例6: Illuminate
Color PointLight::Illuminate(Point3 hitPt) const
{
//create a ray towards light
Point3 dir = position - hitPt;
//dir.Normalize();
Ray sRay = Ray(hitPt, dir);
// return intensity * Shadow(sRay, 1);
Point3 xAxis(1,0,0), yAxis(0,1,0), v1;
if(dir.Dot(xAxis) > 0.8) {
v1 = yAxis.Cross(dir);
}
else{
v1 = xAxis.Cross(dir);
}
float shadow = 0.0;
Point3 v2 = v1.Cross(dir);
v2.Normalize();
v1.Normalize();
Point3 xv1 = v1;
Point3 yv2 = v2;
// srand(time(NULL));
float random = 0.0;
for(int i =0; i< MIN_SHADOW_SAMPLES; i++){
random = rand() / (float) RAND_MAX;
float rRadius = sqrtf(random) * size;
random = rand() / (float) RAND_MAX;
float rAngle = random * (2.0 * M_PI);
float xv = rRadius * cos(rAngle);
float yv = rRadius * sin(rAngle);
xv1 *= xv;
yv2 *= yv;
sRay.dir = (position + xv1.Length()+ yv2.Length() ) - hitPt;
// sRay.dir.Normalize();
shadow += Shadow(sRay, 1);
xv1 = v1; yv2 = v2;
}
shadow /= (float)MIN_SHADOW_SAMPLES;
if(shadow != 0.0 && shadow != 1.0)
{
// cout<<"SHADOW: "<<shadow<<endl;
shadow = 0.0;
for(int i = 0; i< MAX_SHADOW_SAMPLES; i++){
random = rand() / (float) RAND_MAX;
float rRadius = sqrtf(random) * size;
random = rand() / (float) RAND_MAX;
float rAngle = random * (2.0 * M_PI);
float xv = rRadius * cos(rAngle);
float yv = rRadius * sin(rAngle);
xv1 *= -xv;
yv2 *= -yv;
sRay.dir = (position +xv1.Length() + yv2.Length() ) - hitPt;
// sRay.dir.Normalize();
shadow += Shadow(sRay, 1);
xv1 = v1; yv2 = v2;
}
shadow /= (float)(MAX_SHADOW_SAMPLES);
}
return intensity * shadow;
}
示例7: Shade
Color MtlBlinn::Shade(const Ray &ray, const HitInfo &hInfo, const LightList &lights, int bounceCount) const{
float bias = BIAS_SHADING;
Color shade;
Color rShade = Color(0,0,0);
Color tShade = Color(0,0,0);
const Material *mat;
mat = hInfo.node->GetMaterial();
const MtlBlinn* mb =static_cast<const MtlBlinn*>(mat);
// cout<<"HInfo front: "<<hInfo.front<<endl;
/* local copy */
Point3 P;
P.Set(hInfo.p.x,hInfo.p.y,hInfo.p.z);
Ray iRay = ray;
Color ambInt = mb->diffuse;
Color allOther = Color(0,0,0);
Color diffuse = mb->diffuse;;
Color ambComponent = Color(0,0,0);
for ( unsigned int i=0; i<lights.size(); i++ ) {
if(lights[i]->IsAmbient()){
// cout<<"ambient "<<endl;
Color intensity = lights[i]->Illuminate(hInfo.p);
ambComponent += (ambInt * intensity);
continue;
}
else{
// cout<<"other lighting "<<endl;
Point3 L = -lights[i]->Direction(P);
L.Normalize();
Point3 V = ray.p - P;
V.Normalize();
Point3 LplusV = L + V;
Point3 H = (L+V)/LplusV.Length();
H.Normalize();
float alpha = mb->glossiness;
Point3 N = hInfo.N;
float S = H.Dot(N);
S = pow(S,alpha);
float costheta = L.Dot(N)/(L.Length() * N.Length());
Color intensity = lights[i]->Illuminate(P);
// cout<<"costheta "<<endl;
allOther += intensity * (costheta>0?costheta:0) * (diffuse + S * (mb->specular)) ;
}
/* finally add inta*cola + intall*costheta*(cold + s* colS)*/
shade = ambComponent + allOther;
}
/* Calculate refraction */
if(refraction.Grey()>0 && bounceCount>0){
Color reflShade = Color(0,0,0);
float R0, Refl = 0.0f, Trans = 0.0f;
HitInfo temp;
temp.Init();
Point3 N = hInfo.N;
// Point3 V = Point3(iRay.p.x - hInfo.p.x, iRay.p.y - hInfo.p.y, iRay.p.z - hInfo.p.z);
Point3 V = Point3(hInfo.p.x - iRay.p.x, hInfo.p.y - iRay.p.y, hInfo.p.z - iRay.p.z);
V.Normalize();
float n1 = 1, n2 = 1;
if(hInfo.front){ /* Hitting from outside */
// temp.front = false;
n2 = ior;
// cout<<"outside "<<endl;
}
else if(!hInfo.front){ /* Transmission from the inside */
// temp.front = true;
n1 = ior;
// cout<<"intside... "<<endl;
N = -hInfo.N;
}
float ratio_n = n1 / n2;
float costheta_v = -V.Dot(N); /* refer: http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf */
float sin2theta_t = ratio_n * ratio_n * (1 - costheta_v * costheta_v);
Point3 T = ratio_n * V + (ratio_n * costheta_v - sqrtf(1 - sin2theta_t)) * N ;
// cout<<ratio_n<<" "<<"cos_v "<<costheta_v<<" sin2theta_t "<<sin2theta_t<<endl;
Ray tRay = Ray(hInfo.p,T);
//tRay.dir.Normalize();
tRay.p.x = tRay.p.x + bias *tRay.dir.x; /* add bias */
tRay.p.y = tRay.p.y + bias *tRay.dir.y;
tRay.p.z = tRay.p.z + bias *tRay.dir.z;
// cout<<"B temp front: "<< temp.front<<endl;
if(sin2theta_t <= 1){
if(RayTrace_2(tRay, temp)){
// bounceCount--;
// cout<<"A temp front: "<< temp.front<<endl;
tShade = temp.node->GetMaterial()->Shade(tRay,temp,lights,bounceCount);
tShade.r *= exp(-absorption.r * temp.z);
tShade.g *= exp(-absorption.g * temp.z);
tShade.b *= exp(-absorption.b * temp.z);
// shade = tShade; /* remove later */
// return shade;
//.........这里部分代码省略.........