mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
reformat light
This commit is contained in:
parent
9e9d7351bd
commit
368039b57c
2 changed files with 11 additions and 12 deletions
|
@ -12,9 +12,9 @@ void Light::setUseCenter(bool useCenter) { this->useCenter = useCenter; }
|
||||||
|
|
||||||
void Light::setIsUse(bool isUse) { this->use = isUse; }
|
void Light::setIsUse(bool isUse) { this->use = isUse; }
|
||||||
|
|
||||||
Vector3f Light::getDiffuse() const { return diffuse; }
|
Vector3f Light::id() const { return id_; }
|
||||||
|
|
||||||
Vector3f Light::getSpecular() const { return specular; }
|
Vector3f Light::is() const { return is_; }
|
||||||
|
|
||||||
bool Light::isUse() const { return use; }
|
bool Light::isUse() const { return use; }
|
||||||
|
|
||||||
|
@ -32,13 +32,12 @@ Vector3f PointLight::illumination(const HitRecord &hit,
|
||||||
|
|
||||||
Vector3f ambient_ = geometry->ka() * geometry->ca();
|
Vector3f ambient_ = geometry->ka() * geometry->ca();
|
||||||
|
|
||||||
Vector3f diffuse_ = geometry->kd() * geometry->cd().array() *
|
Vector3f diffuse_ = geometry->kd() * geometry->cd().array() * id_.array() *
|
||||||
diffuse.array() *
|
|
||||||
std::max(0.0f, hit.normal().dot(rayDirection));
|
std::max(0.0f, hit.normal().dot(rayDirection));
|
||||||
|
|
||||||
Vector3f halfWay = (hit.viewDirection() + rayDirection).normalized();
|
Vector3f halfWay = (hit.viewDirection() + rayDirection).normalized();
|
||||||
Vector3f specular_ =
|
Vector3f specular_ =
|
||||||
geometry->ks() * geometry->cs().array() * specular.array() *
|
geometry->ks() * geometry->cs().array() * is_.array() *
|
||||||
pow(std::max(0.0f, hit.normal().dot(halfWay)), geometry->phong());
|
pow(std::max(0.0f, hit.normal().dot(halfWay)), geometry->phong());
|
||||||
|
|
||||||
return specular_ + ambient_ + diffuse_;
|
return specular_ + ambient_ + diffuse_;
|
||||||
|
|
14
src/Light.h
14
src/Light.h
|
@ -21,11 +21,11 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Light(Type type, const Vector3f &id, const Vector3f &is)
|
Light(Type type, const Vector3f &id, const Vector3f &is)
|
||||||
: type(type), diffuse(id), specular(is) {}
|
: type_(type), id_(id), is_(is) {}
|
||||||
|
|
||||||
Type type;
|
Type type_;
|
||||||
Vector3f diffuse;
|
Vector3f id_;
|
||||||
Vector3f specular;
|
Vector3f is_;
|
||||||
Matrix4f transform = Matrix4f::Identity(); // optional member `transform`
|
Matrix4f transform = Matrix4f::Identity(); // optional member `transform`
|
||||||
unsigned int gridSize = 0; // optional member `n`
|
unsigned int gridSize = 0; // optional member `n`
|
||||||
bool useCenter = false; // optional member `usecenter`
|
bool useCenter = false; // optional member `usecenter`
|
||||||
|
@ -36,8 +36,8 @@ public:
|
||||||
void setGridSize(unsigned int);
|
void setGridSize(unsigned int);
|
||||||
void setUseCenter(bool);
|
void setUseCenter(bool);
|
||||||
void setIsUse(bool);
|
void setIsUse(bool);
|
||||||
Vector3f getDiffuse() const;
|
Vector3f id() const;
|
||||||
Vector3f getSpecular() const;
|
Vector3f is() const;
|
||||||
bool isUse() const;
|
bool isUse() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public:
|
||||||
: Light(Type::Point, id, is), center(center) {}
|
: Light(Type::Point, id, is), center(center) {}
|
||||||
|
|
||||||
PointLight(const AreaLight &al, const Vector3f ¢er)
|
PointLight(const AreaLight &al, const Vector3f ¢er)
|
||||||
: PointLight(al.getDiffuse(), al.getSpecular(), center) {}
|
: PointLight(al.id(), al.is(), center) {}
|
||||||
|
|
||||||
virtual Vector3f illumination(const HitRecord &,
|
virtual Vector3f illumination(const HitRecord &,
|
||||||
const vector<Geometry *> &) const override;
|
const vector<Geometry *> &) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue