trying new jitter method for soft shadows, getting better
git-svn-id: svn://anubis/fart/trunk@257 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
eb14077ab7
commit
57a4e6ed8a
7 files changed
+74
-40
No files matched your search
+1
-1
@@ -28,7 +28,7 @@ class Light
|
||||
}
|
||||
const Color & getSpecularColor() const { return m_specular_color; }
|
||||
|
||||
void setJitter(int j) { m_jitter = j; }
|
||||
void setJitter(int j) { m_jitter = j >= 1 ? j : 1; }
|
||||
int getJitter() const { return m_jitter; }
|
||||
|
||||
void setRadius(double r) { m_radius = r; }
|
||||
|
||||
+52
-36
@@ -1,5 +1,5 @@
|
||||
|
||||
#include <math.h> /* exp(), pow() */
|
||||
#include <math.h> /* exp(), pow(), M_PI */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
@@ -224,48 +224,64 @@ Color Scene::computePhong(const refptr<Material> material,
|
||||
it != m_lights.end();
|
||||
it++)
|
||||
{
|
||||
for (int jitter_index = 0, jitter_max = (*it)->getJitter();
|
||||
jitter_index < jitter_max;
|
||||
jitter_index++)
|
||||
Vector lightC = (*it)->getPosition();
|
||||
double lightRadius = (*it)->getRadius();
|
||||
Vector directionToLightC = lightC - surfacePoint;
|
||||
Vector lightPlaneX = directionToLightC.getPerpendicular().normalize();
|
||||
Vector lightPlaneY = (directionToLightC * lightPlaneX).normalize();
|
||||
int jitter_samples = 0, jitter_level = (*it)->getJitter();;
|
||||
for (int jitter_index = 0; jitter_index < jitter_level; jitter_index++)
|
||||
{
|
||||
Vector lightPosition = (*it)->getJitterPosition(jitter_index);
|
||||
Vector directionToLight = lightPosition - surfacePoint;
|
||||
directionToLight.normalize();
|
||||
Vector reflectedLightDirection =
|
||||
directionToLight.reflect(surfaceNormal);
|
||||
|
||||
Ray surfaceToLight(surfacePoint, directionToLight);
|
||||
Color light_contribution =
|
||||
calculateLightContribution(surfaceToLight.shift(0.0001),
|
||||
lightPosition);
|
||||
|
||||
if ( light_contribution.r > 0.0
|
||||
|| light_contribution.g > 0.0
|
||||
|| light_contribution.b > 0.0 )
|
||||
#if 0
|
||||
double offset = ((double)rand()) / RAND_MAX * M_2_PI;
|
||||
#endif
|
||||
double offset = 0.0;
|
||||
double jitterRadius = jitter_index * lightRadius
|
||||
/ (jitter_level - 0.5);
|
||||
for (int i = 0, num = (int) (M_PI * jitter_index) + 1; i < num; i++)
|
||||
{
|
||||
/* calculate the diffuse term */
|
||||
double diffuse_coef = directionToLight % surfaceNormal;
|
||||
if (diffuse_coef > 0.0)
|
||||
{
|
||||
result += diffuseColor
|
||||
* (*it)->getDiffuseColor()
|
||||
* diffuse_coef
|
||||
* light_contribution
|
||||
/ jitter_max;
|
||||
}
|
||||
jitter_samples++;
|
||||
double jitter_angle = offset + i * M_2_PI / num;
|
||||
Vector jitterPosition = lightC
|
||||
+ lightPlaneX * jitterRadius * cos(jitter_angle)
|
||||
+ lightPlaneY * jitterRadius * sin(jitter_angle);
|
||||
Vector directionToLight = jitterPosition - surfacePoint;
|
||||
directionToLight.normalize();
|
||||
Vector reflectedLightDirection =
|
||||
directionToLight.reflect(surfaceNormal);
|
||||
|
||||
/* calculate the specular term */
|
||||
double specular_coef = reflectedLightDirection % viewDirection;
|
||||
if (specular_coef > 0.0)
|
||||
Ray surfaceToLight(surfacePoint, directionToLight);
|
||||
Color light_contribution =
|
||||
calculateLightContribution(surfaceToLight.shift(0.0001),
|
||||
jitterPosition);
|
||||
|
||||
if ( light_contribution.r > 0.0
|
||||
|| light_contribution.g > 0.0
|
||||
|| light_contribution.b > 0.0 )
|
||||
{
|
||||
result += specularColor
|
||||
* (*it)->getSpecularColor()
|
||||
* pow(specular_coef, shininess)
|
||||
* light_contribution
|
||||
/ jitter_max;
|
||||
/* calculate the diffuse term */
|
||||
double diffuse_coef = directionToLight % surfaceNormal;
|
||||
if (diffuse_coef > 0.0)
|
||||
{
|
||||
result += diffuseColor
|
||||
* (*it)->getDiffuseColor()
|
||||
* diffuse_coef
|
||||
* light_contribution;
|
||||
}
|
||||
|
||||
/* calculate the specular term */
|
||||
double specular_coef = reflectedLightDirection % viewDirection;
|
||||
if (specular_coef > 0.0)
|
||||
{
|
||||
result += specularColor
|
||||
* (*it)->getSpecularColor()
|
||||
* pow(specular_coef, shininess)
|
||||
* light_contribution;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result /= jitter_samples;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user