This repository has been archived by the owner on Mar 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
椎名深雪
committed
Nov 3, 2019
1 parent
41cb2dd
commit 3f718ad
Showing
13 changed files
with
212 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ namespace miyuki::core { | |
Point3f p; | ||
Float pdf; | ||
Normal3f normal; | ||
Point2f uv; | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2019 椎名深雪 | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#include "arealight.h" | ||
#include <api/mesh.h> | ||
|
||
|
||
namespace miyuki::core { | ||
void AreaLight::setTriangle(MeshTriangle *shape) { | ||
this->triangle = shape; | ||
emission = triangle->getMaterial()->emission; | ||
} | ||
|
||
Spectrum AreaLight::Li(ShadingPoint &sp) const { | ||
return emission->evaluate(sp); | ||
} | ||
|
||
void | ||
AreaLight::sampleLi(const Point2f &u, Intersection &isct, LightSample &sample, VisibilityTester &tester) const { | ||
SurfaceSample surfaceSample; | ||
triangle->sample(u, surfaceSample); | ||
auto wi = surfaceSample.p - isct.p; | ||
tester.shadowRay = Ray(isct.p, wi, RayBias, 1); | ||
ShadingPoint sp; | ||
sp.Ng = triangle->Ng(); | ||
sp.Ns = triangle->normalAt(surfaceSample.uv); | ||
sp.texCoord = triangle->texCoordAt(surfaceSample.uv); | ||
sample.Li = Li(sp); | ||
sample.wi = wi.normalized(); | ||
sample.pdf = wi.lengthSquared() / sample.wi.absDot(surfaceSample.normal) * surfaceSample.pdf; | ||
} | ||
|
||
Float AreaLight::pdfLi(const Intersection &intersection, const Vec3f &wi) const { | ||
Intersection _isct; | ||
Ray ray(intersection.p, wi, RayBias); | ||
if (!triangle->intersect(ray, _isct)) { | ||
return 0.0f; | ||
} | ||
Float SA = triangle->area() * wi.absDot(_isct.Ng) / (_isct.distance * _isct.distance); | ||
return 1.0f / SA; | ||
} | ||
|
||
void AreaLight::sampleLe(const Point2f &u1, const Point2f &u2, LightRaySample &sample) { | ||
MIYUKI_NOT_IMPLEMENTED(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2019 椎名深雪 | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#ifndef MIYUKIRENDERER_AREALIGHT_H | ||
#define MIYUKIRENDERER_AREALIGHT_H | ||
|
||
#include <api/light.h> | ||
#include <api/shader.h> | ||
#include <api/serialize.hpp> | ||
|
||
namespace miyuki::core { | ||
class AreaLight final: public Light { | ||
MeshTriangle *triangle = nullptr; | ||
std::shared_ptr<Shader> emission; | ||
public: | ||
MYK_DECL_CLASS(AreaLight, "AreaLight", interface = "Light") | ||
|
||
Spectrum Li(ShadingPoint &sp) const override; | ||
|
||
void | ||
sampleLi(const Point2f &u, Intersection &isct, LightSample &sample, VisibilityTester &tester) const override; | ||
|
||
Float pdfLi(const Intersection &intersection, const Vec3f &wi) const override; | ||
|
||
void sampleLe(const Point2f &u1, const Point2f &u2, LightRaySample &sample) override; | ||
|
||
void setTriangle(MeshTriangle *shape); | ||
}; | ||
} | ||
#endif //MIYUKIRENDERER_AREALIGHT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2019 椎名深雪 | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#include <api/light.h> | ||
#include <api/scene.h> | ||
|
||
namespace miyuki::core{ | ||
bool VisibilityTester::visible(miyuki::core::Scene &scene) { | ||
Intersection isct; | ||
if (!scene.intersect(shadowRay, isct) || isct.distance >= shadowRay.tMax - RayBias) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters