PlyLoader::PlyLoader( const std::string&   filename,
                      optix::Context       context,
                      optix::GeometryGroup geometrygroup,
                      optix::Material      material,
                      const char* ASBuilder,
                      const char* ASTraverser,
                      bool large_geom )
: _filename( filename ),
  _context( context ),
  _geometrygroup( geometrygroup ),
  _material( material ),
  _large_geom( large_geom),
  _ASBuilder  (ASBuilder),
  _ASTraverser(ASTraverser)
{
  // Error checking on context and geometrygroup done in ModelLoader

  if( material.get() == 0 ) {
    const std::string ptx_path = std::string( sutilSamplesPtxDir() ) + "/cuda_compile_ptx_generated_phong.cu.ptx";
    _material = context->createMaterial();
    _material->setClosestHitProgram( 0, _context->createProgramFromPTXFile( ptx_path, "closest_hit_radiance" ) );
    _material->setAnyHitProgram    ( 1, _context->createProgramFromPTXFile( ptx_path, "any_hit_shadow" ) );
    _material[ "Kd"           ]->setFloat( 0.50f, 0.50f, 0.50f );
    _material[ "Ks"           ]->setFloat( 0.00f, 0.00f, 0.00f );
    _material[ "Ka"           ]->setFloat( 0.05f, 0.05f, 0.05f );
    _material[ "reflectivity" ]->setFloat( 0.00f, 0.00f, 0.00f );
    _material[ "phong_exp"    ]->setFloat( 1.00f );
  }
}
예제 #2
0
optix::Material Glass::getOptixMaterial(optix::Context & context)
{
    if(!m_optixMaterialIsCreated)
    {
        m_optixMaterial = context->createMaterial();
        optix::Program radianceClosestProgram = context->createProgramFromPTXFile( "Glass.cu.ptx", "closestHitRadiance");
        optix::Program radianceAnyHitProgram = context->createProgramFromPTXFile( "Glass.cu.ptx", "anyHitRadiance");
        optix::Program photonClosestProgram = context->createProgramFromPTXFile( "Glass.cu.ptx", "closestHitPhoton");
        optix::Program photonAnyHitProgram = context->createProgramFromPTXFile( "Glass.cu.ptx", "anyHitPhoton");

        //vcmClosestHitLight

        m_optixMaterial->setClosestHitProgram(RayType::RADIANCE, radianceClosestProgram);
        //m_optixMaterial->setAnyHitProgram(RayType::RADIANCE, radianceAnyHitProgram );
        m_optixMaterial->setClosestHitProgram(RayType::RADIANCE_IN_PARTICIPATING_MEDIUM, radianceClosestProgram);
        //m_optixMaterial->setAnyHitProgram(RayType::RADIANCE_IN_PARTICIPATING_MEDIUM, radianceAnyHitProgram);
        
        m_optixMaterial->setClosestHitProgram(RayType::PHOTON, photonClosestProgram);
        //m_optixMaterial->setAnyHitProgram(RayType::PHOTON, photonAnyHitProgram);
        m_optixMaterial->setClosestHitProgram(RayType::PHOTON_IN_PARTICIPATING_MEDIUM, photonClosestProgram);
       // m_optixMaterial->setAnyHitProgram(RayType::PHOTON_IN_PARTICIPATING_MEDIUM, photonAnyHitProgram);

        m_optixMaterial->setClosestHitProgram(RayType::LIGHT_VCM, context->createProgramFromPTXFile( "Glass.cu.ptx", "vcmClosestHitLight"));
        m_optixMaterial->setClosestHitProgram(RayType::CAMERA_VCM, context->createProgramFromPTXFile( "Glass.cu.ptx", "vcmClosestHitCamera"));

        this->registerMaterialWithShadowProgram(context, m_optixMaterial);
        m_optixMaterialIsCreated = true;
    }
    
    return m_optixMaterial;
}
optix::Material ColourMaterial::getOptiXMaterial(optix::Context context) {
	optix::Program chp = context->createProgramFromPTXFile( "ptx/ColourMaterial.ptx", "closest_hit" );
	optix::Material mat = context->createMaterial();
	mat->setClosestHitProgram(0, chp);
	mat["max_wavelength"]->setFloat(mColourWavelengthMax);
	mat["min_wavelength"]->setFloat(mColourWavelengthMin);
	mat["standard_deviation"]->setFloat(std);
	mat["ideal_range"]->setFloat(ideal_range);
	return mat;
}
optix::Material CameraMaterial::getOptiXMaterial(optix::Context context) {
	optix::Program chp = context->createProgramFromPTXFile( "ptx/CameraMaterial.ptx", "closest_hit" );
	optix::Material mat = context->createMaterial();
	mat->setClosestHitProgram(0, chp);
	mat["camera_size"]->setFloat(actualWidth, actualHeight);
	mat["image_size"]->setInt(imageWidth, imageHeight);
	mat["max_intensity"]->setInt(1);
	mat["camera_gamma"]->setFloat(1.0f);
	return mat;
}
bool OmniMaterial::OptixCreateDevice(optix::Context& Context)
{
	if (!isInitialized)
	{
		if (!ContentLoader::LoadOptixProgramFromFile("CUDA\\DiffuseMaterial.cu.ptx", "DirectDiffuse_closest_hit", Context, &closestHit_DirectDiffuse)) return false;
		if (!ContentLoader::LoadOptixProgramFromFile("CUDA\\OmniMaterial.cu.ptx", "PhotonRay_closest_hit", Context, &closestHit_PhotonRay)) return false;
		isInitialized = true;
	}
	_Material = Context->createMaterial();
	_Material->setClosestHitProgram(RayType_DirectDiffuse, closestHit_DirectDiffuse);
	_Material->setClosestHitProgram(RayType_PhotonRay, closestHit_PhotonRay);	

	_Material["Diffuse"]->setFloat(omniCBuffer->Data.diffuseColor.x, omniCBuffer->Data.diffuseColor.y, omniCBuffer->Data.diffuseColor.z);
	_Material["Specular"]->setFloat(omniCBuffer->Data.specularColor.x, omniCBuffer->Data.specularColor.y, omniCBuffer->Data.specularColor.z, omniCBuffer->Data.specularColor.w);
	_Material["Transmissive"]->setFloat(omniCBuffer->Data.transmissive.x, omniCBuffer->Data.transmissive.y, omniCBuffer->Data.transmissive.z, omniCBuffer->Data.transmissive.w);
	return true;
}
예제 #6
0
optix::Material Texture::getOptixMaterial(optix::Context & context)
{
    if(!m_optixMaterialIsCreated)
    {
        m_optixMaterial = context->createMaterial();
        optix::Program radianceProgram = context->createProgramFromPTXFile( "Texture.cu.ptx", "closestHitRadiance");
        optix::Program photonProgram = context->createProgramFromPTXFile( "Texture.cu.ptx", "closestHitPhoton");

        m_optixMaterial->setClosestHitProgram(RayType::RADIANCE, radianceProgram);
        m_optixMaterial->setClosestHitProgram(RayType::RADIANCE_IN_PARTICIPATING_MEDIUM, radianceProgram);
        m_optixMaterial->setClosestHitProgram(RayType::PHOTON, photonProgram);
        m_optixMaterial->setClosestHitProgram(RayType::PHOTON_IN_PARTICIPATING_MEDIUM, photonProgram);
        m_optixMaterial->setClosestHitProgram(RayType::LIGHT_VCM, context->createProgramFromPTXFile( "Texture.cu.ptx", "vcmClosestHitLight"));
        m_optixMaterial->setClosestHitProgram(RayType::CAMERA_VCM, context->createProgramFromPTXFile( "Texture.cu.ptx", "vcmClosestHitCamera"));
        m_optixMaterial->validate();
        this->registerMaterialWithShadowProgram(context, m_optixMaterial);
        m_optixMaterialIsCreated = true;
    }
    
    // Diffuse buffer

    optix::Buffer buffer = createBufferFromImage(context, *m_diffuseImage);
    m_diffuseSampler = createTextureSamplerFromBuffer(context, buffer);

    optix::Buffer normalsBuffer;
    if(m_normalMapImage != NULL)
    {
        normalsBuffer = createBufferFromImage(context, *m_normalMapImage);
    }
    else
    {
        normalsBuffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_BYTE4, 0, 0);
    }

    m_normalMapSampler = createTextureSamplerFromBuffer(context, normalsBuffer);
    return m_optixMaterial;
}
예제 #7
0
void TriangleMesh::optixInit(optix::Context context) {

	try {

		static optix::Program intersectProgram = context->createProgramFromPTXFile("ptx/triangle_mesh_program.cu.ptx", "intersect");
		static optix::Program boundsProgram = context->createProgramFromPTXFile("ptx/triangle_mesh_program.cu.ptx", "bounds");

#if OPTIX_USE_GEOMETRY_VBO
		// Bind vertex VBO
		Optix.posBuffer = context->createBufferFromGLBO(RT_BUFFER_INPUT, vboPos);
		Optix.posBuffer->setFormat(RT_FORMAT_FLOAT3);
		Optix.posBuffer->setSize(posData.size());

		// Bind normal VBO
		Optix.normalBuffer = context->createBufferFromGLBO(RT_BUFFER_INPUT, vboNormal);
		Optix.normalBuffer->setFormat(RT_FORMAT_FLOAT3);
		Optix.normalBuffer->setSize(normalData.size());

		// Bind texture VBO
		Optix.texCoordBuffer = context->createBufferFromGLBO(RT_BUFFER_INPUT, vboTexCoord);
		Optix.texCoordBuffer->setFormat(RT_FORMAT_FLOAT2);
		Optix.texCoordBuffer->setSize(texCoordData.size());

		// Bind index IBO
		Optix.indexBuffer = context->createBufferFromGLBO(RT_BUFFER_INPUT, ibo);
		Optix.indexBuffer->setFormat(RT_FORMAT_UNSIGNED_INT);
		Optix.indexBuffer->setSize(indexData.size());
#else
		// Copy position buffer
		Optix.posBuffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, posData.size());
		memcpy(Optix.posBuffer->map(), &posData[0], posData.size() * sizeof(Vec3));
		Optix.posBuffer->unmap();

		// Copy normal buffer
		Optix.normalBuffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, normalData.size());
		memcpy(Optix.normalBuffer->map(), &normalData[0], normalData.size() * sizeof(Vec3));
		Optix.normalBuffer->unmap();

		// Copy texture buffer
		Optix.texCoordBuffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT2, texCoordData.size());
		memcpy(Optix.texCoordBuffer->map(), &texCoordData[0], texCoordData.size() * sizeof(Vec2));
		Optix.texCoordBuffer->unmap();

		// Copy index buffer
		Optix.indexBuffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_INT3, indexData.size());
		memcpy(Optix.indexBuffer->map(), &indexData[0], indexData.size() * sizeof(TrianglePrimitive));
		Optix.indexBuffer->unmap();
