-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add lighting example in gallery
- Loading branch information
1 parent
3585c68
commit 14fada6
Showing
4 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Lightning\n", | ||
"By default ipyvolume uses a fake lighting model that works ok for depth perception. To get more realistic lighting effects ipyvolume supports a few light models from pythreejs/threejs.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-11T10:23:04.262467Z", | ||
"start_time": "2020-08-11T10:23:02.527104Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipyvolume as ipv\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def scene():\n", | ||
" f = ipv.figure(debug=True)\n", | ||
" ipv.xyzlim(-1, 1)\n", | ||
" x = np.array([0.1, 0.5], dtype=np.float32)\n", | ||
" ipv.material_phong()\n", | ||
" s = ipv.scatter(x, x, x, marker=\"sphere\", size=10);\n", | ||
" k = ipv.examples.klein_bottle(show=False)\n", | ||
" ipv.xyzlim(2)\n", | ||
" m = ipv.plot_plane('bottom')\n", | ||
" ipv.show()\n", | ||
" return f" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Ambient light\n", | ||
"For global illumination, which will not cast shadows" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scene()\n", | ||
"light = ipv.light_ambient(intensity=0.4);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Hemisphere light\n", | ||
"A light source positioned directly above the scene, with color fading from the sky color to the ground color.\n", | ||
"This light cannot be used to cast shadows." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scene()\n", | ||
"ipv.light_hemisphere(intensity=1);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Directional light\n", | ||
"A Directional Light source illuminates all objects equally from a given direction. This light can be used to cast shadows. The light is recommended together with hemisphere." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-11T12:12:33.761830Z", | ||
"start_time": "2020-08-11T12:12:33.685654Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"f = scene()\n", | ||
"ipv.light_ambient(intensity=0.4)\n", | ||
"ipv.light_directional(position=[3, 10, 3]);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Spot light\n", | ||
"A Spot Light produces a directed cone of light. The light becomes more intense closer to the spotlight source and to the center of the light cone. This light can be used to cast shadows." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scene()\n", | ||
"ipv.light_hemisphere(intensity=0.2)\n", | ||
"l = ipv.light_spot(position=[0, 3, 2]);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Point light\n", | ||
"A Point Light originates from a single point and spreads outward in all directions. This light can be used to cast shadows." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scene()\n", | ||
"ipv.light_hemisphere(intensity=0.2)\n", | ||
"l = ipv.light_point(position=[0., 1.6, 1.0]);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Animation example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipyvolume as ipv\n", | ||
"import ipyvolume.datasets\n", | ||
"stream = ipyvolume.datasets.animated_stream.fetch()\n", | ||
"print(\"shape of steam data\", stream.data.shape) # first dimension contains x, y, z, vx, vy, vz, then time, then particle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig = ipv.figure()\n", | ||
"# instead of doing x=stream.data[0], y=stream.data[1], ... vz=stream.data[5], use *stream.data\n", | ||
"# limit to 50 timesteps to avoid having a huge notebook\n", | ||
"ipv.material_physical()\n", | ||
"# q = ipv.quiver(*stream.data[:,0:200:10,:2000:10], color=\"red\", size=7)\n", | ||
"q = ipv.quiver(*stream.data, color=\"red\", size=7)\n", | ||
"ipv.style.use(\"dark\") # looks better\n", | ||
"m = ipv.plot_plane('bottom')\n", | ||
"m = ipv.plot_plane('back')\n", | ||
"m = ipv.plot_plane('left')\n", | ||
"ipv\n", | ||
"l = ipv.light_directional(position=[20, 50, 20], shadow_camera_orthographic_size=1, far=140, near=0.1);\n", | ||
"ipv.animation_control(q, interval=200)\n", | ||
"ipv.show()\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ipv.light_ambient(intensity=0.4);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Volume rendering and lighting\n", | ||
"For volumetric rendering we only support the [Phong lighting model](https://en.wikipedia.org/wiki/Phong_shading). No material needs to be set, only lights need to be setup.\n", | ||
"\n", | ||
"Note that volumetric regions do not cast, not receive shadows." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipyvolume as ipv" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# no material and lighting\n", | ||
"ipv.figure()\n", | ||
"volume = ipv.examples.example_ylm(shape=64, show=False)\n", | ||
"s = ipv.scatter(x=32, y=32, z=50, size=30, marker='sphere', color=\"green\");\n", | ||
"\n", | ||
"volume.tf.level1 = 0.24\n", | ||
"volume.tf.opacity1 = 0.1\n", | ||
"volume.brightness = 2\n", | ||
"ipv.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipyvolume as ipv\n", | ||
"f = ipv.figure(debug=True)\n", | ||
"# we only add two lights\n", | ||
"ipv.light_hemisphere(intensity=0.8)\n", | ||
"ipv.light_directional()\n", | ||
"\n", | ||
"volume = ipv.examples.example_ylm(shape=64, show=False)\n", | ||
"ipv.material_phong(specular='white')\n", | ||
"s = ipv.scatter(x=32, y=32, z=50, size=30, marker='sphere', color=\"green\");\n", | ||
"\n", | ||
"volume.tf.level1 = 0.24\n", | ||
"volume.tf.opacity1 = 0.1\n", | ||
"volume.material.specular = 'white'\n", | ||
"volume.brightness = 2\n", | ||
"ipv.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[screenshot](screenshot/volume-rendering-specular.gif)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.