DXGL r184 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r183‎ | r184 | r185 >
Date:00:07, 27 June 2012
Author:admin
Status:new
Tags:
Comment:
Redo point lights. (no difference)
Add spot lights.
Add specular highlights.
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -319,29 +319,42 @@
320320 }\n";
321321 static const char func_pointlight[] = "void PointLight(in Light light)\n\
322322 {\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\
330328 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\
332336 ambient += light.ambient;\n\
 337+specular += light.specular*pf*attenuation;\n\
333338 }\n";
334339 static const char func_spotlight[] = "void SpotLight(in Light light)\n\
335340 {\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\
343346 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\
345357 ambient += light.ambient;\n\
 358+specular += light.specular*pf*attenuation;\n\
346359 }\n";
347360
348361
@@ -457,7 +470,7 @@
458471 {
459472 if(id>>(38+i)&1)
460473 {
461 - if(id>>(50+i)&1) hasspot = true;
 474+ if(id>>(51+i)&1) hasspot = true;
462475 else haspoint = true;
463476 }
464477 else hasdir = true;
@@ -480,7 +493,7 @@
481494 {
482495 if(id>>(38+i)&1)
483496 {
484 - if(id>>(50+i)&1)
 497+ if(id>>(51+i)&1)
485498 {
486499 tmp = op_spotlight;
487500 tmp.replace(15,1,_itoa(i,idstring,10));