plotoptix icon indicating copy to clipboard operation
plotoptix copied to clipboard

Adding fluid effect

Open SamTov opened this issue 2 years ago • 4 comments

I'm not sure if this is a little specific. But I am using the package to render scenes / videos of bacteria and micro-robot simulations and I want to add this effect of the particles being in a fluid. I have seen on the portfolio website that this has been done but I am far from an expert in this kind of design. Do you have some pointers on what sort of effects to look at in order to make it look like my system is in a fluid?

SamTov avatar Jun 06 '23 17:06 SamTov

Hi Sam,

I guess you are thinking of an impression of seeing things like air bubbles inside the fluid. Then refraction index of e.g. particles should be lower than index of the surrounding volume. That was implement here.

Another option - not possible with the real world physics, but "why not" in the visualization is to simply make refraction index < 1.0. Empty space in the scene is assumed to have refraction index = 1.0, so the effect will be the same like in the fluid, just you don't need the fluid volume that is only slowing down calculatons.

With a few other settings code could look like this:

import numpy as np
from plotoptix import TkOptiX
from plotoptix.materials import m_clear_glass


def main():

    n = 200

    xyz = 3 * (np.random.random((n, 3)) - 0.5)
    r = 0.1 * (1 - (xyz[:,0]/3 + 0.5)) + 0.02

    rt = TkOptiX()
    rt.set_param(min_accumulation_step=6, max_accumulation_frames=256)
    rt.set_uint("path_seg_range", 6, 64)

    #m_clear_glass["VarFloat3"]["refraction_index"] = [1.4, 1.4, 1.4]
    m_clear_glass["VarFloat3"]["refraction_index"] = [0.65, 0.65, 0.65]
    rt.setup_material("glass", m_clear_glass)

    rt.set_data("particles", pos=xyz, r=r, c=100, mat="glass")

    a = np.linspace(0.94, 0, 10)
    b = np.zeros((10, 2, 3))
    for i in range(10):
        b[i,0]=np.full(3, a[i])
        b[i,1]=np.full(3, a[i])
    b[:,:] *= [0.8, 0.87, 1.0] # bluish tone

    rt.set_background_mode("TextureEnvironment")
    rt.set_background(b)

    rt.setup_camera("cam",
                    cam_type="FisheyeChroma",
                    #cam_type="ThinLens",
                    eye=[3, 0, -5], target=[0, 0, 0], up=[0, 1, 0],
                    fov=40, aperture_radius=0.2,
                    chroma_l=0, chroma_t=0.02, # ignored if not "...Chroma" camera type
                    glock=True
    )
    rt.setup_light("light1", pos=[-6, 0, 10], color=10*np.array([0.99, 0.9, 0.7]), radius=2)

    rt.show()

if __name__ == '__main__':
    main()

But... if you'd like to make a fluid surface simulated with a particle system and smoothly rendered with a metaball geometry - then it is not implemented... I was thinking of adding metaballs for a long time, but didn't find that time yet..

Let me know! :)

robertsulej avatar Jun 06 '23 18:06 robertsulej

I know, it is a super simple code and simple images, but I liked the output. I thikn I'll make a few and post on IG :)

render_output

robertsulej avatar Jun 07 '23 13:06 robertsulej

Sorry for the delay in reply but this is perfect! I will make the figures when I am back and can post the results here if you're interested. Thanks a lot for the quick reply and code sample.

My long term hope is to put PlotOptix into my visualiser package ZnVis https://github.com/zincware/ZnVis as a rendering option for either still frames or videos. I have to say the package you have put together is really impressive. It makes the complex problem of rendering very simple and it is one of a kind. Thanks for all the work and making it open source!

SamTov avatar Jun 09 '23 11:06 SamTov

Thanks for nice words! :)

And sure, please, post samples of your outputs, very interested to see how it works.

robertsulej avatar Jun 09 '23 11:06 robertsulej