@@ -789,7 +789,6 @@ public bool LoadDayTexture ()
789789 public override void SetState ( GraphicsDevice graphicsDevice , Material previousMaterial )
790790 {
791791 graphicsDevice . RasterizerState = RasterizerState . CullCounterClockwise ;
792- graphicsDevice . SamplerStates [ 0 ] = SamplerState . LinearWrap ;
793792
794793 var shader = Viewer . MaterialManager . SceneryShader ;
795794 var level9_3 = Viewer . Settings . IsDirectXFeatureLevelIncluded ( ORTS . Settings . UserSettings . DirectXFeature . Level9_3 ) ;
@@ -889,8 +888,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
889888 throw new InvalidDataException ( "Options has unexpected SceneryMaterialOptions.SpecularMask value." ) ;
890889 }
891890
892- graphicsDevice . SamplerStates [ 0 ] = GetShadowTextureAddressMode ( ) ;
893-
894891 if ( NightTexture != null && NightTexture != SharedMaterialManager . MissingTexture && ( ( ( Options & SceneryMaterialOptions . UndergroundTexture ) != 0 &&
895892 ( Viewer . MaterialManager . sunDirection . Y < - 0.085f || Viewer . Camera . IsUnderground ) ) || Viewer . MaterialManager . sunDirection . Y < 0.0f - ( ( float ) KeyLengthRemainder ( ) ) / 5000f ) )
896893 {
@@ -917,6 +914,10 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
917914 shader . SetMatrix ( item . XNAMatrix , ref viewProj ) ;
918915 shader . ZBias = item . RenderPrimitive . ZBias ;
919916 ShaderPasses . Current . Apply ( ) ;
917+
918+ // SamplerStates can only be set after the ShaderPasses.Current.Apply().
919+ graphicsDevice . SamplerStates [ 0 ] = GetShadowTextureAddressMode ( ) ;
920+
920921 item . RenderPrimitive . Draw ( graphicsDevice ) ;
921922 }
922923 }
@@ -1059,8 +1060,9 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
10591060 {
10601061 var wvp = item . XNAMatrix * viewproj ;
10611062 shader . SetData ( ref wvp , item . Material . GetShadowTexture ( ) ) ;
1062- graphicsDevice . SamplerStates [ 0 ] = item . Material . GetShadowTextureAddressMode ( ) ;
10631063 ShaderPasses . Current . Apply ( ) ;
1064+ // SamplerStates can only be set after the ShaderPasses.Current.Apply().
1065+ graphicsDevice . SamplerStates [ 0 ] = item . Material . GetShadowTextureAddressMode ( ) ;
10641066 item . RenderPrimitive . Draw ( graphicsDevice ) ;
10651067 }
10661068 }
0 commit comments