mirror of
https://github.com/DrBeef/Raze.git
synced 2025-01-18 15:11:51 +00:00
Reorganize point light GPU program a bit.
git-svn-id: https://svn.eduke32.com/eduke32@1243 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
8bdb217ca1
commit
62d3116325
1 changed files with 37 additions and 24 deletions
|
@ -244,47 +244,60 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
|||
1 << PR_BIT_POINT_LIGHT,
|
||||
// vert_def
|
||||
"varying vec3 vertexNormal;\n"
|
||||
"varying vec3 vertexPos;\n"
|
||||
"varying vec3 eyeVector;\n"
|
||||
"varying vec3 lightVector;\n"
|
||||
"\n",
|
||||
// vert_prog
|
||||
" vec3 vertexPos;\n"
|
||||
"\n"
|
||||
" vertexNormal = normalize(gl_NormalMatrix * curNormal);\n"
|
||||
" vertexPos = vec3(gl_ModelViewMatrix * curVertex);\n"
|
||||
" eyeVector = -vertexPos;\n"
|
||||
" lightVector = gl_LightSource[0].ambient.rgb - vertexPos;\n"
|
||||
"\n",
|
||||
// frag_def
|
||||
"varying vec3 vertexNormal;\n"
|
||||
"varying vec3 vertexPos;\n"
|
||||
"varying vec3 eyeVector;\n"
|
||||
"varying vec3 lightVector;\n"
|
||||
"\n",
|
||||
// frag_prog
|
||||
" vec3 fragmentNormal;\n"
|
||||
" vec3 lightPos;\n"
|
||||
" vec3 lightDiffuse;\n"
|
||||
" vec2 lightRange;\n"
|
||||
" vec3 lightVector;\n"
|
||||
" float dotNormalLightDir;\n"
|
||||
" float lightAttenuation;\n"
|
||||
" float pointLightDistance;\n"
|
||||
" float lightAttenuation;\n"
|
||||
" vec3 N, L, E, R;\n"
|
||||
" vec3 lightDiffuse;\n"
|
||||
" float lightSpecular;\n"
|
||||
" float NdotL;\n"
|
||||
"\n"
|
||||
" fragmentNormal = normalize(vertexNormal);\n"
|
||||
" L = normalize(lightVector);\n"
|
||||
"\n"
|
||||
" lightPos = gl_LightSource[0].ambient.rgb;\n"
|
||||
" lightDiffuse = gl_LightSource[0].diffuse.rgb;\n"
|
||||
" pointLightDistance = length(lightVector);\n"
|
||||
" lightRange.x = gl_LightSource[0].constantAttenuation;\n"
|
||||
" lightRange.y = gl_LightSource[0].linearAttenuation;\n"
|
||||
"\n"
|
||||
" lightVector = lightPos - vertexPos;\n"
|
||||
" pointLightDistance = length(lightVector);\n"
|
||||
" dotNormalLightDir = max(dot(fragmentNormal, normalize(lightVector)), 0.0);\n"
|
||||
" if (pointLightDistance < lightRange.y)\n"
|
||||
" {\n"
|
||||
" if (pointLightDistance < lightRange.x)\n"
|
||||
" lightAttenuation = 1.0;\n"
|
||||
" else {\n"
|
||||
" lightAttenuation = 1.0 - (pointLightDistance - lightRange.x) /\n"
|
||||
" (lightRange.y - lightRange.x);\n"
|
||||
" if (pointLightDistance > lightRange.y)\n"
|
||||
" lightAttenuation = 0.0;\n"
|
||||
" else if (pointLightDistance < lightRange.x)\n"
|
||||
" lightAttenuation = 1.0;\n"
|
||||
" else\n"
|
||||
" lightAttenuation = 1.0 - (pointLightDistance - lightRange.x) /\n"
|
||||
" (lightRange.y - lightRange.x);\n"
|
||||
"\n"
|
||||
" if (lightAttenuation > 0.0) {\n"
|
||||
" N = normalize(vertexNormal);\n"
|
||||
" NdotL = dot(N, L);\n"
|
||||
"\n"
|
||||
" if (NdotL > 0.0) {\n"
|
||||
" E = normalize(eyeVector);\n"
|
||||
" R = reflect(-L, N);\n"
|
||||
"\n"
|
||||
" lightDiffuse = diffuseTexel.a * gl_Color.a * diffuseTexel.rgb *\n"
|
||||
" gl_LightSource[0].diffuse.rgb * lightAttenuation;\n"
|
||||
" result += vec4(lightDiffuse * NdotL, 0.0);\n"
|
||||
"\n"
|
||||
" lightSpecular = pow( max(dot(R, E), 0.0), 60.0) * 10.0;\n"
|
||||
" result += vec4(lightDiffuse * lightSpecular, 0.0);\n"
|
||||
" }\n"
|
||||
" result += diffuseTexel.a * gl_Color.a * diffuseTexel * vec4(lightAttenuation * dotNormalLightDir * lightDiffuse, 0.0);\n"
|
||||
" float specular = pow( max(dot(reflect(-normalize(lightVector), fragmentNormal), normalize(-vertexPos)), 0.0), 60.0);\n"
|
||||
" result += diffuseTexel.a * gl_Color.a * diffuseTexel * vec4(lightAttenuation * specular * lightDiffuse * 10, 0.0);\n"
|
||||
" } //else { result = vec4(0.0, 1.0, 0.0, 1.0); }\n"
|
||||
"\n",
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue