Skip to content

Commit

Permalink
Merge pull request #45 from rnd-team-dev/r0.16.0
Browse files Browse the repository at this point in the history
R0.16.0
  • Loading branch information
robertsulej authored May 17, 2023
2 parents d00768f + 91463fe commit f69e0c5
Show file tree
Hide file tree
Showing 26 changed files with 782 additions and 106 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Release history
===============

`v0.16.0` - 2023-05-17
----------------------

Added
~~~~~

- set texture data from pytorch tensors
- texture filter modes enabled, default is *trilinear*, optionally can be changed to *nearest*

- set geometry data directly from numpy array or pytorch tensor (no host copy is mada)
- synchronization method to update host copy with data from gpu: NpOptiX.sync_raw_data()

- convenience method to get a copy of geometry data (more simple than PinnedBuffer, though returns a copy): NpOptiX.get_data()

`v0.15.1` - 2023-03-16
----------------------

Expand Down Expand Up @@ -568,6 +582,7 @@ Added
- this changelog, markdown description content type tag for PyPI
- use [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

.. _`v0.16.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.16.0
.. _`v0.15.1`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.1
.. _`v0.15.0`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.15.0
.. _`v0.14.4`: https://github.com/rnd-team-dev/plotoptix/releases/tag/v0.14.4
Expand Down
37 changes: 12 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ PlotOptiX

`Docs <https://plotoptix.rnd.team>`__

- Check what we are doing with PlotOptiX on `Behance <https://www.behance.net/RnDTeam>`__, `Facebook <https://www.facebook.com/rndteam>`__, and `Instagram <https://www.instagram.com/rnd.team.studio/>`__.
- Have a look what is possible with PlotOptiX: `Behance <https://www.behance.net/RnDTeam>`__, `Instagram <https://www.instagram.com/rnd.team.studio/>`__, and `Facebook <https://www.facebook.com/rndteam>`__.
- Join us on `Patreon <https://www.patreon.com/rndteam?fan_landing=true>`__ for news, release plans and hi-res content.

PlotOptiX is a 3D `ray tracing <https://en.wikipedia.org/wiki/Ray_tracing_(graphics)>`__ package for Python, aimed at easy and aesthetic visualization
of large datasets (and small as well). Data features can be represented in images as a position, size/thickness and color of primitives
of several basic shapes, or projected onto surfaces of objects in form of a color textures and displacement maps. Triangular meshes,
generated in the code or loaded from a file, are supported as well. All is finished with a photorealistic lighting, depth of field, and many other physically based effects simulated with a high quality.
generated in the code or loaded from a file, are supported as well. All is finished with a photorealistic lighting, depth of field, and many other
physically based effects simulated with a high quality.

No need to write shaders, intersection algorithms, handle 3D scene technicalities. Basic usage is even more simple than with
`matplotlib <https://matplotlib.org/gallery/mplot3d/scatter3d.html>`__:
Expand Down Expand Up @@ -65,8 +66,9 @@ Features
- *light sources*: spherical and parallelogram, light emission in volumes, uniform environmental light or environment map
- *post-processing*: tonal correction curves, levels adjustment, apply mask/overlay, AI denoiser and upsampler
- *callbacks*: at the scene initialization, start and end of each frame raytracing, end of progressive accumulation
- 8/16/32bps(hdr) image output to `numpy <http://www.numpy.org>`__ array, or save to popular image file formats
- 8/16/32bps(hdr) image output to `numpy <https://numpy.org>`__ array, or save to popular image file formats
- zero-copy access to GPU buffers wrapped in ndarrays: 8/32bpc image, hit and object info, albedo, normals
- direct access to `PyTorch <https://pytorch.org>`__ tensors data stored on GPU (and CPU as well) for texture and geometry updates
- GPU acceleration using RT Cores and everything else what comes with `OptiX <https://developer.nvidia.com/optix>`__
- hardware accelerated video output to MP4 file format using `NVENC 9.0 <https://developer.nvidia.com/nvidia-video-codec-sdk>`__
- Tkinter based simple GUI window or a headless raytracer
Expand Down Expand Up @@ -95,7 +97,7 @@ What's Included
Installation
============

**Note**, at this point, PlotOptiX binaries are tested in: Windows 10/11 (any Python 3), and Linux (Python 3.8 recommended): Ubuntu 18.04, CentOS 7.
**Note**, at this point, PlotOptiX binaries are tested in: Windows 10/11 (any Python 3), and Linux (Python 3.8-3.10 recommended): Ubuntu 18.04, CentOS 7.

PlotOptiX was also successfully tested on the `Google Cloud Platform <https://cloud.google.com/>`__, using Compute Engine instance with 2x V100 GPU's and Ubuntu 18.04 image.
Here are the `installation steps <https://github.com/rnd-team-dev/plotoptix/blob/master/gcp_install_gpu.txt>`__ so you can save some precious seconds (FFmpeg not included).
Expand All @@ -107,15 +109,7 @@ Windows prerequisites

*.NET Framework:*

Most likely you already got the right version with your Windows installation. Just in case of doubts, here is the command verifying this::

C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full
version REG_SZ 4.8.04084

If the number in your output is < 4.8, visit `download page <https://dotnet.microsoft.com/download/dotnet-framework>`__ and
install the most recent release.
You have it built in your Windows. Go ahead and install PlotOptiX.

Linux prerequisites
-------------------
Expand Down Expand Up @@ -191,21 +185,14 @@ Then, try running code from the top of this readme, or one of the examples. You
Development path
================

This is still an early version. There are some important features not available yet, eg. ticks and labels on plot axes.
This is still an experimental version in many aspects.

PlotOptiX is basically an interface to RnD.SharpOptiX library which we are developing and using in our Studio. RnD.SharpOptiX offers
much more functionality than it is now available through PlotOptiX. We'll progressively add more to PlotOptiX if there is interest in
this project (download, star, and `become our Patron <https://www.patreon.com/rndteam>`__
if you like it!).

The idea for development is:

1. Binaries for Linux (done in v0.3.0).
2. Migrate to OptiX 7.0 (done in v0.7.0).
3. Complete the plot layout / cover more raytracing features.
4. Convenience functions for various plot styles. Other GUI's.
much more functionality than it is now available through PlotOptiX. We progressively add more to PlotOptiX based mostly on the interest
of our patrons and applications that this project supports.

*Here, the community input is possible and warmly welcome!*
Download, star, and `become our Patron <https://www.patreon.com/rndteam>`__ if you like the project. Get in touch, share your use case,
we are always happy to help and take part in exciting ideas of our users.

Examples
========
Expand Down
2 changes: 1 addition & 1 deletion docs/npoptix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ basic rules are:
.. image:: images/flow_1.png
:alt: PlotOptiX compute flow

Fig. 1. PlotOptiX computations flow. Details of the OptiX tast are ommited for clarity (i.e. scene compilation and multi-gpu management).
Fig. 1. PlotOptiX computations flow. Details of the OptiX task are ommited for clarity (i.e. scene compilation and multi-gpu management).

.. image:: images/flow_2.png
:alt: PlotOptiX compute flow
Expand Down
18 changes: 13 additions & 5 deletions docs/npoptix_geometry.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Plot geometry
=============
Geometry
========

Create, load, update, and remove a plot
---------------------------------------

.. automethod:: plotoptix.NpOptiX.get_geometry_names
.. automethod:: plotoptix.NpOptiX.get_data
.. automethod:: plotoptix.NpOptiX.set_data
.. automethod:: plotoptix.NpOptiX.update_data
.. automethod:: plotoptix.NpOptiX.set_data_2d
Expand All @@ -19,10 +20,17 @@ Create, load, update, and remove a plot
.. automethod:: plotoptix.NpOptiX.load_displacement
.. automethod:: plotoptix.NpOptiX.delete_geometry

Direct modifications of data
----------------------------
Direct access and modifications of data
---------------------------------------

**Fast updates:**

.. automethod:: plotoptix.NpOptiX.update_raw_data
.. automethod:: plotoptix.NpOptiX.sync_raw_data

**Geometry modifications:**

These methods allow making changes to properties of data points
Following methods allow making changes to properties of data points
stored internally in the raytracer, without re-sending whole data
arrays from the Python code.

Expand Down
73 changes: 73 additions & 0 deletions examples/2_animations_and_callbacks/5_pytorch_texture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Pytorch texture source - game of life.
"""

import torch
import torch.nn.functional as F

from plotoptix import TkOptiX
from plotoptix.materials import m_flat


class params():
if torch.cuda.is_available:
device = torch.device('cuda')
dtype = torch.float16
else:
device = torch.device('cpu')
dtype = torch.float32
w = torch.tensor(
[[[[1.0,1.0,1.0], [1.0,0.0,1.0], [1.0,1.0,1.0]]]],
dtype=dtype, device=device, requires_grad=False
)
cells = torch.rand((1,1,128,128), dtype=dtype, device=device, requires_grad=False)
cells[cells > 0.995] = 1.0
cells[cells < 1.0] = 0.0
tex2D = torch.unsqueeze(cells[0, 0].type(torch.float32), -1).expand(-1, -1, 4).contiguous()


# Update texture data with a simple "game of life" rules.
def compute(rt, delta):
params.cells = F.conv2d(params.cells, weight=params.w, stride=1, padding=1)
params.cells[params.cells < 2.0] = 0.0
params.cells[params.cells > 3.0] = 0.0
params.cells[params.cells != 0.0] = 1.0

# Conversion to float32 and to contiguous memoty layout is ensured by plotoptix,
# though you may wamt to make it explicit like here, eg for performance reasons.
params.tex2D = torch.unsqueeze(params.cells[0, 0].type(torch.float32), -1).expand(-1, -1, 4).contiguous()


# Copy texture data to plotoptix scene.
def update_data(rt):
rt.set_torch_texture_2d("tex2d", params.tex2D, refresh=True)


def main():
rt = TkOptiX(
on_scene_compute=compute,
on_rt_completed=update_data
)
rt.set_param(min_accumulation_step=1)
rt.set_background(0)
rt.set_ambient(0)

# NOTE: pytorch features are not enabled by default. You need
# to call this method before using anything related to pytorch.
rt.enable_torch()

rt.set_torch_texture_2d("tex2d", params.tex2D, addr_mode="Clamp", filter_mode="Nearest")
m_flat["ColorTextures"] = [ "tex2d" ]
rt.setup_material("flat", m_flat)

rt.setup_camera("cam1", eye=[0, 0, 3], target=[0, 0, 0], fov=35, glock=True)

rt.set_data("plane", geom="Parallelograms", mat="flat",
pos=[-1, -1, 0], u=[2, 0, 0], v=[0, 2, 0], c=0.9
)

rt.start()

if __name__ == '__main__':
main()

64 changes: 64 additions & 0 deletions examples/2_animations_and_callbacks/6_direct_data_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Direct update of geometry data on device.
This example uses numpy arrays, but pytorch tensors are supported as well,
just note that rt.enable_torch() call is required before using pytorch.
"""

import numpy as np

from plotoptix import TkOptiX
from plotoptix.utils import simplex


class params():
n = 100
rx = (-20, 20)
r = 0.85 * 0.5 * (rx[1] - rx[0]) / (n - 1)

x = np.linspace(rx[0], rx[1], n)
z = np.linspace(rx[0], rx[1], n)
X, Z = np.meshgrid(x, z)

data = np.stack([X.flatten(), np.zeros(n*n), Z.flatten()], axis=1)
t = 0

# Compute updated geometry data.
def compute(rt, delta):
row = np.ones((params.data.shape[0], 1))
xn = simplex(np.concatenate([params.data, params.t * row], axis=1))
yn = simplex(np.concatenate([params.data, (params.t + 20) * row], axis=1))
zn = simplex(np.concatenate([params.data, (params.t - 20) * row], axis=1))
dv = np.stack([xn, yn, zn], axis=1)
params.data += 0.02 * dv
params.t += 0.05

# Fast copy to geometry buffer on device, without making a host copy.
def update_data(rt):
rt.update_raw_data("balls", pos=params.data)


def main():
rt = TkOptiX(
on_scene_compute=compute,
on_rt_completed=update_data
)
rt.set_param(min_accumulation_step=10, max_accumulation_frames=16)
rt.set_background(0)
rt.set_ambient(0)

rt.setup_camera("cam1", cam_type="ThinLens", eye=[3.5, 1.27, 3.5], target=[0, 0, 0], fov=30, glock=True)
rt.setup_light("light1", pos=[4, 5, 5], color=18, radius=1.0)

exposure = 1.0; gamma = 2.2
rt.set_float("tonemap_exposure", exposure)
rt.set_float("tonemap_gamma", gamma)
rt.add_postproc("Gamma")

rt.set_data("balls", pos=params.data, c=0.82, r=params.r)

rt.start()

if __name__ == '__main__':
main()

4 changes: 2 additions & 2 deletions plotoptix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

__author__ = "Robert Sulej, R&D Team <[email protected]>"
__status__ = "beta"
__version__ = "0.15.1"
__date__ = "16 March 2023"
__version__ = "0.16.0"
__date__ = "17 May 2023"

import logging

Expand Down
Loading

0 comments on commit f69e0c5

Please sign in to comment.