it doesn't take terrain into account because it's a grid of squares and I can't go around to modify each of those squares, as it's already too expensive to draw them being all generic (plus I wouldn't know how to do it
)
but now that I remember (and checked), the squares are actually drawn on top of everything, so even if the squares grid is below the level of a cliff, it still looks on top of it from a mostly vertical view
also forgot to add that since it draws squares based on visible terrain and camera height, a very low camera that looks to the horizon makes it all extremely slow
so yeah I guess I could make updates slower (instead of every frame, like it is now) and would probably get a big performance boost.
however I wouldn't know how to do it because I think it's above my experience
anyway I'm releasing the widget. it was improved abit (now the circles "fade" by having multiple layers at different distances). do know that if you change this "fade" amount (Spheres var) you need to change the alpha value accordingly
it's abit messy as there's probably vars that I don't use anymore, etc
feel free to improve it (and release it again
)
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Fog of war",
desc = "Fog of war",
author = "camera Fog:unknown / modified by Chosker for fog of war",
date = "when?",
license = "GNU GPL, v2 or later",
layer = 10,
enabled = true
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----edit here:
local FogDefs = {
Spheres = 2,
Color = {0.0,0.0,0.0,0.15},
SphereSpacing = 10.5,
Density = 1,
Radius = 15,
MaxHeight = 3000,
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----"global" variable list
local mapy = Game.mapY
local mapx = Game.mapX
local mapSizeX = Game.mapSizeX
local mapSizeZ = Game.mapSizeZ
local e = Spring.Echo
local fog
local layers = FogDefs.Spheres
local density = FogDefs.Density
local distance = FogDefs.Radius
local lsp = FogDefs.SphereSpacing
local fr,fg,fb,fa = unpack(FogDefs.Color)
local diff = layers/lsp
local mh = FogDefs.MaxHeight
local maxres = 800
local minres = 5000
local planeheight = 110
local ringspacing = 30
local templosdistance = 250
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----a simple plane, very complete, would look good with shadows, reflex and stuff.
local DrawPlaneModel = function()
gl.BeginEnd(GL.QUAD_STRIP,function()
gl.Vertex(-mapx*1024,0,-mapy*1024)
gl.TexCoord(0,0)
gl.Normal(0,mapx*256,0)
gl.Vertex(mapx*2048,0,-mapy*1024)
gl.TexCoord(1,0)
gl.Normal(0,mapx*256,0)
gl.Vertex(-mapx*1024,0,mapy*2048)
gl.TexCoord(0,1)
gl.Normal(0,mapx*256,0)
gl.Vertex(mapx*2048,0,mapy*2048)
gl.TexCoord(1,1)
gl.Normal(0,mapx*256,0)
end)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----a simple quad.
local DrawSphereModel = function()
gl.BeginEnd(GL.TRIANGLES,function()
gl.Vertex(1.0,-0.0, 1.0)
gl.Vertex(-1.0, -0.0, 1.0)
gl.Vertex(1.0, -0.0, -1.0)
end)
gl.BeginEnd(GL.TRIANGLES,function()
gl.Vertex(1.0, -0.0, -1.0)
gl.Vertex(-1.0, -0.0, 1.0)
gl.Vertex(-1.0, -0.0, -1.0)
end)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----special effects down here
local GetLocalPlayerID = Spring.GetLocalPlayerID
local GetTeamUnits = Spring.GetTeamUnits
local GetUnitPosition = Spring.GetUnitPosition
local IsSphereInView = Spring.IsSphereInView
local GetCameraPosition = Spring.GetCameraPosition
local ux = {}
local uz = {}
local Fog = function(r,g,b,a)
local _,camy,_ = GetCameraPosition()
if camy < maxres then
camy = maxres
elseif camy > minres then
camy = minres
else
camy = camy
end
for mx = 0, mapSizeX/1, camy/32 do
for mz = 0, mapSizeZ/1, camy/32 do
local x = mx
local y = planeheight
local y2 = templosdistance
local y3 = ringspacing
local z = mz
if IsSphereInView (x,y,z,120) then
for i = 0,layers,1 do
local unit = Spring.GetUnitsInCylinder(x,z,(y2+i*y3))
if (unit[1])==nil then
local d1 = distance*((camy-64)/960)
local d2 = density
gl.PushMatrix()
gl.Translate(x,y,z)
gl.Color(r,g,b,a)
gl.DepthTest(false)
gl.Blending(true)
gl.Scale(d1+density,d1+density,d1+density)
gl.CallList(fog)
gl.PopMatrix()
gl.Smoothing(false,false,false)
end
end
end
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----draw functions, calls all the effect creators.
function widget:DrawWorld()
Fog(fr,fg,fb,fa)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----setup the list arrays
function widget:Initialize()
fog = gl.CreateList(DrawSphereModel)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------