| Index: Help/Help.vcxproj |
| — | — | @@ -101,6 +101,7 @@ |
| 102 | 102 | <ItemGroup>
|
| 103 | 103 | <None Include="configuration.htm">
|
| 104 | 104 | <DeploymentContent>true</DeploymentContent>
|
| | 105 | + <SubType>Designer</SubType>
|
| 105 | 106 | </None>
|
| 106 | 107 | <None Include="dxgl.css" />
|
| 107 | 108 | <None Include="dxgl.hhp" />
|
| Index: ddraw/ShaderGen3D.cpp |
| — | — | @@ -81,6 +81,7 @@ |
| 82 | 82 | Bit 59 - Enable lights VS/FS
|
| 83 | 83 | Bit 60 - Use vertex colors VS
|
| 84 | 84 | Bit 61 - Enable fog VS/FS
|
| | 85 | +Bit 62 - Enable dithering FS
|
| 85 | 86 | */
|
| 86 | 87 |
|
| 87 | 88 | /* Bits in Texture Stage ID:
|
| — | — | @@ -270,8 +271,9 @@ |
| 271 | 272 |
|
| 272 | 273 |
|
| 273 | 274 | static const char header[] =
|
| 274 | | - "//REV" STR(SHADER3DVERSION) "\n\
|
| 275 | | -#version 110\n";
|
| | 275 | + "//REV" STR(SHADER3DVERSION) "\n";
|
| | 276 | +static const char ver110[] = "#version 110\n";
|
| | 277 | +static const char ver120[] = "#version 120\n";
|
| 276 | 278 | static const char vertexshader[] = "//Vertex Shader\n";
|
| 277 | 279 | static const char fragshader[] = "//Fragment Shader\n";
|
| 278 | 280 | static const char idheader[] = "//ID: 0x";
|
| — | — | @@ -282,7 +284,6 @@ |
| 283 | 285 | static const char attr_xyz[] = "attribute vec3 xyz;\n";
|
| 284 | 286 | static const char attr_rhw[] = "attribute float rhw;\n";
|
| 285 | 287 | static const char attr_nxyz[] = "attribute vec3 nxyz;\n";
|
| 286 | | -static const char const_nxyz[] = "const vec3 nxyz = vec3(0,0,0);\n";
|
| 287 | 288 | static const char attr_blend[] = "attribute float blendX;\n";
|
| 288 | 289 | static const char attr_rgba[] = "attribute vec4 rgbaX;\n";
|
| 289 | 290 | static const char attr_s[] = "attribute float sX;\n";
|
| — | — | @@ -318,6 +319,7 @@ |
| 319 | 320 | static const char unif_alpharef[] = "uniform int alpharef;\n";
|
| 320 | 321 | static const char unif_key[] = "uniform ivec3 keyX;\n";
|
| 321 | 322 | static const char unif_world[] = "uniform mat4 matWorld;\n";
|
| | 323 | +static const char unif_ditherbits[] = "uniform ivec4 ditherbits;\n";
|
| 322 | 324 | // Variables
|
| 323 | 325 | static const char var_common[] = "vec4 diffuse;\n\
|
| 324 | 326 | vec4 specular;\n\
|
| — | — | @@ -327,6 +329,17 @@ |
| 328 | 330 | static const char var_xyzw[] = "vec4 xyzw;\n";
|
| 329 | 331 | static const char var_fogfactorvertex[] = "varying float fogfactor;\n";
|
| 330 | 332 | static const char var_fogfactorpixel[] = "float fogfactor;\n";
|
| | 333 | +// Constants
|
| | 334 | +static const char const_nxyz[] = "const vec3 nxyz = vec3(0,0,0);\n";
|
| | 335 | +static const char const_threshold[] = "float threshold[64] = float[64](\n\
|
| | 336 | +0, 32, 8, 40, 2, 34, 10, 42,\n\
|
| | 337 | +48, 16, 56, 24, 50, 18, 58, 26,\n\
|
| | 338 | +12, 44, 4, 36, 14, 46, 6, 38,\n\
|
| | 339 | +60, 28, 52, 20, 62, 30, 54, 22,\n\
|
| | 340 | +3, 35, 11, 43, 1, 33, 9, 41,\n\
|
| | 341 | +51, 19, 59, 27, 49, 17, 57, 25,\n\
|
| | 342 | +15, 47, 7, 39, 13, 45, 5, 37,\n\
|
| | 343 | +63, 31, 55, 23, 61, 29, 53, 21);\n";
|
| 331 | 344 | // Operations
|
| 332 | 345 | static const char op_transform[] = "xyzw = vec4(xyz,1.0);\n\
|
| 333 | 346 | vec4 pos = gl_ModelViewProjectionMatrix*xyzw;\n\
|
| — | — | @@ -348,6 +361,7 @@ |
| 349 | 362 | static const char op_color2vert[] = "gl_FrontSecondaryColor = rgba1.bgra;\n";
|
| 350 | 363 | static const char op_colorwhite[] = "gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n";
|
| 351 | 364 | static const char op_colorfragout[] = "gl_FragColor = color;\n";
|
| | 365 | +static const char op_dither[] = "color = dither(color);\n";
|
| 352 | 366 | static const char op_colorfragin[] = "color = gl_Color;\n";
|
| 353 | 367 | static const char op_colorkey[] = "if(ivec3(texture2DProj(texX,gl_TexCoord[Y])*255.5).rgb == keyZ) discard;\n";
|
| 354 | 368 | static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
|
| — | — | @@ -432,9 +446,36 @@ |
| 433 | 447 | ambient += light.ambient;\n\
|
| 434 | 448 | specular += light.specular*pf*attenuation;\n\
|
| 435 | 449 | }\n";
|
| | 450 | +static const char func_dither[] = "vec4 dither(vec4 color2)\n\
|
| | 451 | +{\n\
|
| | 452 | + vec4 color = color2;\n\
|
| | 453 | + int x = int(mod(gl_FragCoord.x, 8.0));\n\
|
| | 454 | + int y = int(mod(gl_FragCoord.y, 8.0));\n\
|
| | 455 | + vec4 limit;\n\
|
| | 456 | + limit.r = (threshold[x + (y * 8)]) / ((pow(2.0, float(ditherbits.r)) - 1.0)*64.0);\n\
|
| | 457 | + limit.g = (threshold[x + (y * 8)]) / ((pow(2.0, float(ditherbits.g)) - 1.0)*64.0);\n\
|
| | 458 | + limit.b = (threshold[x + (y * 8)]) / ((pow(2.0, float(ditherbits.b)) - 1.0)*64.0);\n\
|
| | 459 | + limit.a = (threshold[x + (y * 8)]) / ((pow(2.0, float(ditherbits.a)) - 1.0)*64.0);\n\
|
| | 460 | + color.r += limit.r;\n\
|
| | 461 | + color.g += limit.g;\n\
|
| | 462 | + color.b += limit.b;\n\
|
| | 463 | + color.a += limit.a;\n\
|
| | 464 | + color.r *= pow(2.0, float(ditherbits.r)) - 1.0;\n\
|
| | 465 | + color.r = floor(color.r);\n\
|
| | 466 | + color.g *= pow(2.0, float(ditherbits.g)) - 1.0;\n\
|
| | 467 | + color.g = floor(color.g);\n\
|
| | 468 | + color.b *= pow(2.0, float(ditherbits.b)) - 1.0;\n\
|
| | 469 | + color.b = floor(color.b);\n\
|
| | 470 | + color.a *= pow(2.0, float(ditherbits.a)) - 1.0;\n\
|
| | 471 | + color.a = floor(color.a);\n\
|
| | 472 | + color.r /= pow(2.0, float(ditherbits.r)) - 1.0;\n\
|
| | 473 | + color.g /= pow(2.0, float(ditherbits.g)) - 1.0;\n\
|
| | 474 | + color.b /= pow(2.0, float(ditherbits.b)) - 1.0;\n\
|
| | 475 | + color.a /= pow(2.0, float(ditherbits.a)) - 1.0;\n\
|
| | 476 | + return color;\n\
|
| | 477 | +}\n";
|
| 436 | 478 |
|
| 437 | 479 |
|
| 438 | | -
|
| 439 | 480 | /**
|
| 440 | 481 | * Creates an OpenGL shader program
|
| 441 | 482 | * @param This
|
| — | — | @@ -456,6 +497,7 @@ |
| 457 | 498 | bool hasdir = false;
|
| 458 | 499 | bool haspoint = false;
|
| 459 | 500 | bool hasspot = false;
|
| | 501 | + bool dither = false;
|
| 460 | 502 | int count;
|
| 461 | 503 | int numlights;
|
| 462 | 504 | int vertexfog,pixelfog;
|
| — | — | @@ -474,6 +516,7 @@ |
| 475 | 517 | //Header
|
| 476 | 518 | STRING *vsrc = &This->genshaders[index].shader.vsrc;
|
| 477 | 519 | String_Append(vsrc, header);
|
| | 520 | + String_Append(vsrc, ver110);
|
| 478 | 521 | String_Append(vsrc, vertexshader);
|
| 479 | 522 | String_Append(vsrc, idheader);
|
| 480 | 523 | String_Append(vsrc, idstring);
|
| — | — | @@ -733,8 +776,15 @@ |
| 734 | 777 | }
|
| 735 | 778 | #endif
|
| 736 | 779 | // Create fragment shader
|
| | 780 | + if ((id>>62)&1)
|
| | 781 | + {
|
| | 782 | + if ((This->ext->glver_major > 2) || ((This->ext->glver_major == 2) && (This->ext->glver_minor >= 1)))
|
| | 783 | + dither = true;
|
| | 784 | + }
|
| 737 | 785 | STRING *fsrc = &This->genshaders[index].shader.fsrc;
|
| 738 | 786 | String_Append(fsrc, header);
|
| | 787 | + if (dither) String_Append(fsrc, ver120);
|
| | 788 | + else String_Append(fsrc, ver110);
|
| 739 | 789 | String_Append(fsrc, fragshader);
|
| 740 | 790 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
| 741 | 791 | idstring[21] = 0;
|
| — | — | @@ -761,11 +811,14 @@ |
| 762 | 812 | }
|
| 763 | 813 | }
|
| 764 | 814 | if((id>>2)&1) String_Append(fsrc, unif_alpharef);
|
| | 815 | + if (dither) String_Append(fsrc, unif_ditherbits);
|
| 765 | 816 | // Variables
|
| 766 | 817 | String_Append(fsrc, var_color);
|
| 767 | 818 | if(vertexfog && !pixelfog) String_Append(fsrc, var_fogfactorvertex);
|
| 768 | 819 | if(pixelfog) String_Append(fsrc, var_fogfactorpixel);
|
| | 820 | + if (dither) String_Append(fsrc, const_threshold);
|
| 769 | 821 | // Functions
|
| | 822 | + if (dither) String_Append(fsrc, func_dither);
|
| 770 | 823 | // Main
|
| 771 | 824 | String_Append(fsrc, mainstart);
|
| 772 | 825 | String_Append(fsrc, op_colorfragin);
|
| — | — | @@ -1253,6 +1306,7 @@ |
| 1254 | 1307 | String_Append(fsrc, op_fogblend);
|
| 1255 | 1308 | }
|
| 1256 | 1309 | if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
|
| | 1310 | + if (dither) String_Append(fsrc,op_dither);
|
| 1257 | 1311 | String_Append(fsrc, op_colorfragout);
|
| 1258 | 1312 | String_Append(fsrc, mainend);
|
| 1259 | 1313 | String_Free(&tmp);
|
| — | — | @@ -1390,6 +1444,7 @@ |
| 1391 | 1445 | unifkey[3] = i + '0';
|
| 1392 | 1446 | This->genshaders[index].shader.uniforms[142 + i] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, unifkey);
|
| 1393 | 1447 | }
|
| | 1448 | + This->genshaders[index].shader.uniforms[150] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"ditherbits");
|
| 1394 | 1449 | }
|
| 1395 | 1450 |
|
| 1396 | 1451 | } |
| \ No newline at end of file |
| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -772,6 +772,7 @@ |
| 773 | 773 | if(renderstate[D3DRENDERSTATE_LIGHTING]) shader |= (1i64 << 59);
|
| 774 | 774 | if(renderstate[D3DRENDERSTATE_COLORVERTEX]) shader |= (1i64 << 60);
|
| 775 | 775 | if(renderstate[D3DRENDERSTATE_FOGENABLE]) shader |= (1i64 << 61);
|
| | 776 | + if(renderstate[D3DRENDERSTATE_DITHERENABLE]) shader |= (1i64 << 62);
|
| 776 | 777 | for(i = 0; i < 8; i++)
|
| 777 | 778 | {
|
| 778 | 779 | if(!texstages[i].dirty) continue;
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -2013,6 +2013,7 @@ |
| 2014 | 2014 | if(prog.uniforms[139]!= -1) This->ext->glUniform1f(prog.uniforms[139],device->viewport.dwX);
|
| 2015 | 2015 | if(prog.uniforms[140]!= -1) This->ext->glUniform1f(prog.uniforms[140],device->viewport.dwY);
|
| 2016 | 2016 | if(prog.uniforms[141]!= -1) This->ext->glUniform1i(prog.uniforms[141],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
|
| | 2017 | + if(prog.uniforms[150]!= -1) This->ext->glUniform4iv(prog.uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
|
| 2017 | 2018 | do
|
| 2018 | 2019 | {
|
| 2019 | 2020 | if (This->util->SetFBO(device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
|