Index: ddraw/shadergen.cpp |
— | — | @@ -319,29 +319,42 @@ |
320 | 320 | }\n";
|
321 | 321 | static const char func_pointlight[] = "void PointLight(in Light light)\n\
|
322 | 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\
|
| 323 | +vec4 pos = ((view*world)*xyzw);\n\
|
| 324 | +vec3 pos3 = pos.xyz / pos.w;\n\
|
| 325 | +vec3 V = light.position - pos3;\n\
|
| 326 | +float d = length(V);\n\
|
| 327 | +V = normalize(V);\n\
|
330 | 328 | float attenuation = 1.0/(light.constant+(d*light.linear)+((d*d)*light.quad));\n\
|
331 | | -diffuse += light.diffuse*NdotL*attenuation;\n\
|
| 329 | +float NdotV = max(0.0,dot(N,V));\n\
|
| 330 | +float NdotHV = max(0.0,dot(N,normalize(V+vec3(0.0,0.0,1.0))));\n\
|
| 331 | +float pf;\n\
|
| 332 | +if(NdotV == 0.0) pf = 0.0;\n\
|
| 333 | +else if(material.power > 0.0) pf = pow(NdotHV,material.power);\n\
|
| 334 | +else pf = 0.0;\n\
|
| 335 | +diffuse += light.diffuse*NdotV*attenuation;\n\
|
332 | 336 | ambient += light.ambient;\n\
|
| 337 | +specular += light.specular*pf*attenuation;\n\
|
333 | 338 | }\n";
|
334 | 339 | static const char func_spotlight[] = "void SpotLight(in Light light)\n\
|
335 | 340 | {\n\
|
336 | | -float NdotHV = 0.0;\n\
|
337 | | -vec3 V = ((view*world)*xyzw).xyz;\n\
|
338 | | -float d = length(light.position - V);\n\
|
339 | | -vec3 L = normalize(light.position - V);\n\
|
340 | | -vec3 H = normalize(L + vec3(0.0, 0.0, 1.0));\n\
|
341 | | -float NdotL = max(dot(N,L),0.0);\n\
|
342 | | -float NdotH = max(dot(N,H),0.0);\n\
|
| 341 | +vec4 pos = ((view*world)*xyzw);\n\
|
| 342 | +vec3 pos3 = pos.xyz / pos.w;\n\
|
| 343 | +vec3 V = light.position - pos3;\n\
|
| 344 | +float d = length(V);\n\
|
| 345 | +V = normalize(V);\n\
|
343 | 346 | float attenuation = 1.0/(light.constant+(d*light.linear)+((d*d)*light.quad));\n\
|
344 | | -diffuse += light.diffuse*NdotL*attenuation;\n\
|
| 347 | +float NdotV = max(0.0,dot(N,V));\n\
|
| 348 | +float NdotHV = max(0.0,dot(N,normalize(V+vec3(0.0,0.0,1.0))));\n\
|
| 349 | +float pf;\n\
|
| 350 | +if(NdotV == 0.0) pf = 0.0;\n\
|
| 351 | +else if(material.power > 0.0) pf = pow(NdotHV,material.power);\n\
|
| 352 | +else pf = 0.0;\n\
|
| 353 | +float spotangle = dot(-V,normalize(light.direction));\n\
|
| 354 | +if(spotangle < cos(light.phi * (180.0/3.14159265)))\n\
|
| 355 | +attenuation = 0.0;\n\
|
| 356 | +diffuse += light.diffuse*NdotV*attenuation;\n\
|
345 | 357 | ambient += light.ambient;\n\
|
| 358 | +specular += light.specular*pf*attenuation;\n\
|
346 | 359 | }\n";
|
347 | 360 |
|
348 | 361 |
|
— | — | @@ -457,7 +470,7 @@ |
458 | 471 | {
|
459 | 472 | if(id>>(38+i)&1)
|
460 | 473 | {
|
461 | | - if(id>>(50+i)&1) hasspot = true;
|
| 474 | + if(id>>(51+i)&1) hasspot = true;
|
462 | 475 | else haspoint = true;
|
463 | 476 | }
|
464 | 477 | else hasdir = true;
|
— | — | @@ -480,7 +493,7 @@ |
481 | 494 | {
|
482 | 495 | if(id>>(38+i)&1)
|
483 | 496 | {
|
484 | | - if(id>>(50+i)&1)
|
| 497 | + if(id>>(51+i)&1)
|
485 | 498 | {
|
486 | 499 | tmp = op_spotlight;
|
487 | 500 | tmp.replace(15,1,_itoa(i,idstring,10));
|