Skip to content

Commit

Permalink
Texture improvements.
Browse files Browse the repository at this point in the history
Fix cliffs and a bug with close cells.
  • Loading branch information
GoogleFrog committed Sep 27, 2021
1 parent 4008632 commit 61d5140
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 52 deletions.
68 changes: 42 additions & 26 deletions luarules/gadgets/map_terrain_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,11 @@ local function GetRandomPointInCircle(pos, radius, edgeBuffer, onBorder)
return PutPointInMap(randomPos, edgeBuffer)
end

local function GetRandomPointInCircleAvoid(avoidDist, avoidPoints, maxAttempts, pos, radius, edgeBuffer)
local point = GetRandomPointInCircle(pos, radius, edgeBuffer)
local function GetRandomPointInCircleAvoid(avoidDist, avoidPoints, maxAttempts, pos, radius, edgeBuffer, onBorder, useOtherSize)
local point = GetRandomPointInCircle(pos, radius, edgeBuffer, onBorder)
local attempts = 1
while (select(2, GetClosestPoint(point, avoidPoints, useOtherSize)) or 0) < avoidDist do
point = GetRandomPointInCircle(pos, radius, edgeBuffer)
point = GetRandomPointInCircle(pos, radius, edgeBuffer, onBorder)
attempts = attempts + 1
if attempts > maxAttempts then
break
Expand Down Expand Up @@ -636,6 +636,11 @@ local CIRCLE_POINTS = {}
for i = pi, pi*3/2 + pi/(4*POINT_COUNT), pi/(2*POINT_COUNT) do
CIRCLE_POINTS[#CIRCLE_POINTS + 1] = {1 + cos(i), 1 + sin(i)}
end
local HIT_EDGE_POINTS = {}
for i = pi, pi*3/2 + pi/(4*POINT_COUNT), pi/(2*POINT_COUNT) do
local prop = math.min(1, (i - pi)/(pi/2 + pi/(4*POINT_COUNT)))
HIT_EDGE_POINTS[#HIT_EDGE_POINTS + 1] = {0.5 + (1 - prop)*cos(i) + prop*0.5, 1 + sin(i)}
end

local STRAIGHT_EDGE_POINTS = 18

Expand Down Expand Up @@ -711,9 +716,6 @@ local function GenerateVoronoiCells(points)
end
if intersections then
if #intersections ~= 2 then
--for e = 1, #cells do
-- CellEcho(cells[e])
--end
--for e = 1, #intersections do
-- PointEcho(intersections[e], "Int: " .. e)
--end
Expand Down Expand Up @@ -894,6 +896,11 @@ local function CleanVoronoiReferences(cells)
end

if thisEdge.length < MIN_EDGE_LENGTH then
-- Restart without one of the cells adjacent to this edge.
--LineEcho(thisEdge, "REMOVED")
--for i = 1, #cells do
-- CellEcho(cells[i])
--end
return cells, edgeList, thisEdge.faces[random(1, #thisEdge.faces)].index
end
end
Expand Down Expand Up @@ -978,10 +985,10 @@ local function DoPointSplit(points, radius, ignoreSplit)
if i < point.mirror and not (ignoreSplit and ignoreSplit[i]) then
local index, dist = GetClosestPoint(point, points, false, i)
if dist > radius then
local newPoint = GetRandomPointInCircle(point, radius*0.45, 50, true)
local newPoint = GetRandomPointInCircle(point, radius*0.5, 50, true)

-- Mirror around point
pointsToAdd[#pointsToAdd + 1] = PutPointInMap(RotateAround(newPoint, point), 50)
-- Mirror around point and add some randomness.
pointsToAdd[#pointsToAdd + 1] = GetRandomPointInCircleAvoid(radius*0.25, {newPoint}, 50, RotateAround(newPoint, point), 50, radius*0.25, 50)

-- Replace and mirror around map centre
local newPointMirror = ApplyRotSymmetry(newPoint)
Expand Down Expand Up @@ -1019,7 +1026,7 @@ local function MakeRandomPoints(params)
end

for i = 1, midPoints do
local point = GetRandomPointInCircleAvoid(params.midPointSpace, points, 50, {MAP_X/2, MAP_Z/2}, params.midPointRadius)
local point = GetRandomPointInCircleAvoid(params.midPointSpace, points, 50, {MAP_X/2, MAP_Z/2}, params.midPointRadius, 50, false, true)
AddPointAndMirror(points, point, params.midPointSpace)
end

Expand All @@ -1041,12 +1048,7 @@ local function GetVoronoi(params)
local thisCell = cells[i]
if thisCell.site and (thisCell.index ~= badSite) and ((not thisCell.mirror) or (thisCell.mirror.index ~= badSite)) then
local point = {thisCell.site[1], thisCell.site[2]}
local pointMirror = ApplyRotSymmetry(point)

points[#points + 1] = point
pointMirror.mirror = #points
points[#points + 1] = pointMirror
point.mirror = #points
AddPointAndMirror(points, point, thisCell.size)

thisCell.site = nil
if thisCell.mirror then
Expand Down Expand Up @@ -1588,6 +1590,18 @@ local function GetCurveHeightModifiers(tierFlood, cellTier, otherTier, heightMod
end
end

local function MakeMapBorderEdgeHit(tierFlood, cellTier, otherTier, heightMod, intPoint, edgeOut, otherOut, startWidth, endWidth, otherClockwise)
local curve = {}
for i = 1, #HIT_EDGE_POINTS do
local randRad = (i - 1)*(#HIT_EDGE_POINTS - i)/(#HIT_EDGE_POINTS*2)
local nextPoint = GetRandomPointInCircle(HIT_EDGE_POINTS[i], 0.04*randRad)
curve[#curve + 1] = Add(intPoint, ChangeBasis(nextPoint, edgeOut[1], otherOut[1], edgeOut[2], otherOut[2]))
--PointEcho(curve[#curve], i)
end

GetCurveHeightModifiers(tierFlood, cellTier, otherTier, heightMod, curve, startWidth, endWidth, otherClockwise)
end

local function GenerateEdgeMeetTerrain(tierFlood, heightMod, cells, cell, edge, otherEdge, edgeIncidence)
local cellIndex = cell.index
local intPoint = edge[edgeIncidence]
Expand All @@ -1611,7 +1625,7 @@ local function GenerateEdgeMeetTerrain(tierFlood, heightMod, cells, cell, edge,
end
local otherTier = otherEdge.otherFace[cellIndex].tier
otherClockwise = not otherClockwise
GetLineHeightModifiers(tierFlood, cellTier, otherTier, heightMod, intPoint, Add(intPoint, otherOut), otherEdge.terrainWidth, otherClockwise)
MakeMapBorderEdgeHit(tierFlood, cellTier, otherTier, heightMod, intPoint, otherOut, edgeOut, otherEdge.terrainWidth, edge.terrainWidth, otherClockwise)
return
end

Expand All @@ -1623,7 +1637,7 @@ local function GenerateEdgeMeetTerrain(tierFlood, heightMod, cells, cell, edge,
return
end
local otherTier = edge.otherFace[cellIndex].tier
GetLineHeightModifiers(tierFlood, cellTier, otherTier, heightMod, intPoint, Add(intPoint, edgeOut), edge.terrainWidth, otherClockwise)
MakeMapBorderEdgeHit(tierFlood, cellTier, otherTier, heightMod, intPoint, edgeOut, otherOut, edge.terrainWidth, otherEdge.terrainWidth, otherClockwise)
return
end

Expand All @@ -1640,7 +1654,9 @@ local function GenerateEdgeMeetTerrain(tierFlood, heightMod, cells, cell, edge,

local curve = {}
for i = 1, #CIRCLE_POINTS do
curve[#curve + 1] = Add(intPoint, ChangeBasis(CIRCLE_POINTS[i], edgeOut[1], otherOut[1], edgeOut[2], otherOut[2]))
local randRad = (i - 1)*(#CIRCLE_POINTS - i)/(#CIRCLE_POINTS*2)
local nextPoint = GetRandomPointInCircle(CIRCLE_POINTS[i], 0.025*randRad)
curve[#curve + 1] = Add(intPoint, ChangeBasis(nextPoint, edgeOut[1], otherOut[1], edgeOut[2], otherOut[2]))
--PointEcho(curve[#curve], i)
end

Expand Down Expand Up @@ -2713,20 +2729,20 @@ local waitCount = 0

local newParams = {
startPoint = {500, 500},
startPointSize = 880,
startPointSize = 800,
points = 21,
midPoints = 3,
midPointRadius = 900,
midPointSpace = 100,
midPointSpace = 160,
minSpace = 150,
maxSpace = 350,
pointSplitRadius = 500,
edgeBias = 1.4,
flatNeighbourIgloo = 560,
lowDiffNeighbourIgloo = 380,
highDiffNeighbourIgloo = 200,
cliffWidth = 22,
rampWidth = 240,
cliffWidth = 36,
rampWidth = 280,
generalWaveMod = 0.9,
waveDirectMult = 0.5,
bucketBase = 55,
Expand All @@ -2743,7 +2759,7 @@ local newParams = {
local function MakeMap()
local params = newParams
local randomSeed = GetSeed()
--randomSeed = 44911 -- A crash
--randomSeed = 44911
math.randomseed(randomSeed)

Spring.SetGameRulesParam("typemap", "temperate2")
Expand Down Expand Up @@ -2841,8 +2857,8 @@ function LineDraw(p1, p2)
end
end

function CellEcho(cell)
--PointEcho(cell.site, "Cell: " .. cell.index .. ", edges: " .. #cell.edges)
function CellEcho(cell, text)
PointEcho(cell.site, "Cell: " .. (cell.index or "NULL") .. (text or (", edges: " .. #cell.edges)))
for k = 1, #cell.edges do
LineDraw(cell.edges[k])
end
Expand Down
52 changes: 35 additions & 17 deletions luarules/gadgets/randommapgen_texture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ local COLOR_TEX_LIMIT = 6
local floor = math.floor
local random = math.random

local SPLAT_DETAIL_TEX_POOL = {
{0.7,0.0,0.0,1.0}, --R
{0.0,0.9,0.0,1.0}, --G
{0.0,0.0,1.0,1.0}, --B
{0.0,0.0,0.0,1.0}, --A
local SPLAT_POOL = {
{0.55,0.0,0.0,0.7}, --R
{0.0,0.75,0.0,0.7}, --G
{0.0,0.0,0.75,0.7}, --B
{0.0,0.0,0.0,0.7}, --A
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -206,7 +206,7 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
for j = 1, #texX do
if i < COLOR_TEX_LIMIT then
local prop = math.max(0, math.min(1, (mapHeight[texX[j]][texZ[j]] - 20)/400))
glColor(0.6 + 0.4*(1 - prop), 0.65 + 0.3*prop, 0.9 + 0.1*(1 - prop), 0.95 + 0.1*(1 - prop))
glColor(0.6 + 0.4*(1 - prop), 0.65 + 0.3*prop, 0.9 + 0.1*(1 - prop), 0.83 + 0.15*(1 - prop))
end
glTexRect(texX[j]*MAP_FAC_X - 1, texZ[j]*MAP_FAC_Z - 1,
texX[j]*MAP_FAC_X + DRAW_OFFSET, texZ[j]*MAP_FAC_Z + DRAW_OFFSET)
Expand Down Expand Up @@ -250,12 +250,19 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
if USE_SHADING_TEXTURE then
local ago2 = Spring.GetTimer()
glRenderToTexture(topSplattex, function ()
for i = 1, #SPLAT_DETAIL_TEX_POOL do
for i = 1, #SPLAT_POOL do
local texX = splatTexX[i]
local texZ = splatTexZ[i]
if texX then
glColor(SPLAT_DETAIL_TEX_POOL[i])
local red, green, blue, alpha = SPLAT_POOL[i][1], SPLAT_POOL[i][2], SPLAT_POOL[i][3], SPLAT_POOL[i][4]
for j = 1, #texX do
--if i == 1 then
-- glColor(0.5 + math.random()*0.5, green + math.random()*0.25, 0.1 + math.random()*0.6, alpha + math.random()*0.3)
--elseif i == 2 then
-- glColor(red + math.random()*0.25, 0.4 + math.random()*0.6, blue + math.random()*0.25, alpha + math.random()*0.3)
--else
glColor(red + math.random()*0.25, green + math.random()*0.25, blue + math.random()*0.25, alpha + math.random()*0.3)
--end
glRect(texX[j]*MAP_FAC_X -1, texZ[j]*MAP_FAC_Z - 1, texX[j]*MAP_FAC_X + DRAW_OFFSET, texZ[j]*MAP_FAC_Z + DRAW_OFFSET)
end
end
Expand Down Expand Up @@ -464,7 +471,11 @@ local function GetTopTex(normal, height, vehiclePass, botPassPlus, botPass, inWa
local textureProp = (1 - (normal - minNorm)/(maxNorm - minNorm))
local topAlpha
if vehiclePass then
topAlpha = 0.95*textureProp
if textureProp > 0.15 then
topAlpha = 0.075 + 0.875*(textureProp - 0.15) / 0.85
else
topAlpha = 0.5*textureProp
end
elseif botPassPlus then
topAlpha = textureProp
elseif botPass then
Expand All @@ -480,15 +491,22 @@ local function GetTopTex(normal, height, vehiclePass, botPassPlus, botPass, inWa
end

if vehiclePass then
if textureProp > 0.2 then
if height%8 > 5 then
local prop = math.max(0, math.min(1, (textureProp - 0.2)/0.3))*0.8 + 0.2
topAlpha = topAlpha - (0.14 + 0.1*prop)
if textureProp > 0.18 then
if height%7 > 4.5 then
local prop = math.max(0, math.min(1, (textureProp - 0.18)/0.3))*0.8 + 0.2
topAlpha = math.max(0, topAlpha - (0.1 + 0.22*prop))
end
end
elseif botPassPlus then
if height%8 > 5 then
local modHeight = height%7
if modHeight > 6.5 then
local prop = 1 - (modHeight - 6)*2
topAlpha = textureProp*(0.1 + 0.2*prop) + (0.9 - 0.2*prop)
elseif modHeight > 4.5 then
topAlpha = textureProp*0.3 + 0.7
elseif modHeight > 4 then
local prop = (modHeight - 4)*2
topAlpha = textureProp*(0.1 + 0.2*prop) + (0.9 - 0.2*prop)
else
topAlpha = textureProp*0.1 + 0.9
end
Expand All @@ -497,9 +515,9 @@ local function GetTopTex(normal, height, vehiclePass, botPassPlus, botPass, inWa
topAlpha = (1 - topAlpha)*textureProp + (1 - topAlpha)*textureProp
end
else
local modHeight = height%60
if modHeight > 24 then
local prop = (1 - math.abs(modHeight - 36)/18)*0.05
local modHeight = (height -2 + 4*math.random())%54
if modHeight > 18 then
local prop = math.min(1, 1.2*(1 - math.abs(modHeight - 36)/18)*0.05)
topAlpha = (1 - topAlpha)*prop + (1 - prop)*topAlpha
else
return false
Expand Down
18 changes: 9 additions & 9 deletions mapinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local mapinfo = {
},
},
splats = {
texScales = {0.006, 0.02, 0.012, 0.012},
texScales = {0.0045, 0.023, 0.061, 0.053},
texMults = {0.5, 0.3, 0.35, 0},
},

Expand Down Expand Up @@ -82,19 +82,19 @@ local mapinfo = {
--// dynsun
sunStartAngle = 0.0,
sunOrbitTime = 1440.0,
sunDir = {0.25, 1.0, 0.2, 1e9},
sunDir = {0.35, 1.0, 0.3, 1e9},

--// unit & ground lighting
groundAmbientColor = {0.5, 0.5, 0.5},
groundDiffuseColor = {0.5, 0.5, 0.5},
groundAmbientColor = {0.35, 0.45, 0.3},
groundDiffuseColor = {0.7, 0.72, 0.43},
groundSpecularColor = {0.1, 0.1, 0.1},
groundShadowDensity = 0.8,
unitAmbientColor = {0.4, 0.4, 0.4},
unitDiffuseColor = {0.7, 0.7, 0.7},
unitSpecularColor = {0.7, 0.7, 0.7},
unitShadowDensity = 0.8,
unitAmbientColor = {0.55, 0.55, 0.45},
unitDiffuseColor = {0.85, 0.85, 0.85},
unitSpecularColor = {0.85, 0.85, 0.85},
unitShadowDensity = 0.4,

specularExponent = 100.0,
specularExponent = 3.0,
},

water = {
Expand Down
Binary file modified unittextures/tacticalview/temperate2/v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 61d5140

Please sign in to comment.