Hello folks. I’m trying to implement an algorithm I found for creating an oil panted effect over a given image:
but I can’t seem to get the lil ■■■■■■ to work. I’m using a custom node in a post process material to handle the nested FOR loops needed to compare the pixels surrounding the pixel being rendered, and everything seems to compile fine, but when I apply the effect in my scene, all I get is some weird noise.
So, obviously something is failing. I’m assuming it’s the SceneTextureLookup call I am making within the custom node, but I can’t find any decent docs or examples of how to use this function to be sure if that’s the cause or not. If anyone is able/willing, could you please take a look at my material & code and point out what idiot thing I am doing, I would be very grateful.
Here’s the material:
And here’s the code in the OilPaint node:
float4 outputBuffer = float4(1,0,1,1);
float4 curPixel = float4(1,0,1,1);
float nSumR[50];
float nSumG[50];
float nSumB[50];
float intensityCount[50];
for(int bob = 0;bob < 50;bob++)
{
nSumR[bob] = 0.0;
nSumG[bob] = 0.0;
nSumB[bob] = 0.0;
intensityCount[bob] = 0.0;
}
for( float yRadInc = (curY - effectRadius); yRadInc <= (curY + effectRadius); yRadInc++ )
{
if(!( (yRadInc < 0.0) || (yRadInc > height)))
{
for( float xRadInc = (curX - effectRadius); xRadInc < (curX + effectRadius); xRadInc++ )
{
if(!( (xRadInc < 0.0) || (xRadInc > width)))
{
curPixel = SceneTextureLookup(float2(xRadInc,yRadInc), 14, false);
float nR = curPixel.r;
float nG = curPixel.g;
float nB = curPixel.b;
// Find intensity of RGB value and apply intensity level.
float curIntensity = ( ( ( nR + nG + nB ) / 3.0 ) * effectIntensity );
if( curIntensity > 1.0 )
curIntensity = 1.0;
int i = (int)curIntensity;
intensityCount[i]++;
nSumR[i] = nSumR[i] + nR;
nSumG[i] = nSumG[i] + nG;
nSumB[i] = nSumB[i] + nB;
}
}
}
}
float nCurMax = 1.0;
int nMaxIndex = 0;
for( int nI = 0; nI < (effectRadius * effectRadius); nI++ )
{
if( intensityCount[nI] > nCurMax )
{
nCurMax = intensityCount[nI];
nMaxIndex = nI;
}
}
outputBuffer = float4((nSumR[nMaxIndex] / nCurMax),(nSumG[nMaxIndex] / nCurMax),(nSumB[nMaxIndex] / nCurMax),1.0);
return outputBuffer;
As you can see, I’ve done my best to duplicate the algorithm from the link at the top, but it’s just not working. Hopefully it’s some simple thing I’m over looking and not some intrinsic limitation to the post process material that is preventing this from working as I’d think it would look pretty cool…
Thanks in advance for any help.
Cheers,
J^2