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

Feature: Lights and Shadows #308

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
2a140da
Test Phong lighting support for plot_mesh. Add lighting_demo notebook.
Mar 17, 2020
29d1d16
Test shadowmap with spotlight. Fix shadow acne.
Mar 19, 2020
55d6b98
Add Lambert lighting model shaders
Mar 19, 2020
88d019f
Add Physical lighting model shaders
Mar 20, 2020
5918a74
Create widgets_test.ipynb
rinftech-github Mar 23, 2020
6cb9964
Update widgets
rinftech-github Mar 25, 2020
5d739f2
Add Light widget classes. Add ambiental_light functionality
Mar 26, 2020
74f2eda
Add directional_light functionality
Mar 26, 2020
e30d1fa
Add hemisphere_light functionality
Mar 26, 2020
0d5f58e
Add spot_light functionality. Add target to directional_light
Mar 27, 2020
b76be11
Add point_light functionality
Mar 27, 2020
69480d3
Updates
rinftech-github Mar 27, 2020
9db5bcf
Add shadowmap support for spot_light
Mar 27, 2020
700c735
[Bugfixes]
rinftech-github Mar 27, 2020
467609d
Add shadowmap support for directional_light
Mar 27, 2020
d4c7d2d
Add shadowmap support for point_light. Add shadow_radius
Mar 27, 2020
2f1478b
Simplify lighting_demo notebook. Replace color with light_color
Mar 29, 2020
fd5e785
Add mesh widget material params. Add shadowmap types. Mesh class cleanup
Mar 29, 2020
b057d00
Propagate material params. Add plot_surface example
Mar 29, 2020
b11a537
Prepare lighting material uniforms for scatter rendering
Mar 29, 2020
2fc6c64
Add Scatter physical shaders
Mar 29, 2020
0eea214
Scatter lighting shaders work in progress - InstancedBufferGeometry s…
Mar 30, 2020
db927ee
Finished notebook lighting demo for plot_mesh, plot_trisurf and plot_…
Mar 30, 2020
56657e7
Fix notebook figure autoupdate. Hardcode lambert and phong diffuse co…
Mar 31, 2020
b7da181
Prepare notebook for plot_mesh material properties change
Mar 31, 2020
b77d204
Switch lighting model automatically to PHYSICAL when adding a new light
Mar 31, 2020
66bc1de
Complete mesh and lighting demo notebook. Fix Lambert emissive intens…
Mar 31, 2020
1b71716
Replace radius with shadow_radius in demo notebook
Mar 31, 2020
f2c6c38
Switch scatter lighting model to PHYSICAL when adding a light. Scatte…
Mar 31, 2020
c0bafd6
Update lighting demo notebook
Mar 31, 2020
1212c8a
Add unit tests. Remove cast_shadow from hemisphere_light
Mar 31, 2020
e1fe838
Add/update function description for plot_mesh, plot_surface, plot_tri…
Apr 1, 2020
d3a8979
Code cleanup
Apr 1, 2020
4978259
Fix shadow_map_size description. Add scatter information about lighti…
Apr 1, 2020
2012bd9
Update unit tests
Apr 1, 2020
fd1c121
Updated lighting demos with animation example
Apr 2, 2020
2ff64a1
Merge all mesh shading models into one vertex and one fragment shader
Jun 29, 2020
554fb99
Remove unnecessary shader files. Remove shader export directives
Jun 29, 2020
659e841
Merge scatter shaders into one vertex and one fragment file. Remove p…
Jul 1, 2020
75e8c77
Remove update_visibility from mesh and scatter. Remove transparent re…
Jul 2, 2020
55099f3
Remove unnecessary computeVertexNormals() call. Add argumentation com…
Jul 2, 2020
2d1a842
Begin removing Light widget
Jul 9, 2020
39ff7f6
Replace emissive_color with color. Adjust default emissive_intensity …
Jul 17, 2020
12b9b4d
lighting_demo notebook UI updates
Jul 23, 2020
235c735
Updated lighting demos with animation example
Apr 2, 2020
358ef8a
begin removing light.ts
Jul 27, 2020
a0eeb5a
add enable_shadows and shadow_map_type to figure.ts, I hope
Jul 27, 2020
f7bcf49
properly merge notebook from fd1c121829c868fa91ebb3a75b670a54a9a92bd6
Jul 27, 2020
8e118fe
cleanup point light
Jul 27, 2020
687e092
fix typo
Jul 27, 2020
13bfaec
really fix typo
Jul 27, 2020
8c63159
add construct light method
Jul 28, 2020
87ce688
dir and spot light seem to work
Jul 28, 2020
966ab9f
not async
Jul 28, 2020
d7f6ffe
attempt to delete previous lights
Jul 28, 2020
5834a91
enable shadows
Jul 28, 2020
caa28a5
test notebook
Jul 28, 2020
d914467
delete lights on re-add
Jul 28, 2020
eba6d62
fix ligthing model for meshes
Jul 28, 2020
c4eb372
cleanup old code
Jul 28, 2020
fd68aed
setup light wapper
Jul 28, 2020
562fe94
attempt at wrapping all light objects
Jul 28, 2020
f414bf3
fix runtime errors
Jul 28, 2020
4dec607
fix inheritance
Jul 28, 2020
9711c39
HemisphereLight typo
Jul 28, 2020
f418d8d
fix typos, update notebook
Jul 28, 2020
a22ab4d
fix notebook
Jul 28, 2020
ffa373c
undo light wrappers
Jul 28, 2020
4d68f43
Add flat_shading option. Improve notebook ui for meshes (lighting_demo)
Jul 28, 2020
8bcbf9f
add wrapper methods and refactor notebook
Jul 29, 2020
e9203c9
finished implemeting light changes update
Jul 29, 2020
bcc01a0
Set shadows cast/received to default True. Improvement to notebook me…
Jul 29, 2020
79d4edd
add target to scene
Jul 29, 2020
9e807d9
wip
Jul 29, 2020
8a883df
update shadows on prop change
Jul 29, 2020
ceecaef
refactor method names
Jul 29, 2020
c44999a
rm todo
Jul 29, 2020
688908c
attempt to hook only needed changes
Jul 29, 2020
ccc9867
hook all the things
Jul 29, 2020
8e5da84
refactor notebook
Jul 29, 2020
4860873
rm console log
Jul 29, 2020
ffe5d54
debug
Jul 29, 2020
421c9cb
Add UI elements for Ambient and Hemisphere lights in light demo notebook
Jul 29, 2020
6c55384
Add ui elements for Directional and Spot Lights in notebook. Remove s…
Jul 29, 2020
8e1f2a4
Add Point Light ui in lighting demo notebook
Jul 29, 2020
ee6c733
Merge branch 'feat_lighting' into feat_lighting_merge
Jul 30, 2020
a654619
rm old notebook
Jul 30, 2020
ce0243d
rm shadow_map_type
Jul 30, 2020
5202b53
start merge
Jul 30, 2020
f71fe10
update widget mesh booleans
Jul 30, 2020
3658c02
forgot to add fields
Jul 30, 2020
35deb4e
no more crashes
Jul 30, 2020
5506daa
Remove target from point light in demo notebook
Jul 30, 2020
60b5afd
watch for child change
Jul 30, 2020
20c349c
fix shadow binding
Jul 30, 2020
9548bed
latest notebook
Jul 30, 2020
707f433
add todo
Jul 30, 2020
2babe15
minor refactor
Jul 30, 2020
8692d07
add note about error
Jul 30, 2020
ab6651e
Remove show_material_widgets and show_light_widgets from notebook and…
Jul 30, 2020
a2caf32
Add function which parses all lights and meshes from figure and gener…
Jul 30, 2020
0be164f
Update show_lighting_widgets name
Aug 6, 2020
d68d33f
Remove name parameter from setup_material_widgets and setup_light_wid…
Aug 6, 2020
3557798
Replace position and target FloatSlider with FloatText
Aug 6, 2020
63b4b64
Customize light widgets ui layout and style
Aug 6, 2020
d48ba29
Fix incorrect lighting model value in UI
Aug 6, 2020
6b069af
proposed fixed from Marteen for directional light
Aug 7, 2020
c8b3992
fix also sptolight
Aug 7, 2020
ad013ab
fix point light
Aug 7, 2020
2e25a24
Merge branch 'feat_lighting' into feat_ligthing_widget
Aug 7, 2020
fa5386e
update notebok
Aug 7, 2020
13e75c9
fix light type and pos
Aug 7, 2020
1de0414
fix target
Aug 7, 2020
3fddedb
castShadow
Aug 7, 2020
cbc474b
fix other params
Aug 7, 2020
1db2655
rm light.ts
Aug 7, 2020
978400f
fix typos
Aug 7, 2020
387845c
fix light_color
Aug 7, 2020
0f1f15a
type name
Aug 7, 2020
d1c088f
fix final
Aug 7, 2020
ff96b4b
rm unused
Aug 7, 2020
7c5f761
fix position
Aug 7, 2020
fcf0be2
Updates to light default param values. Shadowmap fixes
Aug 8, 2020
06e1ac6
Update lighting_demo notebook. Remove shadow_map_type
Aug 8, 2020
3c696ed
Remove emissive_color completely from mesh. Tweak mesh documentation …
Aug 8, 2020
00130c4
Remove completely emissive_color from scatter. Other Directional ligh…
Aug 9, 2020
1e5a79e
Update light unit tests
Aug 9, 2020
69592f1
Fix hemisphere light color set
Aug 9, 2020
6ef4798
Remove scatter fragment flatshading color overwrite. Enable flatshadi…
Aug 9, 2020
e036afb
Extra scatter flatshading set
Aug 10, 2020
a580c9b
Add documentation to widget functions
Aug 10, 2020
48db5a2
Remove wrap_lights
Aug 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
422 changes: 412 additions & 10 deletions ipyvolume/pylab.py

