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

feat: support lighting and shadows for scatter and mesh #342

Merged
merged 15 commits into from
Aug 24, 2021

Conversation

maartenbreddels
Copy link
Collaborator

@maartenbreddels maartenbreddels commented Aug 13, 2020

This supersedes 80% of #341, supporing shadows with instances. I've left out the GUI parts, to avoid getting stuck on that, so we can merge this hopefully quickly:

import ipyvolume as ipv
import numpy as np
f = ipv.figure()
ipv.xyzlim(-4, 4)
ipv.zlim(-10, 10)
x = np.array([0.0, 1.5, 3.0], dtype=np.float32)
s = ipv.scatter(x, x, x, lighting_model='PHYSICAL', roughness=0.4, metalness=0.1, size=20);
l = ipv.light_directional(position=[0, 1.0, 0.5])
# # m = ipv.plot_plane('bottom')
k = 4.
h = -2.
tx = np.array([k, -k, -k, k])
tz = np.array([k, k, -k, -k])
ty = np.array([h, h, h, h])
tri = [(0, 1, 2), (0, 2, 3)]
p = ipv.plot_trisurf(x=tx, y=ty, z=tz, triangles=tri, lighting_model='PHYSICAL')

k = 1.75
h = 1.
tx = np.array([k, -k, -k, k])
tz = np.array([k, k, -k, -k])
ty = np.array([h, h, h, h])
tri = [(0, 1, 2), (0, 2, 3)]
p = ipv.plot_trisurf(x=tx, y=ty, z=tz, triangles=tri, lighting_model='PHYSICAL')

ipv.zlim(-4, 4)
ipv.show()

This gives me:
image

TODO:

  • color is grey in physical mode
  • lighting + default lighting mode is broken
  • mesh shadows are broken
  • several TODO

@maartenbreddels
Copy link
Collaborator Author

Basically my approach was to take the threejs shaders (vertex and fragment) and merge them into 1 shader, where the defines (AS_DEFAULT, AS_PHONG... , AS_DEPTH) decide which shader to execute.
the depth shader was needed to get the shadows to work with instancing for the scatter, and also property with the mesh.

@maartenbreddels
Copy link
Collaborator Author

Mesh shaders were broken, this is fixed now:
image

@maartenbreddels
Copy link
Collaborator Author

colors are fixed:
image

@maartenbreddels maartenbreddels force-pushed the feat_lighting_scatter_mesh branch 2 times, most recently from 63aea8e to e0689f2 Compare May 17, 2021 09:39
…cached

Example program:

import ipyvolume as ipv
import numpy as np

def scene():
    f = ipv.figure(debug=True)
    ipv.xyzlim(-1, 1)
    x = np.array([0.1, 0.5], dtype=np.float32)
    ipv.material_lambert()
    s = ipv.scatter(x, x, x, marker="sphere", size=10);
    ipv.material_clear()
    k = ipv.examples.klein_bottle(show=False)
    ipv.xyzlim(2)
    ipv.material_phong()
    ipv.material_clear()
    m = ipv.plot_plane('bottom')
    ipv.show()
    return f
f = scene()
ipv.light_ambient(intensity=0.4)
ipv.light_directional(position=[-3, 10, 3]);

The klein_bottle would not cast a shadown, unless we modify alphaTest
This appears black if alphaTest for mesh is changed to != 0.5
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

Successfully merging this pull request may close these issues.

1 participant