Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Raytracer.h>
- #include <Core/Integrator.h>
- #include <Integrator/DistributedRayTracingIntegrator.h>
- #include <Accelerator/Accelerator.h>
- #include <Core/Material.h>
- #include <Core/Light.h>
- #include <Core/BSDF.h>
- #include <Core/Scene.h>
- #include <math/Sampling.h>
- #include <iostream>
- using namespace std;
- DistributedRayTracingIntegrator::DistributedRayTracingIntegrator( uint32_t _recursionDepth, uint32_t _sampleCount )
- : m_MaxRecursionDepth(_recursionDepth), m_SampleCount(_sampleCount)
- {
- }
- void DistributedRayTracingIntegrator::Preprocess( const Scene& _scene )
- {
- }
- vec3 DistributedRayTracingIntegrator::L( const Scene& _scene, RayDifferential<scalar_t>& _ray, const Sample& _sample, Random& _random, BSDFAllocator& _bsdfAllocator ) const
- {
- return Lrec( _scene, _ray, _sample, _random, _bsdfAllocator, 0 );
- }
- vec3 DistributedRayTracingIntegrator::Lrec( const Scene& _scene, RayDifferential<scalar_t>& _ray, const Sample& _sample, Random& _random, BSDFAllocator& _bsdfAllocator, uint32_t _recursionDepth ) const
- {
- // find an intersection with a surface
- const Accelerator* accel = _scene.GetAccelerator();
- const LightContainer* lights = _scene.GetLightContainer();
- INTERSECTION isect;
- SURFACE_PROPERTIES surfaceProperties;
- SHADING_PROPERTIES shadingProperties;
- // find an intersection with a surface
- if( !accel->Intersect( _ray, &isect ) )
- return 0;
- const SurfaceSceneObject* sob = static_cast<const SurfaceSceneObject*>( isect.Object );
- sob->GetSurfaceProperties( isect, &surfaceProperties );
- sob->GetShadingProperties( surfaceProperties, &shadingProperties );
- //cout << "Lin= " << surfaceProperties.P.y << " " << endl;
- // obtain a bsdf from the material
- BSDF* bsdf = shadingProperties.material->GetBsdf( surfaceProperties, shadingProperties, &_bsdfAllocator );
- // iterate over all light sources
- vec3 Lout = 0;
- for( LightContainer::const_iterator cit = lights->begin(); cit != lights->end(); cit++ )
- {
- const Light* l = *cit;
- uint32_t sampleCount = l->GetRequestedSampleCount();
- vec3 LL = 0;
- LIGHT_PROPERTIES lightProperties;
- for( uint32_t s = 0; s < sampleCount; s++ )
- {
- l->GetLightPropertiesAt( _random, shadingProperties.P, &lightProperties );
- // shadow ray
- Ray<scalar_t> shadowRay = CreateShadowRay( surfaceProperties, lightProperties );
- if( accel->Intersect( shadowRay, shadowRay.Tmax ) )
- continue;
- // eval bsdf
- BSDF_OUT bsdfOut;
- bsdf->Eval( -_ray.Direction, lightProperties.D, &bsdfOut );
- scalar_t NdL = hlsl::max<scalar_t>( 0, hlsl::dot( lightProperties.D, shadingProperties.N ) ); //hlsl::abs( hlsl::dot( lightProperties.D, shadingProperties.N ) );
- LL += bsdfOut.Color * NdL * lightProperties.L / lightProperties.DistanceSquared;
- }
- //if( 0 != _recursionDepth){
- Lout += LL / scalar_t(sampleCount);
- //}
- }
- if(_recursionDepth <= m_MaxRecursionDepth )
- {
- scalar_t irgendwas;
- vec3 rayOut;
- scalar_t rnd[2];
- _random.Rand( &rnd[0], 2 );
- vec3 Lin;
- vec3 Lcount = 0;
- for(uint32_t i = 0; i < m_SampleCount; i++)
- {
- UniformSampleHemisphere(rnd[0], rnd[1], surfaceProperties.N, &rayOut, &irgendwas );
- RayDifferential<scalar_t> rayi;// = Ray<scalar_t>( isect.P, rayOut );
- rayi.Direction = rayOut;
- rayi.Origin = surfaceProperties.P + (rayi.Direction * rayi.Epsilon*(scalar_t)5);//hlsl::vector<double, 3>(-1110,0,0); //
- Lin = Lrec( _scene, rayi, _sample, _random, _bsdfAllocator, ( _recursionDepth + 1 ) );
- //cout << "Lin= " << hlsl::dot( rayi.Direction, shadingProperties.N ) << " " << endl;
- BSDF_OUT bsdfIn;
- bsdf->Eval( -_ray.Direction, rayi.Direction, &bsdfIn );
- scalar_t NdL = hlsl::max<scalar_t>( 0, hlsl::dot( rayi.Direction, shadingProperties.N ) );
- //cout << "Lin= " << NdL << " " << endl;
- Lcount += bsdfIn.Color *NdL * Lin ;/// hlsl::distance(rayi.Origin, surfaceProperties.P);
- }
- Lcount = (scalar_t)2 * Lcount * hlsl::PI<scalar_t>::value / ((scalar_t)m_SampleCount);
- Lout += Lcount;
- }
- return Lout;
- }
Add Comment
Please, Sign In to add comment