Large diffs are not rendered by default.

274 changes: 274 additions & 0 deletions ipyvolume/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import json
import contextlib
import math

import numpy as np
import pytest
Expand Down Expand Up @@ -449,3 +450,276 @@ def test_datasets():
ipyvolume.datasets.aquariusA2.fetch()
ipyvolume.datasets.hdz2000.fetch()
ipyvolume.datasets.zeldovich.fetch()


def test_mesh_material():
def test_material_components(mesh=None, is_scatter=False):
assert mesh.lighting_model == 'DEFAULT'
assert mesh.opacity == 1
assert mesh.specular_color == 'white'
assert mesh.shininess == 1
assert mesh.emissive_color == 'black'
assert mesh.emissive_intensity == 1
assert mesh.roughness == 0
assert mesh.metalness == 0
if is_scatter == False:
assert mesh.cast_shadow == False
assert mesh.receive_shadow == False

mesh.lighting_model = 'PHYSICAL'
mesh.opacity = 0
mesh.specular_color = 'blue'
mesh.shininess = 10
mesh.emissive_color = 'red'
mesh.emissive_intensity = 2
mesh.roughness = 1
mesh.metalness = 5
if is_scatter == False:
mesh.cast_shadow = True
mesh.receive_shadow = True

assert mesh.lighting_model == 'PHYSICAL'
assert mesh.opacity == 0
assert mesh.specular_color == 'blue'
assert mesh.shininess == 10
assert mesh.emissive_color == 'red'
assert mesh.emissive_intensity == 2
assert mesh.roughness == 1
assert mesh.metalness == 5
if is_scatter == False:
assert mesh.cast_shadow == True
assert mesh.receive_shadow == True

