Add new Assignment version.
This commit is contained in:
parent
20cc279b72
commit
0653874165
3 changed files with 55 additions and 39 deletions
|
|
@ -5,7 +5,7 @@ void Application1::initScene() {
|
||||||
|
|
||||||
/* select scene here */
|
/* select scene here */
|
||||||
standardScene();
|
standardScene();
|
||||||
// standardScenewithAreaLight();
|
// veachScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application1::standardScene() {
|
void Application1::standardScene() {
|
||||||
|
|
@ -16,8 +16,11 @@ void Application1::standardScene() {
|
||||||
camera.to = Vec3fa(278, 273, 0);
|
camera.to = Vec3fa(278, 273, 0);
|
||||||
|
|
||||||
Ref<SceneGraph::GroupNode> sceneGraph = loadOBJ(file, false).cast<SceneGraph::GroupNode>();
|
Ref<SceneGraph::GroupNode> sceneGraph = loadOBJ(file, false).cast<SceneGraph::GroupNode>();
|
||||||
sceneGraph->add(new SceneGraph::LightNodeImpl<SceneGraph::PointLight>(
|
|
||||||
SceneGraph::PointLight(Vec3fa(213, 300, 227), Vec3fa(100000, 100000, 100000))));
|
auto light = new SceneGraph::QuadLightMesh(Vec3fa(343.0, 548.0, 227.0), Vec3fa(213.0, 548.0, 332.0),
|
||||||
|
Vec3fa(343.0, 548.0, 332.0),
|
||||||
|
Vec3fa(213.0, 548.0, 227.0), Vec3fa(100, 100, 100));
|
||||||
|
sceneGraph->add(light);
|
||||||
|
|
||||||
Ref<SceneGraph::GroupNode> flattened_scene = SceneGraph::flatten(sceneGraph, SceneGraph::INSTANCING_NONE);
|
Ref<SceneGraph::GroupNode> flattened_scene = SceneGraph::flatten(sceneGraph, SceneGraph::INSTANCING_NONE);
|
||||||
Scene* scene = new Scene;
|
Scene* scene = new Scene;
|
||||||
|
|
@ -31,17 +34,21 @@ void Application1::standardScene() {
|
||||||
scene = nullptr;
|
scene = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application1::standardScenewithAreaLight() {
|
void Application1::veachScene() {
|
||||||
FileName file = workingDir + FileName("Framework/scenes/cornell_box.obj");
|
FileName file = workingDir + FileName("Framework/scenes/veach.obj");
|
||||||
|
|
||||||
/* set default camera */
|
/* set default camera */
|
||||||
camera.from = Vec3fa(278, 273, -800);
|
camera.from = Vec3fa(1050, 185, 275);
|
||||||
camera.to = Vec3fa(278, 273, 0);
|
camera.to = Vec3fa(255, 273, 271);
|
||||||
|
camera.fov = 60;
|
||||||
|
|
||||||
Ref<SceneGraph::GroupNode> sceneGraph = loadOBJ(file, false).cast<SceneGraph::GroupNode>();
|
Ref<SceneGraph::GroupNode> sceneGraph = loadOBJ(file, false).cast<SceneGraph::GroupNode>();
|
||||||
sceneGraph->add(new SceneGraph::LightNodeImpl<SceneGraph::QuadLight>(
|
|
||||||
SceneGraph::QuadLight(Vec3fa(343.0, 548.0, 227.0), Vec3fa(343.0, 548.0, 332.0), Vec3fa(213.0, 548.0, 332.0),
|
auto light = new SceneGraph::QuadLightMesh(Vec3fa(549.6, 0.0, 559.2), Vec3fa(0.0, 548.8, 559.2),
|
||||||
Vec3fa(213.0, 548.0, 227.0), Vec3fa(100000, 100000, 100000))));
|
Vec3fa(0.0, 0.0, 559.2), Vec3fa(556.0, 548.8, 559.2),
|
||||||
|
Vec3fa(10, 10, 10));
|
||||||
|
sceneGraph->add(light);
|
||||||
|
|
||||||
|
|
||||||
Ref<SceneGraph::GroupNode> flattened_scene = SceneGraph::flatten(sceneGraph, SceneGraph::INSTANCING_NONE);
|
Ref<SceneGraph::GroupNode> flattened_scene = SceneGraph::flatten(sceneGraph, SceneGraph::INSTANCING_NONE);
|
||||||
Scene* scene = new Scene;
|
Scene* scene = new Scene;
|
||||||
|
|
@ -81,39 +88,50 @@ Vec3fa Application1::renderPixel(float x, float y, const ISPCCamera& camera, Ray
|
||||||
sample.P = ray.org + ray.tfar * ray.dir;
|
sample.P = ray.org + ray.tfar * ray.dir;
|
||||||
sample.Ng = ray.Ng;
|
sample.Ng = ray.Ng;
|
||||||
sample.Ns = Ns;
|
sample.Ns = Ns;
|
||||||
int matId = data.scene->geometries[ray.geomID]->materialID;
|
unsigned matId = data.scene->geometries[ray.geomID]->materialID;
|
||||||
sample.Ng = face_forward(ray.dir, normalize(sample.Ng));
|
unsigned lightID = data.scene->geometries[ray.geomID]->lightID;
|
||||||
sample.Ns = face_forward(ray.dir, normalize(sample.Ns));
|
|
||||||
|
|
||||||
/* calculate BRDF */
|
if (lightID != unsigned(-1)) {
|
||||||
BRDF brdf;
|
const Light* l = data.scene->lights[lightID];
|
||||||
std::vector<Material *> material_array = data.scene->materials;
|
Light_EvalRes evalRes = Lights_eval(l, sample, -wo);
|
||||||
Material__preprocess(material_array, matId, brdf, wo, sample);
|
|
||||||
|
|
||||||
/* sample BRDF at hit point */
|
L += evalRes.value;
|
||||||
Sample3f wi1;
|
} else {
|
||||||
Material__sample(material_array, matId, brdf, Lw, wo, sample, wi1, RandomSampler_get2D(sampler));
|
sample.Ng = face_forward(ray.dir, normalize(sample.Ng));
|
||||||
|
sample.Ns = face_forward(ray.dir, normalize(sample.Ns));
|
||||||
|
|
||||||
const Light* l = data.scene->lights[0];
|
/* calculate BRDF */
|
||||||
Light_SampleRes ls = Lights_sample(l, sample, RandomSampler_get2D(sampler));
|
BRDF brdf;
|
||||||
Vec3f lightColor = {colorLight[0], colorLight[1], colorLight[2]};
|
std::vector<Material *> material_array = data.scene->materials;
|
||||||
|
Material__preprocess(material_array, matId, brdf, wo, sample);
|
||||||
|
|
||||||
Vec3fa diffuse = Material__eval(material_array, matId, brdf, wo, sample, ls.dir);
|
/* sample BRDF at hit point */
|
||||||
L += diffuse;
|
Sample3f wi1;
|
||||||
|
Material__sample(material_array, matId, brdf, Lw, wo, sample, wi1, RandomSampler_get2D(sampler));
|
||||||
|
|
||||||
/* initialize shadow ray */
|
int id = (int)(RandomSampler_get1D(sampler) * data.scene->lights.size());
|
||||||
Ray shadow(sample.P, ls.dir, 0.001f, ls.dist, 0.0f);
|
if (id == data.scene->lights.size())
|
||||||
|
id = data.scene->lights.size() - 1;
|
||||||
|
const Light* l = data.scene->lights[id];
|
||||||
|
|
||||||
/* trace shadow ray */
|
Light_SampleRes ls = Lights_sample(l, sample, RandomSampler_get2D(sampler));
|
||||||
RTCOccludedArguments sargs;
|
|
||||||
rtcInitOccludedArguments(&sargs);
|
|
||||||
sargs.feature_mask = RTC_FEATURE_FLAG_TRIANGLE;
|
|
||||||
rtcOccluded1(data.g_scene, RTCRay_(shadow), &sargs);
|
|
||||||
RayStats_addShadowRay(stats);
|
|
||||||
|
|
||||||
/* add light contribution if not occluded */
|
Vec3fa diffuse = Material__eval(material_array, matId, brdf, wo, sample, ls.dir);
|
||||||
if (shadow.tfar >= 0.0f) {
|
|
||||||
L += ls.weight * lightColor * 0.1f;
|
/* initialize shadow ray */
|
||||||
|
Ray shadow(sample.P, ls.dir, 0.001f, ls.dist, 0.0f);
|
||||||
|
|
||||||
|
/* trace shadow ray */
|
||||||
|
RTCOccludedArguments sargs;
|
||||||
|
rtcInitOccludedArguments(&sargs);
|
||||||
|
sargs.feature_mask = RTC_FEATURE_FLAG_TRIANGLE;
|
||||||
|
rtcOccluded1(data.g_scene, RTCRay_(shadow), &sargs);
|
||||||
|
RayStats_addShadowRay(stats);
|
||||||
|
|
||||||
|
/* add light contribution if not occluded */
|
||||||
|
if (shadow.tfar >= 0.0f) {
|
||||||
|
L += diffuse * ls.weight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,13 @@ private:
|
||||||
Vec3fa renderPixel(float x, float y, const ISPCCamera& camera, RayStats& stats, RandomSampler& sampler) override;
|
Vec3fa renderPixel(float x, float y, const ISPCCamera& camera, RayStats& stats, RandomSampler& sampler) override;
|
||||||
|
|
||||||
void drawGUI() override {
|
void drawGUI() override {
|
||||||
ImGui::ColorEdit3("Color", colorLight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initScene() override;
|
void initScene() override;
|
||||||
|
|
||||||
void standardScene();
|
void standardScene();
|
||||||
|
|
||||||
void standardScenewithAreaLight();
|
void veachScene();
|
||||||
|
|
||||||
float colorLight[3] = {1.0f, 1.0f, 1.0f};
|
float colorLight[3] = {1.0f, 1.0f, 1.0f};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include <application.h>
|
#include <application.h>
|
||||||
#include <sampling.hpp>
|
#include <sampling.hpp>
|
||||||
#include <scenegraph/obj_loader.h>
|
#include <scenegraph/obj_loader.h>
|
||||||
#include <sys/filename.h>
|
|
||||||
|
|
||||||
#include <lights/ambient_light.h>
|
#include <lights/ambient_light.h>
|
||||||
#include <lights/directional_light.h>
|
#include <lights/directional_light.h>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue