@@ -786,7 +786,6 @@ public bool LoadDayTexture ()
786786 public override void SetState ( GraphicsDevice graphicsDevice , Material previousMaterial )
787787 {
788788 graphicsDevice . RasterizerState = RasterizerState . CullCounterClockwise ;
789- graphicsDevice . SamplerStates [ 0 ] = SamplerState . LinearWrap ;
790789
791790 var shader = Viewer . MaterialManager . SceneryShader ;
792791 var level9_3 = Viewer . Settings . IsDirectXFeatureLevelIncluded ( ORTS . Settings . UserSettings . DirectXFeature . Level9_3 ) ;
@@ -886,8 +885,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
886885 throw new InvalidDataException ( "Options has unexpected SceneryMaterialOptions.SpecularMask value." ) ;
887886 }
888887
889- graphicsDevice . SamplerStates [ 0 ] = GetShadowTextureAddressMode ( ) ;
890-
891888 if ( NightTexture != null && NightTexture != SharedMaterialManager . MissingTexture && ( ( ( Options & SceneryMaterialOptions . UndergroundTexture ) != 0 &&
892889 ( Viewer . MaterialManager . sunDirection . Y < - 0.085f || Viewer . Camera . IsUnderground ) ) || Viewer . MaterialManager . sunDirection . Y < 0.0f - ( ( float ) KeyLengthRemainder ( ) ) / 5000f ) )
893890 {
@@ -914,6 +911,10 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
914911 shader . SetMatrix ( item . XNAMatrix , ref viewProj ) ;
915912 shader . ZBias = item . RenderPrimitive . ZBias ;
916913 ShaderPasses . Current . Apply ( ) ;
914+
915+ // SamplerStates can only be set after the ShaderPasses.Current.Apply().
916+ graphicsDevice . SamplerStates [ 0 ] = GetShadowTextureAddressMode ( ) ;
917+
917918 item . RenderPrimitive . Draw ( graphicsDevice ) ;
918919 }
919920 }
@@ -1056,8 +1057,9 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
10561057 {
10571058 var wvp = item . XNAMatrix * viewproj ;
10581059 shader . SetData ( ref wvp , item . Material . GetShadowTexture ( ) ) ;
1059- graphicsDevice . SamplerStates [ 0 ] = item . Material . GetShadowTextureAddressMode ( ) ;
10601060 ShaderPasses . Current . Apply ( ) ;
1061+ // SamplerStates can only be set after the ShaderPasses.Current.Apply().
1062+ graphicsDevice . SamplerStates [ 0 ] = item . Material . GetShadowTextureAddressMode ( ) ;
10611063 item . RenderPrimitive . Draw ( graphicsDevice ) ;
10621064 }
10631065 }
0 commit comments