AWS Thinkbox Discussion Forums

How to map particle colour using velocity in Magma?

Hello,

In one of Bobo’s old tutorials he shows how to map a blue and white gradient to particles using the velocity channel of a RealFlow sim.

Krakatoa has changed beyond recognition since then, so how would this be done now within Magma? How would you set up the nodes?

I did find the online tutorial of how to do this with Copy Channel, but still curious how to do it with Magma:
thinkboxsoftware.com/kmy-map … ty-length/
And you can display the velocities as lines in the PRTLoader with Viewport Display Mode: Display Velocities.

Also, is there way to see what channels are available in a PRT sequence opened in the PRTLoader?

Thanks

*Create an Output node, set to Color.
*Connect an InputVector node, set to Velocity.
*Insert a Vector>Magnitude node to get the length of the Velocity.
*Divide the Velocity Magnitude by a Float input (this is the scale factor, defining the maximum velocity). When Velocity Magnitude is 0.0, the result will be 0.0. When the Magnitude is equal to the divisor, you get 1.0.
*Insert a Function > Clamp node after the Divide to clamp the normalized Velocity Magnitude between 0.0 and 1.0.
*Insert a Function > Blend operator to blend two colors based on the normalized Velocity Magnitude.
*Connect two InputVector nodes to define the color at 0.0 and the color at 1.0.


Alternatively, you can output the result of the clamped normalized Velocity Magnitude as the U component of a Mapping channel output. Just use a Convert > ToVector operator, and connect to an Output node set to write the TextureCoord channel. Then you can use the Apply Texture approach seen in the old tutorial to actually use a Gradient map instead of a linear mix of two colors…

Thanks Bobo. You should change your avatar to a wizard.

While this is not available right now, you can check what channels are available in a PRT sequence on disk using this rather rough Python script:

def read_long (file_handle, bytes):
    return_val = 0
    for j in range(0,bytes):
        b = ord(file_handle.read(1))
        return_val += pow(256,j)*b
    return return_val

def prt_file_info (file_name):
    print "================================="
    f = open(file_name, 'rb')
    f.read(8)

    headerlength = read_long(f,4)
    print ('Header Length:' + str(headerlength))

    sig = f.read(32)
    print ('File Signature: '+ sig)

    version = read_long(f, 4)
    formats = ['1.0','1.1']
    print ('File Version: '+ formats[version-1])

    count = read_long(f, 8)
    print ('Particle Count: '+str(count))

    if version > 1: #version 1.0 did not have metadata
        done = False
        while not done:
            chunktype = f.read(4)
            chunklength = read_long(f, 4)
            data = f.read(chunklength)
            if chunktype=='Stop': 
                done = True

    read_long(f, 4) #reserved bytes

    numchannels = read_long(f, 4)
    print ('Number Of Channels: ' + str(numchannels))
    channelsize = read_long(f, 4)

    chtypes = ['int16','int32','int64','float16','float32','float64','uint16','uint32','uint64','int8','uint8']
    print '================================='
    print 'CHANNELS LIST:'
    print '================================='
    for c in range(0,numchannels):
        chname = f.read(32)
        print chname
        chtype = read_long(f,4)
        charity = read_long(f,4)
        print (chtypes[chtype]+ '[' +str(charity)+ ']')
        choffset = read_long(f,4)
        print '---------------------------------'
    
    print '================================='
    f.close()

Example usage:

prt_file_info ('C:/Temp/partitions/Test/particles_0010.prt')

Example output:

prt_file_info ('C:/Temp/partitions/Test/particles_0010.prt')
=================================
Header Length:294
File Signature: Extensible Particle Format
File Version: 1.1
Particle Count: 12096
Number Of Channels: 6
=================================
CHANNELS LIST:
=================================
Position
float32[3]
---------------------------------
ID
int32[1]
---------------------------------
Velocity
float16[3]
---------------------------------
Color
float16[3]
---------------------------------
Normal
float16[3]
---------------------------------
Density
float16[1]
---------------------------------
=================================
Privacy | Site terms | Cookie preferences