Rotating in cop filter.

   1608   10   2
User Avatar
Member
193 posts
Joined: Dec. 2016
Offline
Hello I`m trying to make a flakes normal map.

For this i need gradients applied with a random orientation on preferably the id of the cell noise node.


all of the rotation / transformation nodes dont seem to have an input for the thing that needs rotation.

This confuzes me.

Also i cant seem to find a node that allows you to reapply XY. the texture node could do thtat but it only works on images.
Edited by NicTanghe - Nov. 7, 2022 11:47:24

Attachments:
Lookdev_rnd_v14.hiplc (145.9 KB)

User Avatar
Member
7785 posts
Joined: Sept. 2011
Offline
The multiply node generally does the applying of transformations. given a vector V and matrix M, V * M gives the transformed vector.
User Avatar
Member
193 posts
Joined: Dec. 2016
Offline
Right,
If i multiply my color with a rotation matrix.
It doesn`t change their position it changes their color.


if i multiply my color with my position it also changes the color.
User Avatar
Member
4517 posts
Joined: Feb. 2012
Offline
You can't change the positions of the pixels just like you can't change the position of voxels in volumes. You have to change the look up positions.

Here is how to apply swirl to an input image in COPs for example (Bilinear filtering in this example):





float mirror ( float p )
{
    return abs ( p - 2.0f * floor ( ( p + 1.0f ) / 2.0f ) );
}

vector [ ] computeSamplePoints ( int quality; int xres; int yres )
{
    vector samples [ ];
    int nsamples = quality;
    int tsamples = nsamples * nsamples;
    float n = 1.0f / ( 1.0f + tsamples );
    for ( int i = 1; i <= tsamples; ++i )
    {
        float y = i * n;
        float x = frac ( y * nsamples );
        samples [ i - 1 ] = set ( ( x - 0.5f ) / xres, ( y - 0.5f ) / yres, 0 );
    }
    return samples;
}

cop2 swirl ( float angle = 0; float r = 1; vector2 t = { 0.5, 0.5 }; int quality = 3; int filter = 1; int outside = 0 )
{
    float rx = 0.5 * r;
    float ry = 0.5 * r;
    float maxr = rx;
    float x = X - t.x;
    float y = Y - t.y;
    float sx = max ( 1, 1.0f * XRES / YRES );
    float sy = max ( 1, 1.0f * YRES / XRES );
    
    if ( XRES > YRES )
        rx = 0.5 * r * min ( XRES, YRES ) / max ( XRES, YRES );
    else
        ry = 0.5 * r * min ( XRES, YRES ) / max ( XRES, YRES );
    
    int setSample = 0;
    vector sample = 0;
    vector samplePoints [ ] = computeSamplePoints ( quality, XRES, YRES );
    foreach ( vector p; samplePoints )
    {
        if ( ( x * x ) / ( rx * rx ) + ( y * y ) / ( ry * ry ) <= 1 )
        {
            float xx = x * sx + p.x;
            float yy = y * sy + p.y;
            float amount = ( maxr - sqrt ( x * x * sx * sx + y * y * sy * sy ) ) / maxr;
            float theta = amount * amount * radians ( angle );
            float s = sin ( theta );
            float c = cos ( theta );
            xx = c * x - s * y + t.x;
            yy = s * x + c * y + t.y;
            
            if ( outside == 0 )
            {
                xx = mirror ( xx );
                yy = mirror ( yy );
            }
            
            if ( filter == 0 )
                sample += cinput ( 0, PL, AI, xx % 1, yy % 1, F, "wrap", "streak" );
            else if ( filter == 1 )
                sample += binput ( 0, PL, AI, xx % 1, yy % 1, F, "wrap", "streak" );
            else if ( filter == 2 )
                sample += finput ( 0, PL, AI, xx % 1, yy % 1, F, "wrap", "streak" );
            
            setSample = 1;
        }
    }
    
    if ( setSample )
        assign ( Cr, Cg, Cb, sample / arraylength ( samplePoints ) );
}
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
193 posts
Joined: Dec. 2016
Offline
thx !

I’m having some problems logically deconstructing the code, though.


1. the computeSamplePoints definitions throws me the error,

Syntax error, unexpected identifier, expecting ';'. (7,12) 


I don't understand why I would get this error

So I can't get the code working.

2. I don't understand what the samples actually are. I would think, based on language, it's just taking every so many pixels instead of all of them.

3. the cop2 type is confusing to me and i also didn’t find any documentation on it

4. it's not really used in your code, but I can never figure out how to use inputs and outputs in the snippet node



Any further help is greatly appreciated.
Edited by NicTanghe - Nov. 8, 2022 13:59:45
User Avatar
Member
4517 posts
Joined: Feb. 2012
Offline
That function is for generating multiple sampling positions for supersampling:
https://en.wikipedia.org/wiki/Supersampling [en.wikipedia.org]

Sorry this code is not meant to be put inside a Snippet VOP. It's created using File -> New Asset -> VEX (COP).

I attached the HDA itself because it has HDA level parameters also. Some default COPs are created this way, i.e. Velocity Blur COP. You can tell this if the HDA has a button called Edit VEX Function.

Attachments:
Swirl_COP_Animatrix.otl (34.0 KB)

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
7785 posts
Joined: Sept. 2011
Offline
NicTanghe
thx !

I’m having some problems logically deconstructing the code, though.


1. the computeSamplePoints definitions throws me the error,

Syntax error, unexpected identifier, expecting ';'. (7,12) 


I don't understand why I would get this error

So I can't get the code working.

2. I don't understand what the samples actually are. I would think, based on language, it's just taking every so many pixels instead of all of them.

3. the cop2 type is confusing to me and i also didn’t find any documentation on it

4. it's not really used in your code, but I can never figure out how to use inputs and outputs in the snippet node



Any further help is greatly appreciated.

I thought you were making a normal map. Why do you want to displace the texture space?
User Avatar
Member
193 posts
Joined: Dec. 2016
Offline
Well, I’ve hit a bit of a roadblock.

All of my tiles seem to be rotating both the same amount and contain the same pixels.


Also, my tiling is offset but I'm sure I’d be able to fix that one.

Attachments:
Costum_COP_Ntanghe.otl (18.1 KB)

User Avatar
Member
8567 posts
Joined: July 2007
Offline
to the original question
you can use Sample Sphere VOP to generate random direction for your flakes based on cell id

Attachments:
Lookdev_rnd_v14_fix.hipnc (115.5 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
193 posts
Joined: Dec. 2016
Offline
Thanks ! that a way better solution to getting the normals.


I'm happy I got the costum COP reply first, though.

If anyone is willing to help me think to the problem in my second question, it’s still greatly appreciated.
User Avatar
Member
1742 posts
Joined: May 2006
Online
I've been playing with similar ideas, made a simple setup that might help.

https://www.tokeru.com/cgwiki/index.php?title=HoudiniCops#Cellnoise_with_rotated_gradients [www.tokeru.com]

Attachments:
cops_cellnoise_rotate.gif (877.1 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
  • Quick Links