Simple Rendering

mattloper edited this page Sep 8, 2014 · 3 revisions

Below, we step through what happens in the demonstration given by...

import opendr

First, we import some prerequisites and create a renderer. Here it is a colored renderer, but others (for boundary rendering, textured rendering, and depth rendering) are also available from the same renderer module.

import chumpy as ch
from opendr.renderer import ColoredRenderer
rn = ColoredRenderer()

Next we load our geometry. This will be defined as a set of triangles: by "v" (the Vx3 chumpy array of vertices) and "f" (the Fx3 array of vertex indices). Here we load a mesh, but we could also drive one from parameters.

from opendr.util_tests import get_earthmesh
m = get_earthmesh(trans=ch.array([0,0,4]), rotation=ch.zeros(3))
v = ch.array(m.v)
vc = ch.array( # albedo
f = m.f

Now we set up the camera, filling in the camera parameters necessary to set up a perspective projection.

from import ProjectPoints
w, h = (320, 240) = ProjectPoints(v=v, rt=ch.zeros(3), t=ch.zeros(3), 
    f=ch.array([w,w])/2.,c=ch.array([w,h])/2., k=ch.zeros(5))
rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
rn.v = v
rn.f = f
rn.bgcolor = ch.zeros(3)

Next we construct a Vx3 array of per-vertex colors; each vertex color will be what is observed onscreen, and must therefore incorporate both lighting and albedo. We could construct it from many kinds of differentiable functions, but here we assign a simple light source to it. Simple modifications could include having sums of light sources or spherical harmonics (also built-in).

from import LambertianPointLight = LambertianPointLight(
    light_color=ch.array([1., 1., 1.]))

Finally, we can view the result.

import matplotlib.pyplot as plt
Point light sphere demo

It is important to realize that this is a reactive framework, in the sense that changes to values will affect function which depend on them. As an example, let us perturb the vertices, and see what happens to the result:

rn.v = rn.v + ch.random.randn(rn.v.size).reshape(rn.v.shape)*.1 = rn.v
Point light sphere demo
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.