DXGL r134 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r133‎ | r134 | r135 >
Date:19:25, 10 April 2012
Author:admin
Status:new
Tags:
Comment:
Add no specular directional lighting function
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -249,6 +249,7 @@
250250 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
251251 ambient = ambientcolor / 255.0;\n";
252252 static const char op_dirlight[] = "DirLight(lightX);\n";
 253+static const char op_dirlightnospecular[] = "DirLightNoSpecular(lightX);\n";
253254 static const char op_spotlight[] = "SpotLight(lightX);\n";
254255 static const char op_colorout[] = "vec4 color = (material.diffuse * diffuse) + (material.ambient * ambient) + \n\
255256 (material.specular * specular) + material.emissive;\n\
@@ -275,6 +276,14 @@
276277 ambient += light.ambient;\n\
277278 }\n\
278279 }\n";
 280+static const char func_dirlightnospecular[] = "void DirLightNoSpecular(in Light light)\n\
 281+{\n\
 282+float NdotHV = 0.0;\n\
 283+vec3 dir = normalize(-light.direction);\n\
 284+ambient += light.ambient;\n\
 285+float NdotL = max(dot(N,dir),0.0);\n\
 286+diffuse += light.diffuse*NdotL;\n\
 287+}\n";
279288
280289 void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
281290 {
@@ -351,8 +360,13 @@
352361 else hasdir = true;
353362 }
354363 }
 364+ bool hasspecular = (id >> 11) & 1;
355365 if(hasspot) FIXME("Add spot lights");
356 - if(hasdir) vsrc->append(func_dirlight);
 366+ if(hasdir)
 367+ {
 368+ if(hasspecular) vsrc->append(func_dirlight);
 369+ else vsrc->append(func_dirlightnospecular);
 370+ }
357371 //Main
358372 vsrc->append(mainstart);
359373 if((id>>34)&1) vsrc->append(op_passthru);
@@ -372,9 +386,18 @@
373387 }
374388 else
375389 {
376 - tmp = op_dirlight;
377 - tmp.replace(14,1,_itoa(i,idstring,10));
378 - vsrc->append(tmp);
 390+ if(hasspecular)
 391+ {
 392+ tmp = op_dirlight;
 393+ tmp.replace(14,1,_itoa(i,idstring,10));
 394+ vsrc->append(tmp);
 395+ }
 396+ else
 397+ {
 398+ tmp = op_dirlightnospecular;
 399+ tmp.replace(24,1,_itoa(i,idstring,10));
 400+ vsrc->append(tmp);
 401+ }
379402 }
380403 }
381404 }