DXGL r281 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r280‎ | r281 | r282 >
Date:00:42, 11 December 2012
Author:admin
Status:new
Tags:
Comment:
Tweak ambient calculation.
Add vertex colors (partially works)
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -279,7 +279,7 @@
280280 static const char op_dirlight[] = "DirLight(lightX);\n";
281281 static const char op_pointlight[] = "PointLight(lightX);\n";
282282 static const char op_spotlight[] = "SpotLight(lightX);\n";
283 -static const char op_colorout[] = "gl_FrontColor = (gl_FrontMaterial.diffuse * diffuse) + (gl_FrontMaterial.ambient * ambient)\n\
 283+static const char op_colorout[] = "gl_FrontColor = (gl_FrontMaterial.diffuse * diffuse) + (gl_FrontMaterial.ambient + ambient)\n\
284284 + (gl_FrontMaterial.specular * specular) + gl_FrontMaterial.emission;\n\
285285 gl_FrontSecondaryColor = (gl_FrontMaterial.specular * specular);\n";
286286 static const char op_colorvert[] = "gl_FrontColor = rgba0.bgra;\n";
@@ -482,6 +482,8 @@
483483 else vsrc->append(op_transform);
484484 if((id>>49)&1) vsrc->append(op_normalize);
485485 else vsrc->append(op_normalpassthru);
 486+ const string colorargs[] = {"gl_FrontMaterial.diffuse","gl_FrontMaterial.ambient","gl_FrontMaterial.specular",
 487+ "gl_FrontMaterial.emission","rgba0.bgra","rgba1.bgra"};
486488 if(numlights)
487489 {
488490 vsrc->append(op_resetcolor);
@@ -509,7 +511,36 @@
510512 vsrc->append(tmp);
511513 }
512514 }
513 - vsrc->append(op_colorout);
 515+ if((id>>60)&1)
 516+ {
 517+ bool hascolor1 = false;
 518+ if((id>>35)&1) hascolor1 = true;
 519+ bool hascolor2 = false;
 520+ if((id>>36)&1) hascolor2 = true;
 521+ int matcolor;
 522+ vsrc->append("gl_FrontColor = (");
 523+ matcolor = ((id>>23)&3);
 524+ if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
 525+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
 526+ else vsrc->append(colorargs[0]);
 527+ vsrc->append(" * diffuse) + (");
 528+ matcolor = ((id>>27)&3);
 529+ if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
 530+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
 531+ else vsrc->append(colorargs[1]);
 532+ vsrc->append(" + ambient)\n+ (");
 533+ matcolor = ((id>>25)&3);
 534+ if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
 535+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
 536+ else vsrc->append(colorargs[2]);
 537+ vsrc->append(" * specular) + ");
 538+ matcolor = ((id>>29)&3);
 539+ if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
 540+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
 541+ else vsrc->append(colorargs[3]);
 542+ vsrc->append(";\n");
 543+ }
 544+ else vsrc->append(op_colorout);
514545 }
515546 else
516547 {