Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding fluid effect #48

Open
SamTov opened this issue Jun 6, 2023 · 4 comments
Open

Adding fluid effect #48

SamTov opened this issue Jun 6, 2023 · 4 comments

Comments

@SamTov
Copy link

SamTov commented Jun 6, 2023

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?

@robertsulej
Copy link
Member

robertsulej commented Jun 6, 2023

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
Copy link
Member

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

@SamTov
Copy link
Author

SamTov commented Jun 9, 2023

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!

@robertsulej
Copy link
Member

Thanks for nice words! :)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants