DXGL r175 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r174‎ | r175 | r176 >
Date:18:05, 23 June 2012
Author:admin
Status:new
Tags:
Comment:
Consolidate directional lighting to single function. Begin writing spot light function.
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -281,7 +281,6 @@
282282 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
283283 ambient = ambientcolor / 255.0;\n";
284284 static const char op_dirlight[] = "DirLight(lightX);\n";
285 -static const char op_dirlightnospecular[] = "DirLightNoSpecular(lightX);\n";
286285 static const char op_spotlight[] = "SpotLight(lightX);\n";
287286 static const char op_colorout[] = "gl_FrontColor = (material.diffuse * diffuse) + (material.ambient * ambient) + material.emissive;\n\
288287 gl_FrontSecondaryColor = (material.specular * specular);\n";
@@ -305,7 +304,7 @@
306305 ambient += light.ambient;\n\
307306 float NdotL = max(dot(N,dir),0.0);\n\
308307 diffuse += light.diffuse*NdotL;\n\
309 -if(NdotL > 0.0)\n\
 308+if((NdotL > 0.0) && (material.power != 0.0))\n\
310309 {\n\
311310 vec3 eye = (-view[3].xyz / view[3].w);\n\
312311 vec3 P = vec3((view*world)*xyzw);\n\
@@ -316,16 +315,20 @@
317316 ambient += light.ambient;\n\
318317 }\n\
319318 }\n";
320 -static const char func_dirlightnospecular[] = "void DirLightNoSpecular(in Light light)\n\
 319+static const char func_spotlight[] = "void SpotLight(in Light light)\n\
321320 {\n\
322 -float NdotHV = 0.0;\n\
323 -vec3 dir = normalize(-light.direction);\n\
 321+float NdotHV = 0.0\n\
 322+vec3 V = normalize(eye - P);\n\
 323+float d = length( light.position - V );\n\
 324+vec3 L = normalize( light.position - V );\n\
 325+float NdotL = max(dot(N,L),0.0);\n\
 326+float NdotH = max(dot(N,H),0.0);\n\
 327+diffuse += light.diffuse*NdotL;\n\
324328 ambient += light.ambient;\n\
325 -float NdotL = max(dot(N,dir),0.0);\n\
326 -diffuse += light.diffuse*NdotL;\n\
327329 }\n";
328330
329331
 332+
330333 /**
331334 * Creates an OpenGL shader program
332335 * @param index
@@ -440,11 +443,7 @@
441444 }
442445 bool hasspecular = (id >> 11) & 1;
443446 if(hasspot) FIXME("Add spot lights");
444 - if(hasdir)
445 - {
446 - if(hasspecular) vsrc->append(func_dirlight);
447 - else vsrc->append(func_dirlightnospecular);
448 - }
 447+ if(hasdir) vsrc->append(func_dirlight);
449448 //Main
450449 vsrc->append(mainstart);
451450 if((id>>50)&1) vsrc->append(op_passthru);
@@ -464,18 +463,9 @@
465464 }
466465 else
467466 {
468 - if(hasspecular)
469 - {
470 - tmp = op_dirlight;
471 - tmp.replace(14,1,_itoa(i,idstring,10));
472 - vsrc->append(tmp);
473 - }
474 - else
475 - {
476 - tmp = op_dirlightnospecular;
477 - tmp.replace(24,1,_itoa(i,idstring,10));
478 - vsrc->append(tmp);
479 - }
 467+ tmp = op_dirlight;
 468+ tmp.replace(14,1,_itoa(i,idstring,10));
 469+ vsrc->append(tmp);
480470 }
481471 }
482472 vsrc->append(op_colorout);