Elvas Tower: What abour fog and mist in OR? - Elvas Tower

Jump to content

  • 6 Pages +
  • « First
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

What abour fog and mist in OR? Rate Topic: -----

#51 User is offline   gpz 

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

Posted 02 February 2014 - 03:57 AM

I have a small concern about X1963.

There is a modified section is SkyShader.fx, PSSky() function:
// Calculate angular difference between LightVector and vertex normal, radians
float dotproduct = dot(LightVector, In.Normal);
float angleRcp = 1 / acos(dotproduct / (length(LightVector) * length(In.Normal)));


When inspecting it by fxc.exe, it turns out that the most of these equations are optimized out to a preshader, which means it is impossible to compile it in XNA4. Also, preshaders are unsupported in DX10, so this section must be optimized anyway. Reading about it on internet, turns out that acos() function is a very expensive one, and using it in a pixel shader makes it to be avoidable if at all possible. So the code can be optimized like this:
float dotproduct = dot(LightVector, normalize(In.Normal));
float angleRcp = 1 / (1 - dotproduct) / 1.57; // Pi / 2 = 1.57
It is not exactly as the above, but close enough.

The normalization of the LightVector in the end can be done in Sky.cs, at about line 260, where it is calculated, just a new line needs to be inserted:
solarDirection.Normalize();



Also the following calculations could be done outside of HLSL shader, since they are constants during the whole shader operation:
5000 / Fog.a
saturate(Fog.a / 5000)
saturate(Fog.a / 10000)

As I read everywhere, even in current DX9 preshader optimization they run on the CPU (as the preshaders are getting executed on CPU), but it doesn't work at all in XNA4, and will work, but not optimized out on DX10.


In PSClouds() function the test
if (!Overcast.y && !Overcast.z)
compiles to 6 (preshader) instructions! This could be calculated in Materials.cs, and be passed to HLSL as e.g. Overcast.w

#52 User is offline   gpz 

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

Posted 09 February 2014 - 01:06 AM

James,

With your r2013 mods, if I understand the code well, the length(In.RelPosition) is getting calculated twice in pixel shader. I'm sorry for always shouting from sideline, just you might not noticed it, because you are concentrating to the things really matter, not for these minor ones.

#53 User is offline   James Ross 

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

Posted 09 February 2014 - 03:36 AM

View Postgpz, on 09 February 2014 - 01:06 AM, said:

With your r2013 mods, if I understand the code well, the length(In.RelPosition) is getting calculated twice in pixel shader. I'm sorry for always shouting from sideline, just you might not noticed it, because you are concentrating to the things really matter, not for these minor ones.


You're always welcome to factor out code like that when you spot it. :) It's worth noting, however, that FXC (the shader compiler) is pretty good at doing things like that itself.

#54 User is offline   BB25187 

  • Fireman
  • Group: Status: Active Member
  • Posts: 138
  • Joined: 09-December 12
  • Gender:Male
  • Simulator:OpenRails MSTS
  • Country:

Posted 11 February 2014 - 11:15 AM

Hi,

View PostJames Ross, on 29 January 2014 - 08:16 AM, said:

View PostSVRy_Steve, on 29 January 2014 - 08:11 AM, said:

I've noticed that fog doesn't seem to affect smoke, which leads to some rather strange looks!

Yeah, "known bug". :negative:


I made a first attempt to improve this. The modification I implemented is pretty simple (the fading effect depends only on the fog density, not on the distance). So, this is not perfect, but this seems sufficient to limit the poor rendering illustrated by SVRy_Steve. This could be a first step for further improvements. I will attach the patch to this thread during the next week-end.

#55 User is offline   gpz 

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

Posted 11 February 2014 - 12:13 PM

BB, if you would have a bit of time, may I ask you please to confirm the optimization I proposed above for SkyShader.fx still gives the same effect as the current code?

  • 6 Pages +
  • « First
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

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