Ex06.1
This commit is contained in:
parent
19d92d9e30
commit
f561ceec19
2 changed files with 52 additions and 41 deletions
|
@ -56,7 +56,19 @@ Color Texture::color(float u, float v, bool interpolate) const {
|
|||
color = this->getPixelAt(int(roundf(u * this->width())), int(roundf(v * this->height())));
|
||||
} else {
|
||||
// IMPLEMENT bilinear interpolation
|
||||
color = this->getPixelAt(int(roundf(u * this->width())), int(roundf(v * this->height())));
|
||||
float x1 = std::floor(u * this->width());
|
||||
float x2 = std::ceil(u * this->width());
|
||||
float y1 = std::floor(v * this->height());
|
||||
float y2 = std::ceil(v * this->height());
|
||||
float x = u * this->width();
|
||||
float y = v * this->height();
|
||||
Color x1y1 = this->getPixelAt(int(x1), int(y1));
|
||||
Color x2y1 = this->getPixelAt(int(x2), int(y1));
|
||||
Color x1y2 = this->getPixelAt(int(x1), int(y2));
|
||||
Color x2y2 = this->getPixelAt(int(x2), int(y2));
|
||||
Color fxy1 = ((x2 - x) / (x2 - x1)) * x1y1 + ((x - x1) / (x2 - x1)) * x2y1;
|
||||
Color fxy2 = ((x2 - x) / (x2 - x1)) * x1y2 + ((x - x1) / (x2 - x1)) * x2y2;
|
||||
color = ((y2 - y) / (y2 - y1)) * fxy1 + ((y - y1) / (y2 - y1)) * fxy2;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ Color MaterialShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
|
||||
Color surfaceSpecularColor(0, 0, 0);
|
||||
if (this->specularMap != nullptr) {
|
||||
surfaceSpecularColor = this->specularMap->color(ray.surface);
|
||||
surfaceSpecularColor = this->specularMap->color(ray.surface, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,14 +82,13 @@ Color MaterialShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
fragmentColor += specular * illum.color;
|
||||
}
|
||||
|
||||
// Reflected ray
|
||||
fragmentColor += scene.traceRay(reflectionRay) * surfaceReflectanceCoefficient * illum.color;
|
||||
|
||||
}
|
||||
// Reflected ray
|
||||
fragmentColor += scene.traceRay(reflectionRay) * surfaceReflectanceCoefficient * reflectance;
|
||||
|
||||
// Opacity
|
||||
return fragmentColor * surfaceAlphaCoefficient + scene.traceRay(propagatedRay) * (1 - surfaceAlphaCoefficient);
|
||||
|
||||
// return fragmentColor;
|
||||
}
|
||||
|
||||
bool MaterialShader::isTransparent() const { return this->opacity < 1.0f || this->alphaMap; }
|
||||
|
|
Loading…
Reference in a new issue