@@ -345,7 +345,7 @@ struct VERTEX_OUTPUT_PBR
345
345
void _VSNormalProjection (in float3 InNormal, in float4x4 WorldTransform, inout float4 OutPosition, inout float4 OutRelPosition, inout float4 OutNormal_Light)
346
346
{
347
347
OutRelPosition.xyz = mul (OutPosition, WorldTransform).xyz - ViewerPos;
348
- OutPosition = mul (mul (mul (OutPosition, World ), View), Projection);
348
+ OutPosition = mul (mul (mul (OutPosition, WorldTransform ), View), Projection);
349
349
OutRelPosition.w = OutPosition.z;
350
350
OutNormal_Light.xyz = normalize (mul (InNormal, (float3x3 )WorldTransform).xyz);
351
351
@@ -489,18 +489,13 @@ VERTEX_OUTPUT_PBR VSSkinned(in VERTEX_INPUT_SKINNED In)
489
489
VERTEX_OUTPUT_PBR Out = (VERTEX_OUTPUT_PBR) 0 ;
490
490
491
491
_VSInstances (In.Position, In.Normal, In.Instance);
492
- float4x4 skinTransform = _VSSkinTransform (In.Joints, In.Weights);
492
+ float4x4 worldTransform = _VSSkinTransform (In.Joints, In.Weights);
493
493
494
- // Beware: Out.Position will contain Pos*World, and WorldViewProjection is uploaded as View*Projection here,
495
- // in contrast with e.g. VSGeneral, where Out.Position is just a position, and WorldViewProjection is WVP.
496
- Out.Position = mul (In.Position, skinTransform);
497
- float4 worldPosition = Out.Position;
498
- _VSNormalProjection (In.Normal, skinTransform, Out.Position, Out.RelPosition, Out.Normal_Light);
499
- Out.RelPosition.xyz = worldPosition - ViewerPos; // Need to amend the calculation of _VSNormalProjection here, because of the above.
500
- _VSLightsAndShadows (worldPosition, skinTransform, length (Out.Position.xyz), Out.Tangent.w, Out.Shadow);
501
- Out.Shadow = worldPosition; // Need to amend this as well.
494
+ Out.Position = In.Position;
495
+ _VSNormalProjection (In.Normal, worldTransform, Out.Position, Out.RelPosition, Out.Normal_Light);
496
+ _VSLightsAndShadows (Out.Position, worldTransform, length (Out.Position.xyz), Out.Tangent.w, Out.Shadow);
502
497
503
- _VSNormalMapTransform (In.Tangent, In.Normal, skinTransform , Out);
498
+ _VSNormalMapTransform (In.Tangent, In.Normal, worldTransform , Out);
504
499
505
500
// Z-bias to reduce and eliminate z-fighting on track ballast. ZBias is 0 or 1.
506
501
Out.Position.z -= ZBias_Lighting.x * saturate (In.TexCoords.x) / 1000 ;
@@ -515,12 +510,8 @@ VERTEX_OUTPUT_PBR VSMorphing(in VERTEX_INPUT_MORPHED In)
515
510
{
516
511
VERTEX_OUTPUT_PBR Out = (VERTEX_OUTPUT_PBR)0 ;
517
512
518
- float4x4 skinTransform = { 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 }; // Identity
519
- if (MorphConfig[6 ] == 1 )
520
- skinTransform = _VSSkinTransform (In.Joints, In.Weights);
513
+ float4x4 worldTransform = MorphConfig[6 ] == 1 ? _VSSkinTransform (In.Joints, In.Weights) : World;
521
514
522
- // Beware: Out.Position will contain Pos*World, and WorldViewProjection is uploaded as View*Projection here,
523
- // in contrast with e.g. VSGeneral, where Out.Position is just a position, and WorldViewProjection is WVP.
524
515
Out.Position = In.Position;
525
516
float3 normal = In.Normal;
526
517
float4 tangent = In.Tangent;
@@ -545,14 +536,10 @@ VERTEX_OUTPUT_PBR VSMorphing(in VERTEX_INPUT_MORPHED In)
545
536
Out.Color += In.MorphTargets[MorphConfig[8 ] * i + MorphConfig[5 ]] * MorphWeights[i];
546
537
}
547
538
548
- Out.Position = mul (Out.Position, skinTransform);
549
- float4 worldPosition = Out.Position;
550
- _VSNormalProjection (normal, skinTransform, Out.Position, Out.RelPosition, Out.Normal_Light);
551
- Out.RelPosition.xyz = worldPosition - ViewerPos; // Need to amend the calculation of _VSNormalProjection here, because of the above.
552
- _VSLightsAndShadows (worldPosition, skinTransform, length (Out.Position.xyz), Out.Tangent.w, Out.Shadow);
553
- Out.Shadow = worldPosition; // Need to amend this as well.
539
+ _VSNormalProjection (normal, worldTransform, Out.Position, Out.RelPosition, Out.Normal_Light);
540
+ _VSLightsAndShadows (Out.Position, worldTransform, length (Out.Position.xyz), Out.Tangent.w, Out.Shadow);
554
541
555
- _VSNormalMapTransform (tangent, normal, skinTransform , Out);
542
+ _VSNormalMapTransform (tangent, normal, worldTransform , Out);
556
543
557
544
// Z-bias to reduce and eliminate z-fighting on track ballast. ZBias is 0 or 1.
558
545
Out.Position.z -= ZBias_Lighting.x * saturate (In.TexCoords.x) / 1000 ;
0 commit comments