Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Lightmap UV
- If face.LightMap >= 0 Then
- 'face.LightMapPos int: Pixel position on big lightmap (not counting padding)
- 'face.LightMinUV float: DotProduct(vert.x, vert.y, vert.z, texInfo.VectorS.x, texInfo.VectorS.y, texInfo.VectorS.z) + texInfo.DistS
- 'face.LightDist int: Ceil(LightMaxUV.x / 16) - Floor(LightMinUV.x / 16)
- 'face.LightMapSize int: LightDist + 1
- 'lightU/V float
- 'LightMapTexture.width/height int
- lightU = (s - Floor(face.LightMinUV.x / 16) * 16) / (face.LightDist.x + 1)
- lightV = (t - Ceil(face.LightMinUV.y / 16) * 16) / (face.LightDist.y + 1)
- lightU = (face.LightMapPos.x + lightU * face.LightMapSize.x) / Float(Self.LightMapTexture.width)
- lightV = (face.LightMapPos.y + lightV * face.LightMapSize.y) / Float(Self.LightMapTexture.Height)
- 'surf, vertice count, light U, light V, Light W, Coord set
- VertexTexCoords(surf, vertCount, lightU, lightV, 0, 1)
- EndIf
- Method CalcLightmapSize:TQIntVec2(bsp:TQBSP)
- If Self.LightMap < 0 Then Return New TQIntVec2
- If LightMapSize Then
- 'Return same if already calculated
- Return LightMapSize
- Else
- 'Being a new calculation!
- LightMapSize = New TQIntVec2
- EndIf
- 'Get the vertex data from all edges
- LightDist = New TQIntVec2
- LightMinUV = New TQVec2
- LightMaxUV = New TQVec2
- Local ledge:TQLedge
- Local edge:TQEdge
- Local vert:TQVertex
- Local texInfo:TQSurface = bsp.texInfo[Self.TexInfo_ID]
- For Local eNr:Int = Self.Ledge_ID Until Self.Ledge_ID + Self.Ledge_Num 'Go through edges
- ledge = bsp.Ledges[eNr] 'Get ledge
- edge = bsp.Edges[Abs(ledge.edge)] 'Get edge via ledge
- If ledge.edge < 0 Then
- vert = bsp.Vertices[edge.Vertex0]
- Else
- vert = bsp.Vertices[edge.Vertex1]
- EndIf
- LightS = DotProduct(vert.x, vert.y, vert.z, texInfo.VectorS.x, texInfo.VectorS.y, texInfo.VectorS.z) + texInfo.DistS
- LightT = DotProduct(vert.x, vert.y, vert.z, texInfo.VectorT.x, texInfo.VectorT.y, texInfo.VectorT.z) + texInfo.DistT
- If (eNr = Self.Ledge_ID) Then
- 'Starting point
- LightMinUV.x = LightS
- LightMinUV.y = LightT
- LightMaxUV.x = LightS
- LightMaxUV.y = LightT
- Else
- 'Is this a new minimum?
- If LightS < LightMinUV.x Then LightMinUV.x = LightS
- If LightT < LightMinUV.y Then LightMinUV.y = LightT
- 'Is this a new maximum
- If LightS > LightMaxUV.x Then LightMaxUV.x = LightS
- If LightT > LightMaxUV.y Then LightMaxUV.y = LightT
- End If
- Next
- 'Get distances
- LightDist.x = Ceil(LightMaxUV.x / 16) - Floor(LightMinUV.x / 16)
- LightDist.y = Ceil(LightMaxUV.y / 16) - Floor(LightMinUV.y / 16)
- LightMapSize.x = LightDist.x + 1
- LightMapSize.y = LightDist.y + 1
- LightDist.x:*16
- LightDist.y:*16
- Return LightMapSize
- EndMethod
- Method MakeLightmap(bsp:TQBSP)
- If Self.LightMap < 0 Then Return
- If LightMapSize.x <= 0 Or LightMapSize.y <= 0 Then Return
- If bsp.LightMapPreW + LightMapSize.x >= bsp.LightMapPixmap.width Then
- bsp.LightMapPreW = LIGHT_PAD * 2
- bsp.LightMapPreH:+bsp.LightMapMaxH
- bsp.LightMapMaxH = 0
- EndIf
- Self.LightMapPos = New TQVec2
- Self.LightMapPos.x = bsp.LightMapPreW
- Self.LightMapPos.y = bsp.LightMapPreH
- Local x:Int
- Local y:Int
- Local cI:Int
- Local color:Byte
- For y = 0 Until LightMapSize.y
- For x = 0 Until LightMapSize.x
- color = bsp.LightMapLump[Self.LightMap + cI]
- color = Min(color + bsp.LightMapBrightness, 255)
- If color < bsp.LightMapMinBright Then color = bsp.LightMapMinBright
- If color > bsp.LightMapMaxBright Then color = bsp.LightMapMaxBright
- 'Debug outline
- 'If x = 0 Or y = 0 Or x = LightMapSize.x - 1 Or y = LightMapSize.y - 1 Then
- ' bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x, bsp.LightMapPreH + y, GenRGB(255, 0, 0))
- 'Else
- bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x, bsp.LightMapPreH + y, GenRGB(color, color, color))
- 'EndIf
- 'Padding
- If y = 0 And x = 0 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x - 1, bsp.LightMapPreH + y - 1, GenRGB(color, color, color))
- If y = 0 And x = LightMapSize.x - 1 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x + 1, bsp.LightMapPreH + y - 1, GenRGB(color, color, color))
- If y = LightMapSize.y - 1 And x = 0 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x - 1, bsp.LightMapPreH + y + 1, GenRGB(color, color, color))
- If y = LightMapSize.y - 1 And x = LightMapSize.x - 1 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x + 1, bsp.LightMapPreH + y + 1, GenRGB(color, color, color))
- If y = 0 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x, bsp.LightMapPreH + y - 1, GenRGB(color, color, color))
- If x = 0 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x - 1, bsp.LightMapPreH + y, GenRGB(color, color, color))
- If y = LightMapSize.y - 1 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x, bsp.LightMapPreH + y + 1, GenRGB(color, color, color))
- If x = LightMapSize.x - 1 Then bsp.LightMapPixmap.WritePixel(bsp.LightMapPreW + x + 1, bsp.LightMapPreH + y, GenRGB(color, color, color))
- cI:+1
- Next
- Next
- bsp.LightMapPreW:+LightMapSize.x + LIGHT_PAD * 2
- If bsp.LightMapMaxH < Self.LightMapSize.y + LIGHT_PAD Then bsp.LightMapMaxH = Self.LightMapSize.y + LIGHT_PAD
- EndMethod
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement