@@ -489,10 +489,6 @@ public static void SetupShadowCasterConstantBuffer(CommandBuffer cmd, ref Visibl
489
489
SetupShadowCasterConstantBuffer ( CommandBufferHelpers . GetRasterCommandBuffer ( cmd ) , ref shadowLight , shadowBias ) ;
490
490
}
491
491
492
- private static int _ShadowBias = Shader . PropertyToID ( "_ShadowBias" ) ;
493
- private static int _LightDirection = Shader . PropertyToID ( "_LightDirection" ) ;
494
- private static int _LightPosition = Shader . PropertyToID ( "_LightPosition" ) ;
495
-
496
492
internal static void SetupShadowCasterConstantBuffer ( RasterCommandBuffer cmd , ref VisibleLight shadowLight , Vector4 shadowBias )
497
493
{
498
494
SetShadowBias ( cmd , shadowBias ) ;
@@ -508,17 +504,31 @@ internal static void SetupShadowCasterConstantBuffer(RasterCommandBuffer cmd, re
508
504
509
505
internal static void SetShadowBias ( RasterCommandBuffer cmd , Vector4 shadowBias )
510
506
{
511
- cmd . SetGlobalVector ( _ShadowBias , shadowBias ) ;
507
+ cmd . SetGlobalVector ( ShaderPropertyId . shadowBias , shadowBias ) ;
512
508
}
513
509
514
510
internal static void SetLightDirection ( RasterCommandBuffer cmd , Vector3 lightDirection )
515
511
{
516
- cmd . SetGlobalVector ( _LightDirection , new Vector4 ( lightDirection . x , lightDirection . y , lightDirection . z , 0.0f ) ) ;
512
+ cmd . SetGlobalVector ( ShaderPropertyId . lightDirection , new Vector4 ( lightDirection . x , lightDirection . y , lightDirection . z , 0.0f ) ) ;
517
513
}
518
514
519
515
internal static void SetLightPosition ( RasterCommandBuffer cmd , Vector3 lightPosition )
520
516
{
521
- cmd . SetGlobalVector ( _LightPosition , new Vector4 ( lightPosition . x , lightPosition . y , lightPosition . z , 1.0f ) ) ;
517
+ cmd . SetGlobalVector ( ShaderPropertyId . lightPosition , new Vector4 ( lightPosition . x , lightPosition . y , lightPosition . z , 1.0f ) ) ;
518
+ }
519
+
520
+ internal static void SetCameraPosition ( RasterCommandBuffer cmd , Vector3 worldSpaceCameraPos )
521
+ {
522
+ cmd . SetGlobalVector ( ShaderPropertyId . worldSpaceCameraPos , worldSpaceCameraPos ) ;
523
+ }
524
+
525
+ internal static void SetWorldToCameraMatrix ( RasterCommandBuffer cmd , Matrix4x4 viewMatrix )
526
+ {
527
+ // There's an inconsistency in handedness between unity_matrixV and unity_WorldToCamera
528
+ // Unity changes the handedness of unity_WorldToCamera (see Camera::CalculateMatrixShaderProps)
529
+ // we will also change it here to avoid breaking existing shaders. (case 1257518)
530
+ Matrix4x4 worldToCameraMatrix = Matrix4x4 . Scale ( new Vector3 ( 1.0f , 1.0f , - 1.0f ) ) * viewMatrix ;
531
+ cmd . SetGlobalMatrix ( ShaderPropertyId . worldToCameraMatrix , worldToCameraMatrix ) ;
522
532
}
523
533
524
534
private static RenderTextureDescriptor GetTemporaryShadowTextureDescriptor ( int width , int height , int bits )
0 commit comments