From bd715d1b93b87b6f39746b3cce0cb73d96f84a5d Mon Sep 17 00:00:00 2001 From: Forboding Angel Date: Mon, 19 Feb 2018 16:50:47 -0800 Subject: [PATCH] Add day night weather effects back in disabled by default Add a toggle for weather day and night Set some hopefully better defaults for first time users --- LuaUI/Widgets_Evo/gfx_dualfog.lua | 669 ++++++++++++++++++ LuaUI/Widgets_Evo/gfx_rain.lua | 562 +++++++++++++++ .../gfx_shadow_quality_manager.lua | 2 +- LuaUI/Widgets_Evo/gfx_weather.lua | 226 ++++++ LuaUI/Widgets_Evo/gui_options.lua | 42 +- 5 files changed, 1479 insertions(+), 22 deletions(-) create mode 100644 LuaUI/Widgets_Evo/gfx_dualfog.lua create mode 100644 LuaUI/Widgets_Evo/gfx_rain.lua create mode 100644 LuaUI/Widgets_Evo/gfx_weather.lua diff --git a/LuaUI/Widgets_Evo/gfx_dualfog.lua b/LuaUI/Widgets_Evo/gfx_dualfog.lua new file mode 100644 index 000000000..74d384c62 --- /dev/null +++ b/LuaUI/Widgets_Evo/gfx_dualfog.lua @@ -0,0 +1,669 @@ +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- + +function widget:GetInfo() + return { + name = "GFX Fog", + version = 3, + desc = "Fog Drawing widget", + author = "trepan, user, aegis, jK, widget adaptation by Doo", + date = "2008-2011", + license = "GNU GPL, v2 or later", + layer = 1, + enabled = true + } +end + +local timeCyclesWeatherEffects = Spring.GetConfigInt("evo_timecyclesweathereffects", 0) +if timeCyclesWeatherEffects ~= 1 then + return false +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- Config +mapcfg = {} +mapcfg.custom = { + fog = { + color = {gl.GetAtmosphere("fogColor")}, + height = tostring((1-gl.GetAtmosphere("fogStart"))*100).."%", --// allows either absolue sizes or in percent of map's MaxHeight + fogatten = 0.00125, + + } +} +GroundFogDefs = {} +local GroundFogDefs = mapcfg.custom.fog + +function GetConfig() + mapcfg = {} + mapcfg.custom = { + fog = { + color = {gl.GetAtmosphere("fogColor")}, + height = tostring((1-gl.GetAtmosphere("fogStart"))*100).."%", --// allows either absolue sizes or in percent of map's MaxHeight + fogatten = 0.00125, + } + } + GroundFogDefs = {} + GroundFogDefs = mapcfg.custom.fog + if GroundFogDefs then + if (GroundFogDefs.height == "auto") then + local min,max = Spring.GetGroundExtremes() + GroundFogDefs.height = max * (1-gl.GetAtmosphere("fogStart")) + elseif (GroundFogDefs.height:match("(%d+)%%")) then + local min,max = Spring.GetGroundExtremes() + local percent = GroundFogDefs.height:match("(%d+)%%") + GroundFogDefs.height = max * (1-gl.GetAtmosphere("fogStart")) + end + end + + fogHeight = GroundFogDefs.height + fogColor = GroundFogDefs.color + fogAtten = GroundFogDefs.fogatten + fr,fg,fb = unpack(fogColor) + + assert(type(fogHeight) == "number") + assert(type(fr) == "number") + assert(type(fg) == "number") + assert(type(fb) == "number") + assert(type(fogAtten) == "number") +end + +if GroundFogDefs then + if (GroundFogDefs.height == "auto") then + local min,max = Spring.GetGroundExtremes() + GroundFogDefs.height = max * (1-gl.GetAtmosphere("fogStart")) + elseif (GroundFogDefs.height:match("(%d+)%%")) then + local min,max = Spring.GetGroundExtremes() + local percent = GroundFogDefs.height:match("(%d+)%%") + GroundFogDefs.height = max * (1-gl.GetAtmosphere("fogStart")) + end +end + +fogHeight = GroundFogDefs.height +fogColor = GroundFogDefs.color +fogAtten = GroundFogDefs.fogatten +fr,fg,fb = unpack(fogColor) + +assert(type(fogHeight) == "number") +assert(type(fr) == "number") +assert(type(fg) == "number") +assert(type(fb) == "number") +assert(type(fogAtten) == "number") + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- Automatically generated local definitions + +local GL_MODELVIEW = GL.MODELVIEW +local GL_NEAREST = GL.NEAREST +local GL_ONE = GL.ONE +local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA +local GL_PROJECTION = GL.PROJECTION +local GL_QUADS = GL.QUADS +local GL_SRC_ALPHA = GL.SRC_ALPHA +local glBeginEnd = gl.BeginEnd +local glBlending = gl.Blending +local glCallList = gl.CallList +local glColor = gl.Color +local glColorMask = gl.ColorMask +local glCopyToTexture = gl.CopyToTexture +local glCreateList = gl.CreateList +local glCreateShader = gl.CreateShader +local glCreateTexture = gl.CreateTexture +local glDeleteShader = gl.DeleteShader +local glDeleteTexture = gl.DeleteTexture +local glDepthMask = gl.DepthMask +local glDepthTest = gl.DepthTest +local glGetMatrixData = gl.GetMatrixData +local glGetShaderLog = gl.GetShaderLog +local glGetUniformLocation = gl.GetUniformLocation +local glGetViewSizes = gl.GetViewSizes +local glLoadIdentity = gl.LoadIdentity +local glLoadMatrix = gl.LoadMatrix +local glMatrixMode = gl.MatrixMode +local glMultiTexCoord = gl.MultiTexCoord +local glPopMatrix = gl.PopMatrix +local glPushMatrix = gl.PushMatrix +local glResetMatrices = gl.ResetMatrices +local glTexCoord = gl.TexCoord +local glTexture = gl.Texture +local glRect = gl.Rect +local glUniform = gl.Uniform +local glUniformMatrix = gl.UniformMatrix +local glUseShader = gl.UseShader +local glVertex = gl.Vertex +local glTranslate = gl.Translate +local spEcho = Spring.Echo +local spGetCameraPosition = Spring.GetCameraPosition +local spGetCameraVectors = Spring.GetCameraVectors +local time = Spring.GetGameSeconds +local spGetDrawFrame = Spring.GetDrawFrame + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- +-- Extra GL constants +-- + +local GL_DEPTH_BITS = 0x0D56 + +local GL_DEPTH_COMPONENT = 0x1902 +local GL_DEPTH_COMPONENT16 = 0x81A5 +local GL_DEPTH_COMPONENT24 = 0x81A6 +local GL_DEPTH_COMPONENT32 = 0x81A7 + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +local debugGfx = false --or true + +local GLSLRenderer = true +local forceNonGLSL = false -- force using the non-GLSL renderer +local post83 = false +do + post83 = true +end +if (forceNonGLSL) then + GLSLRenderer = false +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +local gnd_min, gnd_max = Spring.GetGroundExtremes() +if (gnd_min < 0) then gnd_min = 0 end +if (gnd_max < 0) then gnd_max = 0 end +local vsx, vsy +local mx = Game.mapSizeX +local mz = Game.mapSizeZ +local fog +local CurrentCameraY +local timeNow, timeThen = 0,0 + + +local depthShader +local depthTexture + +local uniformEyePos +local uniformNoise +local uniformViewPrjInv + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +----a simple plane, very complete, would look good with shadows, reflex and stuff. + +local function DrawPlaneModel() + local layers = (fogHeight - (gnd_min+50)) / 50 + + glColor(fr,fg,fb,50*fogAtten) + glDepthTest(true) + glBlending(true) + + glBeginEnd(GL_QUADS,function() + for h = gnd_min+50,fogHeight,50 do + local l = -mx*4 + local r = mx + mx*4 + local t = -mz*4 + local b = mz + mz*4 + glVertex(l, h, t) + glVertex(r, h, t) + glVertex(r, h, b) + glVertex(l, h, b) + end + end) + + glDepthTest(false) + glBlending(false) + glColor(1,1,1,1) +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- fog rendering + +local function FogSlices() + local h = 8*(math.sin(time()/1.2)) + 30*(math.sin(time()/7.3)) - 30 + glPushMatrix() + glTranslate(0,h,0) + glCallList(fog) + glPopMatrix() +end + +local function FogFullscreen() + local camY = select(2, spGetCameraPosition()) + local inFogH = fogHeight - camY + + if (inFogH > fogHeight * 0.1) then + glColor(fr,fg,fb, math.min(0.8, inFogH * fogAtten)) + glRect(0,0,vsx,vsy) + glColor(1,1,1,1) + end +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:ViewResize() + vsx, vsy = gl.GetViewSizes() + if (Spring.GetMiniMapDualScreen()=='left') then + vsx=vsx/2; + end + if (Spring.GetMiniMapDualScreen()=='right') then + vsx=vsx/2 + end + + if (depthTexture) then + glDeleteTexture(depthTexture) + end + + depthTexture = glCreateTexture(vsx, vsy, { + format = GL_DEPTH_COMPONENT24, + min_filter = GL_NEAREST, + mag_filter = GL_NEAREST, + }) + + if (depthTexture == nil) then + spEcho("Removing fog widget, bad depth texture") + end +end + +widget:ViewResize() + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +local vertSrc = [[ + + void main(void) + { + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = gl_Vertex; + } +]] + +local fragSrc = ([[ + const float fogAtten = %f; + const float fogHeight = %f; + const vec3 fogColor = vec3(%f, %f, %f); + + uniform sampler2D tex0; + uniform vec3 eyePos; + uniform vec2 noise; +#ifdef USE_INVERSEMATRIX + uniform mat4 viewProjectionInv; +#endif + + //! source: http://www.ozone3d.net/blogs/lab/20110427/glsl-random-generator/ + float rand(vec2 n) + { + return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453); + } + + void main(void) + { + float z = texture2D(tex0, gl_TexCoord[0].st).x; + + vec4 ppos; + ppos.xyz = vec3(gl_TexCoord[0].st, z) * 2. - 1.; + ppos.a = 1.; +#ifdef USE_INVERSEMATRIX + vec4 worldPos4 = viewProjectionInv * ppos; +#else + vec4 worldPos4 = gl_ModelViewProjectionMatrixInverse * ppos; +#endif + vec3 worldPos = worldPos4.xyz / worldPos4.w; + vec3 toPoint = worldPos - eyePos; + +#ifdef DEBUG_GFX // world position debugging + const float k = 100.0; + vec3 debugColor = pow(2.0 * abs(0.5 - fract(worldPos / k)), 6.0); + gl_FragColor = vec4(debugColor, 1.0); + return; // BAIL +#endif + + float h0 = clamp(worldPos.y, 0.0, fogHeight); + float h1 = clamp(eyePos.y, 0.0, fogHeight); // FIXME: uniform ... + + float len = length(toPoint); + float dist = len * abs((h1 - h0) / toPoint.y); // div-by-zero prob? + float atten = clamp(1.0 - exp(-dist * fogAtten), 0.0, 1.0); + + gl_FragColor = vec4(fogColor, atten); + + //! noise + vec2 seed = gl_TexCoord[0].st + noise; + gl_FragColor.rgb += 0.030 * rand(seed); + } +]]):format(fogAtten, fogHeight, fogColor[1], fogColor[2], fogColor[3]) + + +if (post83) then + fragSrc = '#define USE_INVERSEMATRIX\n' .. fragSrc +end + +if (debugGfx) then + fragSrc = '#define DEBUG_GFX\n' .. fragSrc +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:Initialize() + GetConfig() + if (enabled) then + if ((not forceNonGLSL) and Spring.GetMiniMapDualScreen()~='left') then --FIXME dualscreen + if (not glCreateShader) then + spEcho("Shaders not found, reverting to non-GLSL widget") + GLSLRenderer = false + else + depthShader = glCreateShader({ + vertex = vertSrc, + fragment = fragSrc, + uniformInt = { + tex0 = 0, + }, + }) + Spring.Echo(depthShader) + + if (not depthShader) then + spEcho(glGetShaderLog()) + spEcho("Bad shader, reverting to non-GLSL widget.") + GLSLRenderer = false + else + uniformEyePos = glGetUniformLocation(depthShader, 'eyePos') + uniformNoise = glGetUniformLocation(depthShader, 'noise') + uniformViewPrjInv = glGetUniformLocation(depthShader, 'viewProjectionInv') + end + end + else + GLSLRenderer = false + end + if (not GLSLRenderer) then + fog = glCreateList(DrawPlaneModel) + end + else + + end +end +frame = 0 +function widget:Update() + if frame%30 == 0 then + GetConfig() + if (fog) then + gl.DeleteList(fog) + fog = nil + end + if (dl) then + gl.DeleteList(dl) + dl = nil + end + if depthShader then + gl.DeleteShader(depthShader) + depthShader = nil + end + vertSrc = [[ + + void main(void) + { + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = gl_Vertex; + } +]] + + fragSrc = ([[ + const float fogAtten = %f; + const float fogHeight = %f; + const vec3 fogColor = vec3(%f, %f, %f); + + uniform sampler2D tex0; + uniform vec3 eyePos; + uniform vec2 noise; +#ifdef USE_INVERSEMATRIX + uniform mat4 viewProjectionInv; +#endif + + //! source: http://www.ozone3d.net/blogs/lab/20110427/glsl-random-generator/ + float rand(vec2 n) + { + return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453); + } + + void main(void) + { + float z = texture2D(tex0, gl_TexCoord[0].st).x; + + vec4 ppos; + ppos.xyz = vec3(gl_TexCoord[0].st, z) * 2. - 1.; + ppos.a = 1.; +#ifdef USE_INVERSEMATRIX + vec4 worldPos4 = viewProjectionInv * ppos; +#else + vec4 worldPos4 = gl_ModelViewProjectionMatrixInverse * ppos; +#endif + vec3 worldPos = worldPos4.xyz / worldPos4.w; + vec3 toPoint = worldPos - eyePos; + +#ifdef DEBUG_GFX // world position debugging + const float k = 100.0; + vec3 debugColor = pow(2.0 * abs(0.5 - fract(worldPos / k)), 6.0); + gl_FragColor = vec4(debugColor, 1.0); + return; // BAIL +#endif + + float h0 = clamp(worldPos.y, 0.0, fogHeight); + float h1 = clamp(eyePos.y, 0.0, fogHeight); // FIXME: uniform ... + + float len = length(toPoint); + float dist = len * abs((h1 - h0) / toPoint.y); // div-by-zero prob? + float atten = clamp(1.0 - exp(-dist * fogAtten), 0.0, 1.0); + + gl_FragColor = vec4(fogColor, atten); + + //! noise + vec2 seed = gl_TexCoord[0].st + noise; + gl_FragColor.rgb += 0.030 * rand(seed); + } +]]):format(fogAtten, fogHeight, fogColor[1], fogColor[2], fogColor[3]) + if (post83) then + fragSrc = '#define USE_INVERSEMATRIX\n' .. fragSrc + end + if (debugGfx) then + fragSrc = '#define DEBUG_GFX\n' .. fragSrc + end + if (enabled) then + if ((not forceNonGLSL) and Spring.GetMiniMapDualScreen()~='left') then --FIXME dualscreen + if (not glCreateShader) then + spEcho("Shaders not found, reverting to non-GLSL widget") + GLSLRenderer = false + else + depthShader = glCreateShader({ + vertex = vertSrc, + fragment = fragSrc, + uniformInt = { + tex0 = 0, + }, + }) + Spring.Echo(depthShader) + + if (not depthShader) then + spEcho(glGetShaderLog()) + spEcho("Bad shader, reverting to non-GLSL widget.") + GLSLRenderer = false + else + uniformEyePos = glGetUniformLocation(depthShader, 'eyePos') + uniformNoise = glGetUniformLocation(depthShader, 'noise') + uniformViewPrjInv = glGetUniformLocation(depthShader, 'viewProjectionInv') + end + end + else + GLSLRenderer = false + end + if (not GLSLRenderer) then + fog = glCreateList(DrawPlaneModel) + end + else + + end + end + frame = frame + 1 +end + + + + +function widget:Shutdown() + if (GLSLRenderer) then + glDeleteTexture(depthTexture) + if (glDeleteShader) then + glDeleteShader(depthShader) + end + end +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- +-- Vector Math +-- + +local function cross(a, b) + return { + (a[2] * b[3]) - (a[3] * b[2]), + (a[3] * b[1]) - (a[1] * b[3]), + (a[1] * b[2]) - (a[2] * b[1]) + } +end + +local function add(a, b) + return { + a[1] * b[1], + a[2] * b[2], + a[3] * b[3] + } +end + +local function dot(a, b) + return (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]) +end + + +local function normalize(a) + local len = math.sqrt((a[1] * a[1]) + (a[2] * a[2]) + (a[3] * a[3])) + if (len == 0.0) then + return a + end + a[1] = a[1] / len + a[2] = a[2] / len + a[3] = a[3] / len + return { a[1], a[2], a[3] } +end + + +local function scale(a, s) + a[1] = a[1] * s + a[2] = a[2] * s + a[3] = a[3] * s + return { a[1], a[2], a[3] } +end + + + +local function fract(x) + return select(2, math.modf(x,1)) +end + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +local dl + +local function DrawFogNew() + GetConfig() + --//FIXME handle dualscreen correctly! + + -- copy the depth buffer + if (depthTexture) then + glDeleteTexture(depthTexture) + depthTexture = nil + end + + depthTexture = glCreateTexture(vsx, vsy, { + format = GL_DEPTH_COMPONENT24, + min_filter = GL_NEAREST, + mag_filter = GL_NEAREST, + }) + + glCopyToTexture(depthTexture, 0, 0, 0, 0, vsx, vsy) --FIXME scale down? + + -- setup the shader and its uniform values + + glUseShader(depthShader) + + -- set uniforms + local cpx, cpy, cpz = spGetCameraPosition() + glUniform(uniformEyePos, cpx, cpy, cpz) + + local noise1 = (spGetDrawFrame() / 2521) % 1 -- why 2521? it's prime ;) + glUniform(uniformNoise, noise1 + fract(cpx), noise1 + fract(cpz)) + + if (post83) then + glUniformMatrix(uniformViewPrjInv, "viewprojectioninverse") + end + if dl then + gl.DeleteList(dl) + dl = nil + end + if (not dl) then + dl = gl.CreateList(function() + -- render a full screen quad + glTexture(0, depthTexture) + glTexture(0, false) + gl.TexRect(-1, -1, 1, 1, 0, 0, 1, 1) + + --// finished + glUseShader(0) + end) + end + + glCallList(dl) +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:DrawWorld() + GetConfig() + if (GLSLRenderer) then + if (debugGfx) then glBlending(GL_SRC_ALPHA, GL_ONE) end + depthShader = glCreateShader({ + vertex = vertSrc, + fragment = fragSrc, + uniformInt = { + tex0 = 0, + }, + }) + uniformEyePos = glGetUniformLocation(depthShader, 'eyePos') + uniformNoise = glGetUniformLocation(depthShader, 'noise') + uniformViewPrjInv = glGetUniformLocation(depthShader, 'viewProjectionInv') + DrawFogNew() + if (debugGfx) then glBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) end + else + FogSlices() + end +end + +if (not GLSLRenderer) then + function widget:DrawScreenEffects() + FogFullscreen() + end +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- diff --git a/LuaUI/Widgets_Evo/gfx_rain.lua b/LuaUI/Widgets_Evo/gfx_rain.lua new file mode 100644 index 000000000..fd34ba2b7 --- /dev/null +++ b/LuaUI/Widgets_Evo/gfx_rain.lua @@ -0,0 +1,562 @@ +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- +-- file: precipitation.lua +-- brief: precipitation shader gadget +-- author: Dave Rodgers +-- +-- Copyright (C) 2007. +-- Licensed under the terms of the GNU GPL, v2 or later. +-- +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:GetInfo() + return { + name = "GFX Rain", + desc = "Precipitation shader widget", + author = "trepan, Argh, The_Yak", + date = "August 27, 2009, Aug 2, 2013", + license = "GNU GPL, v2 or later", + layer = -24, + enabled = true -- loaded by default? + } +end + +local timeCyclesWeatherEffects = Spring.GetConfigInt("evo_timecyclesweathereffects", 0) +if timeCyclesWeatherEffects ~= 1 then + return false +end + +------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +b = 1 +local particleType = 1 -- 1 for rain, 2 for snow, 3 for clouds (when they finally work) +local particleDensity = 0 -- how many particles? Limit for performance! +f = 0 +nbPlayers = 0 +X = Game.mapSizeX +Z = Game.mapSizeZ +r = 1 +aparticleDensity = 1 +function GameStart() +r = 1 +roster = Spring.GetPlayerRoster(2) +nbPlayers = 0 +for i,isSpec in pairs(roster) do +if isSpec[5] == false then +nbPlayers = nbPlayers + 1 +end +end +end + +function widget:UnitDamaged(_,_,_,da) + +if da >= 1500 then +da = 1500 +end +b = b + da +--Spring.Echo(particleDensity) +end + +--Rain Color Control +local function ColorFunc() + local rainColorR = 0.2*((15000-particleDensity)/15000) + local rainColorG = math.random(2,5)/10*((15000-particleDensity)/15000) + local rainColorB = 0.5*((15000-particleDensity)/15000) + local rainAlpha = (1*(particleDensity/15000))^(1/4) + -- Spring.Echo(rainColorR) + -- Spring.Echo(rainColorG) + -- Spring.Echo(rainColorB) + -- Spring.Echo(rainAlpha) + return rainColorR,rainColorG,rainColorB,rainAlpha +end + +--particleOne +local particleOneGravity = 50 -- how fast does it fall? +local particleOneDriftX = -20 -- how fast does it move on the X axis? Can be positive or negative. +local particleOneDriftZ = -20 -- how fast does it move on the Z axis? Can be positive or negative. +local particleOneTexture = 'LuaUI/Widgets/snowflake1.tga' -- what bitmap are we using? +local particleOneScale = 4000 -- scale, see GLSL for details + +local particleTwoGravity = 40 -- how fast does it fall? +local particleTwoDriftX = -40 -- how fast does it move on the X axis? Can be positive or negative. +local particleTwoDriftZ = 20 -- how fast does it move on the Z axis? Can be positive or negative. +local particleTwoTexture = 'LuaUI/Widgets/snowflake2.tga' -- what bitmap are we using? +local particleTwoScale = 3000 -- scale, see GLSL for details + +local particleThreeGravity = 60 -- how fast does it fall? +local particleThreeDriftX = -60 -- how fast does it move on the X axis? Can be positive or negative. +local particleThreeDriftZ = 20 -- how fast does it move on the Z axis? Can be positive or negative. +local particleThreeTexture = 'LuaUI/Widgets/snowflake3.tga' -- what bitmap are we using? +local particleThreeScale = 2500 -- scale, see GLSL for details + +local math_random = math.random +local math_randomseed = math.randomseed + +local shader +local rainshader +local shaderTimeLoc +local shaderCamPosLoc +local shaderScaleLoc +local shaderSpeedLoc + +local startTimer = Spring.GetTimer() +local diffTime = 0 + +local rainparticleOneList +local rainparticleTwoList +local rainparticleThreeList + +local firstPos = 0 +local secondPos = 0 +local thirdPos = 0 +local camX,camY,camZ + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +--OpenGL stuff. + local glBeginEnd = gl.BeginEnd + local glVertex = gl.Vertex + local glColor = gl.Color + local glBlending = gl.Blending + local glTranslate = gl.Translate + local glCallList = gl.CallList + local glDepthTest = gl.DepthTest + local glCreateList = gl.CreateList + local glDeleteList = gl.DeleteList + local glTexture = gl.Texture + local glGetShaderLog = gl.GetShaderLog + local glCreateShader = gl.CreateShader + local glDeleteShader = gl.DeleteShader + local glUseShader = gl.UseShader + local glUniformMatrix = gl.UniformMatrix + local glUniformInt = gl.UniformInt + local glUniform = gl.Uniform + local glGetUniformLocation = gl.GetUniformLocation + local glGetActiveUniforms = gl.GetActiveUniforms + local glBeginEnd = gl.BeginEnd + local glPointSprite = gl.PointSprite + local glPointSize = gl.PointSize + local glPointParameter = gl.PointParameter + local glResetState = gl.ResetState + local GL_POINTS = GL.POINTS + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +function widget:Shutdown() + --glDeleteList(particleOneSubList) + glDeleteList(particleOneList) +end + +local function CreateParticleOneList() + particleOneList = gl.CreateList(function() + local tmpRand = math.random() + math.randomseed(1) + gl.BeginEnd(GL.POINTS, function() + for i = 1, aparticleDensity do + local x = math.random() + local y = math.random() + local z = math.random() + local w = math.random() + gl.Vertex(x, y, z, w) + end + end) + math.random(1e9 * tmpRand) + end) +end + +local function CreateParticleTwoList() + particleTwoList = gl.CreateList(function() + local tmpRand = math.random() + math.randomseed(2) + gl.BeginEnd(GL.POINTS, function() + for i = 1, aparticleDensity do + local x = math.random() + local y = math.random() + local z = math.random() + local w = math.random() + gl.Vertex(x, y, z, w) + end + end) + math.random(1e9 * tmpRand) + end) +end + +local function CreateParticleThreeList() + particleThreeList = gl.CreateList(function() + local tmpRand = math.random() + math.randomseed(3) + gl.BeginEnd(GL.POINTS, function() + for i = 1, aparticleDensity do + local x = math.random() + local y = math.random() + local z = math.random() + local w = math.random() + gl.Vertex(x, y, z, w) + end + end) + math.random(1e9 * tmpRand) + end) +end + +local function CreateCloudList() + cloudOneList = gl.CreateList(function() + + gl.BeginEnd(GL.POINTS, function() +glVertex(-30,0,40) +glVertex(-40,30,-20) +glVertex(-40,-20,0) +glVertex(-30,-40,30) +glVertex(-30,10,-20) +glVertex(-20,0,-20) +glVertex(-10,-20,-30) +glVertex(-20,50,50) +glVertex(-20,40,0) +glVertex(-20,-30,40) +glVertex(-30,-50,10) +glVertex(30,10,30) +glVertex(30,-30,10) +glVertex(20,-10,40) +glVertex(20,-50,30) +glVertex(30,50,-10) +glVertex(20,20,-20) +glVertex(20,-20,10) +glVertex(0,70,-50) +glVertex(0,-40,30) +glVertex(0,-10,10) +glVertex(0,-20,-20) +glVertex(0,-60,50) +glVertex(0,-40,0) +glVertex(0,-30,80) +glVertex(0,20,0) +glVertex(0,40,60) +glVertex(0,-20,30) + end) + end) +end + + +local function CreateRainDrops() + rainparticleOneList = glCreateList(function() + local tmpRand = math_random() + math_randomseed(6) + glBeginEnd(GL.LINES, function() + for i = 1, particleDensity do + local x = math_random(-3000,3000) + local y = math_random(-5000,10000) + local z = math_random(-3000,3000) + glColor(ColorFunc()) + glVertex(x,y,z) + glVertex(x,y- math_random(20,40),z) + end + end) + math_random(1e9 * tmpRand) + end) + + rainparticleTwoList = glCreateList(function() + local tmpRand = math_random() + math_randomseed(6) + glBeginEnd(GL.LINES, function() + for i = 1, particleDensity do + local x = math_random(-3000,3000) + local y = math_random(-5000,20000) + local z = math_random(-3000,3000) + glColor(ColorFunc()) + glVertex(x,y,z) + glVertex(x,y- math_random(20,40),z) + end + end) + math_random(1e9 * tmpRand) + end) + + rainparticleThreeList = glCreateList(function() + local tmpRand = math_random() + math_randomseed(6) + glBeginEnd(GL.LINES, function() + for i = 1, particleDensity do + local x = math_random(-3000,3000) + local y = math_random(-5000,30000) + local z = math_random(-3000,3000) + glColor(ColorFunc()) + glVertex(x,y,z) + glVertex(x,y- math_random(20,40),z) + end + end) + math_random(1e9 * tmpRand) + end) + + if (rainparticleOneList == nil) then + return false + end + return true +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +function widget:Update(dt) +t = t + dt + +r = r + 2000*dt + f = f +1 + -- Spring.Echo(f) +if r >= b then +r = b +end +K = (X*Z/3500)*nbPlayers +-- Spring.Echo(rfx) +p = 1-(math.exp(-r/K)) +particleDensity = 15000*(1-gl.GetAtmosphere("fogStart")) +-- Spring.Echo(aparticleDensity) +aparticleDensity = 15000*(p) +if particleDensity >= 15000 then +particleDensity = 15000 +end + +if aparticleDensity >= 15000 then +aparticleDensity = 15000 +end + b = b * 0.9995^(dt*30) + -- Spring.Echo(dt*30) + +if f%150 == 0 then + if (Spring.GetMapOptions().alt == "0") then + widgetHandler:RemoveWidget() + return + end + if (glCreateShader == nil) then + Spring.Echo("[Weather Particles:Initialize] no shader support") + widgetHandler:RemoveWidget() + return + end +CreateRainDrops() + -- CreateParticleOneList() + -- CreateParticleTwoList() + -- CreateParticleThreeList() + + -- Spring.Echo("Finished Snow / Rain Shader") + end +end + +function widget:Initialize() +t = 0 +f = 0 +rfx = 0 +roster = Spring.GetPlayerRoster(2) +nbPlayers = 0 +for i,isSpec in pairs(roster) do +if isSpec[5] == false then +nbPlayers = nbPlayers + 1 +end +end + + if (Spring.GetMapOptions().alt == "0") then + widgetHandler:RemoveWidget() + return + end + if (glCreateShader == nil) then + Spring.Echo("[Weather Particles:Initialize] no shader support") + widgetHandler:RemoveWidget() + return + end + + shader = glCreateShader({ + + vertex = [[ + uniform float time; + uniform float scale; + uniform vec3 speed; + uniform vec3 camPos; + void main(void) + { + vec3 scalePos = vec3(gl_Vertex) * scale; + + gl_FrontColor = vec4(0.8,0.8,0.9,0.0 + 0.8 * cos(scalePos.y)); + + vec3 pos = scalePos - mod(camPos, scale); + pos.y -= time * 0.5 * (speed.x * (2.0 + gl_Vertex.w)); + pos.x += (sin(time)*10.0) + (time * speed.y); + pos.z += (cos(time)*10.0) + (time * speed.z); + pos = mod(pos, scale) - (scale * 0.5) + camPos; + if (pos.y < 0.0) { + gl_FrontColor *= 1.0 + 2.0 * (pos.y / scale); + pos.y = 0.0; + } + vec4 eyePos = gl_ModelViewMatrix * vec4(pos, 1.0); + + gl_PointSize = (1.0 + gl_Vertex.w) * 5000.0 / length(eyePos); + + gl_Position = gl_ProjectionMatrix * eyePos; + } + ]], + uniform = { + time = diffTime, + scale = 0, + speed = {0,0,0}, + camPos = {0,0,0}, + }, + }) + +rainshader = glCreateShader({ + vertex = [[ + void main(void) + { + gl_FrontColor = gl_Color; + gl_Position = ftransform(); + } + ]], + }) + +cloudshader = glCreateShader({ + vertex = [[ + uniform vec3 camPos; + void main(void) + { + + //float myLength = distance(gl_Vertex.xyz, camPos.xyz); + //gl_PointSize = 100.0 / myLength / 1000; + gl_Position = ftransform(); + + } + ]], + uniform = { + camPos = {0,0,0}, + }, + }) + + if (shader == nil) then + Spring.Echo("[Weather Particles:Initialize] particle shader compilation failed") + Spring.Echo(glGetShaderLog()) + widgetHandler:RemoveWidget() + return + end + + if (rainshader == nil) then + Spring.Echo("[Weather Particles:Initialize] rain shader compilation failed") + Spring.Echo(glGetShaderLog()) + widgetHandler:RemoveWidget() + return + end + + if (cloudshader == nil) then + Spring.Echo("[Weather Particles:Initialize] cloud shader compilation failed") + Spring.Echo(glGetShaderLog()) + widgetHandler:RemoveWidget() + return + end + + shaderTimeLoc = glGetUniformLocation(shader, 'time') + shaderCamPosLoc = glGetUniformLocation(shader, 'camPos') + + shaderScaleLoc = glGetUniformLocation(shader, 'scale') + shaderSpeedLoc = glGetUniformLocation(shader, 'speed') + + cloudShaderCamPosLoc = glGetUniformLocation(cloudshader, 'camPos') + + CreateParticleOneList() + CreateParticleTwoList() + CreateParticleThreeList() + CreateCloudList() + CreateRainDrops() + + Spring.Echo("Finished Snow / Rain Shader") + +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +function widget:DrawWorld() + + + if particleType == 1 then + camX,camY,camZ = Spring.GetCameraPosition() + glDepthTest(GL.LEQUAL) + glBlending(GL.SRC_ALPHA, GL.ONE) + gl.DepthMask(false) + glUseShader(rainshader) + + firstPos = firstPos - particleOneGravity + if firstPos <= camY-10000 then + firstPos = camY + 100 + end + + gl.Translate(camX,firstPos,camZ) + glCallList(rainparticleOneList) + + secondPos = secondPos - particleTwoGravity + if secondPos <= camY-20000 then + secondPos = camY + 300 + end + gl.Translate(camX,secondPos,camZ) + glCallList(rainparticleTwoList) + + + thirdPos = thirdPos - particleThreeGravity + if thirdPos <= camY-30000 then + thirdPos = camY + 500 + end + gl.Translate(camX,thirdPos,camZ) + glCallList(rainparticleThreeList) + + glUseShader(shader) + camX,camY,camZ = Spring.GetCameraPosition() + diffTime = Spring.DiffTimers(Spring.GetTimer(), startTimer) + --Spring.Echo(diffTime,camX,camY,camZ) + glUniform(shaderTimeLoc,diffTime * 1) + glUniform(shaderCamPosLoc, camX, camY, camZ) + + glDepthTest(true) + glBlending(GL.SRC_ALPHA, GL.ONE) + + gl.PointSprite(true, true) + gl.PointSize(10.0) + gl.PointParameter(0, 0, 0.001, 0, 1e9, 1) + + glTexture(particleOneTexture) + glUniform(shaderScaleLoc, particleOneScale) + glUniform(shaderSpeedLoc, particleOneGravity,particleOneDriftX, particleOneDriftZ) + glCallList(particleOneList) + + + glTexture(particleTwoTexture) + glUniform(shaderScaleLoc, particleTwoScale) + glUniform(shaderSpeedLoc, particleTwoGravity, particleTwoDriftX, particleTwoDriftZ) + glCallList(particleTwoList) + + glTexture(particleThreeTexture) + glUniform(shaderScaleLoc, particleThreeScale) + glUniform(shaderSpeedLoc, particleThreeGravity, particleThreeDriftX, particleThreeDriftZ) + glCallList(particleThreeList) + end + + + + if particleType == 3 then + glColor(1.0,1.0,1.0,1.0) + glUseShader(cloudshader) + camX,camY,camZ = Spring.GetCameraPosition() + glUniform(cloudShaderCamPosLoc, camX, camY, camZ) + diffTime = Spring.DiffTimers(Spring.GetTimer(), startTimer) + + --glUniform(shaderTimeLoc,diffTime * 1) + glDepthTest(true) + --glTexture(cloudTextureThree) + glBlending(GL.SRC_ALPHA, GL.ONE) + + gl.PointSprite(true, true) + gl.PointSize(1) + gl.PointParameter(0, 0, 0, 0, 1, 1) + gl.Translate(500,1500,500) + glCallList(cloudOneList) + end + + gl.PointParameter(1, 0, 0, 0, 1e9, 1) + gl.PointSize(1.0) + gl.PointSprite(false, false) + glResetState() + glUseShader(0) +end + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- diff --git a/LuaUI/Widgets_Evo/gfx_shadow_quality_manager.lua b/LuaUI/Widgets_Evo/gfx_shadow_quality_manager.lua index ebd4761ec..d413dc354 100644 --- a/LuaUI/Widgets_Evo/gfx_shadow_quality_manager.lua +++ b/LuaUI/Widgets_Evo/gfx_shadow_quality_manager.lua @@ -15,7 +15,7 @@ end -- Config -------------------------------------------------------------------------------- -local maxQuality = 6144 +local maxQuality = 8192 local minQuality = 2048 -- I dont think a value below 2048 looks acceptable enough... wont free that much extra cpu power too local disableBelowMinimum = false local skipGameframes = 1611 -- dont check if quality change is needed for X gameframes diff --git a/LuaUI/Widgets_Evo/gfx_weather.lua b/LuaUI/Widgets_Evo/gfx_weather.lua new file mode 100644 index 000000000..122f7c250 --- /dev/null +++ b/LuaUI/Widgets_Evo/gfx_weather.lua @@ -0,0 +1,226 @@ +function widget:GetInfo() + return { + name = "Weather", + desc = "Darkens map, with more red colors while the total damages dealt in game increase to give a warfare feeling", + author = "Doo", + date = "25 april 2015", + version = "133.7", + license = "GNU GPL, v2 or later", + layer = -4, + enabled = true, -- loaded by default? + } +end + +local timeCyclesWeatherEffects = Spring.GetConfigInt("evo_timecyclesweathereffects", 0) +if timeCyclesWeatherEffects ~= 1 then + return false +end + +function widget:Initialize() + spx,spy,spz = gl.GetSun() + r = 1 + b = 1 + f = 0 + t = 0 + diffuse = {} + ambient = {} + specular = {} + fogColor = {} + sunColor = {} + skyColor = {} + cloudColor = {} + + newdiffuse = {} + newambient = {} + newspecular = {} + newfogColor = {} + newsunColor = {} + newskyColor = {} + newcloudColor = {} + + X = Game.mapSizeX + Z = Game.mapSizeZ + shadowDensity = gl.GetSun("shadowDensity") + diffuse.r, diffuse.g, diffuse.b = gl.GetSun("diffuse") + ambient.r, ambient.g, ambient.b = gl.GetSun("ambient") + specular.r, specular.g, specular.b = gl.GetSun("specular") + + fogStart = gl.GetAtmosphere("fogStart") + fogEnd = gl.GetAtmosphere("fogEnd") + fogColor.r, fogColor.g, fogColor.b = gl.GetAtmosphere("fogColor") + + sunColor.r, sunColor.g, sunColor.b = gl.GetAtmosphere("sunColor") + skyColor.r, skyColor.g, skyColor.b = gl.GetAtmosphere("skyColor") + cloudColor.r, cloudColor.g, cloudColor.b = gl.GetAtmosphere("cloudColor") + + --water + -- waterBase = {} + -- waterAbsorb = {} + -- waterMin = {} + -- waterSurface = {} + -- waterSpecular = {} + -- waterPlane = {} + -- newwaterBase = {} + -- newwaterAbsorb = {} + -- newwaterMin = {} + -- newwaterSurface = {} + -- newwaterSpecular = {} + -- newwaterPlane = {} + + -- waterBase.r, waterBase.g, waterBase.b = Game.waterBaseColor[1], Game.waterBaseColor[2], Game.waterBaseColor[3] + -- waterAbsorb.r, waterAbsorb.g, waterAbsorb.b = Game.waterAbsorb[1], Game.waterAbsorb[2], Game.waterAbsorb[3] + -- waterMin.r, waterMin.g, waterMin.b = Game.waterMinColor[1], Game.waterMinColor[2], Game.waterMinColor[3] + -- waterSurface.r, waterSurface.g, waterSurface.b = Game.waterSurfaceColor[1], Game.waterSurfaceColor[2], Game.waterSurfaceColor[3] + -- waterSpecular.r, waterSpecular.g, waterSpecular.b = Game.waterSpecularColor[1], Game.waterSpecularColor[2], Game.waterSpecularColor[3] + -- waterPlane.r, waterPlane.g, waterPlane.b = Game.waterPlaneColor[1], Game.waterSpecularColor[2], Game.waterSpecularColor[3] + rain = 0 + roster = Spring.GetPlayerRoster(2) + nbPlayers = 0 + for i,isSpec in pairs(roster) do + if isSpec[5] == false then + nbPlayers = nbPlayers + 1 + end + end +end + +function widget:UnitDestroyed(unitID) + explosion = UnitDefs[Spring.GetUnitDefID(unitID)].deathExplosion + maxlightningcolor = 0--(WeaponDefs[WeaponDefNames[explosion].id].damages[1]^0.001 * WeaponDefs[WeaponDefNames[explosion].id].damageAreaOfEffect)/160 + -- Spring.Echo(maxlightningcolor) + lightning = true +end + +function GameStart() + spx,spy,spz = gl.GetSun() + r = 1 + roster = Spring.GetPlayerRoster(2) + nbPlayers = 0 + for i,isSpec in pairs(roster) do + if isSpec[5] == false then + nbPlayers = nbPlayers + 1 + end + end +end + +function widget:UnitDamaged(_,_,_,da) +-- if da >= 1500 then +-- da = 1500 +-- end +-- b = b + da +end +sunframe = 0 +function widget:Update(dt) + sunframe = sunframe + dt * 0.15 + lightningcolor = 0 + if n == nil or n == 150 then + n = 1 + lightning = false + end + + if lightning == true then + -- Spring.Echo(lightningcolor) + lightningcolor = (maxlightningcolor/n)/2 + if lightningcolor >= 1 then lightningcolor = 1 end + if lightningcolor <= 0.025 then lightningcolor = 0 end + n = n + 1 + end + -- Spring.Echo(b) + -- Spring.Echo(r) + -- Spring.Echo(p) + -- Spring.Echo(b) + -- Spring.Echo(r) + -- Spring.Echo(p) + r = r + 2000*dt + -- Spring.Echo(X) + -- Spring.Echo(Z) + -- Spring.Echo(X*Z/1000) + -- Spring.Echo(K) + K = (X*Z/3500)*nbPlayers + t = t + dt + if r>=b then + r = b + end + -- Spring.Echo(w) + b = b * 0.9995^(dt*30) + + f = f+1 + px,py,pz = gl.GetSun() + -- Spring.SetSunManualControl(true) + Spring.SetSunDirection(math.cos(sunframe/15), 1+math.sin(sunframe/16), math.sin(sunframe/15)) + normpx, normpy, normpz = px/math.sqrt(px^2+py^2+pz^2),py/math.sqrt(px^2+py^2+pz^2),pz/math.sqrt(px^2+py^2+pz^2) + -- Spring.Echo(px) + if normpy <= 0 then + normpy = 0 + end + -- Spring.Echo(normpy) + -- Spring.Echo(pz) + p = (1-(normpy)) + w = 1-(math.exp(-r/K)) + rain = (((1 + math.sin(t/50))/2.3)-0.7)*5.7 + if rain < 0 then rain = 0 end + + -- Spring.Echo(p) + -- Spring.Echo(b) + -- Spring.Echo(p) + if p >= 1 then + p = 1 + end + if w >= 1 then + w = 1 + end + + -- Spring.Echo((1-p)*shadowDensity) + newshadowDensity = (1-p)*shadowDensity + newdiffuse.r, newdiffuse.g, newdiffuse.b = diffuse.r*(1-p)*(1-w)*(1-rain) + 0.035*1*p*(1-w)*(1-rain) + 0.23*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), diffuse.g*(1-p)*(1-w)*(1-rain)+0.035*1*p*(1-w)*(1-rain)+ 0.07*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), diffuse.b*(1-p)*(1-w)*(1-rain)+0.07*1*p*(1-w)*(1-rain)+ 0.035*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w) + + newambient.r, newambient.g, newambient.b = ambient.r, ambient.g, ambient.b -- Use this if it gets too dark + + --newambient.r, newambient.g, newambient.b = ambient.r*(1-p)*(1-w)*(1-rain)+ 0.15*1*p*(1-w)*(1-rain)+ 0.69*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), ambient.g*(1-p)*(1-rain)*(1-w)+0.30*1*p*(1-rain)*(1-w)+ 0.30*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), ambient.b*(1-p)*(1-w)*(1-rain)+0.65*1*p*(1-w)*(1-rain)+ 0.15*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w) -- This is better, but sometimes it gets pitch black + + newspecular.r, newspecular.g, newspecular.b = specular.r*(1-p)*(1-w)+0.2*0.60*1*p*(1-w)*(1-rain) + 0.5*rain*(1-p)*(1-w), specular.g*(1-p)*(1-w)+0.2*0.60*1*p*(1-w)*(1-rain) + 0.5*rain*(1-p)*(1-w), specular.b*(1-p)*(1-w)+0.2*1*1*p*(1-w)*(1-rain) + 0.5*rain*(1-p)*(1-w) + + newfogStart = 1-(math.max(rain, w)) + newfogEnd = 15 + newfogColor.r, newfogColor.g, newfogColor.b, newfogColor["alpha"] = fogColor.r*(1-p)*(1-w)*(1-rain)+0.03*1*p*(1-w)*(1-rain)+ 0.07*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), fogColor.g*(1-p)*(1-w)*(1-rain)+0.06*1*p*(1-w)*(1-rain)+ 0.05*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), fogColor.b*(1-p)*(1-w)*(1-rain)+0.20*1*p*(1-w)*(1-rain)+ 0.05*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), 0 + + newsunColor.r, newsunColor.g, newsunColor.b = sunColor.r*(1-p)*(1-w)*(1-rain)+0.6*1*p*(1-w)*(1-rain)+ 1*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), sunColor.g*(1-p)*(1-w)*(1-rain)+0.95*1*p*(1-w)*(1-rain)+ 0.95*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), sunColor.b*(1-p)*(1-w)*(1-rain)+0.1*1*p*(1-w)*(1-rain)+ 0.60*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w) + newskyColor.r, newskyColor.g, newskyColor.b = skyColor.r*(1-p)*(1-w)*(1-rain)+0.03*1*p*(1-w)*(1-rain)+ 0.2*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), skyColor.g*(1-p)*(1-w)*(1-rain)+0.06*1*p*(1-w)*(1-rain)+ 0.06*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w), skyColor.b*(1-p)*(1-w)*(1-rain)+0.2*1*p*(1-w)*(1-rain)+ 0.03*w*(1-p)*(1-rain) + 0.5*rain*(1-p)*(1-w) + newcloudColor.r, newcloudColor.g, newcloudColor.b = cloudColor.r*(1-p)*(1-w) + 0.5*rain*(1-p)*(1-w), cloudColor.g*(1-p)*(1-w) + 0.5*rain*(1-p)*(1-w), cloudColor.b*(1-p)*(1-w) + 0.5*rain*(1-p)*(1-w) + + if (newdiffuse.r + newdiffuse.g + newdiffuse.b) <= 1.5 then + factor = 1.5/(newdiffuse.r + newdiffuse.g + newdiffuse.b) + newdiffuse.r = newdiffuse.r * factor + newdiffuse.g = newdiffuse.g * factor + newdiffuse.b = newdiffuse.b * factor + end + + if (newambient.r + newambient.g + newambient.b) <= 1.5 then + factor = 1.5/(newdiffuse.r + newdiffuse.g + newdiffuse.b) + newambient.r = newambient.r * factor + newambient.g = newambient.g * factor + newambient.b = newambient.b * factor + end + -- Spring.Echo(rain) + -- Spring.Echo(newfogStart) + + Spring.SetSunLighting({groundAmbientColor = {newambient.r + lightningcolor, newambient.g + lightningcolor, newambient.b + lightningcolor} , groundDiffuseColor = {newdiffuse.r + lightningcolor, newdiffuse.g + lightningcolor, newdiffuse.b + lightningcolor}, groundSpecularColor = {newspecular.r, newspecular.g, newspecular.b}, unitAmbientColor = {newambient.r + lightningcolor, newambient.g + lightningcolor, newambient.b + lightningcolor} , unitDiffuseColor = {newdiffuse.r + lightningcolor, newdiffuse.g + lightningcolor, newdiffuse.b + lightningcolor}, unitSpecularColor = {newspecular.r, newspecular.g, newspecular.b}}) + Spring.SetAtmosphere({fogStart = newfogStart, fogEnd = newfogEnd, fogColor = {newfogColor.r+ lightningcolor, newfogColor.g+ lightningcolor, newfogColor.b+ lightningcolor, 0}, sunColor = {newsunColor.r+ lightningcolor, newsunColor.g+ lightningcolor, newsunColor.b+ lightningcolor}, skyColor = {newskyColor.r , newskyColor.g, newskyColor.b}, cloudColor = {newcloudColor.r+ lightningcolor, newcloudColor.g+ lightningcolor, newcloudColor.b+ lightningcolor}}) + --WATER + + -- Spring.Echo(waterBase.r) + -- newwaterBase.r, newwaterBase.g, newwaterBase.b = waterBase.r*(1-p)+0.23*p, waterBase.g*(1-p)+0.07*p, waterBase.b*(1-p)+0.035*p + -- newwaterAbsorb.r, newwaterAbsorb.g, newwaterAbsorb.b = waterAbsorb.r*(1+p), waterAbsorb.g*(1+p), waterAbsorb.b*(1+p) + -- newwaterMin.r, newwaterMin.g, newwaterMin.b = waterMin.r*(1-p), waterMin.g*(1-p), waterMin.b*(1-p) + -- newwaterSurface.r, newwaterSurface.g, newwaterSurface.b = waterSurface.r*(1-p)+0.23*p, waterSurface.g*(1-p)+0.07*p, waterSurface.b*(1-p)+0.035*p + -- newwaterSpecular.r, newwaterSpecular.g, newwaterSpecular.b = waterSpecular.r*(1-p)+0.05*p, waterSpecular.g*(1-p)+0.05*p, waterSpecular.b*(1-p)+0.05*p + -- newwaterPlane.r, newwaterPlane.g, newwaterPlane.b = waterPlane.r*(1-p)+0.2*p, waterPlane.g*(1-p)+0.06*p, waterPlane.b*(1-p)+0.03*p + + -- Spring.SetWaterParams( + -- {absorb = {newwaterAbsorb.r, newwaterAbsorb.g, newwaterAbsorb.b}, baseColor = {newwaterBase.r, newwaterBase.g, newwaterBase.b}, minColor = {newwaterMin.r, newwaterMin.g, newwaterMin.b}, surfaceColor = {newwaterSurface.r, newwaterSurface.g, newwaterSurface.b}, diffuseColor = {newdiffuse.r, newdiffuse.g, newdiffuse.b}, specularColor = {newwaterSpecular.r, newwaterSpecular.g, newwaterSpecular.b}, planeColor = {newwaterPlane.r, newwaterPlane.g, newwaterPlane.b}}) + + +end +function widget:Shutdown() + Spring.SetSunLighting({groundAmbientColor = {ambient.r, ambient.g, ambient.b} , groundDiffuseColor = {diffuse.r, diffuse.g, diffuse.b}, groundSpecularColor = {specular.r, specular.g, specular.b}, unitAmbientColor = {ambient.r, ambient.g, ambient.b} , unitDiffuseColor = {diffuse.r, diffuse.g, diffuse.b}, unitSpecularColor = {specular.r, specular.g, specular.b}}) + Spring.SetAtmosphere({fogStart = fogStart, fogEnd = fogEnd, fogColor = {fogColor.r, fogColor.g, fogColor.b, fogColor.alpha}, sunColor = {sunColor.r, sunColor.g, sunColor.b}, skyColor = {skyColor.r, skyColor.g, skyColor.b}, cloudColor = {cloudColor.r, cloudColor.g, cloudColor.b}}) +end \ No newline at end of file diff --git a/LuaUI/Widgets_Evo/gui_options.lua b/LuaUI/Widgets_Evo/gui_options.lua index 52d6767b1..cea643266 100644 --- a/LuaUI/Widgets_Evo/gui_options.lua +++ b/LuaUI/Widgets_Evo/gui_options.lua @@ -115,14 +115,14 @@ local presets = { grassdetail = 0, treeradius = 0, advsky = false, - daynight = false, + timecyclesweathereffects = false, outline = false, guishader = false, shadows = false, advmapshading = false, advmodelshading = false, decals = 0, - grounddetail = 60, + grounddetail = 64, darkenmap_darkenfeatures = false, enemyspotter_highlight = false, }, @@ -141,14 +141,14 @@ local presets = { grassdetail = 0, treeradius = 200, advsky = false, - daynight = false, + timecyclesweathereffects = false, outline = false, guishader = false, shadows = false, advmapshading = true, advmodelshading = true, decals = 0, - grounddetail = 90, + grounddetail = 64, darkenmap_darkenfeatures = false, enemyspotter_highlight = false, }, @@ -167,14 +167,14 @@ local presets = { grassdetail = 0, treeradius = 400, advsky = false, - daynight = false, + timecyclesweathereffects = false, outline = false, guishader = false, shadows = false, advmapshading = true, advmodelshading = true, decals = 1, - grounddetail = 140, + grounddetail = 64, darkenmap_darkenfeatures = false, enemyspotter_highlight = false, }, @@ -193,14 +193,14 @@ local presets = { grassdetail = 0, treeradius = 800, advsky = true, - daynight = true, + timecyclesweathereffects = false, outline = true, guishader = true, shadows = true, advmapshading = true, advmodelshading = true, decals = 2, - grounddetail = 180, + grounddetail = 64, darkenmap_darkenfeatures = false, enemyspotter_highlight = false, }, @@ -219,14 +219,14 @@ local presets = { grassdetail = 0, treeradius = 800, advsky = true, - daynight = true, + timecyclesweathereffects = false, outline = true, guishader = true, shadows = true, advmapshading = true, advmodelshading = true, decals = 3, - grounddetail = 200, + grounddetail = 64, darkenmap_darkenfeatures = true, enemyspotter_highlight = true, }, @@ -822,9 +822,9 @@ function applyOptionValue(i, skipRedrawWindow) Spring.SetConfigInt("AdvModelShading",value) elseif id == 'advsky' then Spring.SetConfigInt("AdvSky",value) - elseif id == 'daynight' then - Spring.SetConfigInt("DynamicSun",value) - Spring.SetConfigString("DynamicSunMinElevation", "0.1") + elseif id == 'timecyclesweathereffects' then + Spring.SetConfigInt("evo_timecyclesweathereffects",value) + Spring.SendCommands("luarules reloadluaui") elseif id == 'shadows' then Spring.SendCommands("Shadows "..value) elseif id == 'vsync' then @@ -1733,12 +1733,12 @@ function init() -- only one of these shadow options are shown, depending if "Shadow Quality Manager" widget is active {id="shadows", group="gfx", name="Shadows", type="bool", value=tonumber(Spring.GetConfigInt("Shadows",1) or 1) == 1, description='Shadow detail is currently controlled by "Shadow Quality Manager" widget\n...this widget will auto reduce detail when fps gets low.\n\nShadows requires "Advanced map shading" option to be enabled'}, - {id="shadowslider", group="gfx", name="Shadows", type="slider", min=1500, max=6000, step=500, value=tonumber(Spring.GetConfigInt("ShadowMapSize",1) or 2000), description='Set shadow detail\nSlider positioned the very left means shadows will be disabled\n\nShadows requires "Advanced map shading" option to be enabled'}, + {id="shadowslider", group="gfx", name="Shadows", type="slider", min=2048, max=8192, step=500, value=tonumber(Spring.GetConfigInt("ShadowMapSize",1) or 2048), description='Set shadow detail\nSlider positioned the very left means shadows will be disabled\n\nShadows requires "Advanced map shading" option to be enabled'}, {id="decals", group="gfx", name="Ground decals", type="slider", min=0, max=5, step=1, value=tonumber(Spring.GetConfigInt("GroundDecals",1) or 1), description='Set how long map decals will stay.\n\nDecals are ground scars, footsteps/tracks and shading under buildings'}, - {id="grounddetail", group="gfx", name="Ground detail", type="slider", min=60, max=200, step=1, value=tonumber(Spring.GetConfigInt("GroundDetail",1) or 1), description='Set how detailed the map mesh/model is'}, + {id="grounddetail", group="gfx", name="Ground detail", type="slider", min=32, max=200, step=1, value=tonumber(Spring.GetConfigInt("GroundDetail",1) or 64), description='Set how detailed the map mesh/model is'}, {id="mapedgeextension", group="gfx", widget="Map Edge Extension", name="Map edge extension", type="bool", value=GetWidgetToggleValue("Map Edge Extension"), description='Mirrors the map at screen edges and darkens and decolorizes them\n\nEnable shaders for best result'}, - {id="grassdetail", group="gfx", name="Grass", type="slider", min=0, max=10, step=1, value=tonumber(Spring.GetConfigInt("GrassDetail",1) or 5), description='Amount of grass rendered\n\nChanges will be applied next game'}, + {id="grassdetail", group="gfx", name="Grass", type="slider", min=0, max=10, step=1, value=tonumber(Spring.GetConfigInt("GrassDetail",0) or 0), description='Amount of grass rendered\n\nChanges will be applied next game'}, {id="water", group="gfx", name="Water type", type="select", options={'basic','reflective','dynamic','reflective&refractive','bump-mapped'}, value=(tonumber(Spring.GetConfigInt("Water",1) or 1)+1)}, {id="bloom", group="gfx", widget="Bloom Shader", name="Bloom", type="bool", value=GetWidgetToggleValue("Bloom Shader"), description='Bloom will make the map and units glow'}, @@ -1759,14 +1759,14 @@ function init() {id="outline", group="gfx", widget="Outline", name="Unit outline", type="bool", value=GetWidgetToggleValue("Outline"), description='Adds a small outline to all units which makes them crisp\n\nLimits total outlined units to 1200.\nStops rendering outlines when average fps falls below 13.'}, {id="xrayshader", group="gfx", widget="XrayShader", name="Unit xray shader", type="bool", value=GetWidgetToggleValue("XrayShader"), description='Highlights all units, highlight effect dissolves on close camera range.\n\nFades out and disables at low fps\nWorks less on dark teamcolors'}, - {id="particles", group="gfx", name="Max particles", type="slider", min=5000, max=25000, step=500, value=tonumber(Spring.GetConfigInt("MaxParticles",1) or 1000), description='Particles used for explosions, smoke, fire and missiletrails\n\nSetting a low value will mean that various effects wont show properly'}, + {id="particles", group="gfx", name="Max particles", type="slider", min=5000, max=25000, step=500, value=tonumber(Spring.GetConfigInt("MaxParticles",1) or 10000), description='Particles used for explosions, smoke, fire and missiletrails\n\nSetting a low value will mean that various effects wont show properly'}, {id="nanoparticles", group="gfx", name="Max nano particles", type="slider", min=500, max=5000, step=100, value=tonumber(Spring.GetConfigInt("MaxNanoParticles",1) or 500), description='NOTE: Nano particles are more expensive regarding the CPU'}, {id="iconadjuster", group="gfx", name="Unit icon scale", min=0.8, max=1.2, step=0.05, type="slider", value=1, description='Sets radar/unit icon size\n\n(Used for unit icon distance and minimap icons)'}, - {id="disticon", group="gfx", name="Icon render distance", type="slider", min=0, max=800, step=10, value=tonumber(Spring.GetConfigInt("UnitIconDist",1) or 800)}, + {id="disticon", group="gfx", name="Icon render distance", type="slider", min=0, max=800, step=10, value=tonumber(Spring.GetConfigInt("UnitIconDist",1) or 300)}, {id="treeradius", group="gfx", name="Tree render distance", type="slider", min=0, max=2000, step=50, value=tonumber(Spring.GetConfigInt("TreeRadius",1) or 1000), description='Applies to SpringRTS engine default trees\n\nChanges will be applied next game'}, - {id="daynight", group="gfx", name="Day/Night Cycles", type="bool", value=tonumber(Spring.GetConfigInt("DynamicSun",1) or 1) == 1, description='Enables Day/Night Cycles\n\nChanges will be applied next game'}, + {id="timecyclesweathereffects", group="gfx", name="Day/Night/Weather Cycles", type="bool", value=tonumber(Spring.GetConfigInt("evo_timecyclesweathereffects",0) or 0) == 1, description='Enables Day/Night Cycles and Weather Effects\n\nTHIS IS HIGHLY EXPERIMENTAL!!! *Could Cause Crashes on older hardware!!!*\n*NOTE* This will cause all widgets to reload'}, {id="snow", group="gfx", widget="Snow", name="Snow", type="bool", value=GetWidgetToggleValue("Snow"), description='Snow widget (By default.. maps with wintery names have snow applied)'}, {id="snowmap", group="gfx", name=widgetOptionColor.." enabled on this map", type="bool", value=true, description='It will remember what you toggled for every map\n\n\(by default: maps with wintery names have this toggled)'}, {id="snowautoreduce", group="gfx", name=widgetOptionColor.." auto reduce", type="bool", value=true, description='Automaticly reduce snow when average FPS gets lower\n\n(re-enabling this needs time to readjust to average fps again'}, @@ -1784,7 +1784,7 @@ function init() {id="sndvolbattle", group="snd", name="Battle volume", type="slider", min=0, max=100, step=2, value=tonumber(Spring.GetConfigInt("snd_volbattle",1) or 100)}, {id="sndvolui", group="snd", name="Interface volume", type="slider", min=0, max=100, step=2, value=tonumber(Spring.GetConfigInt("snd_volui",1) or 100)}, {id="sndvolunitreply", group="snd", name="Unit reply volume", type="slider", min=0, max=100, step=2, value=tonumber(Spring.GetConfigInt("snd_volunitreply",1) or 100)}, - {id="sndvolmusic", group="snd", name="Music volume", type="slider", min=0, max=100, step=2, value=tonumber(Spring.GetConfigInt("snd_volmusic",1) or 100)}, + {id="sndvolmusic", group="snd", name="Music volume", type="slider", min=0, max=100, step=2, value=tonumber(Spring.GetConfigInt("snd_volmusic",1) or 20)}, {id="dynamicmusic", group="snd", name="Dynamic Music", type="bool", value=tonumber(Spring.GetConfigInt("evo_dynamicmusic",1) or 1) == 1, description="If enabled, Music trackks will dynamically switch between war and peace depending on what is going on at that moment."}, {id="interruptmusic", group="snd", name="Dynamic Music Interruption", type="bool", value=tonumber(Spring.GetConfigInt("evo_interruptmusic",1) or 1) == 1, description="If enabled, Music tracks will fade out and switch from peace to war \nand vice versa at that moment instead of allowing the entire peace or war track to finish first."}, --{id="sndairabsorption", group="snd", name="Air absorption", type="slider", min=0, max=0.5, step=0.01, value=tonumber(Spring.GetConfigInt("snd_airAbsorption",1) or.1)}, @@ -1793,7 +1793,7 @@ function init() -- CONTROL {id="camera", group="control", name="Camera", type="select", options={'fps','overhead','spring','rot overhead','free'}, value=(tonumber((Spring.GetConfigInt("CamMode",1)+1) or 2))}, {id="camerashake", group="control", widget="CameraShake", name="Camera shake", type="bool", value=GetWidgetToggleValue("CameraShake"), description='Shakes camera on explosions'}, - {id="scrollspeed", group="control", name="Zoom direction/speed", type="slider", min=-45, max=45, step=1, value=tonumber(Spring.GetConfigInt("ScrollWheelSpeed",1) or 25), description='Leftside of the slider means inversed scrolling direction!\nNOTE: Having the slider centered means no mousewheel zooming at all!'}, + {id="scrollspeed", group="control", name="Zoom direction/speed", type="slider", min=-45, max=45, step=1, value=tonumber(Spring.GetConfigInt("ScrollWheelSpeed",1) or -25), description='Leftside of the slider means inversed scrolling direction!\nNOTE: Having the slider centered means no mousewheel zooming at all!'}, {id="hwcursor", group="control", name="Hardware cursor", type="bool", value=tonumber(Spring.GetConfigInt("hardwareCursor",1) or 1) == 1, description="When disabled: the mouse cursor refresh rate will be the same as your ingame fps"}, {id="crossalpha", group="control", name="Mouse cross alpha", type="slider", min=0, max=1, step=0.05, value=tonumber(Spring.GetConfigString("CrossAlpha",1) or 1), description='Opacity of mouse icon in center of screen when you are in camera pan mode\n\n(The\'icon\' has a dot in center with 4 arrows pointing in all directions)'},