project-10 / openrt Goto Github PK
View Code? Open in Web Editor NEWOpen Source Ray Tracing Library
Home Page: http://www.openrt.org
License: Other
Open Source Ray Tracing Library
Home Page: http://www.openrt.org
License: Other
Is your feature request related to a problem? Please describe.
A new direct light source CLightDirect
class should accompany existing spot light source CLightSpot
class.
Describe the solution you'd like
Implement the CLightDirect
class with the following parameters:
Vec3f intensity
Vec3f org
Vec3f dir
float hotspotRadius
- radius of an inner cylinder with constant surface illuminationfloat falloffRadius
- radius of an outer cylinder with attenuated illumination (attenuation function might be taken from the CLightSpot
class)bool castShadow
There’s currently an issue with the logic in the composite geometry (master). I suspect this is because of the logic we currently have in the CCompositeGeometry. To understand it we can try breaking it down:
When you create a composite geometry, use it to subtract from some other composite, then add it to the scene; the scene actually only contains one IPrim
. The intersect
function defined in the interface is then called inside of the scene and since in that case, it’s the composite then we call for the intersect function inside CCompositeGeometry
. This function has 2 parts: 1) getting the closest and furthest intersection of the left and right geometry; 2) performing some arithmetic logic on the pair of [in, out] rays. The first part is where the bug occurs.
We try to find the intersection for all the IPrim’s in the left and right geometries; however, since these are also composites then it’s actually only one primitive in each. Therefore, the loop that we have that currently retrieves the in and out actually only runs once. Meaning that the [in, out] results are always the same since all the rest of the computations are done a level deeper in the nest and will ALWAYS return the same result for the same ray. Since we only need the [out] ray in the difference function, then this explains why this logic doesn’t cause any issues in any other operations except for the difference.
Steps to reproduce:
void differenceBug() {
const Vec3f bgColor = RGB(1, 1, 1);
const Size resolution = Size(1920, 1200);
const float intensity = 5e4;
// Scene
CScene scene(bgColor);
auto pShaderRed = std::make_shared<CShaderEyelight>(RGB(214.0/ 255.0, 40.0/255.0, 40/255.0));
auto solidCylinder = CSolidCylinder(pShaderRed, Vec3f(1, 0, -13), 0.5, 4, 1, 24, true);
auto solidCylinder2 = CSolidCylinder(pShaderRed, Vec3f(1, 0, -13), 0.5, 4, 1, 24, true);
// Getting the bounding box and setting the correct pivot point
auto bBox = CBoundingBox();
for (const auto& prim : solidCylinder2.getPrims()) {
bBox.extend(prim->getBoundingBox());
}
solidCylinder2.setPivot(bBox.getCenter());
solidCylinder2.transform(CTransform().rotate(Vec3f(0, 0, 1), 90).get());
ptr_prim_t pCylinderComposite = std::make_shared<CCompositeGeometry>(solidCylinder, solidCylinder2, BoolOp::Union);
auto solidSphere1 = CSolidSphere(pShaderRed, Vec3f(1, 2, -13), 1.3f, 30, true);
ptr_prim_t pDifferenceRoot = std::make_shared<CCompositeGeometry>(solidSphere1, pCylinderComposite, BoolOp::Difference);
scene.add(pDifferenceRoot);
// cameras
auto targetCamera = std::make_shared<CCameraPerspectiveTarget>(resolution, Vec3f(-4, 5, -3), pDifferenceRoot->getBoundingBox().getCenter(), Vec3f(0, 1, 0), 45.0f);
scene.add(targetCamera);
// Light
auto pLight = std::make_shared<CLightOmni>(intensity * RGB(1.0f, 0.839f, 0.494f), Vec3f(100, 150.0f, 100), false);
scene.add(pLight);
scene.buildAccelStructure(20, 2);
Timer::start("Rendering... ");
Mat img = scene.render(std::make_shared<CSamplerStratified>(2, true, true));
Timer::stop();
imshow("image", img);
waitKey();
}
Expected result:
The two cylinders to be subtracted from the sphere. Similar to the image below (was able to recreate the image through a workaround). The first image is to show the cylinders used for the difference operation.
Actual result:
An image of the actual result is attached (the artifacts indicate the area where the in is actually indeed needed for the computation; therefore, further strengthening the hypothesis):
hi, could you please update build guide in README.md, I use cmake. & make, it seems doesn't work, thanks very much
Is your feature request related to a problem? Please describe.
When loading geometry from an .obj files containing multiple objects (e.g. as groups [g]) it is often the case that these objects have links to theirs materials, saved in accompanying .mtl files. Thus, it is very important to add reading / saving shaders into / from .mtl files. The description of the Wavefront material template library file format may be found at Wikipedia.
Describe the solution you'd like
Add methods load()
and save()
to CShader
class.
Is your feature request related to a problem? Please describe.
To fit a three-dimensional object into a photo, we also need to render the shadow from that object. To do this, we need a transparent object, such as a plane on which only the shadow is visible. We need a special shader for this plane.
Describe the solution you'd like
Develop a new shader, e.g. CShaderShadow
which would be 100% transparent, except the shadows. A special parameter to tune the shadow's intensity may be passed via constructor.
Given that we typically use the CSolidQuad to generate floor or similar items, I think it would be much friendlier to introduce a constructor that can generate a CSolidQuad from an origin point and length/width parameters. We can also introduce angles for inclination but I also believe that can be achieved with transformation.
@ereator if you think this minor modification can be helpful then I would be happy to quickly work on this :)
CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function main': Demo AreaLight.cpp:(.text+0x833): undefined reference to
rt::CSolid::CSolid(std::shared_ptrrt::IShader, std::_cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
Demo AreaLight.cpp:(.text+0xe20): undefined reference to rt::CSolid::transform(cv::Mat const&)' Demo AreaLight.cpp:(.text+0x129c): undefined reference to
rt::CScene::render(std::shared_ptrrt::CSampler) const'
Demo AreaLight.cpp:(.text+0x12c4): undefined reference to rt::CScene::renderDepth() const' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CCameraPerspective::CCameraPerspective(cv::Size, cv::Vec<float, 3> const&, cv::Vec<float, 3> const&, cv::Vec<float, 3> const&, float)':
Demo AreaLight.cpp:(.text._ZN2rt18CCameraPerspectiveC2EN2cv5Size_IiEERKNS1_3VecIfLi3EEES7_S7_f[_ZN2rt18CCameraPerspectiveC5EN2cv5Size_IiEERKNS1_3VecIfLi3EEES7_S7_f]+0x5a): undefined reference to vtable for rt::CCameraPerspective' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CLightOmni::CLightOmni(cv::Vec<float, 3> const&, cv::Vec<float, 3> const&, bool)':
Demo AreaLight.cpp:(.text._ZN2rt10CLightOmniC2ERKN2cv3VecIfLi3EEES5_b[_ZN2rt10CLightOmniC5ERKN2cv3VecIfLi3EEES5_b]+0x2f): undefined reference to vtable for rt::CLightOmni' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimSphere::CPrimSphere(std::shared_ptrrt::IShader, cv::Vec<float, 3>, float)':
Demo AreaLight.cpp:(.text._ZN2rt11CPrimSphereC2ESt10shared_ptrINS_7IShaderEEN2cv3VecIfLi3EEEf[_ZN2rt11CPrimSphereC5ESt10shared_ptrINS_7IShaderEEN2cv3VecIfLi3EEEf]+0x5e): undefined reference to vtable for rt::CPrimSphere' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimPlane::CPrimPlane(std::shared_ptrrt::IShader, cv::Vec<float, 3>, cv::Vec<float, 3>)':
Demo AreaLight.cpp:(.text.ZN2rt10CPrimPlaneC2ESt10shared_ptrINS_7IShaderEEN2cv3VecIfLi3EEES6[ZN2rt10CPrimPlaneC5ESt10shared_ptrINS_7IShaderEEN2cv3VecIfLi3EEES6]+0x5d): undefined reference to vtable for rt::CPrimPlane' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimTriangle::CPrimTriangle(std::shared_ptrrt::IShader, cv::Vec<float, 3> const&, cv::Vec<float, 3> const&, cv::Vec<float, 3> const&, cv::Vec<float, 2> const&, cv::Vec<float, 2> const&, cv::Vec<float, 2> const&)':
Demo AreaLight.cpp:(.text.ZN2rt13CPrimTriangleC2ESt10shared_ptrINS_7IShaderEERKN2cv3VecIfLi3EEES8_S8_RKNS5_IfLi2EEESB_SB[ZN2rt13CPrimTriangleC5ESt10shared_ptrINS_7IShaderEERKN2cv3VecIfLi3EEES8_S8_RKNS5_IfLi2EEESB_SB]+0x75): undefined reference to vtable for rt::CPrimTriangle' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimTriangle::if_intersect(rt::Ray const&) const':
Demo AreaLight.cpp:(.text._ZNK2rt13CPrimTriangle12if_intersectERKNS_3RayE[_ZNK2rt13CPrimTriangle12if_intersectERKNS_3RayE]+0x32): undefined reference to rt::CPrimTriangle::MoellerTrumbore(rt::Ray const&) const' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CTransform::scale(float) const':
Demo AreaLight.cpp:(.text._ZNK2rt10CTransform5scaleEf[_ZNK2rt10CTransform5scaleEf]+0x4e): undefined reference to rt::CTransform::scale(cv::Vec<float, 3> const&) const' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimTriangle::~CPrimTriangle()':
Demo AreaLight.cpp:(.text._ZN2rt13CPrimTriangleD2Ev[_ZN2rt13CPrimTriangleD5Ev]+0xf): undefined reference to vtable for rt::CPrimTriangle' CMakeFiles/Demo_AreaLight.dir/Demo_AreaLight.cpp.o: In function
rt::CPrimTriangleSmooth::transform(cv::Mat const&)':
Hi @otmanesabir
In class CCompositeGeometry in the method CCompositeGeometry::computeDifference :
OpenRT/modules/core/CompositeGeometry.cpp
Lines 292 to 307 in 0d7a54c
std::shared_ptr<CScene> buildSceneTest(const Vec3f& bgColor, const Size resolution)
{
auto pScene = std::make_shared<CScene>(bgColor);
// shaders
auto pShader = std::make_shared<CShaderFlat>(Vec3f(1, 1, 1));
// geometry
ptr_prim_t largeSphere = std::make_shared<CPrimSphere>(pShader, Vec3f(0, 0, 0), 5.0f);
ptr_prim_t smallSphere = std::make_shared<CPrimSphere>(pShader, Vec3f(0, 0, -5), 1.0f);
ptr_prim_t composite = std::make_shared<CCompositeGeometry>(largeSphere, smallSphere, BoolOp::Difference);
//pScene->add(largeSphere);
//pScene->add(smallSphere);
pScene->add(composite);
// Light
pScene->add(std::make_shared<CLightOmni>(Vec3f::all(1e3), Vec3f(0, 0, 0), true));
// camera
pScene->add(std::make_shared<CCameraPerspective>(resolution, Vec3f(0, 0, 0), Vec3f(0, 0, -1), Vec3f(0, 1, 0), 45.0f));
return pScene;
}
Is your feature request related to a problem? Please describe.
In many cases it makes sense to have a background image in a rendered scene. Currently it is possible to set only the background color.
Describe the solution you'd like
Add one more constructor to the CScene
class, which will take a texture CTexture
as an argument. If a ray goes to infinity, return a texel from that texture according to the rendered pixel coordinates.
Is your feature request related to a problem? Please describe.
Unlike a bitmapped texture, in which the texture is represented as a bitmap, a procedural texture describes the texture mathematically. Although not widely used, this method is resolution independent and can create more precise textures, especially if there is great and varying depth to the objects being textured. Procedural textures may be 2D or 3D.
Describe the solution you'd like
Many procedural textures for such materials as marble, stone and wood are generated based on the Perlin noise.
Additional context
Lecture slides
Wikipedia
Victor’s blog
YouTube
By default when creating a geometric object, its normals point outward of the object. For some cases it is useful to force the normals to point inside the object. Thus there is a need for a void flipNormals(void)
method.
Hi @otmanesabir,
I thought about how to get rid of that class without making the intersect methods to be non-constant. The idea to try is to invert normals in constructor of the composite primitive for the object B, if the boolean operation is substraction B from A.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.