#endif

		// Make geometry
		Optix.geometry = context->createGeometry();
		Optix.geometry->setIntersectionProgram(intersectProgram);
		Optix.geometry->setBoundingBoxProgram(boundsProgram);
		Optix.geometry->setPrimitiveCount(indexData.size());
		Optix.geometry["posData"]->setBuffer(Optix.posBuffer);
		Optix.geometry["normalData"]->setBuffer(Optix.normalBuffer);
		Optix.geometry["texCoordData"]->setBuffer(Optix.texCoordBuffer);
		Optix.geometry["indexData"]->setBuffer(Optix.indexBuffer);

		// Make instance
		if (!material->Optix.material) {
			
#if OPTIX_USE_OPENGL_TEXTURE
			material->Optix.sampler = context->createTextureSamplerFromGLImage(material->image->texture, RT_TARGET_GL_TEXTURE_2D);
#else
			optix::Buffer buf = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT4, material->image->width, material->image->height);
			memcpy(buf->map(), material->image->pixels, material->image->width * material->image->height * sizeof(Color));
			buf->unmap();
			material->Optix.sampler = context->createTextureSampler();
			material->Optix.sampler->setArraySize(1);
			material->Optix.sampler->setMipLevelCount(1);
			material->Optix.sampler->setBuffer(0, 0, buf);
