利用者:Joeedh/SummerOfCode2007

提供: wiki
移動先: 案内検索

Introduction

Deep shadow maps are a technique to create filtered, transparent, colored shadow maps.

Papers used:

http://graphics.stanford.edu/papers/deepshadows/deepshad.pdf

http://www.tabellion.org/et/paper07/egsr07_mtsm.pdf

Design

DSM Structure


/*Each tile has its own memarena to work better with caching.*/
typedef struct DSMTile {
	struct TCS_Tile tile;
	
	/*each of the arrays pointed in these 2 array rects has the length
	  as the first element, stored in the int format.  this way
	  we can use a binary search to make things easier.*/
	float **color_rect; //includes alpha
	unsigned int **depth_rect;
	int x, y;
	int sizex, sizey;
	struct MemArena *arena;
} DSMTile;

typedef struct DSMBuffer {
	TCS_Buffer buffer;
	float winmat[4][4];
	float clipstart, clipend;
	float lens; /*this is in degrees, for field of view*/
	
	DSMTile *poly_rect;
	int sizex, sizey;
	int tilex, tiley;
	int max_depth; /*the maximum number of samples in a single pixel*/
	struct TCS_TileBuffer *cachebuffer;
} DSMBuffer;

These are the deep shadow buffer structures. Each deep shadow buffer is divided into tiles, each of which is allocated with its own memarena. Each tile has 2 2d pointer arrays, one where each cell points to an array of RGBA values, and another where the cell points to an array of depth values (note that these 2 arrays correspond to each other). The initial implementation simply stores depth/rgba pairs instead of visibility functions.

For zbuffering, a special version of zbuffer_abuf has been created, that works with all faces (for now, to avoid the complexity of using 2 zbuffer schemes), rather then just ztransp ones, and allows setting an arbitrary number of oversamples.

Generic Tile System Structure

These are the structures I wrote for the tile system:

typedef struct TCS_Tile {
	struct TCS_Tile *next, *prev;
	void (*loadFromCache)(struct TCS_Tile *self, struct FILE *file, unsigned long start);
	
	/*returns length*/
	unsigned int (*saveToCache(struct TCS_Tile *self, struct FILE *file, unsigned
 long current_position);
	int is_cached;
	struct TCS_TilePool *pool;
	struct TCS_TileBuffer *buffer; /*parent buffer*/
 } TCS_Tile;
 
 /*pools manage tiles, but the the tiles themselves belong to TCS_TileBuffers
   this is a generic container structure.*/
 typedef struct TCS_TilePool {
	struct TCS_TilePool *next, *prev;
	ListBase tiles;
	
	unsigned int tottiles;
	unsigned long maxmem;
 } TCS_TilePool;
 
 typedef struct TCS_TileBuffer {
	struct TCS_TileBuffer *next, *prev;
	void (*makeTiles)(TCS_TileBuffer *self, TCS_TilePool *cachepool);
	void (*freeBuffer)(TCS_TileBuffer *self);

	/*as may dimensions can be used as needed, others can just be passed in as 0.*/
	void (*getTile)(TCS_TileBuffer *self, int x, int y, int z);
	void (*getTileMemUsage)(TCS_TileBuffer *self, int x, int y, int z);
	TCS_TilePool *pool;
 } TCS_TileBuffer;

Note that I havn't done any implementation for this yet. Just needed to figure out how it'd work so I knew how to design the DSM structures.

Low-level Memory Cache System

I've written the start of a system for disk-caching memory chunks with compressed file I/O. The system is designed to support pointer restoration.