Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -500,6 +500,7 @@ |
501 | 501 | }
|
502 | 502 | if(renderstate[D3DRENDERSTATE_LIGHTING]) shader |= (1i64 << 59);
|
503 | 503 | if(renderstate[D3DRENDERSTATE_COLORVERTEX]) shader |= (1i64 << 60);
|
| 504 | + if(renderstate[D3DRENDERSTATE_FOGENABLE]) shader |= (1i64 << 61);
|
504 | 505 | for(i = 0; i < 8; i++)
|
505 | 506 | {
|
506 | 507 | if(!texstages[i].dirty) continue;
|
Index: ddraw/shadergen.cpp |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | 100=greater 101=notequal 110=greaterequal 111=always
|
44 | 44 | Bits 6-7 - Table fog: FS
|
45 | 45 | 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
|
47 | 47 | Bit 10 - Range based fog VS/FS
|
48 | 48 | Bit 11 - Specular highlights VS/FS
|
49 | 49 | Bit 12 - Stippled alpha FS
|
— | — | @@ -66,6 +66,7 @@ |
67 | 67 | Bits 51-58 - Point or spot light VS/FS
|
68 | 68 | Bit 59 - Enable lights VS/FS
|
69 | 69 | Bit 60 - Use vertex colors VS
|
| 70 | +Bit 61 - Enable fog VS/FS
|
70 | 71 | */
|
71 | 72 |
|
72 | 73 | /* Bits in Texture Stage ID:
|
— | — | @@ -299,6 +300,7 @@ |
300 | 301 | static const char op_texpassthru2str[] = "vec4(strX,1);\n";
|
301 | 302 | static const char op_texpassthru2strq[] = "strqX;\n";
|
302 | 303 | static const char op_texpassthru2null[] = "vec4(0,0,0,1);\n";
|
| 304 | +static const char op_fogcoordstandardpixel[] = "gl_FogFragCoord = gl_FragCoord.z;\n";
|
303 | 305 | static const char op_fogcoordstandard[] = "gl_FogFragCoord = (gl_ModelViewMatrix*gl_Vertex).z;\n";
|
304 | 306 | static const char op_fogcoordrange[] = "vec4 eyepos = gl_ModelViewMatrix*gl_Vertex;\n\
|
305 | 307 | vec3 eyepos3 = eyepos.xyz / eyepos.w;\n\
|
— | — | @@ -391,6 +393,12 @@ |
392 | 394 | bool hasspot = false;
|
393 | 395 | int count;
|
394 | 396 | int numlights;
|
| 397 | + int vertexfog,pixelfog;
|
| 398 | + if((id>>61)&1)
|
| 399 | + {
|
| 400 | + vertexfog = (id>>8)&3;
|
| 401 | + pixelfog = (id>>6)&3;
|
| 402 | + }
|
395 | 403 | char idstring[22];
|
396 | 404 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
397 | 405 | idstring[21] = 0;
|
— | — | @@ -474,6 +482,7 @@ |
475 | 483 | // Variables
|
476 | 484 | vsrc->append(var_common);
|
477 | 485 | if(!((id>>50)&1)) vsrc->append(var_xyzw);
|
| 486 | + if(vertexfog && !pixelfog) vsrc->append(var_fogfactorvertex);
|
478 | 487 |
|
479 | 488 | // Functions
|
480 | 489 | if(numlights)
|
— | — | @@ -606,6 +615,23 @@ |
607 | 616 | }
|
608 | 617 | }
|
609 | 618 | }
|
| 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 | + }
|
610 | 636 | vsrc->append(mainend);
|
611 | 637 | #ifdef _DEBUG
|
612 | 638 | OutputDebugStringA("Vertex shader:\n");
|
— | — | @@ -663,6 +689,8 @@ |
664 | 690 | if((id>>2)&1) fsrc->append(unif_alpharef);
|
665 | 691 | // Variables
|
666 | 692 | fsrc->append(var_color);
|
| 693 | + if(vertexfog && !pixelfog) fsrc->append(var_fogfactorvertex);
|
| 694 | + if(pixelfog) fsrc->append(var_fogfactorpixel);
|
667 | 695 | // Functions
|
668 | 696 | // Main
|
669 | 697 | fsrc->append(mainstart);
|
— | — | @@ -962,6 +990,24 @@ |
963 | 991 | break;
|
964 | 992 | }
|
965 | 993 | }
|
| 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 | + }
|
966 | 1012 | fsrc->append(op_colorfragout);
|
967 | 1013 | fsrc->append(mainend);
|
968 | 1014 | #ifdef _DEBUG
|