#endif
			material->Optix.sampler->setWrapMode(0, RT_WRAP_REPEAT);
			material->Optix.sampler->setWrapMode(1, RT_WRAP_REPEAT);
			material->Optix.sampler->setIndexingMode(RT_TEXTURE_INDEX_NORMALIZED_COORDINATES);
			material->Optix.sampler->setReadMode(RT_TEXTURE_READ_NORMALIZED_FLOAT);
			material->Optix.sampler->setMaxAnisotropy(1.f);
			RTfiltermode filter = (material->image->filter == GL_NEAREST) ? RT_FILTER_NEAREST : RT_FILTER_LINEAR;
			material->Optix.sampler->setFilteringModes(filter, filter, RT_FILTER_NONE);
			
			material->Optix.material = context->createMaterial();
			material->Optix.material->setClosestHitProgram(0, materialClosestHitProgram);
			material->Optix.material->setAnyHitProgram(1, materialAnyHitProgram);
			material->Optix.material["sampler"]->setTextureSampler(material->Optix.sampler);
			material->Optix.material["ambient"]->setFloat(material->ambient.r(), material->ambient.g(), material->ambient.b(), material->ambient.a());
			material->Optix.material["specular"]->setFloat(material->specular.r(), material->specular.g(), material->specular.b(), material->specular.a());
			material->Optix.material["diffuse"]->setFloat(material->diffuse.r(), material->diffuse.g(), material->diffuse.b(), material->diffuse.a());
			material->Optix.material["shineExponent"]->setFloat(material->shineExponent);
			material->Optix.material["reflectIntensity"]->setFloat(material->reflectIntensity);
			material->Optix.material["refractIndex"]->setFloat(material->refractIndex);

		}

		Optix.geometryInstance = context->createGeometryInstance();
		Optix.geometryInstance->setGeometry(Optix.geometry);
		Optix.geometryInstance->addMaterial(material->Optix.material);

	} catch (optix::Exception e) {
		printException(e);
	}

}