x, y, z, u, v = ipyvolume.examples.klein_bottle(draw=False)

ipyvolume.figure()
mesh = ipyvolume.plot_mesh( x, y, z)
test_material_components(mesh)

k = 20
h = -15
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)]
trisurf = ipyvolume.plot_trisurf(tx, ty, tz, triangles=tri)
test_material_components(trisurf)

X = np.arange(-10, 10, 0.25*1)-10
Y = np.arange(-10, 10, 0.25*1)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

surf = ipyvolume.plot_surface(X, Z, Y)
test_material_components(surf)

x, y, z = np.random.random((3, 10000))
scatter = ipyvolume.scatter(x, y, z, size=1, marker="sphere")
test_material_components(scatter, True)


def test_light_components():
ambient = ipyvolume.ambient_light()
assert ambient.light_type == 'AMBIENT'
assert ambient.light_color == 'white'
assert ambient.intensity == 1
assert ambient.cast_shadow == False

ambient.light_color = 'blue'
ambient.intensity = 2

ambient.light_color == 'blue'
assert ambient.intensity == 2
#
hemisphere = ipyvolume.hemisphere_light()
assert hemisphere.light_color == 'white'
assert hemisphere.light_color2 == 'red'
assert hemisphere.intensity == 1
assert hemisphere.position_x == 0
assert hemisphere.position_y == 1
assert hemisphere.position_z == 0
assert hemisphere.cast_shadow == False

hemisphere.light_color = 'orange'
hemisphere.light_color2 = 'green'
hemisphere.intensity = 0.5
hemisphere.position_x = 100
hemisphere.position_y = 100
hemisphere.position_z = -100

assert hemisphere.light_color == 'orange'
assert hemisphere.light_color2 == 'green'
assert hemisphere.intensity == 0.5
assert hemisphere.position_x == 100
assert hemisphere.position_y == 100
assert hemisphere.position_z == -100
#
directional = ipyvolume.directional_light()
assert directional.light_color == 'white'
assert directional.intensity == 1
assert directional.position_x == 0
assert directional.position_y == 1
assert directional.position_z == 0
assert directional.target_x == 0
assert directional.target_y == 0
assert directional.target_z == 0
assert directional.cast_shadow==False
assert directional.shadow_map_size==512
assert directional.shadow_bias==-0.0005
assert directional.shadow_radius==1
assert directional.shadow_camera_near==0.5
assert directional.shadow_camera_far==500
assert directional.shadow_camera_orthographic_size==100
assert directional.shadow_map_type=='PCF_SOFT'

