Index: ddraw/shadergen.cpp |
— | — | @@ -262,6 +262,7 @@ |
263 | 263 | static const char unif_size[] = "uniform float width;\n\
|
264 | 264 | uniform float height;\n";
|
265 | 265 | static const char unif_alpharef[] = "uniform int alpharef;\n";
|
| 266 | +static const char unif_key[] = "uniform ivec4 keyX;\n";
|
266 | 267 | // Variables
|
267 | 268 | static const char var_common[] = "vec4 diffuse;\n\
|
268 | 269 | vec4 specular;\n\
|
— | — | @@ -277,7 +278,7 @@ |
278 | 279 | static const char op_normalpassthru[] = "N = gl_NormalMatrix*nxyz;\n";
|
279 | 280 | static const char op_passthru[] = "gl_Position = vec4(((xyz.x/rhw)/(width/2.0))-1.0,((xyz.y/rhw)/(height/2.0))-1.0,(xyz.z/rhw),1.0/rhw);\n";
|
280 | 281 | static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
|
281 | | -ambient = ambientcolor / 255.5;\n";
|
| 282 | +ambient = ambientcolor / 255.0;\n";
|
282 | 283 | static const char op_dirlight[] = "DirLight(lightX);\n";
|
283 | 284 | static const char op_pointlight[] = "PointLight(lightX);\n";
|
284 | 285 | static const char op_spotlight[] = "SpotLight(lightX);\n";
|
— | — | @@ -289,6 +290,7 @@ |
290 | 291 | static const char op_colorwhite[] = "gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n";
|
291 | 292 | static const char op_colorfragout[] = "gl_FragColor = color;\n";
|
292 | 293 | static const char op_colorfragin[] = "color = gl_Color;\n";
|
| 294 | +static const char op_colorkey[] = "if(ivec4(texture2DProj(texX,gl_TexCoord[Y])*255.5) == keyZ) discard;\n";
|
293 | 295 | static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
|
294 | 296 | static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
|
295 | 297 | static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
|
— | — | @@ -648,12 +650,29 @@ |
649 | 651 | bool alphadisabled = false;
|
650 | 652 | const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y])",
|
651 | 653 | "","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a",".aaa"};
|
| 654 | + bool usecolorkey = false;
|
| 655 | + if((id>>13)&1) usecolorkey = true;
|
652 | 656 | for(i = 0; i < 8; i++)
|
653 | 657 | {
|
654 | 658 | if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
|
| 659 | + args[0] = (texstate[i].shaderid>>5)&63;
|
| 660 | + args[1] = (texstate[i].shaderid>>11)&63;
|
| 661 | + args[2] = (texstate[i].shaderid>>22)&63;
|
| 662 | + args[3] = (texstate[i].shaderid>>28)&63;
|
| 663 | + // Color key
|
| 664 | + if(usecolorkey)
|
| 665 | + {
|
| 666 | + if((texstate[i].shaderid>>60)&1)
|
| 667 | + {
|
| 668 | + arg1.assign(op_colorkey);
|
| 669 | + arg1.replace(26,1,_itoa(i,idstring,10));
|
| 670 | + arg1.replace(40,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
| 671 | + arg1.replace(57,1,_itoa(i,idstring,10));
|
| 672 | + fsrc->append(arg1);
|
| 673 | + }
|
| 674 | + }
|
655 | 675 | // Color stage
|
656 | 676 | texfail = false;
|
657 | | - args[0] = (texstate[i].shaderid>>5)&63;
|
658 | 677 | switch(args[0]&7) //arg1
|
659 | 678 | {
|
660 | 679 | case D3DTA_CURRENT:
|
— | — | @@ -683,7 +702,6 @@ |
684 | 703 | if(args[0] & D3DTA_COMPLEMENT) arg1 = "(1.0 - " + arg1 + ")";
|
685 | 704 | if(args[0] & D3DTA_ALPHAREPLICATE) arg1.append(blendargs[10]);
|
686 | 705 | else arg1.append(blendargs[8]);
|
687 | | - args[1] = (texstate[i].shaderid>>11)&63;
|
688 | 706 | switch(args[1]&7) //arg2
|
689 | 707 | {
|
690 | 708 | case D3DTA_CURRENT:
|
— | — | @@ -775,7 +793,6 @@ |
776 | 794 | if(alphadisabled) continue;
|
777 | 795 | // Alpha stage
|
778 | 796 | texfail = false;
|
779 | | - args[2] = (texstate[i].shaderid>>22)&63;
|
780 | 797 | switch(args[2]&7) //arg1
|
781 | 798 | {
|
782 | 799 | case D3DTA_CURRENT:
|
— | — | @@ -804,7 +821,6 @@ |
805 | 822 | }
|
806 | 823 | if(args[2] & D3DTA_COMPLEMENT)
|
807 | 824 | arg1 = "(1.0 - " + arg1 + ")";
|
808 | | - args[3] = (texstate[i].shaderid>>28)&63;
|
809 | 825 | switch(args[3]&7) //arg2
|
810 | 826 | {
|
811 | 827 | case D3DTA_CURRENT:
|
— | — | @@ -1039,4 +1055,10 @@ |
1040 | 1056 | genshaders[index].shader.uniforms[137] = glGetUniformLocation(genshaders[index].shader.prog,"width");
|
1041 | 1057 | genshaders[index].shader.uniforms[138] = glGetUniformLocation(genshaders[index].shader.prog,"height");
|
1042 | 1058 | genshaders[index].shader.uniforms[139] = glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
|
| 1059 | + char unifkey[] = "keyX";
|
| 1060 | + for(int i = 0; i < 8; i++)
|
| 1061 | + {
|
| 1062 | + unifkey[3] = i + '0';
|
| 1063 | + genshaders[index].shader.uniforms[128+i] = glGetUniformLocation(genshaders[index].shader.prog,unifkey);
|
| 1064 | + }
|
1043 | 1065 | }
|