Exemplo n.º 1
0
void BlurCubemap::DoTask(const Texture& inputTex, Texture& outputTex)
{
	if (!inputTex.m_cubemap)
	{
		printf("Error: For this task required cubmap.\n");
		return;
	}
	float s = m_blurRadius / sqrt(inputTex.m_width * inputTex.m_height);

	int size = outputTex.m_width*outputTex.m_height;
	for(int k = 0; k <6; ++k)
	{
		outputTex.m_faces[k].m_buff.resize(size);
		for (int i = 0;i<outputTex.m_height;i++)
		{
			for (int j = 0;j<outputTex.m_width;j++)
			{
				double2 uv = GetUVFromIndices(outputTex.m_width, outputTex.m_height, i, j);
				double3 v = uv2cube(uv, k);
				fpixel p(0.0,0.0,0.0);
				int iterationCount = m_blurQuality;
				for (int itx = 0; itx < iterationCount; ++itx)
				{
					for (int ity = 0; ity < iterationCount; ++ity)
					{
						for (int itz = 0; itz < iterationCount; ++itz)
						{
							float x = fastNormal(itx * (1.0/iterationCount), (itx+1) * (1.0/iterationCount));
							float y = fastNormal(ity * (1.0/iterationCount), (ity+1) * (1.0/iterationCount));
							float z = fastNormal(itz * (1.0/iterationCount), (itz+1) * (1.0/iterationCount));
							double3 noise(x, y, z);
							double3 v_ = v;
							v_ += noise * s;
							v_.Normalize();
							int face = 0;
							double2 uv_ = cube2uv(v_, &face);
							p += FetchTexture(inputTex, uv_, face);
						}
					}
				}
				p /= iterationCount;
				p /= iterationCount;
				p /= iterationCount;
				//p = p * (k!=5) + fpixel(((float)i)/outputTex.m_width,((float)j)/outputTex.m_width,1.0) * (k==5);
				WriteTexture(outputTex, uv, k, p);
			}
		}
	}
	outputTex.m_cubemap = true;
}
Exemplo n.º 2
0
static int FetchSurface( StoreInfo *info, LWSurfaceID surfID, U1 *buff )
{
	OBJ2             *obj      = info->obj;
	LWSurfaceFuncs   *surff    = info->surff;
	LWTextureID       texID;
	LWEnvelopeID      envlID;
	LWChanGroupID     grpID;
	LWImageID		  imageID;
	LWO2_surf         lwo2;
	double           *fval;
	int               ival, size;
	const char       *colorVMap;

	memset( &lwo2, 0x00, sizeof(LWO2_surf) );
											/*  COLR  */
	if ((fval = (*surff->getFlt)( surfID, SURF_COLR )) != NULL) {
		lwo2.colr = (LWO2_surf_colr *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_colr) );
		lwo2.colr->color[0] = (F4) fval[0];
		lwo2.colr->color[1] = (F4) fval[1];
		lwo2.colr->color[2] = (F4) fval[2];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_COLR )) != NULL) {
		if (lwo2.colr == NULL) {
			lwo2.colr = (LWO2_surf_colr *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_colr) );
		}
		lwo2.colr->envelope = FetchEnvelope( info, envlID );
		grpID  = (*surff->chanGrp)( surfID );
		FetchChannel( info, grpID, ENVL_COLR_GREEN );
		FetchChannel( info, grpID, ENVL_COLR_BLUE );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_COLR )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_COLR );
	}

											/*  LUMI  */
	if ((fval = (*surff->getFlt)( surfID, SURF_LUMI )) != NULL) {
		lwo2.lumi = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.lumi->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_LUMI )) != NULL) {
		if (lwo2.lumi == NULL) {
			lwo2.lumi = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.lumi->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_LUMI )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_LUMI );
	}

											/*  DIFF  */
	if ((fval = (*surff->getFlt)( surfID, SURF_DIFF )) != NULL) {
		lwo2.diff = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.diff->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_DIFF )) != NULL) {
		if (lwo2.diff == NULL) {
			lwo2.diff = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.diff->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_DIFF )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_DIFF );
	}

											/*  SPEC  */
	if ((fval = (*surff->getFlt)( surfID, SURF_SPEC )) != NULL) {
		lwo2.spec = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.spec->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_SPEC )) != NULL) {
		if (lwo2.spec == NULL) {
			lwo2.spec = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.spec->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_SPEC )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_SPEC );
	}

											/*  GLOS  */
	if ((fval = (*surff->getFlt)( surfID, SURF_GLOS )) != NULL) {
		lwo2.glos = (LWO2_surf_glos *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_glos) );
		lwo2.glos->glossiness = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_GLOS )) != NULL) {
		if (lwo2.glos == NULL) {
			lwo2.glos = (LWO2_surf_glos *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_glos) );
		}
		lwo2.glos->envelope = FetchEnvelope( info, envlID );
	}

											/*  REFL  */
	if ((fval = (*surff->getFlt)( surfID, SURF_REFL )) != NULL) {
		lwo2.refl = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.refl->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_REFL )) != NULL) {
		if (lwo2.refl == NULL) {
			lwo2.refl = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.refl->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_REFL )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_REFL );
	}

											/*  TRAN  */
	if ((fval = (*surff->getFlt)( surfID, SURF_TRAN )) != NULL) {
		lwo2.tran = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.tran->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_TRAN )) != NULL) {
		if (lwo2.tran == NULL) {
			lwo2.tran = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.tran->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_TRAN )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_TRAN );
	}

											/*  RIND  */
	if ((fval = (*surff->getFlt)( surfID, SURF_RIND )) != NULL) {
		lwo2.rind = (LWO2_surf_rind *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_rind) );
		lwo2.rind->refractive_index = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_RIND )) != NULL) {
		if (lwo2.rind == NULL) {
			lwo2.rind = (LWO2_surf_rind *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_rind) );
		}
		lwo2.rind->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_RIND )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_RIND );
	}

											/*  TRNL  */
	if ((fval = (*surff->getFlt)( surfID, SURF_TRNL )) != NULL) {
		lwo2.trnl = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		lwo2.trnl->intensity = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_TRNL )) != NULL) {
		if (lwo2.trnl == NULL) {
			lwo2.trnl = (LWO2_surf_base *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_base) );
		}
		lwo2.trnl->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_TRNL )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_TRNL );
	}

											/*  BUMP  */
	if ((fval = (*surff->getFlt)( surfID, SURF_BUMP )) != NULL) {
		lwo2.bump = (LWO2_surf_bump *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_bump) );
		lwo2.bump->strenght = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_BUMP )) != NULL) {
		if (lwo2.bump == NULL) {
			lwo2.bump = (LWO2_surf_bump *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_bump) );
		}
		lwo2.bump->envelope = FetchEnvelope( info, envlID );
	}
	if ((texID = (*surff->getTex)( surfID, SURF_BUMP )) != NULL) {
		FetchTexture( info, &lwo2, texID, ID_BUMP );
	}

											/*  GVAL  */
	if ((fval = (*surff->getFlt)( surfID, SURF_GVAL )) != NULL) {
		lwo2.gval = (LWO2_surf_gval *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_gval) );
		lwo2.gval->value = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_GVAL )) != NULL) {
		if (lwo2.gval == NULL) {
			lwo2.gval = (LWO2_surf_gval *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_gval) );
		}
		lwo2.gval->envelope = FetchEnvelope( info, envlID );
	}

											/*  LSIZ  */
	if ((fval = (*surff->getFlt)( surfID, SURF_LSIZ )) != NULL) {
		lwo2.lsiz = (LWO2_surf_lsiz *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_lsiz) );
		lwo2.lsiz->size = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_LSIZ )) != NULL) {
		if (lwo2.lsiz == NULL) {
			lwo2.lsiz = (LWO2_surf_lsiz *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_lsiz) );
		}
		lwo2.lsiz->envelope = FetchEnvelope( info, envlID );
	}

											/*  CLRH  */
	if ((fval = (*surff->getFlt)( surfID, SURF_CLRH )) != NULL) {
		lwo2.clrh = (LWO2_surf_clrh *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_clrh) );
		lwo2.clrh->color_highlights = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_CLRH )) != NULL) {
		if (lwo2.clrh == NULL) {
			lwo2.clrh = (LWO2_surf_clrh *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_clrh) );
		}
		lwo2.clrh->envelope = FetchEnvelope( info, envlID );
	}

											/*  CLRF  */
	if ((fval = (*surff->getFlt)( surfID, SURF_CLRF )) != NULL) {
		lwo2.clrf = (LWO2_surf_clrf *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_clrf) );
		lwo2.clrf->color_filter = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_CLRF )) != NULL) {
		if (lwo2.clrf == NULL) {
			lwo2.clrf = (LWO2_surf_clrf *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_clrf) );
		}
		lwo2.clrf->envelope = FetchEnvelope( info, envlID );
	}

											/*  ADTR  */
	if ((fval = (*surff->getFlt)( surfID, SURF_ADTR )) != NULL) {
		lwo2.adtr = (LWO2_surf_adtr *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_adtr) );
		lwo2.adtr->additive = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_ADTR )) != NULL) {
		if (lwo2.adtr == NULL) {
			lwo2.adtr = (LWO2_surf_adtr *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_adtr) );
		}
		lwo2.adtr->envelope = FetchEnvelope( info, envlID );
	}

											/*  SHRP  */
	if ((fval = (*surff->getFlt)( surfID, SURF_SHRP )) != NULL) {
		lwo2.shrp = (LWO2_surf_shrp *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_shrp) );
		lwo2.shrp->sharpness = (F4) fval[0];
	}
	if ((envlID = (*surff->getEnv)( surfID, SURF_SHRP )) != NULL) {
		if (lwo2.shrp == NULL) {
			lwo2.shrp = (LWO2_surf_shrp *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_shrp) );
		}
		lwo2.shrp->envelope = FetchEnvelope( info, envlID );
	}

											/*  SMAN  */
	if ((fval = (*surff->getFlt)( surfID, SURF_SMAN )) != NULL) {
		lwo2.sman = (LWO2_surf_sman *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_sman) );
		lwo2.sman->max_smoothing_angle = (F4) fval[0];
	}

											/*  RSAN  */
	if ((fval = (*surff->getFlt)( surfID, SURF_RSAN )) != NULL) {
		lwo2.rsan = (LWO2_surf_rsan *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_rsan) );
		lwo2.rsan->seam_angle = (F4) fval[0];
	}

											/*  AVAL  */
	if ((fval = (*surff->getFlt)( surfID, SURF_AVAL )) != NULL) {
		lwo2.aval = (LWO2_surf_aval *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_aval) );
		lwo2.aval->value = (F4) fval[0];
	}

											/*  ALPH  */
	if ((fval = (*surff->getFlt)( surfID, SURF_ALPH )) != NULL) {
		lwo2.alph = (LWO2_surf_alph *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_alph) );
		lwo2.alph->value = (F4) fval[0];
	}

											/*  RFOP  */
	ival = (*surff->getInt)( surfID, SURF_RFOP );
	lwo2.rfop = (LWO2_surf_rfop *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_rfop) );
	lwo2.rfop->options = (U2) ival;

											/*  TROP  */
	ival = (*surff->getInt)( surfID, SURF_TROP );
	lwo2.trop = (LWO2_surf_trop *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_trop) );
	lwo2.trop->options = (U2) ival;

											/*  SIDE  */
	ival = (*surff->getInt)( surfID, SURF_SIDE );
	lwo2.side = (LWO2_surf_side *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_side) );
	lwo2.side->sideness = (U2) ival;

											/*  LINE  */
	ival = (*surff->getInt)( surfID, SURF_LINE );
	lwo2.line = (LWO2_surf_line *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_line) );
	lwo2.line->flags = (U2) ival;

											/*  RIMG  */
	if ((imageID = (*surff->getImg)( surfID, SURF_RIMG )) != NULL) {
		lwo2.rimg = (LWO2_surf_rimg *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_rimg) );
		lwo2.rimg->image = FindImage( info, imageID );
	}

											/*  TIMG  */
	if ((imageID = (*surff->getImg)( surfID, SURF_TIMG )) != NULL) {
		lwo2.timg = (LWO2_surf_timg *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_timg) );
		lwo2.timg->image = FindImage( info, imageID );
	}

											/*  VMAP  */
	if ((colorVMap = (*surff->getColorVMap)( surfID )) != NULL) {
		lwo2.vcol = (LWO2_surf_vcol *) MEM_ALLOC( obj->mem, sizeof(LWO2_surf_vcol) );
		strcpy( lwo2.vcol->name, colorVMap );
		lwo2.vcol->type  = FetchColorType( info, colorVMap );
		lwo2.vcol->value = 1.0f;
		if ((fval = (*surff->getFlt)( surfID, SURF_VCOL )) != NULL) {
			lwo2.vcol->value = (F4) fval[0];
		}
	}

	size = LWO2_packSurf( obj, buff, &lwo2 );
	LWO2_freeSurf( obj, &lwo2 );

	return size;
}