Cube  Diff

Differences From Artifact [a8374cc3dc]:

To Artifact [5690f47554]:


57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
		c2 += d2->vdelta / 4.0f;
	}
	if (c1 <= f1 && c2 <= f2)
		return;
	render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip,
	    y2 << mip, 1 << mip, d1, d2, topleft);
};
};


const int MAX_MIP = 5; // 32x32 unit blocks
const int MIN_LOD = 2;
const int LOW_LOD = 25;
const int MAX_LOD = 1000;

int lod = 40, lodtop, lodbot, lodleft, lodright;







<
>







57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
		c2 += d2->vdelta / 4.0f;
	}
	if (c1 <= f1 && c2 <= f2)
		return;
	render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip,
	    y2 << mip, 1 << mip, d1, d2, topleft);
};

}

const int MAX_MIP = 5; // 32x32 unit blocks
const int MIN_LOD = 2;
const int LOW_LOD = 25;
const int MAX_LOD = 1000;

int lod = 40, lodtop, lodbot, lodleft, lodright;
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
	case CORNER:
	case SOLID:
		break;
	default:
		return true;
	};
	return false;
};


bool render_floor, render_ceil;

// the core recursive function, renders a rect of cubes at a certain mip level
// from a viewer perspective call itself for lower mip levels, on most modern
// machines however this function will use the higher mip levels only for
// perfect mips.







<
>







102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
	case CORNER:
	case SOLID:
		break;
	default:
		return true;
	};
	return false;

}

bool render_floor, render_ceil;

// the core recursive function, renders a rect of cubes at a certain mip level
// from a viewer perspective call itself for lower mip levels, on most modern
// machines however this function will use the higher mip levels only for
// perfect mips.
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
	// loop through the rect 3 times (for floor/ceil/walls seperately, to
	// facilitate dynamic stripify) for each we skip occluded cubes
	// (occlusion at higher mip levels is a big time saver!). during the
	// first loop (ceil) we collect cubes that lie within the lower mip rect
	// and are also deferred, and render them recursively. Anything left
	// (perfect mips and higher lods) we render here.

