Showing posts with label UE5. Show all posts
Showing posts with label UE5. Show all posts

Friday, 14 February 2025

Houdini Workshop Week 5 - Spring 2025

 Part 2 of our VBD smoke session. 

NOTE: I had an issue where I left the display flag on the solver when i saved and exited the file. When I tried to reopen it it kept wanting to cook and would not respond. To fix this, go to the bottom right where it says Auto Update and turn it to manual (you might have to hit escape a bunch of times here). This will make it so that it only updates when you tell it to. Now you can hit the display flag on the file cache we made last time. 

Making a volume to contain it

burger

    We want to contain the smoke so that its not clipping through the pipe we made. To do this we'll make a bounding box for our volume. Make a time shift node and navigate to the frame with the biggest volume in the viewport. For us it was around 450. Right click on the Frame parameter in the timeshift node > delete channel. We want it to be a static frame, we don't want it to change depending on the timeline. 
    Next make a bound box, renamed to BoundingBox. You don't need to change any parameters here. It will create a polygon box around your volume.
    Then you'll need a vdb from polygons node. We want to make sure that the voxel size is the exact same from our pyrosolver. Go back to the pyrosolver node and find the voxel size parameter. Right click on it and select 'copy parameter'. Then go back to our vdb from polygons node. In that voxel size parameter, right click and hit 'Paste Relative References'. You'll see that it pastes 'ch("../pyrosolver_billowy_smoke/divsize")'. This connects the two parameters, so this vdb from polygons node will update when you update the pyrosolver.
    We also need to change the distance vdb to off and the fog vdb on. 
    Now grab a volume mix node. the first input is our vdb from polygons node, the second input is our original smokestack file cache node. The mix group should be @name = temperature. 
we have a defined volume

Clipping the smoke stack

    Now we want to clip the smoke stack so it doesn't look like its going through the geo. 

    We could use another volume mix with the subtract operation, or a volume VOP (node based network to program VEX). But the best solution we've got is to just use a volume wrangle node and write in VEX. 
Example of the inside of a volume VOP to do this. Its reading the first and second input's density primitive name and then mixing them 
    We do need another extruded tube to block out the shape that we don't want our vdb to go through. Add a vdb from polygon node to turn it into a vdb to subtract with. 

    The tube has a center of -0.7 and 20 columns. The poly extrude has a distance of 6 with output back on. Make sure the vdb is a fog one instead of distance one. Also paste the relative reference of voxel size from the pyrosolver.
    Now in the volume wrangle node, write this: 
density = lerp( volumesample(0,"density", @P), 0, volumesample(1, "density", @P));
    It's just a default lerp from the original volume, to 0, with the new volume we made determining where the 0 should go. 
    Our volume should now no longer clip through it

Making Volumes Loop

    Now we need to loop the smoke sim. This is a bit tricky, but we can do it with some vex code. Create a null node and name it LoopControl. 

Press z to bring up the shape node selections and c to bring up the colors for nodes

    In the parameters, go to the icon next to the name at the top left > Parameters and Channels > Edit Parameter Interface.

    You'll see this window pop up. Drag 5 Integer Type parameters from the left side into the middle 'Existing Parameters'. You can change the name of the variable and the label that shows up in the parameter box in the right box 'Parameter Description. You'll need:
  • Transition Amount
  • Offset Amount
  • Start Transition
  • End Frame
  • Offset Second Cache
    For transition amount and offset amount you can change their default values to 40 and 140 respectively in the channels tab to the right. 
Offset amount default value
    Hit apply and you should see these parameters appear for the null node. 
    We're going to edit the channel expressions for start transition, end frame and offset second cache. Press alt + e to bring up the code editor.
Start Transition: 
ch("./end_frame")-ch("./transition_amount")
End Frame: 
ch("../smokeBake1/f2")-ch("./offset_amount")
Offset Second Cache:
ch("./end_frame")-ch("./offset_amount")

Note that '../' means to go up a level to another node, while './' means within this node. The ch("../smokeBake1/f2") is our original file cache node, and the f2 specifically means the second frame or end frame. 
    Now we need two time shift nodes into a volume mix node.

    In the first time shift node's frame, write: 
$F+ch("../LoopControl/offset_amount")
    In the second time shift node's frame, write: 
$F-ch("../LoopControl/offset_second_cache")
    Then for the volume mix, change the mix method to blend. In the blend parameter,  open up the expression editor (alt+e) and write this: 
if($F<ch("../LoopControl/start_transition"), 
    0,
    if($F>ch("../LoopControl/start_transition") + 
        ch("../LoopControl/transition_amount"),
        1,
        ($F-ch("../LoopControl/start_transition"))/
        ch("../LoopControl/transition_amount")
        ))

what's kinda happening with our blend

    If you've done it correctly, you should be able to change the timeline to 1-360 and watch a seamless loop. 

    For the final nodes, make a convert vdb node, and convert to VDB. 

    Make a final file cache node. For the end frame setting, write: 
ch("../LoopControl/end_frame")
    Save this to Disk. This will take awhile but thats all that needs to be done.

Importing into Unreal

