Elvas Tower: (uniform bool ShaderModel3) not received in _PSGetShadowEffect? - Elvas Tower

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

(uniform bool ShaderModel3) not received in _PSGetShadowEffect? Rate Topic: -----

#1 User is offline   Eldorado.Railroad 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 984
  • Joined: 31-May 10
  • Gender:Male
  • Country:

Posted 20 February 2014 - 02:03 PM

While looking at the latest SceneryShader.fx, there is a function called: float _PSGetShadowEffect(uniform bool ShaderModel3, uniform bool NormalLighting, in VERTEX_OUTPUT In) located within. Trying to add a few conditional lines of code spits out an error at runtime which suggests that there are only 64 variables to work with and that Shader Model 2 is being used and not Shader Model 3. In the registry I know that the Shader Model is set to 3.

If I do the following change from:

if (ShaderModel3)
moments = _PS3GetShadowEffect(In);
else
moments = _PS2GetShadowEffect(In);


to

if (ShaderModel3)
moments = _PS3GetShadowEffect(In);
else
moments = _PS3GetShadowEffect(In);


an error at runtime is returned suggesting that Shader Model 2 is in effect. This seemed like an easy way to prove that Shader Model 3 is not being used.

Is this "correct"? In this .fx file there is more than one function that checks the value of ShaderModel3 as a conditional.

#2 User is online   James Ross 

  • Open Rails Developer
  • Group: Status: Elite Member
  • Posts: 5,492
  • Joined: 30-June 10
  • Gender:Not Telling
  • Simulator:Open Rails
  • Country:

Posted 20 February 2014 - 02:23 PM

What graphics card are you using and what does the HUD DEBUG page say?

#3 User is offline   Eldorado.Railroad 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 984
  • Joined: 31-May 10
  • Gender:Male
  • Country:

Posted 20 February 2014 - 02:29 PM

View PostFrom 20 February 2014 - 02:23 PM:

What graphics card are you using and what does the HUD DEBUG page say?


On this machine, ATI HD 5800 series and the HUD does indicate (and OpenRailsLog.txt does say):
ShaderModel = (user set) 3

Thanks.

#4 User is online   James Ross 

  • Open Rails Developer
  • Group: Status: Elite Member
  • Posts: 5,492
  • Joined: 30-June 10
  • Gender:Not Telling
  • Simulator:Open Rails
  • Country:

Posted 21 February 2014 - 12:24 AM

Right.

So what happens (and I forgot about this last night, sorry) is that, because we have multiple shader versions that are chosen by the C# code we always compile all possible options in the .fx file. That means the ImagePS2 and ImagePS3 shaders are always both compiled. (This also means I can't break the PS2 version whilst testing the PS3 version without noticing.)

The upshot is that if you need to add debugging, or other extra statements, put them inside an "if (ShaderModel3) { ... }" block.

#5 User is offline   Eldorado.Railroad 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 984
  • Joined: 31-May 10
  • Gender:Male
  • Country:

Posted 21 February 2014 - 04:29 PM

View PostFrom 21 February 2014 - 12:24 AM:

The upshot is that if you need to add debugging, or other extra statements, put them inside an "if (ShaderModel3) { ... }" block.


So are there conditions where although Shader Model = 3 is set in the registry, uniform bool ShaderModel3 that is sent from the c# code to the .fx code will not have a value of TRUE? This is what seems to be happening and is confusing because I know that I have set the Shader Model = 3 in the registry, yet the runtime compile errors for the .fx file suggest that only Shader Model 2 is being sent, that is uniform bool ShaderModel3 = FALSE?

Hoping to avoid a face palm here...

Thanks.

#6 User is offline   gpz 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,772
  • Joined: 27-October 12
  • Gender:Male
  • Location:Budapest
  • Simulator:OpenRails
  • Country:

Posted 22 February 2014 - 03:04 AM

View PostEldorado.Railroad, on 21 February 2014 - 04:29 PM, said:

So are there conditions where although Shader Model = 3 is set in the registry, uniform bool ShaderModel3 that is sent from the c# code to the .fx code will not have a value of TRUE?

Yes, because compiler compiles both shader model 2 and 3. It only turns out at runtime (when you start the program), which part will run. So you have to make all modifications in a way that they can run (and be compiled) in both cases.

