| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -397,6 +397,8 @@ |
| 398 | 398 | {
|
| 399 | 399 | if(lights[gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
|
| 400 | 400 | shader |= (1i64 << (38+lightindex));
|
| | 401 | + if(lights[gllights[i]]->light.dltType == D3DLIGHT_SPOT)
|
| | 402 | + shader |= (1i64 << (51+lightindex));
|
| 401 | 403 | lightindex++;
|
| 402 | 404 | }
|
| 403 | 405 | }
|
| Index: ddraw/shadergen.cpp |
| — | — | @@ -58,10 +58,11 @@ |
| 59 | 59 | Bit 35 - Use diffuse color VS
|
| 60 | 60 | Bit 36 - Use specular color VS
|
| 61 | 61 | Bit 37 - Enable normals VS
|
| 62 | | -Bits 38-45 - Light types VS/FS
|
| | 62 | +Bits 38-45 - Directional or point/spot light VS/FS
|
| 63 | 63 | Bits 46-48 - Number of blending weights VS
|
| 64 | 64 | Bit 49 - Normalize normals VS
|
| 65 | 65 | Bit 50 - Use transformed vertices VS
|
| | 66 | +Bits 51-58 - Point or spot light VS/FS
|
| 66 | 67 | */
|
| 67 | 68 |
|
| 68 | 69 | /* Bits in Texture Stage ID:
|
| — | — | @@ -281,6 +282,7 @@ |
| 282 | 283 | static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
|
| 283 | 284 | ambient = ambientcolor / 255.0;\n";
|
| 284 | 285 | static const char op_dirlight[] = "DirLight(lightX);\n";
|
| | 286 | +static const char op_pointlight[] = "PointLight(lightX);\n";
|
| 285 | 287 | static const char op_spotlight[] = "SpotLight(lightX);\n";
|
| 286 | 288 | static const char op_colorout[] = "gl_FrontColor = (material.diffuse * diffuse) + (material.ambient * ambient) + material.emissive;\n\
|
| 287 | 289 | gl_FrontSecondaryColor = (material.specular * specular);\n";
|
| — | — | @@ -315,6 +317,19 @@ |
| 316 | 318 | ambient += light.ambient;\n\
|
| 317 | 319 | }\n\
|
| 318 | 320 | }\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";
|
| 319 | 334 | static const char func_spotlight[] = "void SpotLight(in Light light)\n\
|
| 320 | 335 | {\n\
|
| 321 | 336 | float NdotHV = 0.0;\n\
|
| — | — | @@ -347,6 +362,7 @@ |
| 348 | 363 | string tmp;
|
| 349 | 364 | int i;
|
| 350 | 365 | bool hasdir = false;
|
| | 366 | + bool haspoint = false;
|
| 351 | 367 | bool hasspot = false;
|
| 352 | 368 | int count;
|
| 353 | 369 | int numlights;
|
| — | — | @@ -439,12 +455,17 @@ |
| 440 | 456 | {
|
| 441 | 457 | for(i = 0; i < numlights; i++)
|
| 442 | 458 | {
|
| 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 | + }
|
| 444 | 464 | else hasdir = true;
|
| 445 | 465 | }
|
| 446 | 466 | }
|
| 447 | 467 | bool hasspecular = (id >> 11) & 1;
|
| 448 | 468 | if(hasspot) vsrc->append(func_spotlight);
|
| | 469 | + if(haspoint) vsrc->append(func_pointlight);
|
| 449 | 470 | if(hasdir) vsrc->append(func_dirlight);
|
| 450 | 471 | //Main
|
| 451 | 472 | vsrc->append(mainstart);
|
| — | — | @@ -459,9 +480,18 @@ |
| 460 | 481 | {
|
| 461 | 482 | if(id>>(38+i)&1)
|
| 462 | 483 | {
|
| 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 | + }
|
| 466 | 496 | }
|
| 467 | 497 | else
|
| 468 | 498 | {
|