added jitter and radius parameters to light objects; not using them yet
git-svn-id: svn://anubis/fart/trunk@255 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
bc27be0f85
commit
1af787b9ab
@ -1,11 +1,18 @@
|
|||||||
|
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include "util/Vector.h"
|
#include "util/Vector.h"
|
||||||
|
#include "util/Ray.h"
|
||||||
|
|
||||||
Light::Light()
|
Light::Light()
|
||||||
{
|
{
|
||||||
m_position = Vector(0, 0, 0);
|
m_position = Vector(0, 0, 0);
|
||||||
m_diffuse_color = Color::white;
|
m_diffuse_color = Color::white;
|
||||||
m_specular_color = Color::white;
|
m_specular_color = Color::white;
|
||||||
|
m_jitter = 1;
|
||||||
|
m_radius = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector Light::getJitterPosition() const
|
||||||
|
{
|
||||||
|
return m_position + Vector::randomVector() * m_radius;
|
||||||
|
}
|
||||||
|
@ -14,6 +14,8 @@ 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;
|
||||||
|
|
||||||
void setDiffuseColor(const Color & diffuse)
|
void setDiffuseColor(const Color & diffuse)
|
||||||
{
|
{
|
||||||
m_diffuse_color = diffuse;
|
m_diffuse_color = diffuse;
|
||||||
@ -25,11 +27,15 @@ 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; }
|
||||||
|
int getJitter() const { return m_jitter; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Vector m_position;
|
Vector m_position;
|
||||||
Color m_diffuse_color;
|
Color m_diffuse_color;
|
||||||
Color m_specular_color;
|
Color m_specular_color;
|
||||||
|
double m_radius;
|
||||||
|
int m_jitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "PointLight.h"
|
#include "PointLight.h"
|
||||||
|
@ -130,6 +130,12 @@ class ItemsNode : public Node
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class JitterNode : public IntegerNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JitterNode(int i) : IntegerNode(i) {}
|
||||||
|
};
|
||||||
|
|
||||||
class LightNode : public Node
|
class LightNode : public Node
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
@ -49,6 +49,7 @@ diffuse return DIFFUSE;
|
|||||||
exposure return EXPOSURE;
|
exposure return EXPOSURE;
|
||||||
height return HEIGHT;
|
height return HEIGHT;
|
||||||
intersect return INTERSECT;
|
intersect return INTERSECT;
|
||||||
|
jitter return JITTER;
|
||||||
light return LIGHT;
|
light return LIGHT;
|
||||||
look_at return LOOKAT;
|
look_at return LOOKAT;
|
||||||
material return MATERIAL;
|
material return MATERIAL;
|
||||||
|
@ -68,6 +68,7 @@ static refptr<Node> parsed_scene_node;
|
|||||||
%token EXPOSURE;
|
%token EXPOSURE;
|
||||||
%token HEIGHT;
|
%token HEIGHT;
|
||||||
%token INTERSECT;
|
%token INTERSECT;
|
||||||
|
%token JITTER;
|
||||||
%token LIGHT;
|
%token LIGHT;
|
||||||
%token LOOKAT;
|
%token LOOKAT;
|
||||||
%token MATERIAL;
|
%token MATERIAL;
|
||||||
@ -190,6 +191,11 @@ intersect: INTERSECT LCURLY bool_items RCURLY {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
jitter: JITTER number {
|
||||||
|
$$ = new JitterNode($2->getInteger());
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
light: LIGHT LCURLY light_items RCURLY {
|
light: LIGHT LCURLY light_items RCURLY {
|
||||||
$$ = new LightNode();
|
$$ = new LightNode();
|
||||||
$$->addChildren($3);
|
$$->addChildren($3);
|
||||||
@ -216,6 +222,12 @@ light_item: POSITION vector {
|
|||||||
| COLOR vector {
|
| COLOR vector {
|
||||||
$$ = new ColorNode($2->getVector());
|
$$ = new ColorNode($2->getVector());
|
||||||
}
|
}
|
||||||
|
| radius {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| jitter {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
material: MATERIAL LCURLY material_items RCURLY {
|
material: MATERIAL LCURLY material_items RCURLY {
|
||||||
|
@ -15,6 +15,7 @@ scene
|
|||||||
light
|
light
|
||||||
{
|
{
|
||||||
position <-1, -3, 4>
|
position <-1, -3, 4>
|
||||||
|
jitter 5
|
||||||
}
|
}
|
||||||
|
|
||||||
plane
|
plane
|
||||||
|
@ -18,14 +18,7 @@ Ray::Ray(const Vector & origin, const Vector & direction)
|
|||||||
|
|
||||||
Ray Ray::randomRay()
|
Ray Ray::randomRay()
|
||||||
{
|
{
|
||||||
double x, y, z;
|
return Ray(Vector(0, 0, 0), Vector::randomVector());
|
||||||
do
|
|
||||||
{
|
|
||||||
x = 2.0 * rand() / RAND_MAX - 1.0;
|
|
||||||
y = 2.0 * rand() / RAND_MAX - 1.0;
|
|
||||||
z = 2.0 * rand() / RAND_MAX - 1.0;
|
|
||||||
} while (x*x + y*y + z*z <= 1.0);
|
|
||||||
return Ray(Vector(0, 0, 0), Vector(x, y, z));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h> /* rand() */
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
#include <iostream>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
Vector::Vector()
|
Vector::Vector()
|
||||||
{
|
{
|
||||||
@ -17,6 +20,18 @@ Vector::Vector(double x, double y, double z)
|
|||||||
m_array[2] = z;
|
m_array[2] = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector Vector::randomVector()
|
||||||
|
{
|
||||||
|
double x, y, z;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
x = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
y = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
z = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
} while (x*x + y*y + z*z > 1.0);
|
||||||
|
return Vector(x, y, z).normalize();
|
||||||
|
}
|
||||||
|
|
||||||
Vector & Vector::normalize()
|
Vector & Vector::normalize()
|
||||||
{
|
{
|
||||||
double length = mag();
|
double length = mag();
|
||||||
|
@ -9,6 +9,7 @@ class Vector
|
|||||||
public:
|
public:
|
||||||
Vector();
|
Vector();
|
||||||
Vector(double x, double y, double z);
|
Vector(double x, double y, double z);
|
||||||
|
static Vector randomVector();
|
||||||
double & operator[](int idx) { return m_array[idx]; }
|
double & operator[](int idx) { return m_array[idx]; }
|
||||||
double operator[](int idx) const { return m_array[idx]; }
|
double operator[](int idx) const { return m_array[idx]; }
|
||||||
Vector operator-() const;
|
Vector operator-() const;
|
||||||
|
@ -10,7 +10,7 @@ endif
|
|||||||
|
|
||||||
syn case match
|
syn case match
|
||||||
|
|
||||||
syn keyword fartKeywords ambient color define diffuse exposure height look_at material max_depth multisample options position radius reflectance rotate scale shininess size specular translate transparency union up vfov width
|
syn keyword fartKeywords ambient color define diffuse exposure height jitter look_at material max_depth multisample options position radius reflectance rotate scale shininess size specular translate transparency union up vfov width
|
||||||
syn keyword fartObjects box camera cyl intersect light plane scene sphere subtract union
|
syn keyword fartObjects box camera cyl intersect light plane scene sphere subtract union
|
||||||
syn match fartNumber "\(^\|\W\)\@<=[+-]\=\(\d\+\)\=\.\=\d\+\([eE][+-]\=\d\+\)\="
|
syn match fartNumber "\(^\|\W\)\@<=[+-]\=\(\d\+\)\=\.\=\d\+\([eE][+-]\=\d\+\)\="
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user