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

supersampling #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ def sigterm_handler(_signo, _stack_frame):
help="Display framerate")
ap.add_argument('-n', '--noloop', action='store_true', default=False,
help="Run selected pattern(s) only once, don't loop through them")
ap.add_argument('-S', '--scale', type=int, default=1,
help="Supersampling factor for full-scene antialiasing")
ap.add_argument('-g', '--gamma', type=float, default=2.0,
help="Gamma of output device (for supersampling)")
args = ap.parse_args()

debug_frames = args.frames
if args.port is None:
import glcube
Expand All @@ -134,6 +137,11 @@ def sigterm_handler(_signo, _stack_frame):
import serialcube
c = serialcube.Cube(args)

if args.scale != 1:
args.realcube = c
import scaledcube
c = scaledcube.Cube(args)

if c.color:
c.plasma = cubehelper.color_plasma
else:
Expand Down
51 changes: 51 additions & 0 deletions scaledcube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Supersampled virtual cube with gamma correction
# Tom Hargreaves <[email protected]>
import numpy
import cubehelper

class Cube(object):
def __init__(self, args):
self.realcube = args.realcube
self.color = self.realcube.color
size = args.size
self.realsize = size
sc = args.scale
self.scale = sc
self.size = size*sc
self.gamma = args.gamma
self.pixels = numpy.zeros((size*sc, size*sc, size*sc, 3), 'f')

def set_pixel(self, xyz, rgb):
rgb = cubehelper.color_to_float(rgb)
self.pixels[tuple(xyz)] = rgb

def clear(self):
self.pixels.fill(0.0)

def single_buffer(self):
pass

def swap(self):
pass

def render(self):
sc = self.scale
gamma = self.gamma
igamma = 1/self.gamma
sc3 = sc * sc * sc
for x in range(0, self.realsize):
for y in range(0, self.realsize):
for z in range(0, self.realsize):
(r, g, b) = (0, 0, 0)
for xx in range(0, sc):
for yy in range(0, sc):
for zz in range(0, sc):
(rr,gg,bb) = self.pixels[x*sc+xx, y*sc+yy, z*sc+zz]
r += rr**gamma
g += gg**gamma
b += bb**gamma
self.realcube.set_pixel((x,y,z),
((r/sc3)**igamma,
(g/sc3)**igamma,
(b/sc3)**igamma))
self.realcube.render()