New Operator: Lookup

I wrote a new operator called Lookup. It has two inputs, a texture and a bitmap which contains texture coordinates U,V packed into the R and the G channel (B is not used). The output texture has the same size as the texture coordinate bitmap and the colors are looked up in the texture (which can be of arbitrary size).

It can be used for creating some nice marble and wood textures.
I have attached an image showing a cloud colored with a 1D color fade.


IMPLEMENT_CLASS(NLookupOp, NOperator);

NLookupOp::NLookupOp()
{
}

udword NLookupOp::Process(float _ftime, NOperator** _pOpsInts)
{
//Two inputs (texture, texcoords)
if (m_byInputs!=2) return (udword)-1;

//Get input Texture and TexCoords
NBitmap* pSrc = (NBitmap*)(*(_pOpsInts+0))->m_pObj;
NBitmap* pTexCoords = (NBitmap*)(*(_pOpsInts+1))->m_pObj;

udword w = pTexCoords->GetWidth();
udword h = pTexCoords->GetHeight();
udword tw = pSrc->GetWidth();
udword th = pSrc->GetHeight();

float scaleW = tw / 256.0f;
float scaleH = th / 256.0f;

//Bitmap instance
gNFxGen_GetEngine()->GetBitmap(&m_pObj);

//Set Texture size
NBitmap* pDst = (NBitmap*)m_pObj;
pDst->SetSize(w, h);

/////////////////////////////////////////
//Process operator
RGBA* pPxTexCoords = pTexCoords->GetPixels();
RGBA* pPxSrc = pSrc->GetPixels();
RGBA* pPxDst = pDst->GetPixels();

for (udword y=0; y < h; y++)
{
for (udword x=0; x < w; x++)
{
udword u = pPxTexCoords->r * scaleW;
udword v = pPxTexCoords->g * scaleH;
pPxTexCoords++;

*pPxDst++ = pPxSrc[(v*tw) + u];
}
}
return 0;
}

AttachmentSize
lookup.png93.08 KB

Cool!

I've been thinking about how to handle things like this, but haven't really come up with a good idea. Your way is really flexible and uses the current stuff well, so it looks great. I'll add it (along with your warp, sorry for being lazy :) soon!

Glad you like it

It can be also used for creating pixelation effects which afaik were quite hard to do.
Since the texture is not filtered when sampling up or down (if filtering is wanted then RotoZoom can be used to resize the source texture to the right size)

Operators Plugins

I will had a plugins system for new operators. So developers will can shared their operators.