@@ -265,9 +265,9 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]],
265
265
half3 LAmbient = half3 (0.0 , 0.0 , 0.0 );
266
266
half3 LDiffuse = half3 (0.0 , 0.0 , 0.0 );
267
267
268
- const float3 Ndirection = normalize (uniforms. localToWorldMatrix * float4 (in.normal , 0.0 )).xyz ;
268
+ const float3 Ndirection = normalize (float4 (in.normal , 0.0 ) * uniforms. localToWorldMatrix ).xyz ;
269
269
270
- float4 position = (uniforms. localToWorldMatrix * float4 (in.position , 1.0 ));
270
+ float4 position = (float4 (in.position , 1.0 ) * uniforms. localToWorldMatrix );
271
271
if (temp_hasOnlyWeight1) {
272
272
const float4 position2 = blendMatrix1 * float4 (in.position , 1.0 );
273
273
position = (in.weight1 * position) + ((1 .0f - in.weight1 ) * position2);
@@ -317,7 +317,7 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]],
317
317
abs (uniforms.invVtxAlpha - MDiffuse.a ));
318
318
319
319
out.vtxColor = half4 (material.rgb , abs (uniforms.invVtxAlpha - MDiffuse.a ));
320
- const float4 vCamPosition = uniforms. worldToCameraMatrix * position ;
320
+ const float4 vCamPosition = position * uniforms. worldToCameraMatrix ;
321
321
// out.vCamNormal = uniforms.worldToCameraMatrix * (uniforms.localToWorldMatrix * float4(in.position, 0.0));
322
322
323
323
// Fog
@@ -333,13 +333,13 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]],
333
333
}
334
334
out.fogColor .rgb = uniforms.fogColor ;
335
335
336
- const float4 normal = uniforms. worldToCameraMatrix * (uniforms.localToWorldMatrix * float4 (in.normal , 0.0 ));
336
+ const float4 normal = (uniforms.localToWorldMatrix * float4 (in.normal , 0.0 )) * uniforms. worldToCameraMatrix ;
337
337
338
338
for (size_t layer=0 ; layer<num_layers; layer++) {
339
339
(&out.texCoord1 )[layer] = uniforms.sampleLocation (layer, &in.texCoord1 , normal , vCamPosition);
340
340
}
341
341
342
- out.position = uniforms. projectionMatrix * vCamPosition ;
342
+ out.position = vCamPosition * uniforms. projectionMatrix ;
343
343
344
344
return out;
345
345
}
@@ -354,35 +354,35 @@ float3 VertexUniforms::sampleLocation(size_t index, thread float3 *texCoords, co
354
354
// Note: If we want to require newer versions of Metal/newer hardware we could pass function pointers instead of doing these ifs.
355
355
if (flags & (kMiscUseReflectionXform | kMiscUseRefractionXform )) {
356
356
matrix = cameraToWorldMatrix;
357
- matrix[3 ][ 0 ] = matrix[3 ][ 1 ] = matrix[3 ][ 2 ] = 0 ;
357
+ matrix[0 ][ 3 ] = matrix[1 ][ 3 ] = matrix[2 ][ 3 ] = 0 ;
358
358
359
359
// This is just a rotation about X of Pi/2 (y = z, z = -y),
360
360
// followed by flipping Z to reflect back towards us (z = -z).
361
361
362
362
// swap mat[1][0] and mat[2][0]
363
363
float temp;
364
- temp = matrix[0 ][ 1 ];
365
- matrix[0 ][ 1 ] = matrix[0 ][ 2 ];
366
- matrix[0 ][ 2 ] = temp;
364
+ temp = matrix[1 ][ 0 ];
365
+ matrix[1 ][ 0 ] = matrix[2 ][ 0 ];
366
+ matrix[2 ][ 0 ] = temp;
367
367
368
368
// swap mat[1][1] and mat[2][1]
369
369
temp = matrix[1 ][1 ];
370
- matrix[1 ][1 ] = matrix[1 ][ 2 ];
371
- matrix[1 ][ 2 ] = temp;
370
+ matrix[1 ][1 ] = matrix[2 ][ 1 ];
371
+ matrix[2 ][ 1 ] = temp;
372
372
373
373
// swap mat[1][2] and mat[2][2]
374
- temp = matrix[2 ][ 1 ];
375
- matrix[2 ][ 1 ] = matrix[2 ][2 ];
374
+ temp = matrix[1 ][ 2 ];
375
+ matrix[1 ][ 2 ] = matrix[2 ][2 ];
376
376
matrix[2 ][2 ] = temp;
377
377
378
378
if (flags & kMiscUseRefractionXform ) {
379
379
// Same as reflection, but then matrix = matrix * scaleMatNegateZ.
380
380
381
381
// mat[0][2] = -mat[0][2];
382
- matrix[2 ][ 0 ] = -matrix[2 ][ 0 ];
382
+ matrix[0 ][ 2 ] = -matrix[0 ][ 2 ];
383
383
384
384
// mat[1][2] = -mat[1][2];
385
- matrix[2 ][ 1 ] = -matrix[2 ][ 1 ];
385
+ matrix[1 ][ 2 ] = -matrix[1 ][ 2 ];
386
386
387
387
// mat[2][2] = -mat[2][2];
388
388
matrix[2 ][2 ] = -matrix[2 ][2 ];
@@ -398,10 +398,10 @@ float3 VertexUniforms::sampleLocation(size_t index, thread float3 *texCoords, co
398
398
matrix_float4x4 scaleMatrix = matrix_float4x4 (1.0 );
399
399
400
400
// hsVector3 camTrans(0.5f, 0.5f, 0.f);
401
- scaleMatrix[3 ][ 0 ] = 0 .5f ;
402
- scaleMatrix[3 ][ 1 ] = -0 .5f ;
401
+ scaleMatrix[0 ][ 3 ] = 0 .5f ;
402
+ scaleMatrix[1 ][ 3 ] = -0 .5f ;
403
403
404
- matrix = scaleMatrix * translationMatrix ;
404
+ matrix = translationMatrix * scaleMatrix ;
405
405
406
406
// The scale and trans move us from NDC to Screen space. We need to swap
407
407
// the Z and W coordinates so that the texture projection will divide by W
@@ -410,50 +410,50 @@ float3 VertexUniforms::sampleLocation(size_t index, thread float3 *texCoords, co
410
410
411
411
// swap mat[2][2] and mat[3][2]
412
412
temp = matrix[2 ][2 ];
413
- matrix[2 ][2 ] = matrix[2 ][ 3 ];
414
- matrix[2 ][ 3 ] = temp;
413
+ matrix[2 ][2 ] = matrix[3 ][ 2 ];
414
+ matrix[3 ][ 2 ] = temp;
415
415
416
416
// swap mat[2][3] and mat[3][3]
417
- temp = matrix[3 ][ 2 ];
418
- matrix[3 ][ 2 ] = matrix[3 ][3 ];
417
+ temp = matrix[2 ][ 3 ];
418
+ matrix[2 ][ 3 ] = matrix[3 ][3 ];
419
419
matrix[3 ][3 ] = temp;
420
420
421
421
// Multiply by the projection matrix
422
- matrix = matrix * projectionMatrix ;
422
+ matrix = projectionMatrix * matrix ;
423
423
} else if (flags & kMiscProjection ) {
424
424
matrix_float4x4 cam2World = cameraToWorldMatrix;
425
425
if ( !(UVWSrc & kUVWPosition ) ) {
426
- cam2World.columns [3 ][ 0 ] = 0 ;
427
- cam2World.columns [3 ][ 1 ] = 0 ;
428
- cam2World.columns [3 ][ 2 ] = 0 ;
426
+ cam2World.columns [0 ][ 3 ] = 0 ;
427
+ cam2World.columns [1 ][ 3 ] = 0 ;
428
+ cam2World.columns [2 ][ 3 ] = 0 ;
429
429
}
430
430
431
- matrix = matrix * cam2World ;
431
+ matrix = cam2World * matrix ;
432
432
}
433
433
434
434
float4 sampleCoord;
435
435
436
436
switch (UVWSrc) {
437
437
case kUVWNormal :
438
438
{
439
- sampleCoord = matrix * normal ;
439
+ sampleCoord = normal * matrix ;
440
440
}
441
441
break ;
442
442
case kUVWPosition :
443
443
{
444
- sampleCoord = matrix * camPosition ;
444
+ sampleCoord = camPosition * matrix ;
445
445
}
446
446
break ;
447
447
case kUVWReflect :
448
448
{
449
- sampleCoord = matrix * reflect (normalize (camPosition), normalize (normal ));
449
+ sampleCoord = reflect (normalize (camPosition), normalize (normal )) * matrix ;
450
450
}
451
451
break ;
452
452
default :
453
453
{
454
454
const int index = UVWSrc & 0x0F ;
455
455
if (index < num_uvs) {
456
- sampleCoord = matrix * float4 (texCoords[index ], 1.0 );
456
+ sampleCoord = float4 (texCoords[index ], 1.0 ) * matrix ;
457
457
} else {
458
458
// The DX engine will use a UV co-ord of 0,0 if the index is out of range
459
459
sampleCoord = float4 (0.0 );
@@ -649,13 +649,13 @@ vertex ShadowCasterInOut shadowVertexShader(Vertex in [[stage_in]],
649
649
{
650
650
ShadowCasterInOut out;
651
651
652
- const float4 vCamPosition = uniforms. worldToCameraMatrix * (uniforms. localToWorldMatrix * float4 (in.position , 1.0 )) ;
652
+ const float4 vCamPosition = ( float4 (in.position , 1.0 ) * uniforms. localToWorldMatrix ) * uniforms. worldToCameraMatrix ;
653
653
654
654
const float4x4 matrix = uniforms.uvTransforms [0 ].transform ;
655
655
656
- out.texCoord1 = (matrix * vCamPosition ).xyz ;
656
+ out.texCoord1 = (vCamPosition * matrix ).xyz ;
657
657
658
- out.position = uniforms. projectionMatrix * vCamPosition ;
658
+ out.position = vCamPosition * uniforms. projectionMatrix ;
659
659
660
660
return out;
661
661
}
0 commit comments