directional.light_color = 'black'
directional.intensity = 0
directional.position_x = 50.5
directional.position_y = 50.5
directional.position_z = 50.5
directional.target_x = 0.2
directional.target_y = -0.2
directional.target_z = 0.8
directional.cast_shadow=True
directional.shadow_map_size=1024
directional.shadow_bias=-0.0009
directional.shadow_radius=6
directional.shadow_camera_near=0.1
directional.shadow_camera_far=5000
directional.shadow_camera_orthographic_size=200
directional.shadow_map_type='BASIC'

assert directional.light_color == 'black'
assert directional.intensity == 0
assert directional.position_x == 50.5
assert directional.position_y == 50.5
assert directional.position_z == 50.5
assert directional.target_x == 0.2
assert directional.target_y == -0.2
assert directional.target_z == 0.8
assert directional.cast_shadow==True
assert directional.shadow_map_size==1024
assert directional.shadow_bias==-0.0009
assert directional.shadow_radius==6
assert directional.shadow_camera_near==0.1
assert directional.shadow_camera_far==5000
assert directional.shadow_camera_orthographic_size==200
assert directional.shadow_map_type=='BASIC'
#
point = ipyvolume.point_light()
assert point.light_color == 'white'
assert point.intensity == 1
assert point.position_x == 0
assert point.position_y == 1
assert point.position_z == 0
assert point.angle==math.pi/3
assert point.distance==0
assert point.decay==1
assert point.cast_shadow==False
assert point.shadow_map_size==512
assert point.shadow_bias==-0.0005
assert point.shadow_radius==1
assert point.shadow_camera_near==0.5
assert point.shadow_camera_far==500
assert point.shadow_map_type=='PCF_SOFT'

point.light_color = 'grey'
point.intensity = 10
point.position_x = 50.50
point.position_y = -50.50
point.position_z = 10.10
point.angle=math.pi/6
point.distance=70
point.decay=10
point.cast_shadow=True
point.shadow_map_size=256
point.shadow_bias=0
point.shadow_radius=10
point.shadow_camera_near=2
point.shadow_camera_far=10000
point.shadow_map_type='PCF'

assert point.light_color == 'grey'
assert point.intensity == 10
assert point.position_x == 50.50
assert point.position_y == -50.50
assert point.position_z == 10.10
assert point.angle==math.pi/6
assert point.distance==70
assert point.decay==10
assert point.cast_shadow==True
assert point.shadow_map_size==256
assert point.shadow_bias==0
assert point.shadow_radius==10
assert point.shadow_camera_near==2
assert point.shadow_camera_far==10000
assert point.shadow_map_type=='PCF'
#
spot = ipyvolume.spot_light()
assert spot.light_color == 'white'
assert spot.intensity == 1
assert spot.position_x == 0
assert spot.position_y == 1
assert spot.position_z == 0
assert spot.target_x == 0
assert spot.target_y == 0
assert spot.target_z == 0
assert spot.angle==math.pi/3
assert spot.distance==0
assert spot.decay==1
assert spot.penumbra==0
assert spot.cast_shadow==False
assert spot.shadow_map_size==512
assert spot.shadow_bias==-0.0005
assert spot.shadow_radius==1
assert spot.shadow_camera_near==0.5
assert spot.shadow_camera_far==500
assert spot.shadow_camera_perspective_fov==50
assert spot.shadow_camera_perspective_aspect==1
assert spot.shadow_map_type=='PCF_SOFT'

spot.light_color = 'red'
spot.intensity = 100.45
spot.position_x = -5.1
spot.position_y = -5.01
spot.position_z = -5.001
spot.target_x = 1.1
spot.target_y = 1.001
spot.target_z = 1.0001
spot.angle=math.pi/20
spot.distance=5.5
spot.decay=6.7
spot.penumbra=3.1
spot.cast_shadow=True
spot.shadow_map_size=2001
spot.shadow_bias=-0.000005
spot.shadow_radius=6.6
spot.shadow_camera_near=0.509
spot.shadow_camera_far=500.03
spot.shadow_camera_perspective_fov=50.56
spot.shadow_camera_perspective_aspect=1
spot.shadow_map_type='PCF'

assert spot.light_color == 'red'
assert spot.intensity == 100.45
assert spot.position_x == -5.1
assert spot.position_y == -5.01
assert spot.position_z == -5.001
assert spot.target_x == 1.1
assert spot.target_y == 1.001
assert spot.target_z == 1.0001
assert spot.angle==math.pi/20
assert spot.distance==5.5
assert spot.decay==6.7
assert spot.penumbra==3.1
assert spot.cast_shadow==True
assert spot.shadow_map_size==2001
assert spot.shadow_bias==-0.000005
assert spot.shadow_radius==6.6
assert spot.shadow_camera_near==0.509
assert spot.shadow_camera_far==500.03
assert spot.shadow_camera_perspective_fov==50.56
assert spot.shadow_camera_perspective_aspect==1
assert spot.shadow_map_type=='PCF'