DXGL r529 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r528‎ | r529 | r530 >
Date:01:14, 10 September 2014
Author:admin
Status:new
Tags:
Comment:
Use 4x4 matrix for dithering; improves performance.
Downgrade GLSL fragment shaders with dithering to @version 110
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -331,15 +331,12 @@
332332 static const char var_fogfactorpixel[] = "float fogfactor;\n";
333333 // Constants
334334 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";
 335+static const char const_threshold[] = "mat4 threshold = mat4(\n\
 336+1.0, 9.0, 3.0, 11.0,\n\
 337+13.0, 5.0, 15.0, 7.0,\n\
 338+4.0, 12.0, 2.0, 10.0,\n\
 339+16.0, 8.0, 14.0, 6.0);\n";
 340+
344341 // Operations
345342 static const char op_transform[] = "xyzw = vec4(xyz,1.0);\n\
346343 vec4 pos = gl_ModelViewProjectionMatrix*xyzw;\n\
@@ -449,12 +446,12 @@
450447 static const char func_dither[] = "vec4 dither(vec4 color2)\n\
451448 {\n\
452449 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\
 450+ int x = int(mod(gl_FragCoord.x, 4.0));\n\
 451+ int y = int(mod(gl_FragCoord.y, 4.0));\n\
455452 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\
 453+ limit.r = (threshold[x][y]) / ((pow(2.0, float(ditherbits.r)) - 1.0)*16.0);\n\
 454+ limit.g = (threshold[x][y]) / ((pow(2.0, float(ditherbits.g)) - 1.0)*16.0);\n\
 455+ limit.b = (threshold[x][y]) / ((pow(2.0, float(ditherbits.b)) - 1.0)*16.0);\n\
459456 color.r += limit.r;\n\
460457 color.g += limit.g;\n\
461458 color.b += limit.b;\n\
@@ -771,15 +768,10 @@
772769 }
773770 #endif
774771 // Create fragment shader
775 - if ((id>>62)&1)
776 - {
777 - if ((This->ext->glver_major > 2) || ((This->ext->glver_major == 2) && (This->ext->glver_minor >= 1)))
778 - dither = true;
779 - }
 772+ if ((id>>62)&1) dither = true;
780773 STRING *fsrc = &This->genshaders[index].shader.fsrc;
781774 String_Append(fsrc, header);
782 - if (dither) String_Append(fsrc, ver120);
783 - else String_Append(fsrc, ver110);
 775+ String_Append(fsrc, ver110);
784776 String_Append(fsrc, fragshader);
785777 _snprintf(idstring,21,"%0.16I64X\n",id);
786778 idstring[21] = 0;