Guest User

Untitled

a guest
May 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. #include "EngineScripts.wpk\GlobalScriptBase.ws"
  2.  
  3. const float my_PI = 3.1415926535f;
  4. const float duration = 5.0f;
  5.  
  6. class Cubes_Sun : GlobalScriptBase
  7. {
  8.  
  9. WContentMark@ SunPoint;
  10. WContentMark@ SunLight;
  11. WContentMark@ SunRing;
  12. WFile@ DirLight;
  13. WFile@ SceneLight ;
  14. Vect4Property@ SunColor;
  15. Vect4Property@ SceneColor;
  16. float distance;
  17. float oldTime;
  18.  
  19. void OnLoad()
  20. {
  21. AdjustDuration();
  22. oldTime = 0;
  23. @SunPoint = FindContentMark("SunPoint");
  24. @SunLight = FindContentMark("SunLight");
  25. @SunRing = FindContentMark("SunRing");
  26. vector3 loc = SunPoint.GetLocation();
  27. @DirLight = World.FindFile("Env_Cubes.wpk\\Lights\\SunLight_light.wdla");
  28. @SunColor = DirLight.GetVect4Property("LightColor");
  29. @SceneLight = World.FindFile("Env_Cubes.wpk\\Lights\\Indirect_light.wscla");
  30. @SceneColor = SceneLight.GetVect4Property("LightColor");
  31. distance = loc.length(); // distance of SunPoint
  32. }
  33.  
  34. void Tick(float DeltaTime)
  35. {
  36. float newTime = GetEngineTime();
  37. float Time = (newTime-oldTime)*(2*my_PI)*(1/duration); // ***delta time***
  38. oldTime = newTime; // absolute time
  39.  
  40. SunRing.AddRotation(Time, 0, 0); // calculate rotation of SunRing
  41. SunLight.AddRotation(0, 0, Time); // calculate rotation of SunLight
  42. SunPoint.AddRotation(Time, 0, 0); // calculate rotation of SunPoint
  43. vector3 Down = distance*SunPoint.TransformDirection(vector3(0,-1,0)); // calculate rotation of SunRing
  44. SunPoint.SetLocation(Down.x, Down.y, Down.z);
  45.  
  46. }
  47.  
  48. void RenderHUD(ScriptedHUD@ HUD) { // Hack Hack
  49.  
  50. float newTime = GetEngineTime();
  51. float DayTime = ((newTime*(1.0f/duration)*2*my_PI)%(2*my_PI)) ;
  52. float x = sin(DayTime); // adjust fading
  53. float y = -sin(DayTime); // adjust fading
  54.  
  55.  
  56. x = x <0 ? 0 : x; // minimum = 0
  57. y = y <0 ? 0 : y; // minimum = 0
  58.  
  59. x = (2.0f+(1/duration))*x; // adjust fading
  60. y = (2.0f+(1/duration))*y; // adjust fading
  61.  
  62. x = x <1 ? x : 1; // maximum = 1
  63. y = y <1 ? y : 1; // maximum = 1
  64.  
  65. vector3 Sun = x*vector3(0.9f,0.8f,0.7f); // sunlight
  66. float Blend = (x+y) < 1 ? (x+y) : 1;
  67. //Sun += vector3(1,0.5f,0.1f)*(1-Blend); // sunlight at blending
  68. SunColor.Set(vector4(Sun.x,Sun.y,Sun.z,1)); // assign sunlight color
  69. Sun = x*vector3(0.1f,0.15f,0.2f); // overwrite Sun with color for scenelight - day
  70. Sun += y*vector3(0.2f,0.35f,0.5f); // at night
  71. Sun += vector3(0.5,0.3f,0.1f)*(1-Blend); // at blending
  72. SceneColor.Set(vector4(Sun.x, Sun.y,Sun.z,1)); // assign scene light color
  73.  
  74. //HUD.DrawDebugText(" " + DayTime +"\n" + x, 0.0f, 50.0f);
  75. }
  76.  
  77. void DoAdjustDuration (string input) {
  78. WFile@ File;
  79. FloatProperty@ Prop;
  80. @File = World.FindFile(input);
  81. @Prop = File.GetFloatProperty("f1_duration");
  82. Prop.Set(duration);
  83. }
  84.  
  85. void AdjustDuration () {
  86. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Sky.fxi");
  87. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_red.fxi");
  88. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_green.fxi");
  89. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_blue.fxi");
  90. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_1.fxi");
  91. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_2.fxi");
  92. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_3.fxi");
  93. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_4.fxi");
  94. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_5.fxi");
  95. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_6.fxi");
  96. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_7.fxi");
  97. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_8.fxi");
  98. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_9.fxi");
  99. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_10.fxi");
  100. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_11-12.fxi");
  101. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_13.fxi");
  102. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_14-15-16-17-18.fxi");
  103. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_19.fxi");
  104. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_20.fxi");
  105. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_21.fxi");
  106. DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_22.fxi");
  107. }
  108. }
Add Comment
Please, Sign In to add comment