Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -2080,6 +2080,11 @@ |
2081 | 2081 | return (a[0]*b[0])+(a[1]*b[1])+(a[2]*b[2]);
|
2082 | 2082 | }
|
2083 | 2083 |
|
| 2084 | +inline float len3(float in[3])
|
| 2085 | +{
|
| 2086 | + return sqrt((in[0]*in[0])+(in[1]*in[1])+(in[2]*in[2]));
|
| 2087 | +}
|
| 2088 | +
|
2084 | 2089 | INT glDirect3DDevice7::TransformAndLight(D3DTLVERTEX **output, DWORD *outsize, D3DVERTEX *input, WORD start, WORD dest, DWORD count, D3DRECT *extents)
|
2085 | 2090 | {
|
2086 | 2091 | D3DVALUE dir[3];
|
— | — | @@ -2094,7 +2099,11 @@ |
2095 | 2100 | D3DCOLORVALUE color1;
|
2096 | 2101 | D3DCOLORVALUE color2;
|
2097 | 2102 | D3DVALUE NdotHV;
|
| 2103 | + D3DVALUE NdotV;
|
2098 | 2104 | D3DVALUE NdotL;
|
| 2105 | + D3DVALUE length;
|
| 2106 | + D3DVALUE attenuation;
|
| 2107 | + D3DVALUE pf;
|
2099 | 2108 | in[3] = 1.0f;
|
2100 | 2109 | if(transform_dirty) UpdateTransform();
|
2101 | 2110 | if(*outsize < (dest+count)*sizeof(D3DTLVERTEX))
|
— | — | @@ -2124,6 +2133,7 @@ |
2125 | 2134 | {
|
2126 | 2135 | if(gllights[l] != -1)
|
2127 | 2136 | {
|
| 2137 | + AddD3DCV(&ambient,&lights[gllights[l]]->light.dcvAmbient);
|
2128 | 2138 | switch(lights[gllights[l]]->light.dltType)
|
2129 | 2139 | {
|
2130 | 2140 | case D3DLIGHT_DIRECTIONAL:
|
— | — | @@ -2130,7 +2140,6 @@ |
2131 | 2141 | NdotHV = 0;
|
2132 | 2142 | memcpy(dir,&lights[gllights[l]]->light.dvDirection,3*sizeof(D3DVALUE));
|
2133 | 2143 | normalize(dir);
|
2134 | | - AddD3DCV(&ambient,&lights[gllights[l]]->light.dcvAmbient);
|
2135 | 2144 | NdotL = max(dot3((float*)&input[i+start].dvNX,(float*)&dir),0.0f);
|
2136 | 2145 | color1 = lights[gllights[l]]->light.dcvDiffuse;
|
2137 | 2146 | MulD3DCVFloat(&color1,NdotL);
|
— | — | @@ -2138,7 +2147,7 @@ |
2139 | 2148 | if((NdotL > 0.0) && (material.dvPower != 0.0))
|
2140 | 2149 | {
|
2141 | 2150 | __gluMultMatrixVecf(matWorld,&input[i+start].dvX,P);
|
2142 | | - memcpy(L ,&lights[gllights[l]]->light.dvDirection,3*sizeof(D3DVALUE));
|
| 2151 | + memcpy(L,&lights[gllights[l]]->light.dvDirection,3*sizeof(D3DVALUE));
|
2143 | 2152 | NegativeVec3(L);
|
2144 | 2153 | SubVec3(L,P);
|
2145 | 2154 | normalize(L);
|
— | — | @@ -2153,6 +2162,27 @@ |
2154 | 2163 | }
|
2155 | 2164 | break;
|
2156 | 2165 | case D3DLIGHT_POINT:
|
| 2166 | + __gluMultMatrixVecf(matWorld,&input[i+start].dvX,P);
|
| 2167 | + memcpy(V,&lights[gllights[l]]->light.dvPosition,3*sizeof(D3DVALUE));
|
| 2168 | + SubVec3(V,P);
|
| 2169 | + length = len3(V);
|
| 2170 | + if((length > lights[gllights[l]]->light.dvRange) && (lights[gllights[l]]->light.dvRange != 0.0)) continue;
|
| 2171 | + normalize(V);
|
| 2172 | + attenuation = 1.0/(lights[gllights[l]]->light.dvAttenuation0+(length*lights[gllights[l]]->light.dvAttenuation1)
|
| 2173 | + +((length*length)*lights[gllights[l]]->light.dvAttenuation2));
|
| 2174 | + NdotV = max(0.0,dot3((float*)&input[i+start].dvNX,V));
|
| 2175 | + AddVec3(V,eye);
|
| 2176 | + normalize(V);
|
| 2177 | + NdotHV = max(0.0,dot3((float*)&input[i+start].dvNX,V));
|
| 2178 | + if(NdotV == 0.0) pf = 0.0;
|
| 2179 | + else if(material.dvPower != 0.0) pf = pow(NdotHV,material.dvPower);
|
| 2180 | + else pf = 0.0;
|
| 2181 | + color1 = lights[gllights[l]]->light.dcvDiffuse;
|
| 2182 | + MulD3DCVFloat(&color1,NdotV*attenuation);
|
| 2183 | + AddD3DCV(&diffuse,&color1);
|
| 2184 | + color1 = lights[gllights[l]]->light.dcvSpecular;
|
| 2185 | + MulD3DCVFloat(&color1,pf*attenuation);
|
| 2186 | + AddD3DCV(&specular,&color1);
|
2157 | 2187 | break;
|
2158 | 2188 | case D3DLIGHT_SPOT:
|
2159 | 2189 | break;
|
Index: ddraw/shadergen.cpp |
— | — | @@ -339,6 +339,7 @@ |
340 | 340 | }\n";
|
341 | 341 | static const char func_pointlight[] = "void PointLight(in Light light)\n\
|
342 | 342 | {\n\
|
| 343 | +ambient += light.ambient;\n\
|
343 | 344 | vec4 pos = matWorld*xyzw;\n\
|
344 | 345 | vec3 pos3 = pos.xyz / pos.w;\n\
|
345 | 346 | vec3 V = light.position - pos3;\n\
|
— | — | @@ -353,7 +354,6 @@ |
354 | 355 | else if(gl_FrontMaterial.shininess > 0.0) pf = pow(NdotHV,gl_FrontMaterial.shininess);\n\
|
355 | 356 | else pf = 0.0;\n\
|
356 | 357 | diffuse += light.diffuse*NdotV*attenuation;\n\
|
357 | | -ambient += light.ambient;\n\
|
358 | 358 | specular += light.specular*pf*attenuation;\n\
|
359 | 359 | }\n";
|
360 | 360 | static const char func_spotlight[] = "void SpotLight(in Light light)\n\
|