-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eyden-tracer-05 #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,11 @@ class CSamplerRegular : public CSampler | |
virtual Vec2f getSample(size_t s) const | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return Vec2f::all(0.5f); | ||
// n - number of samples | ||
int n = getNumSamples(); | ||
float i = ((s % n) + 0.5) / float(sqrt(n)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you need to use sort(n) instead of n |
||
float j = ((s / sqrt(n)) + 0.5) / float(sqrt(n)); | ||
// return Vec2f::all(0.5f); | ||
return Vec2f(j, i); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,20 @@ class CSamplerStratified : public CSampler { | |
CSamplerStratified(size_t nSamples) : CSampler(nSamples) {} | ||
virtual ~CSamplerStratified(void) = default; | ||
|
||
virtual Vec2f getSample(size_t s) const | ||
{ | ||
virtual Vec2f getSample(size_t s) const { | ||
// --- PUT YOUR CODE HERE --- | ||
return Vec2f::all(0.5f); | ||
// n - number of samples | ||
int n = getNumSamples(); | ||
|
||
// generating random numbers | ||
// from 0 to 1 | ||
float ei = Random::U<float>(); | ||
float ej = Random::U<float>(); | ||
|
||
float i = ((s % n) + ei) / float(sqrt(n)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you need to use sqrt(n) instead of n |
||
float j = ((s / sqrt(n)) + ej) / float(sqrt(n)); | ||
return Vec2f(j, i); | ||
// return Vec2f::all(0.5f); | ||
} | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,17 +27,55 @@ class CShaderGlossy : public CShaderPhong { | |
virtual Vec3f shade(const Ray& ray) const override { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suspection on plagiarism |
||
Vec3f res = CShaderPhong::shade(ray); | ||
|
||
Vec3f normal = ray.hit->getNormal(ray); // shading normal | ||
Vec3f normal = ray.hit->getNormal(ray); // shading normal | ||
|
||
// --- PUT YOUR CODE HERE --- | ||
int N = m_pSampler -> getNumSamples(); | ||
Vec2f disc; | ||
Vec3f deviatedNormal(0, 0, 0); | ||
for(int i = 0; i < N; i++) { | ||
Vec2f sample = m_pSampler -> getSample(i); | ||
|
||
Ray reflected; | ||
reflected.org = ray.org + ray.dir * ray.t; | ||
reflected.dir = normalize(ray.dir - 2 * normal.dot(ray.dir) * normal); | ||
Vec2f s1 = 2 * sample - Vec2f :: all(0); | ||
|
||
Vec3f reflection = m_scene.RayTrace(reflected); | ||
// // handling the origin degeneracy | ||
// if(s1[0] == 0 && s1[1] == 0) { | ||
// disc = Vec2f :: all(0); | ||
// } | ||
|
||
res = 0.5 * res + 0.5 * reflection; | ||
// applying concentric mapping to point | ||
float theta, r; | ||
if(fabs(s1[0]) > fabs(s1[1])) { | ||
r = s1[0]; | ||
theta = 0.25f * Pif * s1[1] / r; | ||
} | ||
else { | ||
r = s1[1]; | ||
theta = 0.5f * Pif - 0.25 * Pif * s1[0] / r; | ||
} | ||
|
||
float x = r * cosf(theta); | ||
float y = r * sinf(theta); | ||
|
||
x += ((-1) * x * m_glossiness); | ||
y += ((-1) * y * m_glossiness); | ||
|
||
disc = Vec2f(x, y); | ||
Vec2f s2 = disc; | ||
|
||
float z = sqrtf(max(0.0f, 1.0f - s2[0] * s2[0] - s2[1] * s2[1])); | ||
|
||
deviatedNormal = Vec3f(normal.val[0] + s2[0], z, normal.val[2] + s2[1]); | ||
|
||
Ray reflected; | ||
reflected.org = ray.org + ray.dir * ray.t; | ||
reflected.dir = normalize(ray.dir - 2 * deviatedNormal.dot(ray.dir) * deviatedNormal); | ||
|
||
Vec3f reflection = m_scene.RayTrace(reflected); | ||
|
||
res += 0.5 * res + 0.5 * reflection; | ||
} | ||
res /= N; | ||
|
||
return res; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be all the time 0
You need to make it static or member variable to save the state over the different calls of the function