| Index: ddraw/glRenderer.cpp |
| — | — | @@ -1031,13 +1031,6 @@ |
| 1032 | 1032 | wndbusy = false;
|
| 1033 | 1033 | return;
|
| 1034 | 1034 | }
|
| 1035 | | - if(dwVertexTypeDesc & D3DFVF_XYZB1)
|
| 1036 | | - {
|
| 1037 | | - outputs[0] = (void*)DDERR_GENERIC;
|
| 1038 | | - wndbusy = false;
|
| 1039 | | - FIXME("glDirect3DDevice::DrawIndexedPrimitive: D3DFVF_XYZB1 stub");
|
| 1040 | | - return;
|
| 1041 | | - }
|
| 1042 | 1035 | SetShader(device->SelectShader(dwVertexTypeDesc),NULL,0);
|
| 1043 | 1036 |
|
| 1044 | 1037 | FIXME("glDirect3DDevice::DrawIndexedPrimitive: stub");
|
| Index: ddraw/shadergen.cpp |
| — | — | @@ -174,12 +174,9 @@ |
| 175 | 175 | static const char mainend[] = "} ";
|
| 176 | 176 | // Attributes
|
| 177 | 177 | static const char attr_xyz[] = "attribute vec3 xyz;\n";
|
| 178 | | -static const char conv_xyz[] = "vec4 xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n";
|
| 179 | 178 | static const char attr_xyzw[] = "attribute vec4 xyzw;\n";
|
| 180 | 179 | static const char attr_nxyz[] = "attribute vec3 nxyz;\n";
|
| 181 | 180 | static const char attr_blend[] = "attribute float blendX;\n";
|
| 182 | | -static const char attr_rgb[] = "attribute vec3 rgbX;\n";
|
| 183 | | -static const char conv_rgb[] = "vec4 rgbaX = vec4(rgbX[0],rgbX[1],rgbX[2],1);\n";
|
| 184 | 181 | static const char attr_rgba[] = "attribute vec4 rgbaX;\n";
|
| 185 | 182 | static const char attr_s[] = "attribute float sX;\n";
|
| 186 | 183 | static const char conv_s[] = "vec4 strqX = vec4(sX,0,0,1);\n";
|
| — | — | @@ -189,16 +186,16 @@ |
| 190 | 187 | static const char conv_str[] = "vec4 strqX = vec4(strX[0],strX[1],strX[2],1);\n";
|
| 191 | 188 | static const char attr_strq[] = "attribute vec4 strqX;\n";
|
| 192 | 189 | // Uniforms
|
| 193 | | -static const char unif_mats[] = "uniform mat4 world;\n\
|
| | 190 | +static const char unif_matrices[] = "uniform mat4 world;\n\
|
| 194 | 191 | uniform mat4 view;\n\
|
| 195 | | -uniform mat4 projection;\n";
|
| 196 | | -static const char modelview[] = "mat4 modelview = world * view;\n";
|
| | 192 | +uniform mat4 projection;\n\
|
| | 193 | +uniform mat4 normalmat;\n";
|
| 197 | 194 | static const char unif_material[] = "struct Material\n\
|
| 198 | 195 | {\n\
|
| 199 | 196 | vec4 diffuse;\n\
|
| 200 | 197 | vec4 ambient;\n\
|
| 201 | 198 | vec4 specular;\n\
|
| 202 | | -vec4 emussive;\n\
|
| | 199 | +vec4 emissive;\n\
|
| 203 | 200 | int power;\n\
|
| 204 | 201 | };\n\
|
| 205 | 202 | uniform Material material;\n";
|
| — | — | @@ -218,13 +215,49 @@ |
| 219 | 216 | float phi;\n\
|
| 220 | 217 | };\n";
|
| 221 | 218 | static const char unif_light[] = "uniform Light lightX;\n";
|
| | 219 | +// Variables
|
| | 220 | +static const char var_colors[] = "vec4 diffuse;\n\
|
| | 221 | +vec4 specular;\n\
|
| | 222 | +vec4 ambient;\n";
|
| | 223 | +static const char var_xyzw[] = "vec4 xyzw;\n";
|
| 222 | 224 | // Operations
|
| 223 | | -static const char normalize[] = "vec3 N = normalize(vec3(modelview*vec4(nxyz,0.0)));\n";
|
| | 225 | +static const char op_transform[] = "xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n\
|
| | 226 | +gl_Position = ((world*view)*projection)*xyzw;\n";
|
| | 227 | +static const char op_passthru[] = "gl_Position = xyzw;\n";
|
| | 228 | +static const char op_resetcolor[] = "diffuse = specular = ambient = vec4(0.0);\n";
|
| | 229 | +static const char op_dirlight[] = "DirLight(lightX);\n";
|
| | 230 | +static const char op_spotlight[] = "SpotLight(lightX);\n";
|
| | 231 | +static const char op_colorout[] = "vec4 color = (material.diffuse * diffuse) + (material.ambient * ambient) + \n\
|
| | 232 | +(material.specular * specular) + material.emissive;\n";
|
| 224 | 233 |
|
| | 234 | +// Functions
|
| | 235 | +static const char func_dirlight[] = "void DirLight(in Light light)\n\
|
| | 236 | +{\n\
|
| | 237 | +float NdotHV = 0.0;\n\
|
| | 238 | +vec3 N = normalize(vec3(normalmat*vec4(nxyz,0.0)));\n\
|
| | 239 | +vec3 dir = normalize(light.direction);\n\
|
| | 240 | +ambient += light.ambient;\n\
|
| | 241 | +float NdotL = max(dot(N,dir),0.0);\n\
|
| | 242 | +diffuse += light.diffuse*NdotL;\n\
|
| | 243 | +if(NdotL > 0.0)\n\
|
| | 244 | +{\n\
|
| | 245 | +vec3 eye = (-view[3].xyz / view[3].w);\n\
|
| | 246 | +vec3 P = vec3((world*view)*xyzw);\n\
|
| | 247 | +vec3 L = normalize(light.position.xyz - P);\n\
|
| | 248 | +vec3 V = normalize(eye - P);\n\
|
| | 249 | +NdotHV = max(dot(N,L+V),0.0);\n\
|
| | 250 | +specular += pow(NdotHV,float(material.power));\n\
|
| | 251 | +}\n\
|
| | 252 | +}\n";
|
| | 253 | +
|
| 225 | 254 | void CreateShader(int index, __int64 id, TexState *texstate)
|
| 226 | 255 | {
|
| 227 | 256 | string tmp;
|
| 228 | 257 | int i;
|
| | 258 | + bool hasdir = false;
|
| | 259 | + bool hasspot = false;
|
| | 260 | + int count;
|
| | 261 | + int numlights;
|
| 229 | 262 | char idstring[22];
|
| 230 | 263 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
| 231 | 264 | idstring[21] = 0;
|
| — | — | @@ -238,23 +271,89 @@ |
| 239 | 272 | vsrc->append(idheader);
|
| 240 | 273 | vsrc->append(idstring);
|
| 241 | 274 | //Variables
|
| 242 | | - vsrc->append(unif_mats);
|
| | 275 | + // Attributes
|
| | 276 | + if((id>>34)&1) vsrc->append(attr_xyzw);
|
| | 277 | + else vsrc->append(attr_xyz);
|
| | 278 | + tmp = attr_rgba;
|
| | 279 | + if((id>>35)&1)
|
| | 280 | + {
|
| | 281 | + tmp.replace(19,1,"0");
|
| | 282 | + vsrc->append(tmp);
|
| | 283 | + }
|
| | 284 | + if((id>>36)&1)
|
| | 285 | + {
|
| | 286 | + tmp.replace(19,1,"1");
|
| | 287 | + vsrc->append(tmp);
|
| | 288 | + }
|
| | 289 | + if((id>>37)&1) vsrc->append(attr_nxyz);
|
| | 290 | + count = (id>>46)&7;
|
| | 291 | + if(count)
|
| | 292 | + {
|
| | 293 | + tmp = attr_blend;
|
| | 294 | + for(i = 0; i < count; i++)
|
| | 295 | + {
|
| | 296 | + tmp.replace(21,1,_itoa(i,idstring,10));
|
| | 297 | + vsrc->append(tmp);
|
| | 298 | + }
|
| | 299 | + }
|
| | 300 | +
|
| | 301 | + // Uniforms
|
| | 302 | + vsrc->append(unif_matrices); // Material
|
| 243 | 303 | vsrc->append(unif_material);
|
| 244 | | - if((id>>15)&8) // Lighting
|
| | 304 | + numlights = (id>>18)&7;
|
| | 305 | + if(numlights) // Lighting
|
| 245 | 306 | {
|
| 246 | 307 | vsrc->append(lightstruct);
|
| 247 | | - for(i = 0; i < ((id>>15)&8); i++)
|
| | 308 | + tmp = unif_light;
|
| | 309 | + for(i = 0; i < numlights; i++)
|
| 248 | 310 | {
|
| 249 | | - tmp = unif_light;
|
| 250 | 311 | tmp.replace(19,1,_itoa(i,idstring,10));
|
| 251 | 312 | vsrc->append(tmp);
|
| 252 | 313 | }
|
| 253 | 314 | }
|
| 254 | 315 |
|
| | 316 | + // Variables
|
| | 317 | + vsrc->append(var_colors);
|
| | 318 | + if(!((id>>34)&1)) vsrc->append(var_xyzw);
|
| | 319 | +
|
| | 320 | + // Functions
|
| | 321 | + if(numlights)
|
| | 322 | + {
|
| | 323 | + for(i = 0; i < numlights; i++)
|
| | 324 | + {
|
| | 325 | + if(id>>(38+i)&1) hasspot = true;
|
| | 326 | + else hasdir = true;
|
| | 327 | + }
|
| | 328 | + }
|
| | 329 | + if(hasspot) FIXME("Add spot lights");
|
| | 330 | + if(hasdir) vsrc->append(func_dirlight);
|
| 255 | 331 | //Main
|
| 256 | 332 | vsrc->append(mainstart);
|
| 257 | | -
|
| 258 | | -
|
| | 333 | + if((id>>34)&1) vsrc->append(op_passthru);
|
| | 334 | + else vsrc->append(op_transform);
|
| | 335 | + vsrc->append(op_resetcolor);
|
| | 336 | + if(numlights)
|
| | 337 | + {
|
| | 338 | + for(i = 0; i < numlights; i++)
|
| | 339 | + {
|
| | 340 | + if(id>>(38+i)&1)
|
| | 341 | + {
|
| | 342 | + tmp = op_spotlight;
|
| | 343 | + tmp.replace(15,1,_itoa(i,idstring,10));
|
| | 344 | + vsrc->append(tmp);
|
| | 345 | + }
|
| | 346 | + else
|
| | 347 | + {
|
| | 348 | + tmp = op_dirlight;
|
| | 349 | + tmp.replace(14,1,_itoa(i,idstring,10));
|
| | 350 | + vsrc->append(tmp);
|
| | 351 | + }
|
| | 352 | + }
|
| | 353 | + }
|
| | 354 | + vsrc->append(op_colorout);
|
| 259 | 355 | vsrc->append(mainend);
|
| 260 | | -
|
| | 356 | +#ifdef _DEBUG
|
| | 357 | + OutputDebugStringA("Vertex shader:\n");
|
| | 358 | + OutputDebugStringA(vsrc->c_str());
|
| | 359 | +#endif
|
| 261 | 360 | }
|