Example #1
0
//-----------------------------------------------------------------------------
//
// Scene update
//
//-----------------------------------------------------------------------------
void SampleScene::updateSphere( float radius)//, float center )
{
    Group            top_level_group = m_context["top_object"]-> getGroup();
    Transform        transform       = top_level_group->getChild<Transform>( 0 );
    GeometryGroup    geometrygroup   = transform->getChild<GeometryGroup>();
    GeometryInstance instance        = geometrygroup->getChild( 0 );
    Geometry         geometry          = instance->getGeometry();

    // Sphere
    //geometry["sphere"]->setFloat( center, 0, 0, radius );

    // Sphere Shell
    geometry["radius2"]->setFloat( radius );        // Set Radius
    //geometry["center"]->setFloat( center, 0, 0 );   // set center

    // Mark Dirty
    int childCount = top_level_group->getChildCount();
    for ( int i = 0; i < childCount; i++) {
        if( top_level_group->getChildType( i ) == RT_OBJECTTYPE_TRANSFORM ){
            transform = top_level_group->getChild<Transform>( i );
            geometrygroup = transform->getChild<GeometryGroup>();
        }else{
            geometrygroup = top_level_group->getChild<GeometryGroup>( i );
            //geometrygroup = transform->getChild<GeometryGroup>();
        }
        geometrygroup->getAcceleration()->markDirty();
    }
    top_level_group->getAcceleration()->markDirty();
}
Example #2
0
void SampleScene::updateMaterial( float refraction_index )
{
    Group            top_level_group = m_context["top_object"]-> getGroup();
    Transform        transform       = top_level_group->getChild<Transform>( 0 );
    GeometryGroup    geometrygroup   = transform->getChild<GeometryGroup>();
    GeometryInstance instance        = geometrygroup->getChild( 0 );
    Material         material        = instance->getMaterial( 0 );

    material["refraction_index"]->setFloat( refraction_index );
}
 void GeometryInstance::enabling () 
 {
   geom->used++;
   if (geom->getType() == Geometry::GROUP) {
     GeometryGroup* group = (GeometryGroup*) geom;
     for (size_t i=0; i<group->size(); i++)
       count((*group)[i],+1);
   }
   else {
     count(geom,+1);
   }
 }