#7 User is online   James Ross 

  • Open Rails Developer
  • Group: Status: Elite Member
  • Posts: 5,492
  • Joined: 30-June 10
  • Gender:Not Telling
  • Simulator:Open Rails
  • Country:

Posted 22 February 2014 - 03:47 AM

View PostEldorado.Railroad, on 21 February 2014 - 04:29 PM, said:

So are there conditions where although Shader Model = 3 is set in the registry, uniform bool ShaderModel3 that is sent from the c# code to the .fx code will not have a value of TRUE? This is what seems to be happening and is confusing because I know that I have set the Shader Model = 3 in the registry, yet the runtime compile errors for the .fx file suggest that only Shader Model 2 is being sent, that is uniform bool ShaderModel3 = FALSE?


There's two different things going on here which we've gotten mixed up.

The uniform bool ShaderModel3 is a value (if you look at the bottom of the .fx file) which is provided for each effect. In other words, the same code is used by both the PS2 and PS3 effects - that means it gets compiled twice, once with ShaderModel3 = false and once with ShaderModel3 = true. That's what the 'uniform' keyword means - this is not dynamic input.

The dynamic part is that the C# code chooses which of ImagePS2 and ImagePS3 to use. Even though both are compiled, only one is run - in your case ImagePS3 (and for most people).

#8 User is offline   Eldorado.Railroad 

  • Foreman Of Engines
  • Group: Status: Contributing Member
  • Posts: 984
  • Joined: 31-May 10
  • Gender:Male
  • Country:

Posted 22 February 2014 - 04:57 PM

View PostFrom 22 February 2014 - 03:47 AM:

The uniform bool ShaderModel3 is a value (if you look at the bottom of the .fx file) which is provided for each effect. In other words, the same code is used by both the PS2 and PS3 effects - that means it gets compiled twice, once with ShaderModel3 = false and once with ShaderModel3 = true. That's what the 'uniform' keyword means - this is not dynamic input.

The dynamic part is that the C# code chooses which of ImagePS2 and ImagePS3 to use. Even though both are compiled, only one is run - in your case ImagePS3 (and for most people).


Oh oh....
This means that whatever you compile at runtime needs two code streams to accommodate PS2 and PS3 in the .fx file. Correct?

Therefore, if you segregate the code streams with the ShaderModel3 = true keyword, can the .fx code utilize the vastly more powerful constraints of Shader Model 3 as opposed to Shader Model 2, WITHOUT generating a runtime compile error for Shader Model 2?

Thanks for you help.

#9 User is online   James Ross 

  • Open Rails Developer
  • Group: Status: Elite Member
  • Posts: 5,492
  • Joined: 30-June 10
  • Gender:Not Telling
  • Simulator:Open Rails
  • Country:

Posted 23 February 2014 - 11:05 AM

View PostEldorado.Railroad, on 22 February 2014 - 04:57 PM, said:

Oh oh....
This means that whatever you compile at runtime needs two code streams to accommodate PS2 and PS3 in the .fx file. Correct?

Therefore, if you segregate the code streams with the ShaderModel3 = true keyword, can the .fx code utilize the vastly more powerful constraints of Shader Model 3 as opposed to Shader Model 2, WITHOUT generating a runtime compile error for Shader Model 2?


Yes, that's exactly it.

IIRC the only difference in OR currently is that shadow maps only support 1 level (i.e. not casecaded) in SM2, but SM3 supports all 4 levels.

#10 User is offline   gpz 

  • Superintendant
  • Group: Status: Elite Member
  • Posts: 1,772
  • Joined: 27-October 12
  • Gender:Male
  • Location:Budapest
  • Simulator:OpenRails
  • Country:

Posted 23 February 2014 - 11:31 AM

Steve, if you want to compile only PS3, the find all such kind of lines in your .fx:
technique ImagePS2 {
	pass Pass_0 {
		VertexShader = compile vs_2_0 VSGeneral(false);
		PixelShader = compile ps_2_0 PSImage(false);
	}
}

And replace vs_2_0 and ps_2_0 to vs_3_0 and ps_3_0. Everywhere.

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users