#define LOOPH                                                                  \
	{                                                                      \
		for (int xx = x; xx < xs; xx++)                                \
			for (int yy = y; yy < ys; yy++) {                      \
				sqr *s = SWS(w, xx, yy, sz);                   \
				if (s->occluded == 1)                          \
					continue;                              \
				if (s->defer && !s->occluded && mip &&         \
				    xx >= lx && xx < rx && yy >= ly &&         \
				    yy < ry)
#define LOOPD                                                                  \
	sqr *t = SWS(s, 1, 0, sz);                                             \
	sqr *u = SWS(s, 1, 1, sz);                                             \
	sqr *v = SWS(s, 0, 1, sz);

	LOOPH // ceils
	{
		int start = yy;
		sqr *next;
		while (yy < ys - 1 && (next = SWS(w, xx, yy + 1, sz))->defer &&
		       !next->occluded)
			yy++; // collect 2xN rect of lower mip
		render_seg_new(vx, vy, vh, mip - 1, xx * 2, start * 2,
		    xx * 2 + 2, yy * 2 + 2);
		continue;
	};

	stats[mip]++;
	LOOPD
	if ((s->type == SPACE || s->type == FHF) && s->ceil >= vh &&
	    render_ceil)
		render_flat(s->ctex, xx << mip, yy << mip, 1 << mip, s->ceil, s,
		    t, u, v, true);
	if (s->type == CHF) // if(s->ceil>=vh)







|
|
|
|
|
|
|
|
|

|
|
|







|




<
>







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
	// loop through the rect 3 times (for floor/ceil/walls seperately, to
	// facilitate dynamic stripify) for each we skip occluded cubes
	// (occlusion at higher mip levels is a big time saver!). during the
	// first loop (ceil) we collect cubes that lie within the lower mip rect
	// and are also deferred, and render them recursively. Anything left
	// (perfect mips and higher lods) we render here.

#define LOOPH                                                          \
	{                                                              \
		for (int xx = x; xx < xs; xx++)                        \
			for (int yy = y; yy < ys; yy++) {              \
				sqr *s = SWS(w, xx, yy, sz);           \
				if (s->occluded == 1)                  \
					continue;                      \
				if (s->defer && !s->occluded && mip && \
				    xx >= lx && xx < rx && yy >= ly && \
				    yy < ry)
#define LOOPD                      \
	sqr *t = SWS(s, 1, 0, sz); \
	sqr *u = SWS(s, 1, 1, sz); \
	sqr *v = SWS(s, 0, 1, sz);

	LOOPH // ceils
	{
		int start = yy;
		sqr *next;
		while (yy < ys - 1 && (next = SWS(w, xx, yy + 1, sz))->defer &&
		    !next->occluded)
			yy++; // collect 2xN rect of lower mip
		render_seg_new(vx, vy, vh, mip - 1, xx * 2, start * 2,
		    xx * 2 + 2, yy * 2 + 2);
		continue;

	}
	stats[mip]++;
	LOOPD
	if ((s->type == SPACE || s->type == FHF) && s->ceil >= vh &&
	    render_ceil)
		render_flat(s->ctex, xx << mip, yy << mip, 1 << mip, s->ceil, s,
		    t, u, v, true);
	if (s->type == CHF) // if(s->ceil>=vh)
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
	float f = 90.0f / lod / widef;
	low = (int)((90 - angle) / f);
	high = (int)(angle / f);
	if (low < min_lod)
		low = min_lod;
	if (high < min_lod)
		high = min_lod;
};


// does some out of date view frustrum optimisation that doesn't contribute much
// anymore

void
render_world(
    float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
{
	loopi(LARGEST_FACTOR) stats[i] = 0;
	min_lod = MIN_LOD + abs(pitch) / 12;
	yaw = 360 - yaw;
	float widef = fov / 75.0f;
	int cdist = abs(yaw % 90 - 45);
	if (cdist < 7) // hack to avoid popup at high fovs at 45 yaw
	{
		min_lod = max(min_lod,
		    (int)(MIN_LOD + (10 - cdist) / 1.0f *

		                        widef)); // less if lod worked better
		widef = 1.0f;
	};
	lod = MAX_LOD;
	lodtop = lodbot = lodleft = lodright = min_lod;
	if (yaw > 45 && yaw <= 135) {
		lodleft = lod;
		distlod(lodtop, lodbot, yaw - 45, widef);







<
>
















|
>
|







307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
	float f = 90.0f / lod / widef;
	low = (int)((90 - angle) / f);
	high = (int)(angle / f);
	if (low < min_lod)
		low = min_lod;
	if (high < min_lod)
		high = min_lod;

}

// does some out of date view frustrum optimisation that doesn't contribute much
// anymore

void
render_world(
    float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
{
	loopi(LARGEST_FACTOR) stats[i] = 0;
	min_lod = MIN_LOD + abs(pitch) / 12;
	yaw = 360 - yaw;
	float widef = fov / 75.0f;
	int cdist = abs(yaw % 90 - 45);
	if (cdist < 7) // hack to avoid popup at high fovs at 45 yaw
	{
		min_lod = max(min_lod,
		    (int)(MIN_LOD +
		        (10 - cdist) / 1.0f *
		            widef)); // less if lod worked better
		widef = 1.0f;
	};
	lod = MAX_LOD;
	lodtop = lodbot = lodleft = lodright = min_lod;
	if (yaw > 45 && yaw <= 135) {
		lodleft = lod;
		distlod(lodtop, lodbot, yaw - 45, widef);
351
352
353
354
355
356
357
358

	float hyfov = fov * h / w / 2;
	render_floor = pitch < hyfov;
	render_ceil = -pitch < hyfov;

	render_seg_new(
	    vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP);
	mipstats(stats[0], stats[1], stats[2]);
};








<
>
352
353
354
355
356
357
358

359
	float hyfov = fov * h / w / 2;
	render_floor = pitch < hyfov;
	render_ceil = -pitch < hyfov;

	render_seg_new(
	    vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP);
	mipstats(stats[0], stats[1], stats[2]);

}