DXGL r298 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r297‎ | r298 | r299 >
Date:03:27, 1 January 2013
Author:admin
Status:new
Tags:
Comment:
Add broken fog implementation to shaders.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -500,6 +500,7 @@
501501 }
502502 if(renderstate[D3DRENDERSTATE_LIGHTING]) shader |= (1i64 << 59);
503503 if(renderstate[D3DRENDERSTATE_COLORVERTEX]) shader |= (1i64 << 60);
 504+ if(renderstate[D3DRENDERSTATE_FOGENABLE]) shader |= (1i64 << 61);
504505 for(i = 0; i < 8; i++)
505506 {
506507 if(!texstages[i].dirty) continue;
Index: ddraw/shadergen.cpp
@@ -42,7 +42,7 @@
4343 100=greater 101=notequal 110=greaterequal 111=always
4444 Bits 6-7 - Table fog: FS
4545 00 = none 01=exp 10=exp2 11=linear
46 -Bits 8-9 - Vertex fog: same as table VS
 46+Bits 8-9 - Vertex fog: same as table VS/FS
4747 Bit 10 - Range based fog VS/FS
4848 Bit 11 - Specular highlights VS/FS
4949 Bit 12 - Stippled alpha FS
@@ -66,6 +66,7 @@
6767 Bits 51-58 - Point or spot light VS/FS
6868 Bit 59 - Enable lights VS/FS
6969 Bit 60 - Use vertex colors VS
 70+Bit 61 - Enable fog VS/FS
7071 */
7172
7273 /* Bits in Texture Stage ID:
@@ -299,6 +300,7 @@
300301 static const char op_texpassthru2str[] = "vec4(strX,1);\n";
301302 static const char op_texpassthru2strq[] = "strqX;\n";
302303 static const char op_texpassthru2null[] = "vec4(0,0,0,1);\n";
 304+static const char op_fogcoordstandardpixel[] = "gl_FogFragCoord = gl_FragCoord.z;\n";
303305 static const char op_fogcoordstandard[] = "gl_FogFragCoord = (gl_ModelViewMatrix*gl_Vertex).z;\n";
304306 static const char op_fogcoordrange[] = "vec4 eyepos = gl_ModelViewMatrix*gl_Vertex;\n\
305307 vec3 eyepos3 = eyepos.xyz / eyepos.w;\n\
@@ -391,6 +393,12 @@
392394 bool hasspot = false;
393395 int count;
394396 int numlights;
 397+ int vertexfog,pixelfog;
 398+ if((id>>61)&1)
 399+ {
 400+ vertexfog = (id>>8)&3;
 401+ pixelfog = (id>>6)&3;
 402+ }
395403 char idstring[22];
396404 _snprintf(idstring,21,"%0.16I64X\n",id);
397405 idstring[21] = 0;
@@ -474,6 +482,7 @@
475483 // Variables
476484 vsrc->append(var_common);
477485 if(!((id>>50)&1)) vsrc->append(var_xyzw);
 486+ if(vertexfog && !pixelfog) vsrc->append(var_fogfactorvertex);
478487
479488 // Functions
480489 if(numlights)
@@ -606,6 +615,23 @@
607616 }
608617 }
609618 }
 619+ if(vertexfog && !pixelfog)
 620+ {
 621+ if((id>>10)&1) vsrc->append(op_fogcoordrange);
 622+ else vsrc->append(op_fogcoordstandard);
 623+ switch(vertexfog)
 624+ {
 625+ case D3DFOG_LINEAR:
 626+ vsrc->append(op_foglinear);
 627+ break;
 628+ case D3DFOG_EXP:
 629+ vsrc->append(op_fogexp);
 630+ break;
 631+ case D3DFOG_EXP2:
 632+ vsrc->append(op_fogexp2);
 633+ break;
 634+ }
 635+ }
610636 vsrc->append(mainend);
611637 #ifdef _DEBUG
612638 OutputDebugStringA("Vertex shader:\n");
@@ -663,6 +689,8 @@
664690 if((id>>2)&1) fsrc->append(unif_alpharef);
665691 // Variables
666692 fsrc->append(var_color);
 693+ if(vertexfog && !pixelfog) fsrc->append(var_fogfactorvertex);
 694+ if(pixelfog) fsrc->append(var_fogfactorpixel);
667695 // Functions
668696 // Main
669697 fsrc->append(mainstart);
@@ -962,6 +990,24 @@
963991 break;
964992 }
965993 }
 994+ if(vertexfog && !pixelfog) fsrc->append(op_fogblend);
 995+ if(pixelfog)
 996+ {
 997+ fsrc->append(op_fogcoordstandardpixel);
 998+ switch(pixelfog)
 999+ {
 1000+ case D3DFOG_LINEAR:
 1001+ vsrc->append(op_foglinear);
 1002+ break;
 1003+ case D3DFOG_EXP:
 1004+ vsrc->append(op_fogexp);
 1005+ break;
 1006+ case D3DFOG_EXP2:
 1007+ vsrc->append(op_fogexp2);
 1008+ break;
 1009+ }
 1010+ fsrc->append(op_fogblend);
 1011+ }
9661012 fsrc->append(op_colorfragout);
9671013 fsrc->append(mainend);
9681014 #ifdef _DEBUG