DXGL r234 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r233‎ | r234 | r235 >
Date:23:25, 9 August 2012
Author:admin
Status:new
Tags:
Comment:
Combine color and alpha registers in fragment shader
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -262,8 +262,7 @@
263263 vec4 specular;\n\
264264 vec4 ambient;\n\
265265 vec3 N;";
266 -static const char var_color[] = "vec3 color;\n\
267 -float alpha;\n";
 266+static const char var_color[] = "vec4 color;\n";
268267 static const char var_xyzw[] = "vec4 xyzw;\n";
269268 // Operations
270269 static const char op_transform[] = "xyzw = vec4(xyz,1);\n\
@@ -283,9 +282,8 @@
284283 static const char op_colorvert[] = "gl_FrontColor = rgba0.bgra;\n";
285284 static const char op_color2vert[] = "gl_FrontSecondaryColor = rgba1.bgra;\n";
286285 static const char op_colorwhite[] = "gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n";
287 -static const char op_colorfragout[] = "gl_FragColor = vec4(color,alpha);\n";
288 -static const char op_colorfragin[] = "color = gl_Color.rgb;\n\
289 -alpha = gl_Color.a;\n";
 286+static const char op_colorfragout[] = "gl_FragColor = color;\n";
 287+static const char op_colorfragin[] = "color = gl_Color;\n";
290288 static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
291289 static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
292290 static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
@@ -607,8 +605,8 @@
608606 string arg1,arg2;
609607 int args[4];
610608 bool texfail;
611 - const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y]).rgb",
612 - "texture2DProj(texX,gl_TexCoord[Y]).a","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a","alpha"};
 609+ const string blendargs[] = {"color.rgb","gl_Color","texture2DProj(texX,gl_TexCoord[Y]).rgb",
 610+ "texture2DProj(texX,gl_TexCoord[Y]).a","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a","color.a"};
613611 for(i = 0; i < 8; i++)
614612 {
615613 if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
@@ -678,34 +676,34 @@
679677 default:
680678 break;
681679 case D3DTOP_SELECTARG1:
682 - fsrc->append("color = " + arg1 + ";\n");
 680+ fsrc->append("color.rgb = " + arg1 + ";\n");
683681 break;
684682 case D3DTOP_SELECTARG2:
685 - fsrc->append("color = " + arg2 + ";\n");
 683+ fsrc->append("color.rgb = " + arg2 + ";\n");
686684 break;
687685 case D3DTOP_MODULATE:
688 - fsrc->append("color = " + arg1 + " * " + arg2 + ";\n");
 686+ fsrc->append("color.rgb = " + arg1 + " * " + arg2 + ";\n");
689687 break;
690688 case D3DTOP_MODULATE2X:
691 - fsrc->append("color = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
 689+ fsrc->append("color.rgb = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
692690 break;
693691 case D3DTOP_MODULATE4X:
694 - fsrc->append("color = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
 692+ fsrc->append("color.rgb = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
695693 break;
696694 case D3DTOP_ADD:
697 - fsrc->append("color = " + arg1 + " + " + arg2 + ";\n");
 695+ fsrc->append("color.rgb = " + arg1 + " + " + arg2 + ";\n");
698696 break;
699697 case D3DTOP_ADDSIGNED:
700 - fsrc->append("color = " + arg1 + " + " + arg2 + " - .5;\n");
 698+ fsrc->append("color.rgb = " + arg1 + " + " + arg2 + " - .5;\n");
701699 break;
702700 case D3DTOP_ADDSIGNED2X:
703 - fsrc->append("color = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
 701+ fsrc->append("color.rgb = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
704702 break;
705703 case D3DTOP_SUBTRACT:
706 - fsrc->append("color = " + arg1 + " - " + arg2 + ";\n");
 704+ fsrc->append("color.rgb = " + arg1 + " - " + arg2 + ";\n");
707705 break;
708706 case D3DTOP_ADDSMOOTH:
709 - fsrc->append("color = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
 707+ fsrc->append("color.rgb = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
710708 break;
711709 }
712710 if(((texstate[i].shaderid>>17) & 31) == D3DTOP_DISABLE)break;
@@ -775,34 +773,34 @@
776774 default:
777775 break;
778776 case D3DTOP_SELECTARG1:
779 - fsrc->append("alpha = " + arg1 + ";\n");
 777+ fsrc->append("color.a = " + arg1 + ";\n");
780778 break;
781779 case D3DTOP_SELECTARG2:
782 - fsrc->append("alpha = " + arg2 + ";\n");
 780+ fsrc->append("color.a = " + arg2 + ";\n");
783781 break;
784782 case D3DTOP_MODULATE:
785 - fsrc->append("alpha = " + arg1 + " * " + arg2 + ";\n");
 783+ fsrc->append("color.a = " + arg1 + " * " + arg2 + ";\n");
786784 break;
787785 case D3DTOP_MODULATE2X:
788 - fsrc->append("alpha = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
 786+ fsrc->append("color.a = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
789787 break;
790788 case D3DTOP_MODULATE4X:
791 - fsrc->append("alpha = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
 789+ fsrc->append("color.a = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
792790 break;
793791 case D3DTOP_ADD:
794 - fsrc->append("alpha = " + arg1 + " + " + arg2 + ";\n");
 792+ fsrc->append("color.a = " + arg1 + " + " + arg2 + ";\n");
795793 break;
796794 case D3DTOP_ADDSIGNED:
797 - fsrc->append("alpha = " + arg1 + " + " + arg2 + " - .5;\n");
 795+ fsrc->append("color.a = " + arg1 + " + " + arg2 + " - .5;\n");
798796 break;
799797 case D3DTOP_ADDSIGNED2X:
800 - fsrc->append("alpha = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
 798+ fsrc->append("color.a = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
801799 break;
802800 case D3DTOP_SUBTRACT:
803 - fsrc->append("alpha = " + arg1 + " - " + arg2 + ";\n");
 801+ fsrc->append("color.a = " + arg1 + " - " + arg2 + ";\n");
804802 break;
805803 case D3DTOP_ADDSMOOTH:
806 - fsrc->append("alpha = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
 804+ fsrc->append("color.a = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
807805 break;
808806 }
809807 }