1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
|
/*
Copyright (C) 2009 COR Entertainment, LLC
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// r_program.c
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "r_local.h"
//ARB fragment program extensions
PFNGLGENPROGRAMSARBPROC qglGenProgramsARB = NULL;
PFNGLDELETEPROGRAMSARBPROC qglDeleteProgramsARB = NULL;
PFNGLBINDPROGRAMARBPROC qglBindProgramARB = NULL;
PFNGLPROGRAMSTRINGARBPROC qglProgramStringARB = NULL;
PFNGLPROGRAMENVPARAMETER4FARBPROC qglProgramEnvParameter4fARB = NULL;
PFNGLPROGRAMLOCALPARAMETER4FARBPROC qglProgramLocalParameter4fARB = NULL;
unsigned int g_water_program_id;
char *fragment_program_text;
//GLSL
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL;
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL;
PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
PFNGLUNIFORM3FARBPROC glUniform3fARB = NULL;
PFNGLUNIFORM2FARBPROC glUniform2fARB = NULL;
PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL;
PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB = NULL;
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB = NULL;
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB = NULL;
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB = NULL;
PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB = NULL;
GLhandleARB g_programObj;
GLhandleARB g_waterprogramObj;
GLhandleARB g_meshprogramObj;
GLhandleARB g_fbprogramObj;
GLhandleARB g_blurprogramObj;
GLhandleARB g_rblurprogramObj;
GLhandleARB g_vertexShader;
GLhandleARB g_fragmentShader;
//standard bsp
GLuint g_location_surfTexture;
GLuint g_location_eyePos;
GLuint g_tangentSpaceTransform;
GLuint g_location_heightTexture;
GLuint g_location_lmTexture;
GLuint g_location_normalTexture;
GLuint g_location_bspShadowmapTexture;
GLuint g_location_bspShadowmapTexture2;
GLuint g_location_fog;
GLuint g_location_parallax;
GLuint g_location_dynamic;
GLuint g_location_shadowmap;
GLuint g_Location_statshadow;
GLuint g_location_lightPosition;
GLuint g_location_staticLightPosition;
GLuint g_location_lightColour;
GLuint g_location_lightCutoffSquared;
//water
GLuint g_location_baseTexture;
GLuint g_location_normTexture;
GLuint g_location_refTexture;
GLuint g_location_tangent;
GLuint g_location_time;
GLuint g_location_lightPos;
GLuint g_location_reflect;
GLuint g_location_trans;
GLuint g_location_fogamount;
//mesh
GLuint g_location_meshlightPosition;
GLuint g_location_baseTex;
GLuint g_location_normTex;
GLuint g_location_fxTex;
GLuint g_location_color;
GLuint g_location_minLight;
GLuint g_location_meshNormal;
GLuint g_location_meshTime;
GLuint g_location_meshFog;
GLuint g_location_useFX;
GLuint g_location_useGlow;
//fullscreen distortion effects
GLuint g_location_framebuffTex;
GLuint g_location_distortTex;
GLuint g_location_dParams;
GLuint g_location_fxPos;
//gaussian blur
GLuint g_location_scale;
GLuint g_location_source;
//radial blur
GLuint g_location_rscale;
GLuint g_location_rsource;
GLuint g_location_rparams;
static char water_ARB_program[] =
"!!ARBfp1.0\n"
"# Scroll and scale the distortion texture coordinates.\n"
"# Scroll coordinates are specified externally.\n"
"PARAM scroll1 = program.local[0];\n"
"PARAM scroll2 = program.local[1];\n"
"PARAM texScale1 = { 0.008, 0.008, 1.0, 1.0 };\n"
"PARAM texScale2 = { 0.007, 0.007, 1.0, 1.0 };\n"
"TEMP texCoord1;\n"
"TEMP texCoord2;\n"
"MUL texCoord1, fragment.texcoord[1], texScale1;\n"
"MUL texCoord2, fragment.texcoord[1], texScale2;\n"
"ADD texCoord1, texCoord1, scroll1;\n"
"ADD texCoord2, texCoord2, scroll2;\n"
"# Load the distortion textures and add them together.\n"
"TEMP distortColor;\n"
"TEMP distortColor2;\n"
"TXP distortColor, texCoord1, texture[0], 2D;\n"
"TXP distortColor2, texCoord2, texture[0], 2D;\n"
"ADD distortColor, distortColor, distortColor2;\n"
"# Subtract 1.0 and scale by 2.0.\n"
"# Textures will be distorted from -2.0 to 2.0 texels.\n"
"PARAM scaleFactor = { 2.0, 2.0, 2.0, 2.0 };\n"
"PARAM one = { 1.0, 1.0, 1.0, 1.0 };\n"
"SUB distortColor, distortColor, one;\n"
"MUL distortColor, distortColor, scaleFactor;\n"
"# Apply distortion to reflection texture coordinates.\n"
"TEMP distortCoord;\n"
"TEMP endColor;\n"
"ADD distortCoord, distortColor, fragment.texcoord[0];\n"
"TXP endColor, distortCoord, texture, 2D;\n"
"# Get a vector from the surface to the view origin\n"
"PARAM vieworg = program.local[2];\n"
"TEMP eyeVec;\n"
"TEMP trans;\n"
"SUB eyeVec, vieworg, fragment.texcoord[1];\n"
"# Normalize the vector to the eye position\n"
"TEMP temp;\n"
"TEMP invLen;\n"
"DP3 temp, eyeVec, eyeVec;\n"
"RSQ invLen, temp.x;\n"
"MUL eyeVec, eyeVec, invLen;\n"
"ABS eyeVec.z, eyeVec.z; # so it works underwater, too\n"
"# Load the ripple normal map\n"
"TEMP normalColor;\n"
"TEMP normalColor2;\n"
"# Scale texture\n"
"MUL texCoord1, fragment.texcoord[2], texScale2;\n"
"MUL texCoord2, fragment.texcoord[2], texScale1;\n"
"# Scroll texture\n"
"ADD texCoord1, texCoord1, scroll1;\n"
"ADD texCoord2, texCoord2, scroll2;\n"
"# Get texel color\n"
"TXP normalColor, texCoord1, texture[1], 2D;\n"
"TXP normalColor2, texCoord2, texture[1], 2D;\n"
"# Combine normal maps\n"
"ADD normalColor, normalColor, normalColor2;\n"
"SUB normalColor, normalColor, 1.0;\n"
"# Normalize normal texture\n"
"DP3 temp, normalColor, normalColor;\n"
"RSQ invLen, temp.x;\n"
"MUL normalColor, invLen, normalColor;\n"
"# Fresenel approximation\n"
"DP3 trans.w, normalColor, eyeVec;\n"
"SUB endColor.w, 1.0, trans.w;\n"
"MAX endColor.w, endColor.w, 0.4; # MAX sets the min? How odd.\n"
"MIN endColor.w, endColor.w, 0.9; # Leave a LITTLE bit of transparency always\n"
"# Put the color in the output (TODO: put this in final OP)\n"
"MOV result.color, endColor;\n"
"END\n";
void R_LoadARBPrograms(void)
{
if (strstr(gl_config.extensions_string, "GL_ARB_fragment_program"))
{
gl_state.fragment_program = true;
qglGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)qwglGetProcAddress("glGenProgramsARB");
qglDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)qwglGetProcAddress("glDeleteProgramsARB");
qglBindProgramARB = (PFNGLBINDPROGRAMARBPROC)qwglGetProcAddress("glBindProgramARB");
qglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)qwglGetProcAddress("glProgramStringARB");
qglProgramEnvParameter4fARB =
(PFNGLPROGRAMENVPARAMETER4FARBPROC)qwglGetProcAddress("glProgramEnvParameter4fARB");
qglProgramLocalParameter4fARB =
(PFNGLPROGRAMLOCALPARAMETER4FARBPROC)qwglGetProcAddress("glProgramLocalParameter4fARB");
if (!(qglGenProgramsARB && qglDeleteProgramsARB && qglBindProgramARB &&
qglProgramStringARB && qglProgramEnvParameter4fARB && qglProgramLocalParameter4fARB))
{
gl_state.fragment_program = false;
Com_Printf("...GL_ARB_fragment_program not found\n");
}
}
else
{
gl_state.fragment_program = false;
Com_Printf("...GL_ARB_fragment_program not found\n");
}
if (gl_state.fragment_program)
{
gl_arb_fragment_program = Cvar_Get("gl_arb_fragment_program", "1", CVAR_ARCHIVE);
qglGenProgramsARB(1, &g_water_program_id);
qglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, g_water_program_id);
qglProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, 1.0f, 0.1f, 0.6f, 0.5f);
qglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(water_ARB_program), water_ARB_program);
// Make sure the program loaded correctly
{
int err = 0;
assert((err = qglGetError()) == GL_NO_ERROR);
err = err; // for debugging only -- todo, remove
}
}
else
gl_arb_fragment_program = Cvar_Get("gl_arb_fragment_program", "0", CVAR_ARCHIVE);
}
//GLSL Programs
//BSP Surfaces
static char bsp_vertex_program[] =
"uniform mat3 tangentSpaceTransform;\n"
"uniform vec3 Eye;\n"
"uniform vec3 lightPosition;\n"
"uniform vec3 staticLightPosition;\n"
"uniform int FOG;\n"
"varying vec3 EyeDir;\n"
"varying vec3 LightDir;\n"
"varying vec3 StaticLightDir;\n"
"varying vec4 sPos;\n"
"varying float fog;\n"
"void main( void )\n"
"{\n"
" sPos = gl_Vertex;\n"
" gl_Position = ftransform();\n"
" gl_FrontColor = gl_Color;\n"
" EyeDir = tangentSpaceTransform * ( Eye - gl_Vertex.xyz );\n"
" LightDir = tangentSpaceTransform * (lightPosition - gl_Vertex.xyz);\n"
" StaticLightDir = tangentSpaceTransform * (staticLightPosition - gl_Vertex.xyz);\n"
" // pass any active texunits through\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_TexCoord[1] = gl_MultiTexCoord1;\n"
" //fog\n"
" if(FOG > 0){\n"
" fog = (gl_Position.z - gl_Fog.start) / (gl_Fog.end - gl_Fog.start);\n"
" fog = clamp(fog, 0.0, 1.0);\n"
" }\n"
"}\n";
static char bsp_fragment_program[] =
"uniform sampler2D surfTexture;\n"
"uniform sampler2D HeightTexture;\n"
"uniform sampler2D NormalTexture;\n"
"uniform sampler2D lmTexture;\n"
"uniform sampler2D ShadowMap;\n"
"uniform sampler2D StatShadowMap;\n"
"uniform vec3 lightColour;\n"
"uniform float lightCutoffSquared;\n"
"uniform int FOG;\n"
"uniform int PARALLAX;\n"
"uniform int DYNAMIC;\n"
"uniform int STATSHADOW;\n"
"uniform int SHADOWMAP;\n"
"varying vec4 sPos;\n"
"varying vec3 EyeDir;\n"
"varying vec3 LightDir;\n"
"varying vec3 StaticLightDir;\n"
"varying float fog;\n"
"float lookupDynshadow( void )\n"
"{\n"
" vec4 ShadowCoord;\n"
" vec4 shadowCoordinateWdivide;\n"
" float distanceFromLight;\n"
" vec4 tempShadowCoord;\n"
" float shadow1 = 1.0;\n"
" float shadow2 = 1.0;\n"
" float shadow3 = 1.0;\n"
" float shadows = 1.0;\n"
" if(SHADOWMAP > 0) {\n"
" ShadowCoord = gl_TextureMatrix[7] * sPos;\n"
" shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;\n"
" // Used to lower moir pattern and self-shadowing\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow1 = distanceFromLight < shadowCoordinateWdivide.z ? 0.25 : 1.0 ;\n"
" //Blur shadows a bit\n"
" tempShadowCoord = ShadowCoord + vec4(.2, 0, 0, 0);\n"
" shadowCoordinateWdivide = tempShadowCoord / tempShadowCoord.w ;\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow2 = distanceFromLight < shadowCoordinateWdivide.z ? 0.25 : 1.0 ;\n"
" tempShadowCoord = ShadowCoord + vec4(0, .2, 0, 0);\n"
" shadowCoordinateWdivide = tempShadowCoord / tempShadowCoord.w ;\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow3 = distanceFromLight < shadowCoordinateWdivide.z ? 0.25 : 1.0 ;\n"
" shadows = 0.33 * (shadow1 + shadow2 + shadow3);\n"
" }\n"
" return shadows;\n"
"}\n"
"float lookupStatshadow( void )\n"
"{\n"
" vec4 ShadowCoord;\n"
" vec4 shadowCoordinateWdivide;\n"
" float distanceFromLight;\n"
" vec4 tempShadowCoord;\n"
" float shadow1 = 1.0;\n"
" float shadow2 = 1.0;\n"
" float shadow3 = 1.0;\n"
" float shadows = 1.0;\n"
" if(SHADOWMAP > 0) {\n"
" ShadowCoord = gl_TextureMatrix[6] * sPos;\n"
" shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;\n"
" // Used to lower moir pattern and self-shadowing\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(StatShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow1 = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0 ;\n"
" //Blur shadows a bit\n"
" tempShadowCoord = ShadowCoord + vec4(.2, 0, 0, 0);\n"
" shadowCoordinateWdivide = tempShadowCoord / tempShadowCoord.w ;\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(StatShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow2 = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0 ;\n"
" tempShadowCoord = ShadowCoord + vec4(0, .2, 0, 0);\n"
" shadowCoordinateWdivide = tempShadowCoord / tempShadowCoord.w ;\n"
" shadowCoordinateWdivide.z += 0.0005;\n"
" distanceFromLight = texture2D(StatShadowMap,shadowCoordinateWdivide.xy).z;\n"
" if (ShadowCoord.w > 0.0)\n"
" shadow3 = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0 ;\n"
" shadows = 0.33 * (shadow1 + shadow2 + shadow3);\n"
" }\n"
" return shadows;\n"
"}\n"
"void main( void )\n"
"{\n"
" vec4 diffuse;\n"
" vec4 lightmap;\n"
" vec4 alphamask;\n"
" float distanceSquared;\n"
" vec3 relativeLightDirection;\n"
" float diffuseTerm;\n"
" vec3 colour;\n"
" vec3 halfAngleVector;\n"
" float specularTerm;\n"
" float swamp;\n"
" float attenuation;\n"
" vec4 litColour;\n"
" vec3 varyingLightColour;\n"
" float varyingLightCutoffSquared;\n"
" float dynshadowval;\n"
" float statshadowval;\n"
" varyingLightColour = lightColour;\n"
" varyingLightCutoffSquared = lightCutoffSquared;\n"
" vec3 relativeEyeDirection = normalize( EyeDir );\n"
" vec3 normal = 2.0 * ( texture2D( NormalTexture, gl_TexCoord[0].xy).xyz - vec3( 0.5, 0.5, 0.5 ) );\n"
" vec3 textureColour = texture2D( surfTexture, gl_TexCoord[0].xy ).rgb;\n"
" lightmap = texture2D( lmTexture, gl_TexCoord[1].st );\n"
" alphamask = texture2D( surfTexture, gl_TexCoord[0].xy );\n"
" //shadows\n"
" if(DYNAMIC > 0)\n"
" dynshadowval = lookupDynshadow();\n"
" else\n"
" dynshadowval = 0.0;\n"
" if(STATSHADOW > 0)\n"
" statshadowval = lookupStatshadow();\n"
" else\n"
" statshadowval = 1.0;\n"
" if(PARALLAX > 0) {\n"
" //do the parallax mapping\n"
" vec4 Offset = texture2D( HeightTexture,gl_TexCoord[0].xy );\n"
" Offset = Offset * 0.04 - 0.02;\n"
" vec2 TexCoords = Offset.xy * relativeEyeDirection.xy + gl_TexCoord[0].xy;\n"
" diffuse = texture2D( surfTexture, TexCoords );\n"
" distanceSquared = dot( StaticLightDir, StaticLightDir );\n"
" relativeLightDirection = StaticLightDir / sqrt( distanceSquared );\n"
" diffuseTerm = clamp( dot( normal, relativeLightDirection ), 0.0, 1.0 );\n"
" colour = vec3( 0.0, 0.0, 0.0 );\n"
" if( diffuseTerm > 0.0 )\n"
" {\n"
" halfAngleVector = normalize( relativeLightDirection + relativeEyeDirection );\n"
" specularTerm = clamp( dot( normal, halfAngleVector ), 0.0, 1.0 );\n"
" specularTerm = pow( specularTerm, 32.0 );\n"
" colour = specularTerm * vec3( 1.0, 1.0, 1.0 ) / 2.0;\n"
" }\n"
" attenuation = 0.25;\n"
" swamp = attenuation;\n"
" swamp *= swamp;\n"
" swamp *= swamp;\n"
" swamp *= swamp;\n"
" colour += ( ( ( 0.5 - swamp ) * diffuseTerm ) + swamp ) * textureColour * 4.0;\n"
" litColour = vec4( attenuation * colour, 1.0 );\n"
" litColour = litColour * lightmap * 6.0;\n"
" gl_FragColor = max(litColour, diffuse * lightmap * 2.0);\n"
" gl_FragColor = (gl_FragColor * statshadowval);\n"
" }\n"
" else {\n"
" diffuse = texture2D(surfTexture, gl_TexCoord[0].xy);\n"
" gl_FragColor = (diffuse * lightmap * 2.0);\n"
" gl_FragColor = (gl_FragColor * statshadowval);\n"
" }\n"
" if(DYNAMIC > 0) {\n"
" lightmap = texture2D(lmTexture, gl_TexCoord[1].st);\n"
" //now do the dynamic lighting\n"
" distanceSquared = dot( LightDir, LightDir );\n"
" relativeLightDirection = LightDir / sqrt( distanceSquared );\n"
" diffuseTerm = clamp( dot( normal, relativeLightDirection ), 0.0, 1.0 );\n"
" colour = vec3( 0.0, 0.0, 0.0 );\n"
" if( diffuseTerm > 0.0 )\n"
" {\n"
" halfAngleVector = normalize( relativeLightDirection + relativeEyeDirection );\n"
" float specularTerm = clamp( dot( normal, halfAngleVector ), 0.0, 1.0 );\n"
" specularTerm = pow( specularTerm, 32.0 );\n"
" colour = specularTerm * vec3( 1.0, 1.0, 1.0 ) / 2.0;\n"
" }\n"
" attenuation = clamp( 1.0 - ( distanceSquared / varyingLightCutoffSquared ), 0.0, 1.0 );\n"
" swamp = attenuation;\n"
" swamp *= swamp;\n"
" swamp *= swamp;\n"
" swamp *= swamp;\n"
" colour += ( ( ( 0.5 - swamp ) * diffuseTerm ) + swamp ) * textureColour * 3.0;\n"
" vec4 dynamicColour = vec4( attenuation * colour * dynshadowval * varyingLightColour, 1.0 );\n"
" if(PARALLAX > 0) {\n"
" dynamicColour = max(dynamicColour, gl_FragColor);\n"
" }\n"
" else {\n"
" dynamicColour = max(dynamicColour, vec4(textureColour, 1.0) * lightmap * 2.0);\n"
" }\n"
" gl_FragColor = dynamicColour;\n"
" }\n"
" gl_FragColor = mix(vec4(0.0, 0.0, 0.0, alphamask.a), gl_FragColor, alphamask.a);\n"
" if(FOG > 0)\n"
" gl_FragColor = mix(gl_FragColor, gl_Fog.color, fog);\n"
"}\n";
//MESHES
static char mesh_vertex_program[] =
"uniform vec3 lightPos;\n"
"uniform float time;\n"
"uniform int FOG;\n"
"attribute vec4 tangent;\n"
"varying vec3 LightDir;\n"
"varying vec3 EyeDir;\n"
"varying float fog;\n"
"void main()\n"
"{\n"
" vec3 t;\n"
" vec3 b;\n"
" gl_Position = ftransform();\n"
" EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex);\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" vec3 n = normalize(gl_NormalMatrix * gl_Normal);\n"
" vec3 tangent3 = vec3(tangent);\n"
" t = normalize(gl_NormalMatrix * tangent3);\n"
" b = tangent[3] * cross(n, t);\n"
" vec3 v;\n"
" v.x = dot(lightPos, t);\n"
" v.y = dot(lightPos, b);\n"
" v.z = dot(lightPos, n);\n"
" LightDir = normalize(v);\n"
" v.x = dot(EyeDir, t);\n"
" v.y = dot(EyeDir, b);\n"
" v.z = dot(EyeDir, n);\n"
" EyeDir = normalize(v);\n"
" //for scrolling fx\n"
" vec4 texco = gl_MultiTexCoord0;\n"
" texco.s = texco.s + time*1.0;\n"
" texco.t = texco.t + time*1.0;\n"
" gl_TexCoord[1] = texco;\n"
" //fog\n"
" if(FOG > 0){\n"
" fog = (gl_Position.z - gl_Fog.start) / (gl_Fog.end - gl_Fog.start);\n"
" fog = clamp(fog, 0.0, 0.3); //any higher and meshes disappear\n"
" }\n"
"}\n";
static char mesh_fragment_program[] =
"uniform sampler2D baseTex;\n"
"uniform sampler2D normalTex;\n"
"uniform sampler2D fxTex;\n"
"uniform vec3 baseColor;\n"
"uniform int FOG;\n"
"uniform int useFX;\n"
"uniform int useGlow;\n"
"uniform float minLight;\n"
"const float SpecularFactor = 0.5;\n"
"varying vec3 LightDir;\n"
"varying vec3 EyeDir;\n"
"varying float fog;\n"
"void main()\n"
"{\n"
" vec3 litColor;\n"
" vec4 fx;\n"
" vec4 glow;\n"
" vec3 textureColour = texture2D( baseTex, gl_TexCoord[0].xy ).rgb;\n"
" vec3 normal = 2.0 * ( texture2D( normalTex, gl_TexCoord[0].xy).xyz - vec3( 0.5, 0.5, 0.5 ) );\n"
" vec4 alphamask = texture2D( baseTex, gl_TexCoord[0].xy);\n"
" vec4 specmask = texture2D( normalTex, gl_TexCoord[0].xy);\n"
" //moving fx texture\n"
" if(useFX > 0)\n"
" fx = texture2D( fxTex, gl_TexCoord[1].xy );\n"
" else\n"
" fx = vec4(0.0, 0.0, 0.0, 0.0);\n"
" //glowing fx texture\n"
" if(useGlow > 0)\n"
" glow = texture2D(fxTex, gl_TexCoord[0].xy );\n"
" litColor = textureColour * max(dot(normal, LightDir), 0.0);\n"
" vec3 reflectDir = reflect(LightDir, normal);\n"
" float spec = max(dot(EyeDir, reflectDir), 0.0);\n"
" spec = pow(spec, 6.0);\n"
" spec *= (SpecularFactor*specmask.a);\n"
" litColor = min(litColor + spec, vec3(1.0));\n"
" //keep shadows from making meshes completely black\n"
" litColor = max(litColor, (textureColour * vec3(minLight)));\n"
" gl_FragColor = vec4(litColor * baseColor, 1.0);\n"
" gl_FragColor = mix(fx, gl_FragColor, alphamask.a);\n"
" if(useGlow > 0)\n"
" gl_FragColor = mix(gl_FragColor, glow, glow.a);\n"
" if(FOG > 0)\n"
" gl_FragColor = mix(gl_FragColor, gl_Fog.color, fog);\n"
"}\n";
static char water_vertex_program[] =
"const float Eta = 0.66;\n"
"const float FresnelPower = 5.0;\n"
"const float F = ((1.0-Eta) * (1.0-Eta))/((1.0+Eta) * (1.0+Eta));\n"
"varying float FresRatio;\n"
"varying vec3 lightDir;\n"
"varying vec3 eyeDir;\n"
"varying vec3 reflectDir;\n"
"varying vec3 refractDir;\n"
"varying float fog;\n"
"uniform vec3 stangent;\n"
"uniform vec3 LightPos;\n"
"uniform float time;\n"
"uniform int REFLECT;\n"
"uniform int FOG;\n"
"void main(void)\n"
"{\n"
" vec4 v = vec4(gl_Vertex);\n"
" gl_Position = ftransform();\n"
" vec3 norm = normalize(gl_NormalMatrix * gl_Normal);\n"
" vec3 tang = normalize(gl_NormalMatrix * stangent);\n"
" vec3 binorm = cross(norm,tang);\n"
" eyeDir = vec3(gl_ModelViewMatrix * v);\n"
" //for refraction\n"
" vec4 neyeDir = gl_ModelViewMatrix * v;\n"
" vec3 refeyeDir = neyeDir.xyz / neyeDir.w;\n"
" refeyeDir = normalize(refeyeDir);\n"
" refeyeDir.x *= -1.0;\n"
" refeyeDir.y *= -1.0;\n"
" refeyeDir.z *= -1.0;\n"
" reflectDir = reflect(eyeDir,norm);\n"
" refractDir = refract(eyeDir,norm,Eta);\n"
" refractDir = vec3(gl_TextureMatrix[0] * vec4(refractDir,1.0));\n"
" FresRatio = F + (1.0-F) * pow((1.0-dot(-refeyeDir,norm)),FresnelPower);\n"
" vec3 tmp;\n"
" tmp.x = dot(LightPos,tang);\n"
" tmp.y = dot(LightPos,binorm);\n"
" tmp.z = dot(LightPos,norm);\n"
" lightDir = normalize(tmp);\n"
" tmp.x = dot(eyeDir,tang);\n"
" tmp.y = dot(eyeDir,binorm);\n"
" tmp.z = dot(eyeDir,norm);\n"
" eyeDir = normalize(tmp);\n"
" vec4 texco = gl_MultiTexCoord0;\n"
" if(REFLECT > 0) {\n"
" texco.s = texco.s - LightPos.x/256.0;\n"
" texco.t = texco.t + LightPos.y/256.0;\n"
" }\n"
" gl_TexCoord[0] = texco;\n"
" texco = gl_MultiTexCoord0;\n"
" texco.s = texco.s + time*0.05;\n"
" texco.t = texco.t + time*0.05;\n"
" gl_TexCoord[1] = texco;\n"
" texco = gl_MultiTexCoord0;\n"
" texco.s = texco.s + -time*0.05;\n"
" texco.t = texco.t + -time*0.05;\n"
" gl_TexCoord[2] = texco;\n"
" //fog\n"
" if(FOG > 0){\n"
" fog = (gl_Position.z - gl_Fog.start) / (gl_Fog.end - gl_Fog.start);\n"
" fog = clamp(fog, 0.0, 1.0);\n"
" }\n"
"}\n";
static char water_fragment_program[] =
"varying vec3 lightDir;\n"
"varying vec3 eyeDir;\n"
"varying float FresRatio;\n"
"varying float fog;\n"
"uniform sampler2D refTexture;\n"
"uniform sampler2D normalMap;\n"
"uniform sampler2D baseTexture;\n"
"uniform int REFLECT;\n"
"uniform int TRANSPARENT;\n"
"uniform int FOG;\n"
"void main (void)\n"
"{\n"
" vec4 refColor;\n"
" float distSqr = dot(lightDir, lightDir);\n"
" float att = clamp(1.0 - 0.0 * sqrt(distSqr), 0.0, 1.0);\n"
" vec3 lVec = lightDir * inversesqrt(distSqr);\n"
" vec3 vVec = normalize(eyeDir);\n"
" vec4 base = vec4(0.15,0.67,0.93,1.0); //base water color\n"
" if(REFLECT > 0)\n"
" refColor = mix(base, texture2D(refTexture, gl_TexCoord[0].xy), 1.0);\n"
" else\n"
" refColor = mix(base, texture2D(baseTexture, gl_TexCoord[0].xy), 1.0);\n"
" vec3 bump = normalize( texture2D(normalMap, gl_TexCoord[1].xy).xyz * 2.0 - 1.0);\n"
" vec3 secbump = normalize( texture2D(normalMap, gl_TexCoord[2].xy).xyz * 2.0 - 1.0);\n"
" vec3 modbump = mix(secbump,bump,0.5);\n"
" vec3 reflection = reflect(eyeDir,modbump);\n"
" vec3 refraction = refract(eyeDir,modbump,0.66);\n"
" vec4 Tl = texture2DProj(baseTexture, vec4(reflection.xy, 1.0, 1.0) );\n"
" vec4 Tr = texture2DProj(baseTexture, vec4(refraction.xy, 1.0, 1.0) );\n"
" vec4 cubemap = mix(Tl,Tr,FresRatio);\n"
" gl_FragColor = mix(cubemap,refColor,0.5);\n"
" if(TRANSPARENT > 0)\n"
" gl_FragColor.a = 0.5;\n"
" if(FOG > 0)\n"
" gl_FragColor = mix(gl_FragColor, gl_Fog.color, fog);\n"
"}\n";
//FRAMEBUFFER DISTORTION EFFECTS
static char fb_vertex_program[] =
"void main( void )\n"
"{\n"
" gl_Position = ftransform();\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"}\n";
static char fb_fragment_program[] =
"uniform sampler2D fbtexture;\n"
"uniform sampler2D distortiontexture;\n"
"uniform vec2 dParams;\n"
"uniform vec2 fxPos;\n"
"void main(void)\n"
"{\n"
" vec3 noiseVec;\n"
" vec2 displacement;\n"
" float wScissor;\n"
" float hScissor;\n"
" displacement = gl_TexCoord[0].st;\n"
" displacement.x -= fxPos.x;\n"
" displacement.y -= fxPos.y;\n"
" noiseVec = normalize(texture2D(distortiontexture, displacement.xy)).xyz;\n"
" noiseVec = (noiseVec * 2.0 - 0.635) * 0.035;\n"
" //clamp edges to prevent artifacts\n"
" wScissor = dParams.x - 0.008;\n"
" hScissor = dParams.y - 0.008;\n"
" if(gl_TexCoord[0].s > 0.1 && gl_TexCoord[0].s < wScissor)\n"
" displacement.x = gl_TexCoord[0].s + noiseVec.x;\n"
" else\n"
" displacement.x = gl_TexCoord[0].s;\n"
" if(gl_TexCoord[0].t > 0.1 && gl_TexCoord[0].t < hScissor) \n"
" displacement.y = gl_TexCoord[0].t + noiseVec.y;\n"
" else\n"
" displacement.y = gl_TexCoord[0].t;\n"
" gl_FragColor = texture2D(fbtexture, displacement.xy);\n"
"}\n";
//GAUSSIAN BLUR EFFECTS
static char blur_vertex_program[] =
"void main()\n"
"{\n"
" gl_Position = ftransform();\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"}\n";
static char blur_fragment_program[] =
"uniform vec2 ScaleU;\n"
"uniform sampler2D textureSource;\n"
"void main()\n"
"{\n"
" vec4 sum = vec4(0.0);\n"
" // take nine samples\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x - 4.0*ScaleU.x, gl_TexCoord[0].y - 4.0*ScaleU.y)) * 0.05;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x - 3.0*ScaleU.x, gl_TexCoord[0].y - 3.0*ScaleU.y)) * 0.09;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x - 2.0*ScaleU.x, gl_TexCoord[0].y - 2.0*ScaleU.y)) * 0.12;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x - ScaleU.x, gl_TexCoord[0].y - ScaleU.y)) * 0.15;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y)) * 0.16;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x + ScaleU.x, gl_TexCoord[0].y + ScaleU.y)) * 0.15;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x + 2.0*ScaleU.x, gl_TexCoord[0].y + 2.0*ScaleU.y)) * 0.12;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x + 3.0*ScaleU.x, gl_TexCoord[0].y + 3.0*ScaleU.y)) * 0.09;\n"
" sum += texture2D(textureSource, vec2(gl_TexCoord[0].x + 4.0*ScaleU.x, gl_TexCoord[0].y + 4.0*ScaleU.y)) * 0.05;\n"
" gl_FragColor = sum;\n"
"}\n";
//RADIAL BLUR EFFECTS // xy = radial center screen space position, z = radius attenuation, w = blur strength
static char rblur_vertex_program[] =
"void main()\n"
"{\n"
" gl_Position = ftransform();\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"}\n";
static char rblur_fragment_program[] =
"uniform sampler2D rtextureSource;\n"
"uniform vec3 radialBlurParams;\n"
"uniform vec3 rblurScale;\n"
"void main(void)\n"
"{\n"
" float wScissor;\n"
" float hScissor;\n"
" vec2 dir = vec2(radialBlurParams.x - gl_TexCoord[0].x, radialBlurParams.x - gl_TexCoord[0].x);\n"
" float dist = sqrt(dir.x*dir.x + dir.y*dir.y);\n"
" dir = dir/dist;\n"
" vec4 color = texture2D(rtextureSource,gl_TexCoord[0].xy);\n"
" vec4 sum = color;\n"
" float strength = radialBlurParams.z;\n"
" vec2 pDir = vec2(rblurScale.y * 0.5 - gl_TexCoord[0].s, rblurScale.z * 0.5 - gl_TexCoord[0].t);\n"
" float pDist = sqrt(pDir.x*pDir.x + pDir.y*pDir.y);\n"
" clamp(pDist, 0.0, 1.0);\n"
" //the following ugliness is due to ATI's drivers inablity to handle a simple for-loop!\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * -0.06 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * -0.05 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * -0.03 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * -0.02 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * -0.01 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * 0.01 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * 0.02 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * 0.03 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * 0.05 * strength * pDist );\n"
" sum += texture2D( rtextureSource, gl_TexCoord[0].xy + dir * 0.06 * strength * pDist );\n"
" sum *= 1.0/11.0;\n"
" float t = dist * rblurScale.x;\n"
" t = clamp( t ,0.0,1.0);\n"
" vec4 final = mix( color, sum, t );\n"
" //clamp edges to prevent artifacts\n"
" wScissor = rblurScale.y - 0.008;\n"
" hScissor = rblurScale.z - 0.008;\n"
" if(gl_TexCoord[0].s > 0.008 && gl_TexCoord[0].s < wScissor && gl_TexCoord[0].t > 0.008 && gl_TexCoord[0].t < hScissor)\n"
" gl_FragColor = final;\n"
" else\n"
" gl_FragColor = color;\n"
"}\n";
void R_LoadGLSLPrograms(void)
{
const char *shaderStrings[1];
int nResult;
char str[4096];
//load glsl (to do - move to own file)
if (strstr(gl_config.extensions_string, "GL_ARB_shader_objects" ) && gl_state.fragment_program)
{
gl_state.glsl_shaders = true;
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)qwglGetProcAddress("glCreateProgramObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)qwglGetProcAddress("glDeleteObjectARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)qwglGetProcAddress("glUseProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)qwglGetProcAddress("glCreateShaderObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)qwglGetProcAddress("glShaderSourceARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)qwglGetProcAddress("glCompileShaderARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)qwglGetProcAddress("glGetObjectParameterivARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)qwglGetProcAddress("glAttachObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)qwglGetProcAddress("glGetInfoLogARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)qwglGetProcAddress("glLinkProgramARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)qwglGetProcAddress("glGetUniformLocationARB");
glUniform3fARB = (PFNGLUNIFORM3FARBPROC)qwglGetProcAddress("glUniform3fARB");
glUniform2fARB = (PFNGLUNIFORM2FARBPROC)qwglGetProcAddress("glUniform2fARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)qwglGetProcAddress("glUniform1iARB");
glUniform1fARB = (PFNGLUNIFORM1FARBPROC)qwglGetProcAddress("glUniform1fARB");
glUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC)qwglGetProcAddress("glUniformMatrix3fvARB");
glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)qwglGetProcAddress("glVertexAttribPointerARB");
glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)qwglGetProcAddress("glEnableVertexAttribArrayARB");
glDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)qwglGetProcAddress("glDisableVertexAttribArrayARB");
glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC)qwglGetProcAddress("glBindAttribLocationARB");
if( !glCreateProgramObjectARB || !glDeleteObjectARB || !glUseProgramObjectARB ||
!glCreateShaderObjectARB || !glCreateShaderObjectARB || !glCompileShaderARB ||
!glGetObjectParameterivARB || !glAttachObjectARB || !glGetInfoLogARB ||
!glLinkProgramARB || !glGetUniformLocationARB || !glUniform3fARB ||
!glUniform1iARB || !glUniform1fARB || !glUniformMatrix3fvARB ||
!glVertexAttribPointerARB || !glEnableVertexAttribArrayARB ||
!glBindAttribLocationARB)
{
Com_Printf("...One or more GL_ARB_shader_objects functions were not found\n");
gl_state.glsl_shaders = false;
}
}
else
{
Com_Printf("...One or more GL_ARB_shader_objects functions were not found\n");
gl_state.glsl_shaders = false;
}
if(gl_state.glsl_shaders)
{
//we have them, set defaults accordingly
gl_glsl_shaders = Cvar_Get("gl_glsl_shaders", "1", CVAR_ARCHIVE);
gl_dynamic = Cvar_Get ("gl_dynamic", "1", CVAR_ARCHIVE);
//standard bsp surfaces
g_programObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)bsp_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_programObj, g_vertexShader );
else
{
Com_Printf("...Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)bsp_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_programObj, g_fragmentShader );
else
{
Com_Printf("...Fragment Shader Compile Error\n");
}
glLinkProgramARB( g_programObj );
glGetObjectParameterivARB( g_programObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_programObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_surfTexture = glGetUniformLocationARB( g_programObj, "surfTexture" );
g_location_eyePos = glGetUniformLocationARB( g_programObj, "Eye" );
g_tangentSpaceTransform = glGetUniformLocationARB( g_programObj, "tangentSpaceTransform");
g_location_heightTexture = glGetUniformLocationARB( g_programObj, "HeightTexture" );
g_location_lmTexture = glGetUniformLocationARB( g_programObj, "lmTexture" );
g_location_normalTexture = glGetUniformLocationARB( g_programObj, "NormalTexture" );
g_location_bspShadowmapTexture = glGetUniformLocationARB( g_programObj, "ShadowMap" );
g_location_bspShadowmapTexture2 = glGetUniformLocationARB( g_programObj, "StatShadowMap" );
g_location_fog = glGetUniformLocationARB( g_programObj, "FOG" );
g_location_parallax = glGetUniformLocationARB( g_programObj, "PARALLAX" );
g_location_dynamic = glGetUniformLocationARB( g_programObj, "DYNAMIC" );
g_location_shadowmap = glGetUniformLocationARB( g_programObj, "SHADOWMAP" );
g_Location_statshadow = glGetUniformLocationARB( g_programObj, "STATSHADOW" );
g_location_lightPosition = glGetUniformLocationARB( g_programObj, "lightPosition" );
g_location_staticLightPosition = glGetUniformLocationARB( g_programObj, "staticLightPosition" );
g_location_lightColour = glGetUniformLocationARB( g_programObj, "lightColour" );
g_location_lightCutoffSquared = glGetUniformLocationARB( g_programObj, "lightCutoffSquared" );
//warp(water) bsp surfaces
g_waterprogramObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)water_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_waterprogramObj, g_vertexShader );
else
{
Com_Printf("...Water Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)water_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_waterprogramObj, g_fragmentShader );
else
{
Com_Printf("...Water Fragment Shader Compile Error\n");
}
glLinkProgramARB( g_waterprogramObj );
glGetObjectParameterivARB( g_waterprogramObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_waterprogramObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_baseTexture = glGetUniformLocationARB( g_waterprogramObj, "baseTexture" );
g_location_normTexture = glGetUniformLocationARB( g_waterprogramObj, "normalMap" );
g_location_refTexture = glGetUniformLocationARB( g_waterprogramObj, "refTexture" );
g_location_tangent = glGetUniformLocationARB( g_waterprogramObj, "stangent" );
g_location_time = glGetUniformLocationARB( g_waterprogramObj, "time" );
g_location_lightPos = glGetUniformLocationARB( g_waterprogramObj, "LightPos" );
g_location_reflect = glGetUniformLocationARB( g_waterprogramObj, "REFLECT" );
g_location_trans = glGetUniformLocationARB( g_waterprogramObj, "TRANSPARENT" );
g_location_fogamount = glGetUniformLocationARB( g_waterprogramObj, "FOG" );
//meshes
g_meshprogramObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)mesh_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_meshprogramObj, g_vertexShader );
else
{
Com_Printf("...Mesh Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)mesh_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_meshprogramObj, g_fragmentShader );
else
{
Com_Printf("...Mesh Fragment Shader Compile Error\n");
}
glBindAttribLocationARB(g_meshprogramObj, 1, "tangent");
glLinkProgramARB( g_meshprogramObj );
glGetObjectParameterivARB( g_meshprogramObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_meshprogramObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_meshlightPosition = glGetUniformLocationARB( g_meshprogramObj, "lightPos" );
g_location_baseTex = glGetUniformLocationARB( g_meshprogramObj, "baseTex" );
g_location_normTex = glGetUniformLocationARB( g_meshprogramObj, "normalTex" );
g_location_fxTex = glGetUniformLocationARB( g_meshprogramObj, "fxTex" );
g_location_color = glGetUniformLocationARB( g_meshprogramObj, "baseColor" );
g_location_minLight = glGetUniformLocationARB( g_meshprogramObj, "minLight" );
g_location_meshNormal = glGetUniformLocationARB( g_meshprogramObj, "meshNormal" );
g_location_meshTime = glGetUniformLocationARB( g_meshprogramObj, "time" );
g_location_meshFog = glGetUniformLocationARB( g_meshprogramObj, "FOG" );
g_location_useFX = glGetUniformLocationARB( g_meshprogramObj, "useFX" );
g_location_useGlow = glGetUniformLocationARB( g_meshprogramObj, "useGlow");
//fullscreen distortion effects
g_fbprogramObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)fb_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_fbprogramObj, g_vertexShader );
else
{
Com_Printf("...Framebuffer Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)fb_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_fbprogramObj, g_fragmentShader );
else
{
Com_Printf("...Framebuffer Fragment Shader Compile Error\n");
}
glLinkProgramARB( g_fbprogramObj );
glGetObjectParameterivARB( g_fbprogramObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_fbprogramObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_framebuffTex = glGetUniformLocationARB( g_fbprogramObj, "fbtexture" );
g_location_distortTex = glGetUniformLocationARB( g_fbprogramObj, "distorttexture");
g_location_dParams = glGetUniformLocationARB( g_fbprogramObj, "dParams" );
g_location_fxPos = glGetUniformLocationARB( g_fbprogramObj, "fxPos" );
//gaussian blur
g_blurprogramObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)blur_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_blurprogramObj, g_vertexShader );
else
{
Com_Printf("...Blur Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)blur_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_blurprogramObj, g_fragmentShader );
else
{
Com_Printf("...Framebuffer Blur Shader Compile Error\n");
}
glLinkProgramARB( g_blurprogramObj );
glGetObjectParameterivARB( g_blurprogramObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_blurprogramObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_scale = glGetUniformLocationARB( g_blurprogramObj, "ScaleU" );
g_location_source = glGetUniformLocationARB( g_blurprogramObj, "textureSource");
//radial blur
g_rblurprogramObj = glCreateProgramObjectARB();
//
// Vertex shader
//
g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
shaderStrings[0] = (char*)rblur_vertex_program;
glShaderSourceARB( g_vertexShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_vertexShader);
glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_rblurprogramObj, g_vertexShader );
else
{
Com_Printf("...Radial Blur Vertex Shader Compile Error\n");
}
//
// Fragment shader
//
g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
shaderStrings[0] = (char*)rblur_fragment_program;
glShaderSourceARB( g_fragmentShader, 1, shaderStrings, NULL );
glCompileShaderARB( g_fragmentShader );
glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &nResult );
if( nResult )
glAttachObjectARB( g_rblurprogramObj, g_fragmentShader );
else
{
Com_Printf("...Radial Fragment Blur Shader Compile Error\n");
}
glLinkProgramARB( g_rblurprogramObj );
glGetObjectParameterivARB( g_rblurprogramObj, GL_OBJECT_LINK_STATUS_ARB, &nResult );
if( !nResult )
{
glGetInfoLogARB( g_rblurprogramObj, sizeof(str), NULL, str );
Com_Printf("...Linking Error\n");
}
//
// Locate some parameters by name so we can set them later...
//
g_location_rscale = glGetUniformLocationARB( g_rblurprogramObj, "rblurScale" );
g_location_rsource = glGetUniformLocationARB( g_rblurprogramObj, "rtextureSource");
g_location_rparams = glGetUniformLocationARB( g_rblurprogramObj, "radialBlurParams");
}
else
{
gl_glsl_shaders = Cvar_Get("gl_glsl_shaders", "0", CVAR_ARCHIVE);
gl_dynamic = Cvar_Get ("gl_dynamic", "0", CVAR_ARCHIVE);
}
}
|