Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -636,7 +636,7 @@ |
637 | 637 | GLfloat tmp[16];
|
638 | 638 | ZeroMemory(&worldview,sizeof(D3DMATRIX));
|
639 | 639 | ZeroMemory(&tmp,sizeof(D3DMATRIX));
|
640 | | - __gluMultMatricesf(matWorld,matView,worldview); // Get worldview
|
| 640 | + __gluMultMatricesf(matView,matWorld,worldview); // Get worldview
|
641 | 641 | if(__gluInvertMatrixf(worldview,tmp)) // Invert
|
642 | 642 | memcpy(matNormal,tmp,16*sizeof(GLfloat));
|
643 | 643 | else memcpy(matNormal,worldview,16*sizeof(GLfloat));
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -98,11 +98,11 @@ |
99 | 99 | glDirect3DLight **lights;
|
100 | 100 | int gllights[8];
|
101 | 101 | glDirectDrawSurface7 *glDDS7;
|
| 102 | + DWORD renderstate[153];
|
102 | 103 |
|
103 | 104 | private:
|
104 | 105 | glDirect3D7 *glD3D7;
|
105 | 106 | ULONG refcount;
|
106 | | - DWORD renderstate[153];
|
107 | 107 | GLuint gltextures[8];
|
108 | 108 | DWORD lightsmax;
|
109 | 109 | bool inscene;
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | #include "ddraw.h"
|
28 | 28 | #include "scalers.h"
|
29 | 29 | #include "shadergen.h"
|
| 30 | +#include "matrix.h"
|
30 | 31 |
|
31 | 32 | WNDCLASSEXA wndclass;
|
32 | 33 | bool wndclasscreated = false;
|
— | — | @@ -1033,6 +1034,7 @@ |
1034 | 1035 | void glRenderer::_DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
1035 | 1036 | LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
1036 | 1037 | {
|
| 1038 | + GLfloat tmpmat[16];
|
1037 | 1039 | bool transformed;
|
1038 | 1040 | int normalptr = 0;
|
1039 | 1041 | int colorptr[2] = {0,0};
|
— | — | @@ -1165,11 +1167,14 @@ |
1166 | 1168 | }
|
1167 | 1169 | if(device->normal_dirty) device->UpdateNormalMatrix();
|
1168 | 1170 | GLint loc = glGetUniformLocation(prog,"world");
|
1169 | | - glUniformMatrix4fv(loc,1,false,device->matWorld);
|
| 1171 | + viewLHtoRH(tmpmat,device->matWorld);
|
| 1172 | + glUniformMatrix4fv(loc,1,false,tmpmat);
|
1170 | 1173 | loc = glGetUniformLocation(prog,"view");
|
1171 | | - glUniformMatrix4fv(loc,1,false,device->matView);
|
| 1174 | + viewLHtoRH(tmpmat,device->matView);
|
| 1175 | + glUniformMatrix4fv(loc,1,false,tmpmat);
|
1172 | 1176 | loc = glGetUniformLocation(prog,"projection");
|
1173 | | - glUniformMatrix4fv(loc,1,false,device->matProjection);
|
| 1177 | + prjLHtoRH(tmpmat,device->matProjection);
|
| 1178 | + glUniformMatrix4fv(loc,1,false,tmpmat);
|
1174 | 1179 | loc = glGetUniformLocation(prog,"normalmat");
|
1175 | 1180 | glUniformMatrix4fv(loc,1,true,device->matNormal);
|
1176 | 1181 | loc = glGetUniformLocation(prog,"material.diffuse");
|
— | — | @@ -1182,6 +1187,10 @@ |
1183 | 1188 | glUniform4fv(loc,1,(GLfloat*)&device->material.emissive);
|
1184 | 1189 | loc = glGetUniformLocation(prog,"material.power");
|
1185 | 1190 | glUniform1f(loc,device->material.power);
|
| 1191 | + loc = glGetUniformLocation(prog,"ambientcolor");
|
| 1192 | + DWORD ambient = device->renderstate[D3DRENDERSTATE_AMBIENT];
|
| 1193 | + glUniform4f(loc,RGBA_GETRED(ambient),RGBA_GETGREEN(ambient),
|
| 1194 | + RGBA_GETBLUE(ambient),RGBA_GETALPHA(ambient));
|
1186 | 1195 | int lightindex = 0;
|
1187 | 1196 | char lightname[] = "lightX.xxxxxxxxxxxxxxxx";
|
1188 | 1197 | for(i = 0; i < 8; i++)
|
Index: ddraw/matrix.cpp |
— | — | @@ -46,10 +46,34 @@ |
47 | 47 | * other dealings in this Software without prior written authorization from
|
48 | 48 | * Silicon Graphics, Inc.
|
49 | 49 | */
|
50 | | -
|
| 50 | +// Portions of this file are from the dxglwrap project, and are licensed under
|
| 51 | +// the following terms:
|
| 52 | +/*
|
| 53 | + *
|
| 54 | + * dxglwrapper 0.08 - Sept. 12, 2002
|
| 55 | + * For conditions of distribution and use, see copyright notice in d3dprj.h
|
| 56 | + * Copyright (c) 1991-2002 realtech VR
|
| 57 | + *
|
| 58 | + * Copyright (c) 2002 realtech VR
|
| 59 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
| 60 | + * and associated documentation files (the "Software"), to deal in the Software without
|
| 61 | + * restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
| 62 | + * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
| 63 | + * Software is furnished to do so, subject to the following conditions:
|
| 64 | + * The above copyright notice and this permission notice shall be included in all copies or
|
| 65 | + * substantial portions of the Software.
|
| 66 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
| 67 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 68 | + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
| 69 | + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
| 70 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 71 | + * DEALINGS IN THE SOFTWARE.
|
| 72 | + *
|
| 73 | + */
|
51 | 74 | #include "common.h"
|
52 | 75 | #include "matrix.h"
|
53 | 76 |
|
| 77 | +// From project.c:
|
54 | 78 | /*
|
55 | 79 | ** Invert 4x4 matrix.
|
56 | 80 | ** Contributed by David Moore (See Mesa bug #6748)
|
— | — | @@ -128,3 +152,39 @@ |
129 | 153 | m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
|
130 | 154 | m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
|
131 | 155 | }
|
| 156 | +
|
| 157 | +
|
| 158 | +// from dxglwrap:
|
| 159 | +/*
|
| 160 | +
|
| 161 | + This is one basic difference between OpenGL and Direct3D.
|
| 162 | + In both coordinate systems, the X and Y axis are as normal.
|
| 163 | + The Y positive axis going upwards and the X positive axis going to the right.
|
| 164 | +
|
| 165 | + However, the two systems differ in their Z-axis implementation.
|
| 166 | + A Left-Handed System, which Direct3D uses, is one where the Z-axis is positive INTO the screen.
|
| 167 | + Take your Left Hand, face the palm upwards with your fingers pointing in the direction of the positive x-axis (to the right), and curl your fingers in the direction of the Y-positive axis (up). Now if you stick your thumb STRAIGHT (like you were giving a sideways "thumbs-up" sign), your thumb is now pointing in the direction of the positive Z-axis.
|
| 168 | +
|
| 169 | + OpenGL, on the other hand, uses a Right-Handed system, where the positive Z-axis is coming OUT of the screen.
|
| 170 | + Again, to remember this, take your right hand, point your palm upwards and your fingers pointing in the direction of the positive x-axis
|
| 171 | + (to the right). Now curl your fingers up to the direction of the positive y-axis (up), and point your thumb out. It is now pointing in the direction of the positive Z-axis (out)..
|
| 172 | +
|
| 173 | + Note: no doc exists how to do the conversion
|
| 174 | +*/
|
| 175 | +
|
| 176 | +
|
| 177 | +void prjLHtoRH(float *d, const float *s) // Exclusive function
|
| 178 | +{
|
| 179 | + d[0] = -s[0]; d[1] = -s[1]; d[2] = -s[2]; d[3] = -s[3];
|
| 180 | + d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
|
| 181 | + d[8] = -s[8]; d[9] = -s[9]; d[10] = -s[10]; d[11] = -s[11];
|
| 182 | + d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
|
| 183 | +}
|
| 184 | +
|
| 185 | +void viewLHtoRH(float *d, const float *s)
|
| 186 | +{
|
| 187 | + d[0] = -s[0]; d[1] = s[1]; d[2] = -s[2]; d[3] = s[3];
|
| 188 | + d[4] = -s[4]; d[5] = s[5]; d[6] = -s[6]; d[7] = s[7];
|
| 189 | + d[8] = -s[8]; d[9] = s[9]; d[10] = -s[10]; d[11] = s[11];
|
| 190 | + d[12] = -s[12]; d[13] = s[13]; d[14] = -s[14]; d[15] = s[15];
|
| 191 | +}
|
Index: ddraw/matrix.h |
— | — | @@ -46,6 +46,30 @@ |
47 | 47 | * other dealings in this Software without prior written authorization from
|
48 | 48 | * Silicon Graphics, Inc.
|
49 | 49 | */
|
| 50 | +// Portions of this file are from the dxglwrap project, and are licensed under
|
| 51 | +// the following terms:
|
| 52 | +/*
|
| 53 | + *
|
| 54 | + * dxglwrapper 0.08 - Sept. 12, 2002
|
| 55 | + * For conditions of distribution and use, see copyright notice in d3dprj.h
|
| 56 | + * Copyright (c) 1991-2002 realtech VR
|
| 57 | + *
|
| 58 | + * Copyright (c) 2002 realtech VR
|
| 59 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
| 60 | + * and associated documentation files (the "Software"), to deal in the Software without
|
| 61 | + * restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
| 62 | + * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
| 63 | + * Software is furnished to do so, subject to the following conditions:
|
| 64 | + * The above copyright notice and this permission notice shall be included in all copies or
|
| 65 | + * substantial portions of the Software.
|
| 66 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
| 67 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 68 | + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
| 69 | + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
| 70 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 71 | + * DEALINGS IN THE SOFTWARE.
|
| 72 | + *
|
| 73 | + */
|
50 | 74 | #pragma once
|
51 | 75 | #ifndef _MATRIX_H
|
52 | 76 | #define _MATRIX_H
|
— | — | @@ -55,4 +79,7 @@ |
56 | 80 | GLfloat r[16]);
|
57 | 81 | void __gluMakeIdentityf(GLfloat m[16]);
|
58 | 82 |
|
| 83 | +void prjLHtoRH(float *d, const float *s);
|
| 84 | +void viewLHtoRH(float *d, const float *s);
|
| 85 | +
|
59 | 86 | #endif //_MATRIX_H |
\ No newline at end of file |
Index: ddraw/shadergen.cpp |
— | — | @@ -215,6 +215,7 @@ |
216 | 216 | float phi;\n\
|
217 | 217 | };\n";
|
218 | 218 | static const char unif_light[] = "uniform Light lightX;\n";
|
| 219 | +static const char unif_ambient[] = "uniform vec4 ambientcolor;\n";
|
219 | 220 | // Variables
|
220 | 221 | static const char var_colors[] = "vec4 diffuse;\n\
|
221 | 222 | vec4 specular;\n\
|
— | — | @@ -225,7 +226,8 @@ |
226 | 227 | static const char op_transform[] = "xyzw = vec4(xyz,1);\n\
|
227 | 228 | gl_Position = (projection*(view*world))*xyzw;\n";
|
228 | 229 | static const char op_passthru[] = "gl_Position = xyzw;\n";
|
229 | | -static const char op_resetcolor[] = "diffuse = specular = ambient = vec4(0.0);\n";
|
| 230 | +static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
|
| 231 | +ambient = ambientcolor / 255.0;\n";
|
230 | 232 | static const char op_dirlight[] = "DirLight(lightX);\n";
|
231 | 233 | static const char op_spotlight[] = "SpotLight(lightX);\n";
|
232 | 234 | static const char op_colorout[] = "vec4 color = (material.diffuse * diffuse) + (material.ambient * ambient) + \n\
|
— | — | @@ -238,7 +240,7 @@ |
239 | 241 | static const char func_dirlight[] = "void DirLight(in Light light)\n\
|
240 | 242 | {\n\
|
241 | 243 | float NdotHV = 0.0;\n\
|
242 | | -vec3 N = normalize(vec3(normalmat*vec4(nxyz,0.0)));\n\
|
| 244 | +vec3 N = normalize(vec3(normalmat*vec4(nxyz,1.0)));\n\
|
243 | 245 | vec3 dir = normalize(light.direction);\n\
|
244 | 246 | ambient += light.ambient;\n\
|
245 | 247 | float NdotL = max(dot(N,dir),0.0);\n\
|
— | — | @@ -246,11 +248,12 @@ |
247 | 249 | if(NdotL > 0.0)\n\
|
248 | 250 | {\n\
|
249 | 251 | vec3 eye = (-view[3].xyz / view[3].w);\n\
|
250 | | -vec3 P = vec3((world*view)*xyzw);\n\
|
| 252 | +vec3 P = vec3((view*world)*xyzw);\n\
|
251 | 253 | vec3 L = normalize(light.direction.xyz - P);\n\
|
252 | 254 | vec3 V = normalize(eye - P);\n\
|
253 | 255 | NdotHV = max(dot(N,L+V),0.0);\n\
|
254 | | -specular += pow(NdotHV,float(material.power));\n\
|
| 256 | +specular += (pow(NdotHV,float(material.power))*light.specular);\n\
|
| 257 | +ambient += light.ambient;\n\
|
255 | 258 | }\n\
|
256 | 259 | }\n";
|
257 | 260 |
|
— | — | @@ -303,6 +306,7 @@ |
304 | 307 | // Uniforms
|
305 | 308 | vsrc->append(unif_matrices); // Material
|
306 | 309 | vsrc->append(unif_material);
|
| 310 | + vsrc->append(unif_ambient);
|
307 | 311 | numlights = (id>>18)&7;
|
308 | 312 | if(numlights) // Lighting
|
309 | 313 | {
|