DXGL r183 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r182‎ | r183 | r184 >
Date:21:41, 26 June 2012
Author:admin
Status:new
Tags:
Comment:
Separate point and spot lights
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -397,6 +397,8 @@
398398 {
399399 if(lights[gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
400400 shader |= (1i64 << (38+lightindex));
 401+ if(lights[gllights[i]]->light.dltType == D3DLIGHT_SPOT)
 402+ shader |= (1i64 << (51+lightindex));
401403 lightindex++;
402404 }
403405 }
Index: ddraw/shadergen.cpp
@@ -58,10 +58,11 @@
5959 Bit 35 - Use diffuse color VS
6060 Bit 36 - Use specular color VS
6161 Bit 37 - Enable normals VS
62 -Bits 38-45 - Light types VS/FS
 62+Bits 38-45 - Directional or point/spot light VS/FS
6363 Bits 46-48 - Number of blending weights VS
6464 Bit 49 - Normalize normals VS
6565 Bit 50 - Use transformed vertices VS
 66+Bits 51-58 - Point or spot light VS/FS
6667 */
6768
6869 /* Bits in Texture Stage ID:
@@ -281,6 +282,7 @@
282283 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
283284 ambient = ambientcolor / 255.0;\n";
284285 static const char op_dirlight[] = "DirLight(lightX);\n";
 286+static const char op_pointlight[] = "PointLight(lightX);\n";
285287 static const char op_spotlight[] = "SpotLight(lightX);\n";
286288 static const char op_colorout[] = "gl_FrontColor = (material.diffuse * diffuse) + (material.ambient * ambient) + material.emissive;\n\
287289 gl_FrontSecondaryColor = (material.specular * specular);\n";
@@ -315,6 +317,19 @@
316318 ambient += light.ambient;\n\
317319 }\n\
318320 }\n";
 321+static const char func_pointlight[] = "void PointLight(in Light light)\n\
 322+{\n\
 323+float NdotHV = 0.0;\n\
 324+vec3 V = ((view*world)*xyzw).xyz;\n\
 325+float d = length(light.position - V);\n\
 326+vec3 L = normalize(light.position - V);\n\
 327+vec3 H = normalize(L + vec3(0.0, 0.0, 1.0));\n\
 328+float NdotL = max(dot(N,L),0.0);\n\
 329+float NdotH = max(dot(N,H),0.0);\n\
 330+float attenuation = 1.0/(light.constant+(d*light.linear)+((d*d)*light.quad));\n\
 331+diffuse += light.diffuse*NdotL*attenuation;\n\
 332+ambient += light.ambient;\n\
 333+}\n";
319334 static const char func_spotlight[] = "void SpotLight(in Light light)\n\
320335 {\n\
321336 float NdotHV = 0.0;\n\
@@ -347,6 +362,7 @@
348363 string tmp;
349364 int i;
350365 bool hasdir = false;
 366+ bool haspoint = false;
351367 bool hasspot = false;
352368 int count;
353369 int numlights;
@@ -439,12 +455,17 @@
440456 {
441457 for(i = 0; i < numlights; i++)
442458 {
443 - if(id>>(38+i)&1) hasspot = true;
 459+ if(id>>(38+i)&1)
 460+ {
 461+ if(id>>(50+i)&1) hasspot = true;
 462+ else haspoint = true;
 463+ }
444464 else hasdir = true;
445465 }
446466 }
447467 bool hasspecular = (id >> 11) & 1;
448468 if(hasspot) vsrc->append(func_spotlight);
 469+ if(haspoint) vsrc->append(func_pointlight);
449470 if(hasdir) vsrc->append(func_dirlight);
450471 //Main
451472 vsrc->append(mainstart);
@@ -459,9 +480,18 @@
460481 {
461482 if(id>>(38+i)&1)
462483 {
463 - tmp = op_spotlight;
464 - tmp.replace(15,1,_itoa(i,idstring,10));
465 - vsrc->append(tmp);
 484+ if(id>>(50+i)&1)
 485+ {
 486+ tmp = op_spotlight;
 487+ tmp.replace(15,1,_itoa(i,idstring,10));
 488+ vsrc->append(tmp);
 489+ }
 490+ else
 491+ {
 492+ tmp = op_pointlight;
 493+ tmp.replace(16,1,_itoa(i,idstring,10));
 494+ vsrc->append(tmp);
 495+ }
466496 }
467497 else
468498 {