Arbitrary camera, part 2

This commit is contained in:
Steven Robertson 2011-05-04 01:30:22 -04:00
parent b2ee583b08
commit e8a31bb4a5
3 changed files with 17 additions and 12 deletions

View File

@ -7,7 +7,7 @@ __global__
void logfilt(float4 *pixbuf, float k1, float k2,
float gamma, float vibrancy, float highpow) {
// TODO: test if over an edge of the framebuffer
int i = 1024 * blockIdx.x + threadIdx.x;
int i = blockDim.x * blockIdx.x + threadIdx.x;
float4 pix = pixbuf[i];
if (pix.w <= 0) return;

View File

@ -70,7 +70,8 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
iter_info *info = &(infos[blockIdx.x]);
int consec_bad = -{{features.fuse}};
int nsamps = 2560;
// TODO: make nsteps adjustable via genome
int nsamps = {{packer.get('cp.width * cp.height / 512000. * cp.adj_density')}};
float x, y, color;
x = mwc_next_11(&rctx);
@ -121,7 +122,7 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
continue;
}
int i = iy * {{features.height}} + ix;
int i = iy * {{features.width}} + ix;
// since info was declared const, C++ barfs unless it's loaded first
float cp_step_frac = {{packer.get('cp_step_frac')}};
@ -140,9 +141,10 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
**globals())
def render(features, cps):
# TODO: make this adjustable via genome
nsteps = 1000
abuf = np.zeros((1024, 1024, 4), dtype=np.float32)
dbuf = np.zeros((1024, 1024), dtype=np.float32)
abuf = np.zeros((features.height, features.width, 4), dtype=np.float32)
dbuf = np.zeros((features.height, features.width), dtype=np.float32)
seeds = mwc.MWC.make_seeds(512 * nsteps)
iter = IterCode(features)
@ -200,14 +202,16 @@ def render(features, cps):
f = np.float32
k1 = cp.contrast * cp.brightness * 268 / 256
area = 1
k2 = 1 / (cp.contrast * (5 * nsteps))
npix = features.width * features.height
k1 = cp.brightness * 268 / 256
area = features.width * features.height / cp.ppu ** 2
k2 = 1 / (area * cp.adj_density)
fun = mod.get_function("logfilt")
t = fun(abufd, f(k1), f(k2),
f(1 / cp.gamma), f(cp.vibrancy), f(cp.highlight_power),
block=(1024,1,1), grid=(1024,1), time_kernel=True)
block=(256,1,1), grid=(npix/256,1), time_kernel=True)
print "Completed color filtering in %g seconds" % t
abuf = cuda.from_device_like(abufd, abuf)

View File

@ -39,7 +39,6 @@ def main(args):
MWCTest.test_mwc()
membench()
window = pyglet.window.Window(1024, 1024) if '-g' in args else None
with open(args[1]) as fp:
genomes = Genome.from_string(fp.read())
@ -52,9 +51,11 @@ def main(args):
if '-g' not in args:
return
window = pyglet.window.Window(anim.features.width, anim.features.height)
imgbuf = (np.minimum(accum * 255, 255)).astype(np.uint8)
image = pyglet.image.ImageData(1024, 1024, 'RGBA', imgbuf.tostring(), -4096)
image = pyglet.image.ImageData(anim.features.width, anim.features.height,
'RGBA', imgbuf.tostring(),
-anim.features.width * 4)
tex = image.texture
#pal = (anim.ctx.ptx.instances[PaletteLookup].pal * 255.).astype(np.uint8)