Arbitrary camera, part 1

This commit is contained in:
Steven Robertson
2011-05-04 01:06:18 -04:00
parent 765cf6b2e0
commit b2ee583b08
5 changed files with 95 additions and 36 deletions

View File

@ -39,7 +39,7 @@ __device__
void apply_xf{{xfid}}(float *ix, float *iy, float *icolor,
const iter_info *info, mwc_st *rctx) {
float tx, ty, ox = *ix, oy = *iy;
{{apply_affine('ox', 'oy', 'tx', 'ty', px, 'xf.c', 'pre')}}
{{apply_affine_flam3('ox', 'oy', 'tx', 'ty', px, 'xf.c', 'pre')}}
ox = 0;
oy = 0;
@ -97,7 +97,20 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
nsamps--;
if (x <= -0.5f || x >= 0.5f || y <= -0.5f || y >= 0.5f) {
// TODO: this may not optimize well, verify.
float cx, cy;
{{apply_affine('x', 'y', 'cx', 'cy', packer,
'cp.camera_transform', 'cam')}}
float ditherwidth = {{packer.get('0.5 * cp.spatial_filter_radius')}};
float ditherx = mwc_next_11(&rctx) * ditherwidth;
float dithery = mwc_next_11(&rctx) * ditherwidth;
int ix = trunca(cx+ditherx), iy = trunca(cy+dithery);
if (ix < 0 || ix >= {{features.width}} ||
iy < 0 || iy >= {{features.height}} ) {
consec_bad++;
if (consec_bad > {{features.max_oob}}) {
x = mwc_next_11(&rctx);
@ -108,11 +121,7 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
continue;
}
float ditherx = mwc_next_11(&rctx) * 0.5f;
float dithery = mwc_next_11(&rctx) * 0.5f;
int i = ((int)((y + 0.5f) * 1022.0f + ditherx) * 1024)
+ (int)((x + 0.5f) * 1022.0f + dithery) + 1025;
int i = iy * {{features.height}} + ix;
// since info was declared const, C++ barfs unless it's loaded first
float cp_step_frac = {{packer.get('cp_step_frac')}};
@ -127,8 +136,8 @@ void iter(mwc_st *msts, iter_info *infos, float *accbuf, float *denbuf) {
""")
return tmpl.substitute(
features = self.features,
packer = self.packer.view('info'))
packer = self.packer.view('info'),
**globals())
def render(features, cps):
nsteps = 1000

View File

@ -17,6 +17,18 @@ def assemble_code(*sections):
for kind in ['headers', 'decls', 'defs']])
def apply_affine(x, y, xo, yo, packer, base_accessor, base_name):
return tempita.Template("""
{{xo}} = {{packer.get(ba + '[0,0]', bn + '_xx')}} * {{x}}
+ {{packer.get(ba + '[0,1]', bn + '_xy')}} * {{y}}
+ {{packer.get(ba + '[0,2]', bn + '_xo')}};
{{yo}} = {{packer.get(ba + '[1,0]', bn + '_yx')}} * {{x}}
+ {{packer.get(ba + '[1,1]', bn + '_yy')}} * {{y}}
+ {{packer.get(ba + '[1,2]', bn + '_yo')}};
""").substitute(x=x, y=y, xo=xo, yo=yo, packer=packer,
ba=base_accessor, bn=base_name)
def apply_affine_flam3(x, y, xo, yo, packer, base_accessor, base_name):
"""Read an affine transformation in *flam3 order* and apply it."""
return tempita.Template("""
{{xo}} = {{packer.get(ba + '[0][0]', bn + '_xx')}} * {{x}}
+ {{packer.get(ba + '[1][0]', bn + '_xy')}} * {{y}}
@ -42,6 +54,14 @@ uint32_t gtid() {
(threadIdx.z + blockDim.z *
(blockIdx.x + (gridDim.x * blockIdx.y))));
}
__device__
int trunca(float f) {
// truncate as used in address calculations
int ret;
asm("cvt.rni.s32.f32 %0, %1;" : "=r"(ret) : "f"(f));
return ret;
}
"""
class DataPackerView(object):