Look into the folder, you'll see a bunch of files were generate them. You only need to drag one of these into the unreal project. It understands it is part of an animated sequence, so long as they're all named the same. 


    For the settings, change the attributes A to 32bit float. The dimensions at the bottom is how big our smoke is going to be. 

    WARNING: this can be memory intensive and can cause Unreal to crash. Close out any other programs to help with importing this.

    Once that's done importing. Go into the content browser, in the engine folder look for sparse volume texture viewer. Drag it into the scene. This is only used to see if we've imported it correctly.


    Change the sparse volume to our looping smoke and make sure that playing and looping is turned on. If you don't see it it might be because it's really small. 
    Now that we know it worked. Look for a SparseVolumeMaterial in the engine folder. Make a copy of it and put it in your content folder. Create a material instance of this. 
    Inside the material instance, change the sparse volume texture to our vdb we exported. 
    Look for heterogenous Volume in the place actors box. Drag and drop it in the scene. Change the material of the volume to our material instance we just made. Also make sure looping and playing is turned on as well. 

        Now the heterogenous volume should show our smoke (although still tiny). Rotate it 90 degrees and scale it up, and it should be done. This material should also allow you to color the smoke however you want for now. 



Friday, 24 January 2025

Houdini Workshop Week 3 - Spring 2025

     We'll be looking at the Legacy Pyro FX today.

    We want to export this out not as a volumetric but as dynamically remeshing object.

    In Houdini create a non animated test geo. We went with the Tommy Test geo.


    You'll want to go to the top right shelf and add a new shelf named "Legacy Pyro FX". It might be hidden in the extra 'shelves' options.

    On this shelf, click the 'Flames' with your geo selected. 


    It'll generate a DOP network and a pyro import geo node. You no longer need the source, and can turn off the autoDopNetwork. Just into the pyro import node. 


        You'll see these nodes. Click on the import_pyrofields node

    These are what goes into a pyro sim. You can change the 'heat' field to visualization: rainbow to see how it looks.
    Create a delete node.

    In the parameters change the group to '@name= density' and delete non-selected. So we delete everything else. 
    This is VEX code. What it's saying is to get all the objects that are part of the density group. The @ means an attribute, so look for the attribute name.
    Do the same thing to isolate the heat

    Now we're going to bake out this simulation so we're not constantly recalculating the sim. Create a file cache. Check on 'load from disk' option and change the name to FireSource. Save to Disk. The sim should run better now since we'll be loading from the disk (if we change any previous attributes before this node, we'll have to resave it disk). 
    Find two frames about 100 frames apart that look somewhat similar to each other. We'll make a cycle out of this. Drop in a make loops SOP

    When you first look at the parameters for make loop. You'll see that the Start frame and End frame are highlighted as blue. This is because they are connected to the timeline. You can left click on these options to see the VEXpression that is driving this.

    Make another file cache node to save the loop out. 
    Now for the isooffset SOP.

    Output Type should be Iso Surface and the mode should be Volume Sample. We adjusted the offset until we got a mesh that looked like fire but wasn't cut off by the top.
    These polygons are actually inside out. You can tell something isn't right since the faces are dark blue. Hit the D key to show the display options

    Now we need to put a reverse SOP to reverse the normals. It should display normally now. But now we need them as tris. Bring in a Remesh SOP. This turns it into tris.
    Add an attribute blur node to help with smoothing the geo out.

    Now for this sim, the Poly Reduce node doesn't help much, but it does help to know about this. You can use it quickly to make different Level of Detail models (LODs). You can determine the percentage of polys you want to keep or the max amount it should have
Turn on bypass for the poly reduce node so we don't work with it

    Add a Clean sop to help clean up the model. Turn on 'Manifold-Only Topology'

    Add a Normal SOP, group type: points. 
It calculates the normals of the vertex by taking the 3 vectors point to the other vertices this one is pointing to, adds them up together and then divide by 3. (this is an important step, we need this)
    Next, attribute from volume SOP. We need to go back up to the make loop node, drag off of it and input it to the 2nd input of the attribute from volume SOP. If its too far up, drag off of the make loops node, and alt click to make a pin dot to help organize it a bit better. 
    

    Create a final null node for the output.

Exporting

    Create a ROP node, inside the rop node create a labs vertex animation. Take the input geometry as the null node we just made. 

    Change the Lookup table format to HDR (ExR/TIFF as RGB 16/32 in Engine) .exr
Render all.
    Exrs are useful as the cover the entire range of colors possible and stores them in a linear color space. 
    Name it what you want in the export tab and then hit render all. 
    NOTE: This one you'll need to render two passes. One for the lookup table and one for the rotation/position/color exrs. After the first one is finished, change the 'Render Pass' to Second Pass. 

In Unreal

    The import options for the fbx are the same as last times

The only settings you should have on are: 
  • Vertex Color Import Option: Replace
  • Transform Vertex to Absolute: Yes
  •  Normal Import Method: Import Normals and Tangets
  • Convert Scene: Yes
  • Override Full Name: Yes
  • Material Import Method: Do not create Material
  • Reorder material to FBX order: Yes
    If you need mesh lods you can turn it on but we don't need it, so we'll keep it off. 



    When you import the geo, its gonna import as a bunch of floating tris. You'll need to make the material to make it right. 

    Similar to the other houdini materials, turn off tangent space normals, and make 4 custom uvs. Here we've just added two colors with a lerp node. 
    Make a material instance and attach the exrs we rendered out. MAKE SURE you've right clicked on them in the content browser, scripted asset actions> Houdini Config Textures for VATs (HDR).
    Apply to the static mesh and you're done.

Note: this week we didn't entirely get it to a work state. Its a start. We'll have to look into this more.

Easy Notes Archive

 Tech Art Blueprints Demo Animation State Machines Part 1 Animation State Machines Part 2 Math for Tech Art Part 1 Math for Tech Art Part 2 ...