-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneReflectiveObject.cpp
44 lines (38 loc) · 1.21 KB
/
SceneReflectiveObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "StdAfx.h"
#include "SceneReflectiveObject.h"
Ray SceneReflectiveObject::scatter(Ray& inRay) const
{
Ray outRay;
vec3f position = inRay.origin + inRay.direction*inRay.intersectDist;
LocalFrame lf = inRay.intersectObject->getAutoGenWorldLocalFrame(inRay.intersectObjectTriangleID, position);
vec3f normal = lf.n;
outRay.intersectObject = NULL;
outRay.insideObject = inRay.insideObject;
// scatter--start
outRay.origin = position;
vec3f reflDir = -normal.dot(inRay.direction)*normal*2 + inRay.direction;
reflDir.normalize();
outRay.direction = reflDir;
float p = maxVecComp(color);
if(RandGenerator::genFloat() < p)
{
outRay.directionProb = p;
outRay.contactObject = (SceneObject*) this;
outRay.contactObjectTriangleID = inRay.intersectObjectTriangleID;
outRay.directionSampleType = Ray::DEFINITE;
outRay.directionSampleType = outRay.originSampleType = Ray::DEFINITE;
outRay.color = color / outRay.getCosineTerm();
}
else
{
outRay.direction = vec3f(0, 0, 0);
outRay.color = vec3f(0, 0, 0);
outRay.directionProb = 1 - p;
}
// scatter--end
return outRay;
}
float SceneReflectiveObject::getDirectionSampleProbDensity(const Ray& inRay, const Ray& outRay) const
{
return maxVecComp(color);
}