working on die scene, fixed bug in Scene-load for loading colors applied to lights

git-svn-id: svn://anubis/fart/trunk@216 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-03-15 21:11:01 +00:00
parent 5590c533ce
commit 7d9eb65fde
4 changed files with 124 additions and 51 deletions

View File

@ -375,17 +375,17 @@ refptr<Light> Scene::processLight(refptr<Node> node)
} }
else if ( typeid(**it) == typeid(DiffuseNode) ) else if ( typeid(**it) == typeid(DiffuseNode) )
{ {
Color c(node->getVector()); Color c((*it)->getVector());
light->setDiffuseColor(c); light->setDiffuseColor(c);
} }
else if ( typeid(**it) == typeid(SpecularNode) ) else if ( typeid(**it) == typeid(SpecularNode) )
{ {
Color c(node->getVector()); Color c((*it)->getVector());
light->setSpecularColor(c); light->setSpecularColor(c);
} }
else if ( typeid(**it) == typeid(ColorNode) ) else if ( typeid(**it) == typeid(ColorNode) )
{ {
Color c(node->getVector()); Color c((*it)->getVector());
light->setDiffuseColor(c); light->setDiffuseColor(c);
light->setSpecularColor(c); light->setSpecularColor(c);
} }

View File

@ -26,7 +26,7 @@ Scene::Scene(const map<string, const char *> & options,
m_vfov = 60.0; m_vfov = 60.0;
m_verbose = true; m_verbose = true;
m_data = NULL; m_data = NULL;
m_ambient_light = Color(0.1, 0.1, 0.1); m_ambient_light = Color(0.2, 0.2, 0.2);
m_max_depth = 10; m_max_depth = 10;
m_transforms.push(Transform()); m_transforms.push(Transform());
@ -252,6 +252,9 @@ Color Scene::computePhong(const refptr<Material> material,
double shininess = material->getShininess(); double shininess = material->getShininess();
const Color & diffuseColor = material->getDiffuseColor(); const Color & diffuseColor = material->getDiffuseColor();
const Color & specularColor = material->getSpecularColor(); const Color & specularColor = material->getSpecularColor();
Vector normal = surfaceNormal;
if (normal % viewRay.getDirection() > 0.0) /* back face */
normal = -normal;
for (std::vector< refptr<Light> >::const_iterator it = m_lights.begin(); for (std::vector< refptr<Light> >::const_iterator it = m_lights.begin();
it != m_lights.end(); it != m_lights.end();
@ -260,7 +263,7 @@ Color Scene::computePhong(const refptr<Material> material,
Vector directionToLight = (*it)->getPosition() - surfacePoint; Vector directionToLight = (*it)->getPosition() - surfacePoint;
directionToLight.normalize(); directionToLight.normalize();
Vector reflectedLightDirection = Vector reflectedLightDirection =
directionToLight.reflect(surfaceNormal); directionToLight.reflect(normal);
Ray surfaceToLight(surfacePoint, directionToLight); Ray surfaceToLight(surfacePoint, directionToLight);
Color light_contribution = Color light_contribution =
@ -271,7 +274,7 @@ Color Scene::computePhong(const refptr<Material> material,
|| light_contribution.b > 0.0 ) || light_contribution.b > 0.0 )
{ {
/* calculate the diffuse term */ /* calculate the diffuse term */
double diffuse_coef = directionToLight % surfaceNormal; double diffuse_coef = directionToLight % normal;
if (diffuse_coef > 0.0) if (diffuse_coef > 0.0)
{ {
result += diffuseColor result += diffuseColor

View File

@ -1,56 +1,126 @@
scene scene
{ {
options
{
multisample 3
}
camera camera
{ {
position <1.5, -2.5, 1.5> position <1.2, -2, 1.2>
look_at <0, 0, 0> look_at <0, 0, 0>
} }
light light { position <10, 4, 10> color <.7, .7, .7> }
light { position <-10, -5, 10> color <.7, .7, .7> }
plane { position <0, 0, 1>, 0.501 }
subtract
{ {
position <10, 4, 10> union
}
plane
{
position <0, 0, 1>, 0.501
}
union
{
box { size <1, 0.8, 0.8> }
box { size <0.8, 1, 0.8> }
box { size <0.8, 0.8, 1> }
cyl { size <0.1, 0.1, 0.8> translate <0.4, 0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <0.4, -0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <-0.4, 0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <-0.4, -0.4, -0.4> }
cyl { size <.1, .1, .8> translate <.4, -.4, .4> rotate -90, <1, 0, 0> }
cyl { size <.1, .1, .8> translate <.4, -.4, -.4> rotate -90, <1, 0, 0> }
cyl { size <.1, .1, .8> translate <-.4, -.4, .4> rotate -90, <1, 0, 0> }
cyl { size <.1, .1, .8> translate <-.4, -.4, -.4> rotate -90, <1, 0, 0> }
cyl { size <.1, .1, .8> translate <.4, -.4, .4> rotate -90, <0, 1, 0> }
cyl { size <.1, .1, .8> translate <.4, -.4, -.4> rotate -90, <0, 1, 0> }
cyl { size <.1, .1, .8> translate <.4, .4, .4> rotate -90, <0, 1, 0> }
cyl { size <.1, .1, .8> translate <.4, .4, -.4> rotate -90, <0, 1, 0> }
sphere { radius .1 translate <.4, .4, .4> }
sphere { radius .1 translate <.4, .4, -.4> }
sphere { radius .1 translate <.4, -.4, .4> }
sphere { radius .1 translate <.4, -.4, -.4> }
sphere { radius .1 translate <-.4, .4, .4> }
sphere { radius .1 translate <-.4, .4, -.4> }
sphere { radius .1 translate <-.4, -.4, .4> }
sphere { radius .1 translate <-.4, -.4, -.4> }
material
{ {
color <1, 0.2, 1> box { size <1, 0.8, 0.8> }
transparency 0.5 box { size <0.8, 1, 0.8> }
box { size <0.8, 0.8, 1> }
cyl { size <0.1, 0.1, 0.8> translate <0.4, 0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <0.4, -0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <-0.4, 0.4, -0.4> }
cyl { size <0.1, 0.1, 0.8> translate <-0.4, -0.4, -0.4> }
cyl {
size <.1, .1, .8>
translate <.4, -.4, .4>
rotate -90, <1, 0, 0>
}
cyl {
size <.1, .1, .8>
translate <.4, -.4, -.4>
rotate -90, <1, 0, 0>
}
cyl {
size <.1, .1, .8>
translate <-.4, -.4, .4>
rotate -90, <1, 0, 0>
}
cyl {
size <.1, .1, .8>
translate <-.4, -.4, -.4>
rotate -90, <1, 0, 0>
}
cyl {
size <.1, .1, .8>
translate <.4, -.4, .4>
rotate -90, <0, 1, 0>
}
cyl {
size <.1, .1, .8>
translate <.4, -.4, -.4>
rotate -90, <0, 1, 0>
}
cyl {
size <.1, .1, .8>
translate <.4, .4, .4>
rotate -90, <0, 1, 0>
}
cyl {
size <.1, .1, .8>
translate <.4, .4, -.4>
rotate -90, <0, 1, 0>
}
sphere { radius .1 translate <.4, .4, .4> }
sphere { radius .1 translate <.4, .4, -.4> }
sphere { radius .1 translate <.4, -.4, .4> }
sphere { radius .1 translate <.4, -.4, -.4> }
sphere { radius .1 translate <-.4, .4, .4> }
sphere { radius .1 translate <-.4, .4, -.4> }
sphere { radius .1 translate <-.4, -.4, .4> }
sphere { radius .1 translate <-.4, -.4, -.4> }
material
{
color <1, 0.4, 1>
transparency 0.4
}
}
union
{
sphere { radius .1 translate <0, -.5, 0> }
sphere { radius .1 translate <-.5, .25, -.25> }
sphere { radius .1 translate <-.5, -.25, .25> }
sphere { radius .1 translate <0, 0, -.5> }
sphere { radius .1 translate <.25, -.25, -.5> }
sphere { radius .1 translate <-.25, .25, -.5> }
sphere { radius .1 translate <-.25, -.25, .5> }
sphere { radius .1 translate <-.25, .25, .5> }
sphere { radius .1 translate <.25, -.25, .5> }
sphere { radius .1 translate <.25, .25, .5> }
sphere { radius .1 translate <.5, 0, 0> }
sphere { radius .1 translate <.5, .25, .25> }
sphere { radius .1 translate <.5, .25, -.25> }
sphere { radius .1 translate <.5, -.25, .25> }
sphere { radius .1 translate <.5, -.25, -.25> }
sphere { radius .1 translate <.25, .5, 0> }
sphere { radius .1 translate <.25, .5, -.25> }
sphere { radius .1 translate <.25, .5, .25> }
sphere { radius .1 translate <-.25, .5, 0> }
sphere { radius .1 translate <-.25, .5, -.25> }
sphere { radius .1 translate <-.25, .5, .25> }
material
{
color <1, 1, 1>
}
} }
} }
} }

View File

@ -10,8 +10,8 @@ scene
camera camera
{ {
position <3, -4, 4> position <2, -2.5, 3>
look_at <0, 0, 0> look_at <-0.5, 0, 0>
up <0, 0, 1> up <0, 0, 1>
} }