Skip to content

Commit

Permalink
Enhance: make shading method a runtime option instead of compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
wjzhou-ep committed Mar 19, 2012
1 parent c9fbdef commit 1bae878
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ try{
po::options_description orthographic ("Orthographic Camera options");
orthographic.add_options()
("pixelsize,p", po::value<float>(&garg_pixelsize)->default_value(0.005f), "Override the pixelsize setting in file");

po::options_description shading("Shading method options");
shading.add_options()
("shadingMethod,s", po::value<string>(&shadingMethod)->default_value("blinn_phong_shadow"), "Select shading method, allowed value:\nsimple: assume light is at view point\nblinn_phong: using blinn-phong model\nblinn_phong_shadow: using blinn-phong model with hard shadow");

po::options_description misc("Miscellaneous options");
misc.add_options()
Expand All @@ -86,7 +90,7 @@ try{
;

po::options_description all("All allowed options");
all.add(generic).add(required).add(perspective).add(orthographic).add(misc);
all.add(generic).add(required).add(shading).add(perspective).add(orthographic).add(misc);

po::options_description show("Options");
show.add(generic).add(required);
Expand Down Expand Up @@ -148,7 +152,10 @@ std::string& Options::getOutputDepthFileName()
return depth;
}


std::string& Options::getShadingMethod()
{
return shadingMethod;
}


/*
Expand Down
2 changes: 2 additions & 0 deletions src/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class Options
std::string& getInputFileName();
std::string& getOutputFileName();
std::string& getOutputDepthFileName();
std::string& getShadingMethod();
//int getXres(){return xres;}
//int getYres(){return yres;}
private:
std::string input;
std::string output;
std::string depth;
std::string shadingMethod;
//int xres;
//int yres;
std::string config_file;
Expand Down
10 changes: 10 additions & 0 deletions src/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
#include <boost/foreach.hpp>
#include "Light.hpp"
#include "Scene.hpp"
#include <iostream>
#include <algorithm>
Shader* Shader::getShader(std::string shadingMethod,Scene& scene)
{
if ( shadingMethod == "simple" ) return new SimpleDiffuseShader();
if ( shadingMethod == "blinn_phong" ) return new PhongShader(scene);
if ( shadingMethod == "blinn_phong_shadow" )
return new PhongShaderWithShadow(scene);
std::cout<<"unknown shading method:"<<shadingMethod<<std::endl;
exit(4);
}
Color
SimpleDiffuseShader::doShading(Ray& ray)
{
Expand Down
1 change: 1 addition & 0 deletions src/Shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Shader
{
public:
Shader(){}
static Shader* getShader(std::string shadingMethod,Scene& scene);
virtual Color doShading(Ray& ray)=0;
virtual ~Shader(){};
};
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ main(int argc, char *argv[])
ParseDriver pd(scene);
pd.parse(opt.getInputFileName());
ImageBuffer image(garg_xres,garg_yres);
//Shader* shaderp = new SimpleDiffuseShader();
//Shader* shaderp = new PhongShader(scene);
Shader* shaderp = new PhongShaderWithShadow(scene);
Shader* shaderp=Shader::getShader(opt.getShadingMethod(),scene);
Raytracer tracer=Raytracer(&scene,&image,shaderp);
tracer.doRaytrace();
image.outputImage(opt.getOutputFileName());
Expand Down

0 comments on commit 1bae878

Please sign in to comment.