added jitter parameter to lights, currently uses random vectors, which i'm not happy with; added Vector::getPerpendicularVector() which will be used to replace random jitter for lights
git-svn-id: svn://anubis/fart/trunk@256 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
1af787b9ab
commit
eb14077ab7
@ -12,7 +12,9 @@ Light::Light()
|
|||||||
m_radius = 1.0;
|
m_radius = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector Light::getJitterPosition() const
|
Vector Light::getJitterPosition(int index) const
|
||||||
{
|
{
|
||||||
|
if (index == 0)
|
||||||
|
return m_position;
|
||||||
return m_position + Vector::randomVector() * m_radius;
|
return m_position + Vector::randomVector() * m_radius;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class Light
|
|||||||
void setPosition(refptr<Vector> vec) { setPosition(*vec); }
|
void setPosition(refptr<Vector> vec) { setPosition(*vec); }
|
||||||
const Vector & getPosition() const { return m_position; }
|
const Vector & getPosition() const { return m_position; }
|
||||||
|
|
||||||
Vector getJitterPosition() const;
|
Vector getJitterPosition(int index) const;
|
||||||
|
|
||||||
void setDiffuseColor(const Color & diffuse)
|
void setDiffuseColor(const Color & diffuse)
|
||||||
{
|
{
|
||||||
@ -27,9 +27,13 @@ class Light
|
|||||||
m_specular_color = specular;
|
m_specular_color = specular;
|
||||||
}
|
}
|
||||||
const Color & getSpecularColor() const { return m_specular_color; }
|
const Color & getSpecularColor() const { return m_specular_color; }
|
||||||
|
|
||||||
void setJitter(int j) { m_jitter = j; }
|
void setJitter(int j) { m_jitter = j; }
|
||||||
int getJitter() const { return m_jitter; }
|
int getJitter() const { return m_jitter; }
|
||||||
|
|
||||||
|
void setRadius(double r) { m_radius = r; }
|
||||||
|
double getRadius() const { return m_radius; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Vector m_position;
|
Vector m_position;
|
||||||
Color m_diffuse_color;
|
Color m_diffuse_color;
|
||||||
|
@ -395,6 +395,14 @@ refptr<Light> Scene::processLight(refptr<Node> node)
|
|||||||
light->setDiffuseColor(c);
|
light->setDiffuseColor(c);
|
||||||
light->setSpecularColor(c);
|
light->setSpecularColor(c);
|
||||||
}
|
}
|
||||||
|
else if ( typeid(**it) == typeid(RadiusNode) )
|
||||||
|
{
|
||||||
|
light->setRadius((*it)->getNumber());
|
||||||
|
}
|
||||||
|
else if ( typeid(**it) == typeid(JitterNode) )
|
||||||
|
{
|
||||||
|
light->setJitter((*it)->getInteger());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return light;
|
return light;
|
||||||
|
@ -224,14 +224,20 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
it != m_lights.end();
|
it != m_lights.end();
|
||||||
it++)
|
it++)
|
||||||
{
|
{
|
||||||
Vector directionToLight = (*it)->getPosition() - surfacePoint;
|
for (int jitter_index = 0, jitter_max = (*it)->getJitter();
|
||||||
|
jitter_index < jitter_max;
|
||||||
|
jitter_index++)
|
||||||
|
{
|
||||||
|
Vector lightPosition = (*it)->getJitterPosition(jitter_index);
|
||||||
|
Vector directionToLight = lightPosition - surfacePoint;
|
||||||
directionToLight.normalize();
|
directionToLight.normalize();
|
||||||
Vector reflectedLightDirection =
|
Vector reflectedLightDirection =
|
||||||
directionToLight.reflect(surfaceNormal);
|
directionToLight.reflect(surfaceNormal);
|
||||||
|
|
||||||
Ray surfaceToLight(surfacePoint, directionToLight);
|
Ray surfaceToLight(surfacePoint, directionToLight);
|
||||||
Color light_contribution =
|
Color light_contribution =
|
||||||
calculateLightContribution(surfaceToLight.shift(0.0001), *it);
|
calculateLightContribution(surfaceToLight.shift(0.0001),
|
||||||
|
lightPosition);
|
||||||
|
|
||||||
if ( light_contribution.r > 0.0
|
if ( light_contribution.r > 0.0
|
||||||
|| light_contribution.g > 0.0
|
|| light_contribution.g > 0.0
|
||||||
@ -244,7 +250,8 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
result += diffuseColor
|
result += diffuseColor
|
||||||
* (*it)->getDiffuseColor()
|
* (*it)->getDiffuseColor()
|
||||||
* diffuse_coef
|
* diffuse_coef
|
||||||
* light_contribution;
|
* light_contribution
|
||||||
|
/ jitter_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate the specular term */
|
/* calculate the specular term */
|
||||||
@ -254,7 +261,9 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
result += specularColor
|
result += specularColor
|
||||||
* (*it)->getSpecularColor()
|
* (*it)->getSpecularColor()
|
||||||
* pow(specular_coef, shininess)
|
* pow(specular_coef, shininess)
|
||||||
* light_contribution;
|
* light_contribution
|
||||||
|
/ jitter_max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,10 +272,10 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Color Scene::calculateLightContribution(const Ray & toLight,
|
Color Scene::calculateLightContribution(const Ray & toLight,
|
||||||
refptr<Light> light)
|
const Vector & lightPosition)
|
||||||
{
|
{
|
||||||
Color contrib(1.0, 1.0, 1.0);
|
Color contrib(1.0, 1.0, 1.0);
|
||||||
double dist_to_light = toLight.getOrigin().dist_to(light->getPosition());
|
double dist_to_light = lightPosition - toLight.getOrigin();
|
||||||
double dist_so_far = 0.0;
|
double dist_so_far = 0.0;
|
||||||
|
|
||||||
Ray currentRay = toLight;
|
Ray currentRay = toLight;
|
||||||
|
@ -49,7 +49,7 @@ class Scene
|
|||||||
const Vector & surfacePoint,
|
const Vector & surfacePoint,
|
||||||
const Vector & surfaceNormal);
|
const Vector & surfaceNormal);
|
||||||
Color calculateLightContribution(const Ray & toLight,
|
Color calculateLightContribution(const Ray & toLight,
|
||||||
refptr<Light> light);
|
const Vector & lightPosition);
|
||||||
|
|
||||||
/* In Scene-load.cc */
|
/* In Scene-load.cc */
|
||||||
void load(const char * filename);
|
void load(const char * filename);
|
||||||
|
@ -15,7 +15,7 @@ scene
|
|||||||
light
|
light
|
||||||
{
|
{
|
||||||
position <-1, -3, 4>
|
position <-1, -3, 4>
|
||||||
jitter 5
|
jitter 50
|
||||||
}
|
}
|
||||||
|
|
||||||
plane
|
plane
|
||||||
|
@ -83,6 +83,18 @@ Vector Vector::reflect(const Vector & target) const
|
|||||||
return (*this) + me_to_proj * 2.0;
|
return (*this) + me_to_proj * 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector Vector::getPerpendicularVector() const
|
||||||
|
{
|
||||||
|
Vector t = *this;
|
||||||
|
t.normalize();
|
||||||
|
Vector p = t * Vector(0, 0, 1);
|
||||||
|
if (p.mag() <= 0.1)
|
||||||
|
{
|
||||||
|
p = t * Vector(1, 0, 0);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
||||||
{
|
{
|
||||||
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
||||||
|
@ -19,7 +19,8 @@ class Vector
|
|||||||
double dist_to(const Vector & other) const;
|
double dist_to(const Vector & other) const;
|
||||||
Vector proj(const Vector & target) const;
|
Vector proj(const Vector & target) const;
|
||||||
Vector reflect(const Vector & target) const;
|
Vector reflect(const Vector & target) const;
|
||||||
operator double() { return mag(); }
|
operator double() const { return mag(); }
|
||||||
|
Vector getPerpendicularVector() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_array[3];
|
double m_array[3];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user