Add new Assignment version.

This commit is contained in:
hal8174 2024-05-02 11:09:34 +02:00
parent 20cc279b72
commit 0653874165
3 changed files with 55 additions and 39 deletions

View file

@ -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,7 +88,15 @@ 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;
unsigned lightID = data.scene->geometries[ray.geomID]->lightID;
if (lightID != unsigned(-1)) {
const Light* l = data.scene->lights[lightID];
Light_EvalRes evalRes = Lights_eval(l, sample, -wo);
L += evalRes.value;
} else {
sample.Ng = face_forward(ray.dir, normalize(sample.Ng)); sample.Ng = face_forward(ray.dir, normalize(sample.Ng));
sample.Ns = face_forward(ray.dir, normalize(sample.Ns)); sample.Ns = face_forward(ray.dir, normalize(sample.Ns));
@ -94,12 +109,14 @@ Vec3fa Application1::renderPixel(float x, float y, const ISPCCamera& camera, Ray
Sample3f wi1; Sample3f wi1;
Material__sample(material_array, matId, brdf, Lw, wo, sample, wi1, RandomSampler_get2D(sampler)); Material__sample(material_array, matId, brdf, Lw, wo, sample, wi1, RandomSampler_get2D(sampler));
const Light* l = data.scene->lights[0]; int id = (int)(RandomSampler_get1D(sampler) * data.scene->lights.size());
if (id == data.scene->lights.size())
id = data.scene->lights.size() - 1;
const Light* l = data.scene->lights[id];
Light_SampleRes ls = Lights_sample(l, sample, RandomSampler_get2D(sampler)); Light_SampleRes ls = Lights_sample(l, sample, RandomSampler_get2D(sampler));
Vec3f lightColor = {colorLight[0], colorLight[1], colorLight[2]};
Vec3fa diffuse = Material__eval(material_array, matId, brdf, wo, sample, ls.dir); Vec3fa diffuse = Material__eval(material_array, matId, brdf, wo, sample, ls.dir);
L += diffuse;
/* initialize shadow ray */ /* initialize shadow ray */
Ray shadow(sample.P, ls.dir, 0.001f, ls.dist, 0.0f); Ray shadow(sample.P, ls.dir, 0.001f, ls.dist, 0.0f);
@ -113,7 +130,8 @@ Vec3fa Application1::renderPixel(float x, float y, const ISPCCamera& camera, Ray
/* add light contribution if not occluded */ /* add light contribution if not occluded */
if (shadow.tfar >= 0.0f) { if (shadow.tfar >= 0.0f) {
L += ls.weight * lightColor * 0.1f; L += diffuse * ls.weight;
}
} }
} }

View file

@ -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};
}; };

View file

@ -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>