29 #include "../idlib/precompiled.h"
33 #include "../sys/win32/win_local.h"
61 static int lightBufferSize = 1024;
62 static int maxLightBufferSize = 1024;
63 static float lightBufferSizeFraction = 0.5;
65 static int viewBufferSize = 1024;
66 static int viewBufferHeight = 768;
67 static int maxViewBufferSize = 1024;
68 static float viewBufferSizeFraction = 0.5;
69 static float viewBufferHeightFraction = 0.5;
70 static bool nativeViewBuffer =
false;
73 static HDC floatPbufferDC;
74 static idImage *floatPbufferImage;
77 static HDC floatPbuffer2DC;
78 static idImage *floatPbuffer2Image;
81 static HDC floatPbufferQuarterDC;
82 static idImage *floatPbufferQuarterImage;
84 static HGLRC floatContext;
87 static HDC shadowPbufferDC;
90 static HDC viewPbufferDC;
97 static idImage *viewShadowImage;
103 static idImage *random256Image;
105 static int shadowVertexProgram;
106 static int shadowFragmentProgram16;
107 static int shadowFragmentProgram4;
108 static int shadowFragmentProgram1;
109 static int shadowFragmentProgram0;
111 static int screenSpaceShadowVertexProgram;
112 static int screenSpaceShadowFragmentProgram16;
113 static int screenSpaceShadowFragmentProgram4;
114 static int screenSpaceShadowFragmentProgram1;
115 static int screenSpaceShadowFragmentProgram0;
117 static int depthMidpointVertexProgram;
118 static int depthMidpointFragmentProgram;
120 static int shadowResampleVertexProgram;
121 static int shadowResampleFragmentProgram;
123 static int gammaDitherVertexProgram;
124 static int gammaDitherFragmentProgram;
126 static int downSampleVertexProgram;
127 static int downSampleFragmentProgram;
129 static int bloomVertexProgram;
130 static int bloomFragmentProgram;
132 static float viewLightAxialSize;
163 static float unflippedLightMatrix[16];
166 static float lightMatrix[16];
169 static float lightProjectionMatrix[16];
180 {
"WGL_NUMBER_PIXEL_FORMATS_ARB", 0x2000 },
181 {
"WGL_DRAW_TO_WINDOW_ARB", 0x2001 },
182 {
"WGL_DRAW_TO_BITMAP_ARB", 0x2002 },
183 {
"WGL_ACCELERATION_ARB", 0x2003 },
184 {
"WGL_NEED_PALETTE_ARB", 0x2004 },
185 {
"WGL_NEED_SYSTEM_PALETTE_ARB", 0x2005 },
186 {
"WGL_SWAP_LAYER_BUFFERS_ARB", 0x2006 },
187 {
"WGL_SWAP_METHOD_ARB", 0x2007 },
188 {
"WGL_NUMBER_OVERLAYS_ARB", 0x2008 },
189 {
"WGL_NUMBER_UNDERLAYS_ARB", 0x2009 },
190 {
"WGL_TRANSPARENT_ARB", 0x200A },
191 {
"WGL_TRANSPARENT_RED_VALUE_ARB", 0x2037 },
192 {
"WGL_TRANSPARENT_GREEN_VALUE_ARB", 0x2038 },
193 {
"WGL_TRANSPARENT_BLUE_VALUE_ARB", 0x2039 },
194 {
"WGL_TRANSPARENT_ALPHA_VALUE_ARB", 0x203A },
195 {
"WGL_TRANSPARENT_INDEX_VALUE_ARB", 0x203B },
196 {
"WGL_SHARE_DEPTH_ARB", 0x200C },
197 {
"WGL_SHARE_STENCIL_ARB", 0x200D },
198 {
"WGL_SHARE_ACCUM_ARB", 0x200E },
199 {
"WGL_SUPPORT_GDI_ARB", 0x200F },
200 {
"WGL_SUPPORT_OPENGL_ARB", 0x2010 },
201 {
"WGL_DOUBLE_BUFFER_ARB", 0x2011 },
202 {
"WGL_STEREO_ARB", 0x2012 },
203 {
"WGL_PIXEL_TYPE_ARB", 0x2013 },
204 {
"WGL_COLOR_BITS_ARB", 0x2014 },
205 {
"WGL_RED_BITS_ARB", 0x2015 },
206 {
"WGL_RED_SHIFT_ARB", 0x2016 },
207 {
"WGL_GREEN_BITS_ARB", 0x2017 },
208 {
"WGL_GREEN_SHIFT_ARB", 0x2018 },
209 {
"WGL_BLUE_BITS_ARB", 0x2019 },
210 {
"WGL_BLUE_SHIFT_ARB", 0x201A },
211 {
"WGL_ALPHA_BITS_ARB", 0x201B },
212 {
"WGL_ALPHA_SHIFT_ARB", 0x201C },
213 {
"WGL_ACCUM_BITS_ARB", 0x201D },
214 {
"WGL_ACCUM_RED_BITS_ARB", 0x201E },
215 {
"WGL_ACCUM_GREEN_BITS_ARB", 0x201F },
216 {
"WGL_ACCUM_BLUE_BITS_ARB", 0x2020 },
217 {
"WGL_ACCUM_ALPHA_BITS_ARB", 0x2021 },
218 {
"WGL_DEPTH_BITS_ARB", 0x2022 },
219 {
"WGL_STENCIL_BITS_ARB", 0x2023 },
220 {
"WGL_AUX_BUFFERS_ARB", 0x2024 },
222 {
"WGL_NO_ACCELERATION_ARB", 0x2025 },
223 {
"WGL_GENERIC_ACCELERATION_ARB", 0x2026 },
224 {
"WGL_FULL_ACCELERATION_ARB", 0x2027 },
226 {
"WGL_SWAP_EXCHANGE_ARB", 0x2028 },
227 {
"WGL_SWAP_COPY_ARB", 0x2029 },
228 {
"WGL_SWAP_UNDEFINED_ARB", 0x202A },
230 {
"WGL_TYPE_RGBA_ARB", 0x202B },
231 {
"WGL_TYPE_COLORINDEX_ARB", 0x202C },
234 static const int NUM_WGL_STRINGS =
sizeof(
wglString ) /
sizeof( wglString[0] );
236 static void R_CheckWglErrors(
void ) {
237 int err = GetLastError();
242 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
245 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
253 case 13: name =
"ERROR_INVALID_DATA";
break;
254 case 6: name =
"ERROR_INVALID_HANDLE";
break;
255 case 4317: name =
"ERROR_INVALID_OPERATION";
break;
256 default: name =
va(
"code %i", err );
break;
269 if ( !qwglMakeCurrent( dc, context ) ) {
275 static void R_BindTexImage(
HPBUFFERARB pbuffer ) {
286 static void R_ReportTextureParms(
void ) {
299 static const int BLOOM_RADIUS = 8;
300 static void RB_CreateBloomTable(
void ) {
301 float bloom[BLOOM_RADIUS];
306 for (
int i = 0 ;
i < BLOOM_RADIUS ;
i++ ) {
308 bloom[
i] = exp( -0.5 * f * f );
312 total = ( total - bloom[0] ) * 2 + bloom[0];
315 for (
int i = 0 ;
i < BLOOM_RADIUS ;
i++ ) {
316 bloom[
i] *= 1.0 / total;
340 static void R_CreateShadowBufferImage(
idImage *
image ) {
343 memset( data, 0, lightBufferSize*lightBufferSize );
352 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, data );
360 color[0] = color[1] = color[2] = color[3] = 0;
368 static void R_CreateViewAlphaImage(
idImage *image ) {
369 int c = viewBufferSize*viewBufferSize*4;
373 for (
int i = 0 ;
i <
c ;
i++ ) {
376 memset( data, 0, viewBufferSize*viewBufferSize );
382 static void R_CreateStubImage(
idImage *image ) {
388 memset( data, 0,
sizeof( data ) );
398 const static int JITTER_SIZE = 128;
399 static void R_CreateJitterImage16(
idImage *image ) {
400 byte data[JITTER_SIZE][JITTER_SIZE*16][4];
402 for (
int i = 0 ;
i < JITTER_SIZE ;
i++ ) {
403 for (
int s = 0 ;
s < 16 ;
s++ ) {
404 int sOfs = 64 * (
s & 3 );
405 int tOfs = 64 * ( (
s >> 2 ) & 3 );
407 for (
int j = 0 ;
j < JITTER_SIZE ;
j++ ) {
408 data[
i][
s*JITTER_SIZE+
j][0] = (rand() & 63 ) | sOfs;
409 data[
i][
s*JITTER_SIZE+
j][1] = (rand() & 63 ) | tOfs;
410 data[
i][
s*JITTER_SIZE+
j][2] = rand();
411 data[
i][
s*JITTER_SIZE+
j][3] = 0;
420 static void R_CreateJitterImage4(
idImage *image ) {
421 byte data[JITTER_SIZE][JITTER_SIZE*4][4];
423 for (
int i = 0 ;
i < JITTER_SIZE ;
i++ ) {
424 for (
int s = 0 ;
s < 4 ;
s++ ) {
425 int sOfs = 128 * (
s & 1 );
426 int tOfs = 128 * ( (
s >> 1 ) & 1 );
428 for (
int j = 0 ;
j < JITTER_SIZE ;
j++ ) {
429 data[
i][
s*JITTER_SIZE+
j][0] = (rand() & 127 ) | sOfs;
430 data[
i][
s*JITTER_SIZE+
j][1] = (rand() & 127 ) | tOfs;
431 data[
i][
s*JITTER_SIZE+
j][2] = rand();
432 data[
i][
s*JITTER_SIZE+
j][3] = 0;
441 static void R_CreateJitterImage1(
idImage *image ) {
442 byte data[JITTER_SIZE][JITTER_SIZE][4];
444 for (
int i = 0 ;
i < JITTER_SIZE ;
i++ ) {
445 for (
int j = 0 ;
j < JITTER_SIZE ;
j++ ) {
446 data[
i][
j][0] = rand();
447 data[
i][
j][1] = rand();
448 data[
i][
j][2] = rand();
457 static void R_CreateRandom256Image(
idImage *image ) {
458 byte data[256][256][4];
460 for (
int i = 0 ;
i < 256 ;
i++ ) {
461 for (
int j = 0 ;
j < 256 ;
j++ ) {
462 data[
i][
j][0] = rand();
463 data[
i][
j][1] = rand();
464 data[
i][
j][2] = rand();
465 data[
i][
j][3] = rand();
484 common->
Printf(
"----- pixelFormat %i -----\n", pixelFormat );
486 for (
int i = 1 ;
i < NUM_WGL_STRINGS ;
i++ ) {
487 iAttribute = wglString[
i].
num;
489 if ( res && iValue ) {
503 int iAttributes[NUM_WGL_STRINGS*2], *atr_p;
504 FLOAT fAttributes[] = {0, 0};
506 int pixelformats[1024];
508 int pbiAttributes[] = {0, 0};
534 sizeof( pixelformats ) /
sizeof( pixelformats[0] ), pixelformats, &numFormats );
537 for (
int i = 0 ;
i < (
int)numFormats ;
i++ ) {
545 int pbiAttributesTexture[] = {
552 if ( !floatPbuffer ) {
562 if ( !floatPbuffer2 ) {
572 if ( !floatPbufferQuarter ) {
580 floatContext = wglCreateContext( floatPbufferDC );
581 if ( !floatContext ) {
582 common->
Printf(
"failed to create context for floatPbufferDC.\n" );
586 if ( !wglShareLists( floatContext,
win32.
hGLRC ) ) {
621 sizeof( pixelformats ) /
sizeof( pixelformats[0] ), pixelformats, &numFormats );
623 for (
int i = 0 ;
i < (
int)numFormats ;
i++ ) {
634 lightBufferSize = maxLightBufferSize;
638 lightBufferSize, pbiAttributes );
650 lightBufferSize = maxViewBufferSize;
654 maxViewBufferSize, pbiAttributes );
706 static const int CULL_RECEIVER = 1;
707 static const int CULL_OCCLUDER_AND_RECEIVER = 2;
722 if ( inter->numSurfaces < 1 ) {
732 for ( plane = 0 ; plane < 6 ; plane++ ) {
739 for (
int i = 0 ;
i < 8 ;
i++ ) {
745 for ( plane = 0 ; plane < 6 ; plane++ ) {
747 for ( j = 0 ; j < 8 ; j++ ) {
750 if ( corners[j] * localPlanes[plane].ToVec4().ToVec3() + localPlanes[plane][3] < 0 ) {
759 culled = CULL_OCCLUDER_AND_RECEIVER;
763 for (
int i = 0 ;
i < inter->numSurfaces ;
i++ ) {
786 if ( inter->numSurfaces < 1 ) {
793 myGlMultMatrix( inter->entityDef->modelMatrix, lightMatrix, matrix );
797 for (
int i = 0 ;
i < inter->numSurfaces ;
i++ ) {
808 if ( surfInt->
expCulled == CULL_OCCLUDER_AND_RECEIVER ) {
834 float xmin, xmax, ymin, ymax;
852 height = ymax - ymin;
854 lightProjectionMatrix[0] = 2 * zNear /
width;
855 lightProjectionMatrix[4] = 0;
856 lightProjectionMatrix[8] = 0;
857 lightProjectionMatrix[12] = 0;
859 lightProjectionMatrix[1] = 0;
860 lightProjectionMatrix[5] = 2 * zNear /
height;
861 lightProjectionMatrix[9] = 0;
862 lightProjectionMatrix[13] = 0;
867 lightProjectionMatrix[2] = 0;
868 lightProjectionMatrix[6] = 0;
869 lightProjectionMatrix[10] = -0.999f;
870 lightProjectionMatrix[14] = -2.0f *
zNear;
872 lightProjectionMatrix[3] = 0;
873 lightProjectionMatrix[7] = 0;
874 lightProjectionMatrix[11] = -1;
875 lightProjectionMatrix[15] = 0;
887 qglViewport( 0, 0, lightBufferSize, lightBufferSize );
888 qglScissor( 0, 0, lightBufferSize, lightBufferSize );
893 qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
902 static float s_flipMatrix[16] = {
911 float viewMatrix[16];
920 viewMatrix[0] = vec[0];
921 viewMatrix[4] = vec[1];
922 viewMatrix[8] = vec[2];
926 viewMatrix[1] = -vec[0];
927 viewMatrix[5] = -vec[1];
928 viewMatrix[9] = -vec[2];
932 viewMatrix[2] = vec[0];
933 viewMatrix[6] = vec[1];
934 viewMatrix[10] = vec[2];
937 memset( viewMatrix, 0,
sizeof( viewMatrix ) );
972 viewMatrix[12] = -origin[0] * viewMatrix[0] + -origin[1] * viewMatrix[4] + -origin[2] * viewMatrix[8];
973 viewMatrix[13] = -origin[0] * viewMatrix[1] + -origin[1] * viewMatrix[5] + -origin[2] * viewMatrix[9];
974 viewMatrix[14] = -origin[0] * viewMatrix[2] + -origin[1] * viewMatrix[6] + -origin[2] * viewMatrix[10];
981 memcpy( unflippedLightMatrix, viewMatrix,
sizeof( unflippedLightMatrix ) );
988 globalFrustum[0][0] = -viewMatrix[0];
989 globalFrustum[0][1] = -viewMatrix[4];
990 globalFrustum[0][2] = -viewMatrix[8];
991 globalFrustum[0][3] = -(origin[0] * globalFrustum[0][0] + origin[1] * globalFrustum[0][1] + origin[2] * globalFrustum[0][2]);
994 globalFrustum[1][0] = viewMatrix[0];
995 globalFrustum[1][1] = viewMatrix[4];
996 globalFrustum[1][2] = viewMatrix[8];
997 globalFrustum[1][3] = -globalFrustum[0][3] - viewLightAxialSize;
1000 globalFrustum[2][0] = -viewMatrix[0] + viewMatrix[1];
1001 globalFrustum[2][1] = -viewMatrix[4] + viewMatrix[5];
1002 globalFrustum[2][2] = -viewMatrix[8] + viewMatrix[9];
1004 globalFrustum[3][0] = -viewMatrix[0] - viewMatrix[1];
1005 globalFrustum[3][1] = -viewMatrix[4] - viewMatrix[5];
1006 globalFrustum[3][2] = -viewMatrix[8] - viewMatrix[9];
1008 globalFrustum[4][0] = -viewMatrix[0] + viewMatrix[2];
1009 globalFrustum[4][1] = -viewMatrix[4] + viewMatrix[6];
1010 globalFrustum[4][2] = -viewMatrix[8] + viewMatrix[10];
1012 globalFrustum[5][0] = -viewMatrix[0] - viewMatrix[2];
1013 globalFrustum[5][1] = -viewMatrix[4] - viewMatrix[6];
1014 globalFrustum[5][2] = -viewMatrix[8] - viewMatrix[10];
1017 for (
int i = 0 ;
i < 6 ;
i++ ) {
1021 for (
int i = 2 ;
i < 6 ;
i++ ) {
1022 globalFrustum[
i][3] = - (origin * globalFrustum[
i].
ToVec4().
ToVec3() );
1052 shadowImage[2]->
Bind();
1056 shadowImage[1]->
Bind();
1066 shadowImage[1]->
Bind();
1072 shadowImage[2]->
Bind();
1091 qglTexCoord2f( lightBufferSizeFraction, lightBufferSizeFraction );
1105 shadowImage[0]->
Bind();
1153 sRow[0] = 0.5 * lightBufferSizeFraction * ( matrix2[0] + matrix2[3] );
1154 sRow[1] = 0.5 * lightBufferSizeFraction * ( matrix2[4] + matrix2[7] );
1155 sRow[2] = 0.5 * lightBufferSizeFraction * ( matrix2[8] + matrix2[11] );
1156 sRow[3] = 0.5 * lightBufferSizeFraction * ( matrix2[12] + matrix2[15] );
1158 tRow[0] = 0.5 * lightBufferSizeFraction * ( matrix2[1] + matrix2[3] );
1159 tRow[1] = 0.5 * lightBufferSizeFraction * ( matrix2[5] + matrix2[7] );
1160 tRow[2] = 0.5 * lightBufferSizeFraction * ( matrix2[9] + matrix2[11] );
1161 tRow[3] = 0.5 * lightBufferSizeFraction * ( matrix2[13] + matrix2[15] );
1163 rRow[0] = 0.5 * ( matrix2[2] + matrix2[3] );
1164 rRow[1] = 0.5 * ( matrix2[6] + matrix2[7] );
1165 rRow[2] = 0.5 * ( matrix2[10] + matrix2[11] );
1166 rRow[3] = 0.5 * ( matrix2[14] + matrix2[15] );
1168 qRow[0] = matrix2[3];
1169 qRow[1] = matrix2[7];
1170 qRow[2] = matrix2[11];
1171 qRow[3] = matrix2[15];
1181 static const float zero[4] = { 0, 0, 0, 0 };
1182 static const float one[4] = { 1, 1, 1, 1 };
1183 static const float negOne[4] = { -1, -1, -1, -1 };
1209 parm[1] = 1.0 / JITTER_SIZE;
1223 parm[0] = (rand()&255) / 255.0;
1224 parm[1] = (rand()&255) / 255.0;
1226 parm[0] = parm[1] = 0;
1418 r[12] = -(r[ 0]*a[12] + r[ 4]*a[13] + r[ 8]*a[14]);
1419 r[13] = -(r[ 1]*a[12] + r[ 5]*a[13] + r[ 9]*a[14]);
1420 r[14] = -(r[ 2]*a[12] + r[ 6]*a[13] + r[10]*a[14]);
1427 for (
int i = 0 ;
i < 4 ;
i++ ) {
1428 for (
int j = 0 ;
j < 4 ;
j++ ) {
1429 am[
i][
j] = a[
j*4+
i];
1442 for (
int i = 0 ;
i < 4 ;
i++ ) {
1443 for (
int j = 0 ;
j < 4 ;
j++ ) {
1444 r[
j*4+
i] = am[
i][
j];
1459 static glIndex_t indexes[18] = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1, 2, 1, 4, 2, 4, 3 };
1464 memset( verts, 0,
sizeof( verts ) );
1466 for (
int i = 0 ;
i < 5 ;
i++ ) {
1470 memset( &frustumTri, 0,
sizeof( frustumTri ) );
1472 frustumTri.
verts = verts;
1478 float size = viewLightAxialSize;
1649 shadowImage[0]->
Bind();
1653 jitterImage16->
Bind();
1655 jitterImage4->
Bind();
1657 jitterImage1->
Bind();
1661 viewDepthImage->
Bind();
1683 float invertedView[16];
1684 float invertedProjection[16];
1712 sRow[0] = 0.5 * ( matrix2[0] + matrix2[3] ) * lightBufferSizeFraction;
1713 sRow[1] = 0.5 * ( matrix2[4] + matrix2[7] ) * lightBufferSizeFraction;
1714 sRow[2] = 0.5 * ( matrix2[8] + matrix2[11] ) * lightBufferSizeFraction;
1715 sRow[3] = 0.5 * ( matrix2[12] + matrix2[15] ) * lightBufferSizeFraction;
1717 tRow[0] = 0.5 * ( matrix2[1] + matrix2[3] ) * lightBufferSizeFraction;
1718 tRow[1] = 0.5 * ( matrix2[5] + matrix2[7] ) * lightBufferSizeFraction;
1719 tRow[2] = 0.5 * ( matrix2[9] + matrix2[11] ) * lightBufferSizeFraction;
1720 tRow[3] = 0.5 * ( matrix2[13] + matrix2[15] ) * lightBufferSizeFraction;
1722 rRow[0] = 0.5 * ( matrix2[2] + matrix2[3] );
1723 rRow[1] = 0.5 * ( matrix2[6] + matrix2[7] );
1724 rRow[2] = 0.5 * ( matrix2[10] + matrix2[11] );
1725 rRow[3] = 0.5 * ( matrix2[14] + matrix2[15] );
1727 qRow[0] = matrix2[3];
1728 qRow[1] = matrix2[7];
1729 qRow[2] = matrix2[11];
1730 qRow[3] = matrix2[15];
1737 int w = viewBufferSize;
1739 parm[0] = 1.0 / maxViewBufferSize;
1740 int h = viewBufferHeight;
1757 parm[2] = 2.0/viewBufferSize;
1758 parm[3] = 2.0/viewBufferSize;
1763 parm[1] = 1.0 / JITTER_SIZE;
1777 parm[0] = (rand()&255) / 255.0;
1778 parm[1] = (rand()&255) / 255.0;
1780 parm[0] = parm[1] = 0;
1828 for (
int i = 0 ;
i < 3 ;
i++ ) {
1860 RB_LogComment(
"---------- R_EXP_RenderViewDepthImage ----------\n" );
1869 qglViewport( 0, 0, viewBufferSize, viewBufferHeight );
1870 qglScissor( 0, 0, viewBufferSize, viewBufferHeight );
1885 viewDepthImage->
Bind();
1951 R_MakeCurrent( floatPbufferDC, floatContext, floatPbuffer );
1984 viewAlphaImage->
Bind();
2042 parm[0] = 1.0 / (maxViewBufferSize+1) * viewBufferSize / maxViewBufferSize;
2100 float *buf = (
float *)
R_StaticAlloc( pixels * 4 *
sizeof(
float ) );
2104 float mins[4] = { 9999, 9999, 9999, 9999 };
2105 float maxs[4] = { -9999, -9999, -9999, -9999 };
2107 for (
int j = 0 ;
j < 4 ;
j++ ) {
2108 float v = buf[
i*4 +
j ];
2109 if ( v < mins[
j] ) {
2112 if ( v > maxs[j] ) {
2181 R_BindTexImage( floatPbufferQuarter );
2188 R_BindTexImage( floatPbuffer );
2210 parm[0] = 1.0 / 256;
2212 parm[2] = rand()/65535.0;
2213 parm[3] = rand()/65535.0;
2261 R_MakeCurrent( floatPbuffer2DC, floatContext, floatPbuffer2 );
2277 R_BindTexImage( floatPbuffer );
2290 R_MakeCurrent( floatPbufferQuarterDC, floatContext, floatPbufferQuarter );
2294 R_BindTexImage( floatPbuffer2 );
2309 R_MakeCurrent( floatPbuffer2DC, floatContext, floatPbuffer2 );
2320 R_BindTexImage( floatPbufferQuarter );
2335 R_MakeCurrent( floatPbufferQuarterDC, floatContext, floatPbufferQuarter );
2338 R_BindTexImage( floatPbuffer2 );
2385 lightBufferSizeFraction = (
float)lightBufferSize / maxLightBufferSize;
2394 viewBufferHeight = viewBufferSize * 3 / 4;
2395 viewBufferSizeFraction = (
float)viewBufferSize / maxViewBufferSize;
2396 viewBufferHeightFraction = (
float)viewBufferHeight / maxViewBufferSize;
2398 nativeViewBuffer =
true;
2400 nativeViewBuffer =
false;
2442 qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
2455 const idMaterial *lightShader = vLight->lightShader;
2465 if ( !vLight->localInteractions && !vLight->globalInteractions
2466 && !vLight->translucentInteractions ) {
2470 if ( !vLight->frustumTris->ambientCache ) {
2480 if ( vLight->lightDef->parms.pointLight ) {
2493 for ( ; side < sideStop ; side++ ) {
2508 R_MakeCurrent( viewPbufferDC,
win32.
hGLRC, viewPbuffer );
2510 qglViewport( 0, 0, viewBufferSize, viewBufferHeight );
2511 qglScissor( 0, 0, viewBufferSize, viewBufferHeight );
2532 if ( !nativeViewBuffer ) {
2555 for (
int i = 7 ;
i >= 0 ;
i-- ) {
2565 for (
int i = 0 ;
i < 8 ;
i++ ) {
2586 common->
Printf(
"---------- R_Exp_Init ----------\n" );
2592 RB_CreateBloomTable();
2615 common->
Printf(
"--------------------------------------------\n" );
idImage * specular2DTableImage
bool SurfaceCastsShadow(void) const
#define WGL_FRONT_LEFT_ARB
const int GLS_DSTBLEND_ONE
PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB
const idMaterial * shader
idImage * GetEditorImage(void) const
#define qglTexCoordPointer
void RB_EXP_CreateDrawInteractions(const drawSurf_t *surf)
#define GL_TEXTURE_COMPARE_FUNC_ARB
const srfTriangles_t * geo
const int GLS_DEPTHFUNC_LESS
#define GL_COMPARE_R_TO_TEXTURE
#define WGL_ALPHA_BITS_ARB
void RB_Exp_SelectFrustum(viewLight_t *vLight, int side)
void GL_SelectTextureNoClient(int unit)
idCVar r_sb_viewResolution("r_sb_viewResolution","1024", CVAR_RENDERER|CVAR_INTEGER,"Width of screen space shadow sampling")
PFNGLVERTEXATTRIBPOINTERARBPROC qglVertexAttribPointerARB
void RB_shadowResampleAlpha(void)
#define qglEnableClientState
#define qglDisableClientState
void GenerateImage(const byte *pic, int width, int height, textureFilter_t filter, bool allowDownSize, textureRepeat_t repeat, textureDepth_t depth)
GLdouble GLdouble GLdouble GLdouble zNear
void GL_CheckErrors(void)
stageVertexColor_t vertexColor
idInteraction * lightNext
CONST PIXELFORMATDESCRIPTOR UINT
float GetFloat(void) const
void RB_RenderShadowBuffer(viewLight_t *vLight, int side)
idCVar r_testARBProgram("r_testARBProgram","0", CVAR_RENDERER|CVAR_BOOL,"experiment with vertex/fragment programs")
void RB_EXP_SetRenderBuffer(viewLight_t *vLight)
const float * ToFloatPtr(void) const
bool R_CheckExtension(char *name)
#define GL_TEXTURE_BINDING_RECTANGLE_NV
idCVar r_hdr_monitorDither("r_hdr_monitorDither","0.01", CVAR_RENDERER|CVAR_FLOAT,"random dither in monitor space")
idImage * fragmentProgramImages[MAX_FRAGMENT_IMAGES]
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC qglDisableVertexAttribArrayARB
idCVar r_sb_singleSide("r_sb_singleSide","-1", CVAR_RENDERER|CVAR_INTEGER,"only draw a single side (0-5) of point lights")
void R_EXP_RenderViewDepthImage(void)
idCVar r_sb_samples("r_sb_samples","4", CVAR_RENDERER|CVAR_INTEGER,"0, 1, 4, or 16")
void R_Exp_Allocate(void)
#define WGL_TEXTURE_FORMAT_ARB
const idVec4 & ToVec4(void) const
GLExtension_t GLimp_ExtensionPointer(const char *name)
void RB_EXP_CoverScreen(void)
idCVar r_renderer("r_renderer","best", CVAR_RENDERER|CVAR_ARCHIVE,"hardware specific renderer path to use", r_rendererArgs, idCmdSystem::ArgCompletion_String< r_rendererArgs >)
GLenum GLsizei GLenum GLenum const GLvoid * image
#define GL_FLOAT_RGBA16_NV
#define WGL_DRAW_TO_PBUFFER_ARB
const int GLS_DEPTHFUNC_ALWAYS
idCVar r_sb_frustomFOV("r_sb_frustomFOV","92", CVAR_RENDERER|CVAR_FLOAT,"oversize FOV for point light side matching")
bool IsBlendLight() const
idRenderLightLocal * lightDef
#define WGL_STENCIL_BITS_ARB
#define WGL_BLUE_BITS_ARB
const struct viewEntity_s * space
struct vertCache_s * ambientCache
idCVar r_hdr_exposure("r_hdr_exposure","1.0", CVAR_RENDERER|CVAR_FLOAT,"maximum light scale")
float projectionMatrix[16]
void RB_EXP_GammaDither(void)
bool IsAmbientLight() const
const viewEntity_t * currentSpace
void RB_EXP_CullInteractions(viewLight_t *vLight, idPlane frustumPlanes[6])
int Icmp(const char *text) const
const idMaterial * lightShader
void RB_Exp_DrawInteractions(void)
void GL_Cull(int cullType)
void RB_BeginDrawingView(void)
#define WGL_FLOAT_COMPONENTS_NV
idCVar r_ignore("r_ignore","0", CVAR_RENDERER,"used for random debugging without defining new vars")
bool LightCastsShadows() const
const int GLS_DEPTHFUNC_EQUAL
void RB_CreateSingleDrawInteractions(const drawSurf_t *surf, void(*DrawInteraction)(const drawInteraction_t *))
PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB
struct viewLight_s * next
void RB_RenderDrawSurfListWithFunction(drawSurf_t **drawSurfs, int numDrawSurfs, void(*triFunc_)(const drawSurf_t *))
struct viewLight_s * viewLights
const srfTriangles_t * RB_Exp_TrianglesForFrustum(viewLight_t *vLight, int side)
idCVar r_hdr_useFloats("r_hdr_useFloats","0", CVAR_RENDERER|CVAR_BOOL,"use a floating point rendering buffer")
#define WGL_DEPTH_BITS_ARB
idCVar r_sb_showFrustumPixels("r_sb_showFrustumPixels","0", CVAR_RENDERER|CVAR_BOOL,"color the pixels contained in the frustum")
GLubyte GLubyte GLubyte GLubyte w
idCVar r_sb_randomize("r_sb_randomize","1", CVAR_RENDERER|CVAR_BOOL,"randomly offset jitter texture each draw")
idCVar r_sb_noShadows("r_sb_noShadows","0", CVAR_RENDERER|CVAR_BOOL,"don't draw any occluders")
idImage * normalCubeMapImage
const shaderStage_t * GetStage(const int index) const
PFNGLENABLEVERTEXATTRIBARRAYARBPROC qglEnableVertexAttribArrayARB
idCVar r_sb_usePbuffer("r_sb_usePbuffer","1", CVAR_RENDERER|CVAR_BOOL,"draw offscreen")
PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB
newShaderStage_t * newStage
#define WGL_TEXTURE_TARGET_ARB
idCVar r_hdr_bloomFraction("r_hdr_bloomFraction","0.1", CVAR_RENDERER|CVAR_FLOAT,"fraction to smear across neighbors")
idImage * lightFalloffImage
idCVar r_sb_polyOfsFactor("r_sb_polyOfsFactor","2", CVAR_RENDERER|CVAR_FLOAT,"polygonOffset factor for drawing shadow buffer")
void RB_ARB2_DrawInteraction(const drawInteraction_t *din)
PFNGLBINDPROGRAMARBPROC qglBindProgramARB
void SetInteger(const int value)
GLsizei GLsizei GLenum GLenum const GLvoid * data
idInteraction * firstInteraction
int GetInteger(void) const
const int GLS_SRCBLEND_ONE
idImageManager * globalImages
bool ARBVertexProgramAvailable
virtual void virtual void FatalError(const char *fmt,...) id_attribute((format(printf
#define GL_TEXTURE_COMPARE_MODE_ARB
void RB_EXP_SetNativeBuffer(void)
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB
void RB_SetDefaultGLState(void)
#define GL_DEPTH_COMPONENT24_ARB
idImage * ImageFromFunction(const char *name, void(*generatorFunction)(idImage *image))
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
idCVar r_sb_polyOfsUnits("r_sb_polyOfsUnits","3000", CVAR_RENDERER|CVAR_FLOAT,"polygonOffset units for drawing shadow buffer")
void RB_DrawElementsWithCounters(const srfTriangles_t *tri)
const float * ToFloatPtr(void) const
void RB_T_FillDepthBuffer(const drawSurf_t *surf)
const int GLS_SRCBLEND_DST_ALPHA
vertCache_t * AllocFrameTemp(void *data, int bytes)
GLenum GLsizei GLsizei height
const int GLS_DSTBLEND_ZERO
void myGlMultMatrix(const float *a, const float *b, float *out)
idCVar r_testGamma("r_testGamma","0", CVAR_RENDERER|CVAR_FLOAT,"if > 0 draw a grid pattern to test gamma levels", 0, 195)
void InvertByTranspose(const float a[16], float r[16])
const char * GetString(void) const
idCVar r_sb_lightResolution("r_sb_lightResolution","1024", CVAR_RENDERER|CVAR_INTEGER,"Pixel dimensions for each shadow buffer, 64 - 2048")
void RB_LogComment(const char *comment,...)
GLdouble GLdouble GLdouble r
#define WGL_TEXTURE_RECTANGLE_NV
static WindowRef ValidModeCallbackProc inCallback OSStatus err
#define qglCopyTexSubImage2D
idCVar r_sb_occluderFacing("r_sb_occluderFacing","0", CVAR_RENDERER|CVAR_INTEGER,"0 = front faces, 1 = back faces, 2 = midway between")
PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB
idVec4 lightProjection[4]
const float * ToFloatPtr(void) const
void * R_StaticAlloc(int bytes)
void RB_STD_FillDepthBuffer(drawSurf_t **drawSurfs, int numDrawSurfs)
void * Position(vertCache_t *buffer)
void RB_EXP_ReadFloatBuffer(void)
void R_PrintPixelFormat(int pixelFormat)
const struct drawSurf_s * nextOnLight
#define GL_VERTEX_PROGRAM_ARB
bool R_CreateAmbientCache(srfTriangles_t *tri, bool needsLighting)
srfTriangles_t * ambientTris
idCVar r_hdr_gamma("r_hdr_gamma","1", CVAR_RENDERER|CVAR_FLOAT,"monitor gamma power")
float modelViewMatrix[16]
PFNGLPROGRAMENVPARAMETER4FVARBPROC qglProgramEnvParameter4fvARB
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC qglProgramLocalParameter4fvARB
typedef LPVOID(WINAPI *PFNWGLCREATEIMAGEBUFFERI3DPROC)(HDC hDC
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
idCVar r_sb_screenSpaceShadow("r_sb_screenSpaceShadow","1", CVAR_RENDERER|CVAR_BOOL,"build shadows in screen space instead of on surfaces")
idVertexCache vertexCache
void SetBool(const bool value)
const idVec3 & ToVec3(void) const
idCVar r_sb_useCulling("r_sb_useCulling","1", CVAR_RENDERER|CVAR_BOOL,"cull geometry to individual side frustums")
void GL_State(int stateBits)
float R_EXP_CalcLightAxialSize(viewLight_t *vLight)
void * Mem_Alloc(const int size)
#define WGL_GREEN_BITS_ARB
idCVar r_useScissor("r_useScissor","1", CVAR_RENDERER|CVAR_BOOL,"scissor clip as portals and lights are processed")
#define qglTexParameterfv
char * va(const char *fmt,...)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
const srfTriangles_t * frustumTris
void GL_SelectTexture(int unit)
void R_StaticFree(void *data)
idImage * specularTableImage
#define WGL_TEXTURE_FLOAT_RGBA_NV
virtual void Error(const char *fmt,...) id_attribute((format(printf
#define GL_TEXTURE_RECTANGLE_NV
int MakePowerOfTwo(int num)
idScreenRect currentScissor
bool ARBFragmentProgramAvailable
void CopyDepthbuffer(int x, int y, int width, int height)
idCVar r_sb_biasScale("r_sb_biasScale","0.0001", CVAR_RENDERER|CVAR_FLOAT,"scale factor for jitter bias")
typedef HPBUFFERARB(WINAPI *PFNWGLCREATEPBUFFERARBPROC)(HDC hDC
idCVar r_sb_linearFilter("r_sb_linearFilter","1", CVAR_RENDERER|CVAR_BOOL,"use GL_LINEAR instead of GL_NEAREST on shadow maps")
int R_FindARBProgram(GLenum target, const char *program)
void FullInvert(const float a[16], float r[16])
void R_GlobalPlaneToLocal(const float modelMatrix[16], const idPlane &in, idPlane &out)
idCVar r_sb_jitterScale("r_sb_jitterScale","0.006", CVAR_RENDERER|CVAR_FLOAT,"scale factor for jitter offset")
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
void RB_EXP_RenderOccluders(viewLight_t *vLight)
GLenum const GLfloat * params
void RB_EXP_DrawInteraction(const drawInteraction_t *din)
tmu_t tmu[MAX_MULTITEXTURE_UNITS]
#define GL_FRAGMENT_PROGRAM_ARB
const viewDef_t * viewDef