Re: Blurring / Sharpening images in Real Time

New Message Reply Date view Thread view Subject view Author view

Rob Jenkins (robj++at++barney.reading.sgi.com)
Tue, 9 May 1995 16:29:45 +0100


Sorry - I didn't attach the attachment :-)

note - you may find that the number of images you need to accumulate makes this
method less than realtime also - let me know what you think.

-- 
________________________________________________________________
Rob Jenkins, Software Support Group, Silicon Graphics UK Ltd.       
1530 Arlington Business Park, Theale, Reading, UK, RG7 4SB. 
tel 01734 257736, fax 01734 257553, email robj++at++reading.sgi.com,

/* dof.c

This program draws a torus and beam using the accumulation buffer to simulate depth of field. */

#include <gl/gl.h> #include <gl/device.h> #include <stdio.h> #include <math.h> #include "shapes.h" #include "dof.h" #include "jitter.h"

float shiny_material[] = { DIFFUSE, 0.4, 0.4, 0.4, SPECULAR, 1.0, 1.0, 1.0, SHININESS, 128.0, LMNULL };

void def_simple_light_calc(void) { lmdef(DEFMATERIAL, 1, 11, shiny_material); lmdef(DEFLIGHT, 1, 0, NULL); lmdef(DEFLMODEL, 1, 0, NULL); }

void use_simple_light_calc(void) { lmbind(LIGHT0, 1); lmbind(LMODEL, 1); }

void main(void) { short attached; short value; int dev;

attached = 1; if (!getgdesc(GD_BITS_ACBUF)) { fprintf(stderr, "This machine does not support the accumulation buffer.\n"); exit(0); }

initialize();

while (TRUE) { while (qtest() || !attached) { dev = qread (&value); if ((dev == ESCKEY) && (value == 0)) exit(0); else if (dev == REDRAW) { reshapeviewport(); drawscene(); } else if (dev == INPUTCHANGE) attached = value; } /* end while qtest or not attached */ drawscene(); } /* end while (TRUE) */ } /* end main() */

/* The initialize subroutine positions the window and specifies * its future constraints. The program is in double buffer * and RGB mode. The simplest lighting model is used. */ void initialize(void) { long gid1; long xmax, ymax;

xmax = getgdesc(GD_XPMAX); ymax = getgdesc(GD_YPMAX); prefposition( xmax/4, xmax*3/4, ymax/4, ymax*3/4 ); gid1 = winopen ("Depth of Field"); minsize (xmax/10, ymax/10); keepaspect (xmax, ymax); winconstraints();

doublebuffer(); RGBmode(); acsize(16); gconfig(); zbuffer(TRUE); subpixel(TRUE);

qdevice (ESCKEY); qenter (REDRAW, gid1);

mmode(MVIEWING);

def_simple_light_calc(); use_simple_light_calc(); }

/* Draw a beam and torus with depth of field. */ void drawscene(void) { int jitter; static Angle angle = 0;

acbuf(AC_CLEAR, 0.0);

for(jitter = 0; jitter < 8; jitter++) { czclear(0,getgdesc(GD_ZMAX));

pushmatrix(); accperspective(450, 1.0, 3.0, 6.0, 0.0, 0.0, j8[jitter].x, j8[jitter].y, 5.0);

lookat(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0);

rotate(angle, 'x'); lmbind(MATERIAL,1); ftorus();

scale(1.0,3.0,0.5); fcube(); popmatrix();

acbuf(AC_ACCUMULATE, 1.0); }

angle += 50;

acbuf(AC_RETURN, 1.0/8.0); swapbuffers(); }

/* accwindow()

The first six arguments are identical to standard gl window() call

pixdx and pixdy are anti-alias jitter in pixels. Set both equal to 0.0 for no anti-alias jitter.

eyedx and eyedy are depth-of field jitter in pixels. Set both equal to 0.0 for no depth of field effects.

focus is distance from eye to plane in focus. focus must be greater than, but not equal to 0.0

Note that accwindow() calls translate(). You will probably want to insure that your ModelView matrix has been initialized to identity before calling accwindow() */ void accwindow( float left, float right, float bottom, float top, float near, float far, float pixdx, float pixdy, float eyedx, float eyedy, float focus) { float xwsize, ywsize; float dx, dy; long xpixels, ypixels;

getsize(&xpixels, &ypixels); xwsize = right - left; ywsize = top - bottom; dx = -(pixdx*xwsize/xpixels + eyedx*near/focus); dy = -(pixdy*ywsize/ypixels + eyedy*near/focus); window(left + dx, right + dx, bottom + dy, top + dy, near, far); translate(-eyedx, -eyedy, 0.0); }

/* accperspective() The first four arguments are identical to standard gl perspective() call

pixdx and pixdy are anti-alias jitter in pixels. Set both equal to 0.0 for no anti-alias jitter. eyedx and eyedy are depth-of field jitter in pixels. Set both equal to 0.0 for no depth of field effects. focus is distance from eye to plane in focus. focus must be greater than, but not equal to 0.0 Note that accperspective() calls accwindow() */ void accperspective( Angle fovy, float aspect, float near, float far, float pixdx, float pixdy, float eyedx, float eyedy, float focus) { float fov2,left,right,bottom,top;

fov2 = ((fovy*M_PI) / 1800.0) / 2.0;

top = near / (fcos(fov2) / fsin(fov2)); bottom = -top;

right = top * aspect; left = -right;

accwindow(left,right,bottom,top,near,far,pixdx,pixdy,eyedx,eyedy,focus); }

/* include file for dof.c */ void def_simple_light_calc(void); void use_simple_light_calc(void); void initialize(void); void drawscene(void); void accwindow( float left, float right, float bottom, float top, float near, float far, float pixdx, float pixdy, float eyedx, float eyedy, float focus); void accperspective( Angle fovy, float aspect, float near, float far, float pixdx, float pixdy, float eyedx, float eyedy, float focus);


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:29 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.