Example #4
0
void WhittedScene::createGeometry()
{
  // Create glass sphere geometry
  std::string shell_ptx( ptxpath( "whitted", "sphere_shell.cu" ) ); 
  Geometry glass_sphere = m_context->createGeometry();
  glass_sphere->setPrimitiveCount( 1u );
  glass_sphere->setBoundingBoxProgram( m_context->createProgramFromPTXFile( shell_ptx, "bounds" ) );
  glass_sphere->setIntersectionProgram( m_context->createProgramFromPTXFile( shell_ptx, "intersect" ) );
  glass_sphere["center"]->setFloat( 4.0f, 2.3f, -4.0f );
  glass_sphere["radius1"]->setFloat( 0.96f );
  glass_sphere["radius2"]->setFloat( 1.0f );
  
  // Metal sphere geometry
  std::string sphere_ptx( ptxpath( "whitted", "sphere.cu" ) ); 
  Geometry metal_sphere = m_context->createGeometry();
  metal_sphere->setPrimitiveCount( 1u );
  metal_sphere->setBoundingBoxProgram( m_context->createProgramFromPTXFile( sphere_ptx, "bounds" ) );
  metal_sphere->setIntersectionProgram( m_context->createProgramFromPTXFile( sphere_ptx, "robust_intersect" ) );
  metal_sphere["sphere"]->setFloat( 2.0f, 1.5f, -2.5f, 1.0f );

  // Floor geometry
  std::string pgram_ptx( ptxpath( "whitted", "parallelogram.cu" ) );
  Geometry parallelogram = m_context->createGeometry();
  parallelogram->setPrimitiveCount( 1u );
  parallelogram->setBoundingBoxProgram( m_context->createProgramFromPTXFile( pgram_ptx, "bounds" ) );
  parallelogram->setIntersectionProgram( m_context->createProgramFromPTXFile( pgram_ptx, "intersect" ) );
  float3 anchor = make_float3( -16.0f, 0.01f, -8.0f );
  float3 v1 = make_float3( 32.0f, 0.0f, 0.0f );
  float3 v2 = make_float3( 0.0f, 0.0f, 16.0f );
  float3 normal = cross( v1, v2 );
  normal = normalize( normal );
  float d = dot( normal, anchor );
  v1 *= 1.0f/dot( v1, v1 );
  v2 *= 1.0f/dot( v2, v2 );
  float4 plane = make_float4( normal, d );
  parallelogram["plane"]->setFloat( plane );
  parallelogram["v1"]->setFloat( v1 );
  parallelogram["v2"]->setFloat( v2 );
  parallelogram["anchor"]->setFloat( anchor );

  // Glass material
  Program glass_ch = m_context->createProgramFromPTXFile( ptxpath( "whitted", "glass.cu" ), "closest_hit_radiance" );
  Program glass_ah = m_context->createProgramFromPTXFile( ptxpath( "whitted", "glass.cu" ), "any_hit_shadow" );
  Material glass_matl = m_context->createMaterial();
  glass_matl->setClosestHitProgram( 0, glass_ch );
  glass_matl->setAnyHitProgram( 1, glass_ah );

  glass_matl["importance_cutoff"]->setFloat( 1e-2f );
  glass_matl["cutoff_color"]->setFloat( 0.034f, 0.055f, 0.085f );
  glass_matl["fresnel_exponent"]->setFloat( 3.0f );
  glass_matl["fresnel_minimum"]->setFloat( 0.1f );
  glass_matl["fresnel_maximum"]->setFloat( 1.0f );
  glass_matl["refraction_index"]->setFloat( 1.4f );
  glass_matl["refraction_color"]->setFloat( 1.0f, 1.0f, 1.0f );
  glass_matl["reflection_color"]->setFloat( 1.0f, 1.0f, 1.0f );
  glass_matl["refraction_maxdepth"]->setInt( 10 );
  glass_matl["reflection_maxdepth"]->setInt( 5 );
  float3 extinction = make_float3(.83f, .83f, .83f);
  glass_matl["extinction_constant"]->setFloat( log(extinction.x), log(extinction.y), log(extinction.z) );
  glass_matl["shadow_attenuation"]->setFloat( 0.6f, 0.6f, 0.6f );

  // Metal material
  Program phong_ch = m_context->createProgramFromPTXFile( ptxpath( "whitted", "phong.cu" ), "closest_hit_radiance" );
  Program phong_ah = m_context->createProgramFromPTXFile( ptxpath( "whitted", "phong.cu" ), "any_hit_shadow" );

  Material metal_matl = m_context->createMaterial();
  metal_matl->setClosestHitProgram( 0, phong_ch );
  metal_matl->setAnyHitProgram( 1, phong_ah );
  metal_matl["Ka"]->setFloat( 0.2f, 0.5f, 0.5f );
  metal_matl["Kd"]->setFloat( 0.2f, 0.7f, 0.8f );
  metal_matl["Ks"]->setFloat( 0.9f, 0.9f, 0.9f );
  metal_matl["phong_exp"]->setFloat( 64 );
  metal_matl["reflectivity"]->setFloat( 0.5f,  0.5f,  0.5f);

  // Checker material for floor
  Program check_ch = m_context->createProgramFromPTXFile( ptxpath( "whitted", "checker.cu" ), "closest_hit_radiance" );
  Program check_ah = m_context->createProgramFromPTXFile( ptxpath( "whitted", "checker.cu" ), "any_hit_shadow" );
  Material floor_matl = m_context->createMaterial();
  floor_matl->setClosestHitProgram( 0, check_ch );
  floor_matl->setAnyHitProgram( 1, check_ah );

  floor_matl["Kd1"]->setFloat( 0.8f, 0.3f, 0.15f);
  floor_matl["Ka1"]->setFloat( 0.8f, 0.3f, 0.15f);
  floor_matl["Ks1"]->setFloat( 0.0f, 0.0f, 0.0f);
  floor_matl["Kd2"]->setFloat( 0.9f, 0.85f, 0.05f);
  floor_matl["Ka2"]->setFloat( 0.9f, 0.85f, 0.05f);
  floor_matl["Ks2"]->setFloat( 0.0f, 0.0f, 0.0f);
  floor_matl["inv_checker_size"]->setFloat( 32.0f, 16.0f, 1.0f );
  floor_matl["phong_exp1"]->setFloat( 0.0f );
  floor_matl["phong_exp2"]->setFloat( 0.0f );
  floor_matl["reflectivity1"]->setFloat( 0.0f, 0.0f, 0.0f);
  floor_matl["reflectivity2"]->setFloat( 0.0f, 0.0f, 0.0f);

  // Create GIs for each piece of geometry
  std::vector<GeometryInstance> gis;
  gis.push_back( m_context->createGeometryInstance( glass_sphere, &glass_matl, &glass_matl+1 ) );
  gis.push_back( m_context->createGeometryInstance( metal_sphere,  &metal_matl,  &metal_matl+1 ) );
  gis.push_back( m_context->createGeometryInstance( parallelogram, &floor_matl,  &floor_matl+1 ) );

  // Place all in group
  GeometryGroup geometrygroup = m_context->createGeometryGroup();
  geometrygroup->setChildCount( static_cast<unsigned int>(gis.size()) );
  geometrygroup->setChild( 0, gis[0] );
  geometrygroup->setChild( 1, gis[1] );
  geometrygroup->setChild( 2, gis[2] );
  geometrygroup->setAcceleration( m_context->createAcceleration("NoAccel","NoAccel") );

  m_context["top_object"]->set( geometrygroup );
  m_context["top_shadower"]->set( geometrygroup );
}
void assigment4_1_and_2()
{
	Image img(800, 600);
	img.addRef();

	//Set up the scene
	GeometryGroup scene;
	LWObject cow;
	cow.read("models/cow.obj", true);
	cow.addReferencesToScene(scene.primitives);
	scene.rebuildIndex();

	BumpMirrorPhongShader sh4;
	sh4.diffuseCoef = float4(0.2f, 0.2f, 0, 0);
	sh4.ambientCoef = sh4.diffuseCoef;
	sh4.specularCoef = float4::rep(0.8f);
	sh4.specularExponent = 10000.f;
	sh4.reflCoef = 0.4f;
	sh4.addRef();
	cow.materials[cow.materialMap["Floor"]].shader = &sh4;
	
 	//Enable bi-linear filtering on the walls
	((TexturedPhongShader*)cow.materials[cow.materialMap["Stones"]].shader.data())->diffTexture->filterMode = Texture::TFM_Bilinear;
 	((TexturedPhongShader*)cow.materials[cow.materialMap["Stones"]].shader.data())->amibientTexture->filterMode = Texture::TFM_Bilinear;


	//Set up the cameras
	PerspectiveCamera cam1(Point(-9.398149f, -6.266083f, 5.348377f), Point(-6.324413f, -2.961229f, 4.203216f), Vector(0, 0, 1), 30,
		std::make_pair(img.width(), img.height()));

	PerspectiveCamera cam2(Point(2.699700f, 6.437226f, 0.878297f), Point(4.337114f, 8.457443f,- 0.019007f), Vector(0, 0, 1), 30,
		std::make_pair(img.width(), img.height()));
	
	cam1.addRef();
	cam2.addRef();

	//Set up the integrator
	IntegratorImpl integrator;
	integrator.addRef();
	integrator.scene = &scene;
	PointLightSource pls;

	pls.falloff = float4(0, 0, 1, 0);

	pls.intensity  = float4::rep(0.9f);
	pls.position = Point(-2.473637f, 3.119330f, 9.571486f);
	integrator.lightSources.push_back(pls);

	integrator.ambientLight = float4::rep(0.1f);

	DefaultSampler samp;
	samp.addRef();

	//Render
	Renderer r;
	r.integrator = &integrator;
	r.target = &img;
	r.sampler = &samp;

	r.camera = &cam1;
	r.render();
	img.writePNG("result_cam1.png");

	//For seeing the difference in texture filtering
	r.camera = &cam2;
	r.render();
	img.writePNG("result_cam2.png");
}
Example #6
0
void setup_and_render()
{

	Image img(WIDTH, HEIGHT);
	img.addRef();

	//Set up the scene
	GeometryGroup scene;

	// load scene
	LWObject objects;
	objects.read("models/cube.obj", true);
	objects.addReferencesToScene(scene.primitives);	
	scene.rebuildIndex();
	
	//apply custom shaders
	BumpTexturePhongShader as;
	as.addRef();
	Image  grass;
	grass.addRef();
	grass.readPNG("models/mat.png");
	Texture textureGrass;
	textureGrass.addRef();
	textureGrass.image = &grass;
	as.diffTexture = &textureGrass;
	as.amibientTexture = &textureGrass;
	as.specularCoef = float4::rep(0);
	as.specularExponent = 10000.f;
	as.transparency = float4::rep(0.9);
	FractalLandscape f(Point(-4419,-8000,-569), Point(3581,0, -569),9, 0.1, &as, 5.0f);
	f.addReferencesToScene(scene.primitives);
	scene.rebuildIndex();
	
	// my phong
	RRPhongShader glass;
	glass.n1 = 1.0f;
	glass.n2 = 1.5f;
	glass.diffuseCoef = float4(0.1, 0.1, 0.1, 0);
	glass.ambientCoef = glass.diffuseCoef;
	glass.specularCoef = float4::rep(0.9);
	glass.specularExponent = 10000;
	glass.transparency = float4::rep(0.9);
	glass.addRef();
	Sphere sphere(Point(-78,1318,40), 25, &glass);;
	scene.primitives.push_back(&sphere);
	scene.rebuildIndex();	
	objects.materials[objects.materialMap["Glass"]].shader = &glass;

	
	//sample shader for noise
	ProceduralPhongShader skyShader;
	skyShader.addRef();
	CloudTexture nt;
	nt.addRef();
	skyShader.amibientNoiseTexture = &nt;
	skyShader.diffuseCoef = float4::rep(0.0f);
	skyShader.specularCoef = float4::rep(0.0f);

// 	float w = skyShader.amibientNoiseTexture->perlin->width;
 objects.materials[objects.materialMap["Sky"]].shader = &skyShader;

	//Set up the cameras
	PerspectiveCamera cam1(Point(-23, 1483, 30 ), forwardForCamera((0.0)*PI/180.0), Vector(0, 0, 1), 45,
		std::make_pair(img.width(), img.height()));
	
	cam1.addRef();

	//Set up the integrator
	IntegratorImpl integrator;
	integrator.addRef();
	integrator.scene = &scene;

	PointLightSource pls3;

	pls3.falloff = float4(0, 0, 1, 0);

	pls3.intensity  = float4::rep(0.9f);
	pls3.position = Point(299.5, 99, 518);
	integrator.lightSources.push_back(pls3);

// 	PointLightSource pls4;
// 
// 	pls4.falloff = float4(0, 0, 1, 0);
// 
// 	pls4.intensity  = float4::rep(0.9f);
// 	pls4.position = Point(1289.5, 99, 518);
// 	integrator.lightSources.push_back(pls4);
	
	areaLightSource(integrator, 0.9, 2, Point(-1180, -3860, -1718), 1000);
	integrator.ambientLight = float4::rep(0.1f);

	StratifiedSampler samp;
	samp.addRef();
 	samp.samplesX = 3;
	samp.samplesY = 3;

	//Render
	Renderer r;
	r.integrator = &integrator;
	r.target = &img;
	r.sampler = &samp;

	r.camera = &cam1;
	r.render();
	img.writePNG("result.png");
	
}