Ejemplo n.º 1
0
void SDFShadowDemo::LoadSDFBuffer()
{
    const std::wstring sdfFile = L"testScene.sdf";
    FileLoader loader;
    loader.Open(FileSystem::getSingleton().GetModelsFolder() + sdfFile);
    auto ptr = loader.GetDataPtr();
    std::string sdfText(ptr);
    std::vector<std::string> lines;

    pystring::splitlines(sdfText, lines);
    std::string line0 = lines[0];
    std::vector<std::string> line0Split;
    pystring::split(line0, line0Split, " ");
    m_sdfParams.x = strtof(line0Split[0].c_str(), 0);
    m_sdfParams.y = strtof(line0Split[1].c_str(), 0);
    m_sdfParams.z = strtof(line0Split[2].c_str(), 0);
    m_sdfParams.w = strtof(lines[2].c_str(), 0);

    std::string line1 = lines[1];
    std::vector<std::string> line1Split;
    pystring::split(line1, line1Split, " ");
    m_sdfOrigin.x = strtof(line1Split[0].c_str(), 0);
    m_sdfOrigin.y = strtof(line1Split[1].c_str(), 0);
    m_sdfOrigin.z = strtof(line1Split[2].c_str(), 0);

    const auto SDFCount = m_sdfParams.x * m_sdfParams.y * m_sdfParams.z;
    for (auto i = 0; i < SDFCount; ++i)
    {
        f32 value = strtof(lines[3 + i].c_str(), 0);
        m_sdf.push_back(value);
    }

    Texture3dConfigDX11 texConfig;
    texConfig.SetDefaults();
    texConfig.SetWidth(static_cast<u32>(m_sdfParams.x));
    texConfig.SetHeight(static_cast<u32>(m_sdfParams.y));
    texConfig.SetDepth(static_cast<u32>(m_sdfParams.z));
    texConfig.SetFormat(DXGI_FORMAT_R32_FLOAT);

    D3D11_SUBRESOURCE_DATA data;
    data.pSysMem = &m_sdf[0];
    data.SysMemPitch = static_cast<u32>(sizeof(f32) * m_sdfParams.x);
    data.SysMemSlicePitch = static_cast<u32>(sizeof(f32) * m_sdfParams.x * m_sdfParams.y);

    ShaderResourceViewConfigDX11 srvConfig;
    srvConfig.SetFormat(DXGI_FORMAT_R32_FLOAT);
    srvConfig.SetViewDimensions(D3D11_SRV_DIMENSION_TEXTURE3D);
    D3D11_TEX3D_SRV srv;
    srv.MostDetailedMip = 0;
    srv.MipLevels = 1;
    srvConfig.SetTexture3D(srv);

    m_SDFTex3D = m_pRender->CreateTexture3D(&texConfig, &data, &srvConfig);
}
Ejemplo n.º 2
0
bool QTBuilder::build_eqg(const char *shortname) {
//	char bufm[96];
	char bufs[96];
  Archive *archive;
  FileLoader *fileloader;
  Zone_Model *zm;
	
	sprintf(bufs, "%s.eqg", shortname);

	archive = new PFSLoader();
	FILE *fff = fopen(bufs, "rb");
	if(fff == NULL) {
		printf("Failed to open '%s'\n", bufs);
		return(false);
	}
  if(archive->Open(fff) == 0) {
	  printf("Unable to open eqg file '%s'.\n", bufs);
	  return(false);
  }
  
  fileloader = new ZonLoader();
  if(fileloader->Open(NULL, (char *) shortname, archive) == 0) {
	  printf("Error reading ZON from %s\n", bufs);
	  return(false);
  }
  zm = fileloader->model_data.zone_model;

	long i;
	VERTEX v1, v2, v3;
	for(i = 0; i < zm->poly_count; ++i) {
#ifdef INVERSEXY
		v1.y = zm->verts[zm->polys[i]->v1]->x;
		v1.x = zm->verts[zm->polys[i]->v1]->y;
#else
		v1.x = zm->verts[zm->polys[i]->v1]->x;
		v1.y = zm->verts[zm->polys[i]->v1]->y;
#endif
		v1.z = zm->verts[zm->polys[i]->v1]->z;
#ifdef INVERSEXY
		v2.y = zm->verts[zm->polys[i]->v2]->x;
		v2.x = zm->verts[zm->polys[i]->v2]->y;
#else
		v2.x = zm->verts[zm->polys[i]->v2]->x;
		v2.y = zm->verts[zm->polys[i]->v2]->y;
#endif
		v2.z = zm->verts[zm->polys[i]->v2]->z;
#ifdef INVERSEXY
		v3.y = zm->verts[zm->polys[i]->v3]->x;
		v3.x = zm->verts[zm->polys[i]->v3]->y;
#else
		v3.x = zm->verts[zm->polys[i]->v3]->x;
		v3.y = zm->verts[zm->polys[i]->v3]->y;
#endif
		v3.z = zm->verts[zm->polys[i]->v3]->z;
		
		AddFace(v1, v2, v3);
	}

	printf("	There are %lu vertices and %u faces.\n", _FaceList.size()*3, _FaceList.size());
	
	unsigned long r;
	
//	vertexCount = _VertexList.size();
	faceCount = _FaceList.size();
	
	
/*	vertexBlock = new VERTEX[vertexCount];
	//im not going to assume I know vectors are stored in contiguous blocks
	for(r = 0; r < vertexCount; r++) {
		vertexBlock[r] = _VertexList[r];
	}*/
	
	faceBlock = new FACE[faceCount];
	//im not going to assume I know vectors are stored in contiguous blocks
	for(r = 0; r < faceCount; r++) {
		faceBlock[r] = _FaceList[r];
	}
	
	//build quad tree... prolly much slower than it needs to be.
	float minx, miny, maxx, maxy;
	minx = 1e12;
	miny = 1e12;
	maxx = -1e12;
	maxy = -1e12;
	
	//find our limits.
	for(r = 0; r < faceCount; r++) {
		//a bit of lazyness going on here...
		{
		VERTEX &v = faceBlock[r].a;
		if(v.x > maxx)
			maxx = v.x;
		if(v.x < minx)
			minx = v.x;
		if(v.y > maxy)
			maxy = v.y;
		if(v.y < miny)
			miny = v.y;
		}
		{
		VERTEX &v = faceBlock[r].b;
		if(v.x > maxx)
			maxx = v.x;
		if(v.x < minx)
			minx = v.x;
		if(v.y > maxy)
			maxy = v.y;
		if(v.y < miny)
			miny = v.y;
		}
		{
		VERTEX &v = faceBlock[r].c;
		if(v.x > maxx)
			maxx = v.x;
		if(v.x < minx)
			minx = v.x;
		if(v.y > maxy)
			maxy = v.y;
		if(v.y < miny)
			miny = v.y;
		}
	}
	
	printf("	Bounding box: %.2f < x < %.2f, %.2f < y < %.2f\n", minx, maxx, miny, maxy);
	printf("World file loaded.\n");

	printf("Building quadtree.\n");
		
	_root = new QTNode(this, minx, maxx, miny, maxy);
	if(_root == NULL) {
		printf("Unable to allocate new QTNode.\n");
		return(false);
	}
	
	//build our initial set of faces... all of them:
	FACE *faceptr = faceBlock;
	_root->faces.resize(faceCount);
	for(r = 0; r < faceCount; r++) {
		_root->faces[r].face = faceptr;
		_root->faces[r].index = r;
		faceptr++;
	}
/*	_root->faces.resize(faceCount);
	for(r = 0; r < faceCount; r++) {
		_root->faces[r].face = &faceBlock[r];	//this is kinda bad, we dont own this 
											//memory, so we shouldent be taking addrs...
		_root->faces[r].index = r;
	}*/
	
	_root->divideYourself(0);
	
	printf("Done building quad tree...\n");

#ifdef COUNT_MACTHES
	fprintf(stderr, "Match counters: %lu easy in, %lu easy out, %lu hard in, %lu hard out.\n", gEasyMatches, gEasyExcludes, gHardMatches, gHardExcludes);
#endif
	
	
	return(true);
}