Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "EngineScripts.wpk\GlobalScriptBase.ws"
- const float my_PI = 3.1415926535f;
- const float duration = 5.0f;
- class Cubes_Sun : GlobalScriptBase
- {
- WContentMark@ SunPoint;
- WContentMark@ SunLight;
- WContentMark@ SunRing;
- WFile@ DirLight;
- WFile@ SceneLight ;
- Vect4Property@ SunColor;
- Vect4Property@ SceneColor;
- float distance;
- float oldTime;
- void OnLoad()
- {
- AdjustDuration();
- oldTime = 0;
- @SunPoint = FindContentMark("SunPoint");
- @SunLight = FindContentMark("SunLight");
- @SunRing = FindContentMark("SunRing");
- vector3 loc = SunPoint.GetLocation();
- @DirLight = World.FindFile("Env_Cubes.wpk\\Lights\\SunLight_light.wdla");
- @SunColor = DirLight.GetVect4Property("LightColor");
- @SceneLight = World.FindFile("Env_Cubes.wpk\\Lights\\Indirect_light.wscla");
- @SceneColor = SceneLight.GetVect4Property("LightColor");
- distance = loc.length(); // distance of SunPoint
- }
- void Tick(float DeltaTime)
- {
- float newTime = GetEngineTime();
- float Time = (newTime-oldTime)*(2*my_PI)*(1/duration); // ***delta time***
- oldTime = newTime; // absolute time
- SunRing.AddRotation(Time, 0, 0); // calculate rotation of SunRing
- SunLight.AddRotation(0, 0, Time); // calculate rotation of SunLight
- SunPoint.AddRotation(Time, 0, 0); // calculate rotation of SunPoint
- vector3 Down = distance*SunPoint.TransformDirection(vector3(0,-1,0)); // calculate rotation of SunRing
- SunPoint.SetLocation(Down.x, Down.y, Down.z);
- }
- void RenderHUD(ScriptedHUD@ HUD) { // Hack Hack
- float newTime = GetEngineTime();
- float DayTime = ((newTime*(1.0f/duration)*2*my_PI)%(2*my_PI)) ;
- float x = sin(DayTime); // adjust fading
- float y = -sin(DayTime); // adjust fading
- x = x <0 ? 0 : x; // minimum = 0
- y = y <0 ? 0 : y; // minimum = 0
- x = (2.0f+(1/duration))*x; // adjust fading
- y = (2.0f+(1/duration))*y; // adjust fading
- x = x <1 ? x : 1; // maximum = 1
- y = y <1 ? y : 1; // maximum = 1
- vector3 Sun = x*vector3(0.9f,0.8f,0.7f); // sunlight
- float Blend = (x+y) < 1 ? (x+y) : 1;
- //Sun += vector3(1,0.5f,0.1f)*(1-Blend); // sunlight at blending
- SunColor.Set(vector4(Sun.x,Sun.y,Sun.z,1)); // assign sunlight color
- Sun = x*vector3(0.1f,0.15f,0.2f); // overwrite Sun with color for scenelight - day
- Sun += y*vector3(0.2f,0.35f,0.5f); // at night
- Sun += vector3(0.5,0.3f,0.1f)*(1-Blend); // at blending
- SceneColor.Set(vector4(Sun.x, Sun.y,Sun.z,1)); // assign scene light color
- //HUD.DrawDebugText(" " + DayTime +"\n" + x, 0.0f, 50.0f);
- }
- void DoAdjustDuration (string input) {
- WFile@ File;
- FloatProperty@ Prop;
- @File = World.FindFile(input);
- @Prop = File.GetFloatProperty("f1_duration");
- Prop.Set(duration);
- }
- void AdjustDuration () {
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Sky.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_red.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_green.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Glow_blue.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_1.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_2.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_3.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_4.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_5.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_6.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_7.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_8.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_9.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_10.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_11-12.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_13.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_14-15-16-17-18.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_19.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_20.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_21.fxi");
- DoAdjustDuration("Env_Cubes.wpk\\Shader\\Cubes_22.fxi");
- }
- }
Add Comment
Please, Sign In to add comment