├── radiosity_engine_11-25-24.rbxl
├── RadiosityEngine
├── MathHelper.lua
├── Canvas.lua
├── Rendering.lua
├── Manager.lua
└── TopologyHelper.lua
├── main.lua
├── README.md
└── LICENSE
/radiosity_engine_11-25-24.rbxl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Razorboot/radiosity_engine_luau/HEAD/radiosity_engine_11-25-24.rbxl
--------------------------------------------------------------------------------
/RadiosityEngine/MathHelper.lua:
--------------------------------------------------------------------------------
1 | --# Point
2 | local MathHelper = {}
3 |
4 |
5 | --# Quick References
6 | local vec2, cf, vec3, udim2, c3, mr, mp, sqrt, abs, clamp, vec3FromNormalId = Vector2.new, CFrame.new, Vector3.new, UDim2.new, Color3.new, math.random, math.pow, math.sqrt, math.abs, math.clamp, Vector3.FromNormalId
7 | local DOUBLE_PI = 2 * math.pi
8 | MathHelper.EPSILON = 0.0001
9 |
10 |
11 | --# Functions
12 | @native
13 | function MathHelper.lengthSquaredVec3(vector: Vector3)
14 | return mp(vector.Magnitude, 2)
15 | end
16 |
17 | @native
18 | function MathHelper.randomDouble()
19 | return mr(-100000, 100000) * 0.00001
20 | end
21 |
22 | @native
23 | function MathHelper.quickRandomDouble()
24 | return mr(-1000, 1000) * 0.001
25 | end
26 |
27 | @native
28 | function MathHelper.randomPointInCircle(maxRadius: number)
29 | -- Generate a random point within the circle
30 | local randomRadiusX = MathHelper.quickRandomDouble() * maxRadius
31 | local randomTheta = MathHelper.randomDouble() * DOUBLE_PI
32 | local randomTheta2 = MathHelper.randomDouble() * DOUBLE_PI
33 |
34 | local xOffset = randomRadiusX * math.cos(randomTheta)
35 | local zOffset = randomRadiusX * math.sin(randomTheta2)
36 | return xOffset, zOffset
37 | end
38 |
39 | @native
40 | function MathHelper.randomVec3()
41 | return vec3(MathHelper.randomDouble(), MathHelper.randomDouble(), MathHelper.randomDouble())
42 | end
43 |
44 | @native
45 | function MathHelper.randomInUnitSphere()
46 | while true do
47 | local p = MathHelper.randomVec3()
48 |
49 | if (MathHelper.lengthSquaredVec3(p) < 1) then
50 | return p
51 | end
52 | end
53 | end
54 |
55 | @native
56 | function MathHelper.randomUnitVector()
57 | return MathHelper.randomInUnitSphere().Unit
58 | end
59 |
60 | @native
61 | function MathHelper.randomOnHemisphere(normal: Vector3)
62 | local onUnitHemisphere = MathHelper.randomUnitVector()
63 | if (onUnitHemisphere:Dot(normal) > 0.0) then -- In the same hemisphere as the normal
64 | return onUnitHemisphere
65 | else
66 | return -onUnitHemisphere
67 | end
68 | end
69 |
70 | @native
71 | function MathHelper.linearToGamma(linearComponent: number)
72 | if (linearComponent > 0) then
73 | return math.pow(linearComponent, 0.7)
74 | else
75 | return 0
76 | end
77 | end
78 |
79 | @native
80 | function MathHelper.lerpNum(a: number, b: number, t: number)
81 | return a + (b - a) * t
82 | end
83 |
84 | @native
85 | function MathHelper.nearZero(vector: Vector3)
86 | local s = 1e-8
87 | return (vector.X < s) or (vector.Y < s) or (vector.Z < s)
88 | end
89 |
90 | @native
91 | function MathHelper.col3ToVec3(color: Color3)
92 | return vec3(color.R, color.G, color.B)
93 | end
94 |
95 | @native
96 | function MathHelper.vec3ToGamma(myVec: Vector3)
97 | return vec3(MathHelper.linearToGamma(myVec.X), MathHelper.linearToGamma(myVec.Y), MathHelper.linearToGamma(myVec.Z))
98 | end
99 |
100 | @native
101 | function MathHelper.clampVec3(myVec: Vector3, minClamp: number, maxClamp: number)
102 | minClamp = minClamp or 0
103 | maxClamp = maxClamp or 1
104 | return vec3(clamp(myVec.X, minClamp, maxClamp), clamp(myVec.Y, minClamp, maxClamp), clamp(myVec.Z, minClamp, maxClamp))
105 | end
106 |
107 |
108 | --# Finalize
109 | return MathHelper
--------------------------------------------------------------------------------
/main.lua:
--------------------------------------------------------------------------------
1 | --# Services
2 | local ServerScriptService = game:GetService("ServerScriptService")
3 | local ReplicatedStorage = game:GetService("ReplicatedStorage")
4 |
5 |
6 | --# Include
7 | local RadiosityEngine = ServerScriptService:WaitForChild("RadiosityEngine")
8 | local RadiosityEngineManager = require(RadiosityEngine:WaitForChild("Manager"))
9 | local MathHelper = require(RadiosityEngine:WaitForChild("MathHelper"))
10 |
11 |
12 | --# References
13 | local radiosityActor = script:GetActor()
14 |
15 |
16 | --# Set up your scene
17 | local MyRadiosityManager
18 | local maxBroadPatchRenderCount = 5
19 | local currentBroadPatchRenderCount = 0
20 |
21 | if radiosityActor == nil then
22 | -- Let's create a new radiosity manager and set it's properties!
23 | MyRadiosityManager = RadiosityEngineManager:new(script)
24 |
25 | MyRadiosityManager.BakeGlobalLights = true
26 | MyRadiosityManager.BakeLocalLights = false
27 | MyRadiosityManager.RandomLightSamplingEnabled = true
28 | MyRadiosityManager.SamplesPerPixel = 900
29 | MyRadiosityManager.DirectLightingEnabled = false
30 | MyRadiosityManager.IndirectLightingEnabled = true
31 | MyRadiosityManager.SunRadius = 0.1
32 | MyRadiosityManager.NarrowSurfacePatchScale = 32
33 | MyRadiosityManager.BroadSurfacePatchScale = 26
34 |
35 | -- Let's add some parts to render!
36 | -- This script automatically ignores all parts that aren't in the "Geometry" folder, are invisible, or are too small to lightmap.
37 | for _, part in workspace.Geometry:GetDescendants() do
38 | if part:IsA("Part") or part:IsA("WedgePart") then -- We wan't to make sure we're not rendering parts that aren't shaped as boxes.
39 | if part.Size.Magnitude > 2 and part.Transparency < 0.7 then
40 | local cannotMap = false
41 |
42 | for _, child in part:GetChildren() do
43 | if child.ClassName == "SpecialMesh" then
44 | cannotMap = true
45 | end
46 |
47 | if child:IsA("Light") then
48 | cannotMap = true
49 | end
50 | end
51 |
52 | if cannotMap == false then
53 | MyRadiosityManager:createCanvasOnAllSurfaces(part)
54 | end
55 | end
56 | end
57 | end
58 |
59 | -- We can also add lights that affect the final image!
60 | -- Point lights, Surface lights, and Spot lights are supported!
61 | if MyRadiosityManager.BakeLocalLights == true then
62 | for _, light in workspace.Geometry:GetDescendants() do
63 | if light:IsA("Light") then
64 | MyRadiosityManager:insertLight(light)
65 | end
66 | end
67 | end
68 | end
69 |
70 |
71 | --# Execution
72 | if radiosityActor == nil then
73 | MyRadiosityManager:prepareLights()
74 | local workers = MyRadiosityManager:prepareRenderWorkers()
75 |
76 | -- Assign tasks to workers
77 | MyRadiosityManager:updateRenderVars()
78 |
79 | local startRender = os.clock()
80 | local numCanvases = #MyRadiosityManager.Canvases
81 |
82 | for canvasIndex, canvas in pairs(MyRadiosityManager.Canvases) do
83 | canvas:prepareRender()
84 |
85 | task.wait()
86 |
87 | for _, BroadPatch in pairs(canvas.BroadSurfacePatches) do
88 | -- OPTIONAL: task.defer allows multiple patches to be rendered at once
89 | local function renderPass()
90 | for xPixel = 0, MyRadiosityManager.NarrowSurfacePatchScale - 1 do
91 | workers[xPixel + 1]:SendMessage(
92 | table.unpack(MyRadiosityManager:getRenderInfo(canvas, BroadPatch, xPixel))
93 | )
94 | end
95 |
96 | currentBroadPatchRenderCount += 1
97 | end
98 |
99 | if currentBroadPatchRenderCount >= maxBroadPatchRenderCount then
100 | renderPass()
101 | task.wait()
102 | else
103 | task.defer(renderPass)
104 | end
105 | end
106 | end
107 |
108 | -- OPTIONAL: You can enable this if you enable task.defer()
109 | --MyRadiosityManager:waitUntilAllCanvasesAreRendered()
110 |
111 | print("Baked Lighting Complete: "..tostring(os.clock() - startRender))
112 |
113 | -- finalize
114 | return
115 | end
116 |
117 | radiosityActor:BindToMessageParallel("RenderPatch", function(...)
118 | RadiosityEngineManager:renderPatch(...)
119 | end)
120 |
--------------------------------------------------------------------------------
/RadiosityEngine/Canvas.lua:
--------------------------------------------------------------------------------
1 | --# Point
2 | local Canvas = {
3 | Patches = {}
4 | }
5 | Canvas.__index = Canvas
6 |
7 |
8 | --# Services
9 | local Lighting = game:GetService("Lighting")
10 | local Asset = game:GetService("AssetService")
11 |
12 |
13 | --# Include
14 | local Modules = script.Parent
15 | local MathHelper = require(Modules:WaitForChild("MathHelper"))
16 | local TopologyHelper = require(Modules:WaitForChild("TopologyHelper"))
17 | local Rendering = require(Modules:WaitForChild("Rendering"))
18 |
19 |
20 | --# Quick References
21 | local vec2, cf, vec3, udim2, c3, mr, mp, sqrt, abs, vec3FromNormalId = Vector2.new, CFrame.new, Vector3.new, UDim2.new, Color3.new, math.random, math.pow, math.sqrt, math.abs, Vector3.FromNormalId
22 |
23 |
24 | --# Preparation Methods
25 | function Canvas:new(myRadiosityManager)
26 | local newCanvas = {
27 | SurfaceGui = Instance.new("SurfaceGui"),
28 | SurfaceImage = Asset:CreateEditableImage(),
29 | BroadSurfacePatches = {},
30 |
31 | NarrowSurfacePatches = {},
32 | Part = nil,
33 | PartCF = nil,
34 | PartCornerCF = nil,
35 | PartRotationCF = nil,
36 | PartColorVec3 = nil,
37 | PartSize = nil,
38 | HalfPartSize = nil,
39 |
40 | Surface = Enum.NormalId.Top,
41 | WorldSpaceNormal = nil,
42 |
43 | InitRaycastParams = RaycastParams.new(),
44 | CurrentRadiosityManager = myRadiosityManager
45 | }
46 | newCanvas.SurfaceGui.Name = "RadiosityCanvas"
47 | newCanvas.SurfaceGui.Face = newCanvas.Surface
48 | newCanvas.SurfaceGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
49 | newCanvas.SurfaceGui.ClipsDescendants = true
50 |
51 | setmetatable(newCanvas, Canvas)
52 | return newCanvas
53 | end
54 |
55 | function Canvas:assignPixelsPerStud(scale: number)
56 | self.PixelsPerStud = scale
57 | self.SurfaceGui.PixelsPerStud = scale
58 | end
59 |
60 | function Canvas:assignSurface(surfaceAssignment)
61 | self.Surface = surfaceAssignment
62 | self.SurfaceGui.Face = self.Surface
63 | end
64 |
65 | function Canvas:assignPart(partAssignment)
66 | self.Part = partAssignment
67 | self.SurfaceGui.Parent = self.Part
68 | self.Part:SetAttribute("RadiosityEnabled", true)
69 |
70 | self.PartColorVec3 = MathHelper.col3ToVec3(self.Part.Color)
71 | self.InitRaycastParams.FilterDescendantsInstances = {self.Part}
72 | self.InitRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
73 |
74 | self.PartSize = partAssignment.Size
75 | self.HalfPartSize = partAssignment.Size / 2
76 | self.PartRotationCF = self.Part.CFrame - self.Part.Position
77 |
78 | TopologyHelper.setCornerCF(self)
79 | end
80 |
81 |
82 | --# Render Methods
83 | function Canvas:createSurfacePatches()
84 | -- clear previous broad surface patches
85 | self.BroadSurfacePatches = {}
86 |
87 | -- sizing variables
88 | local xSize, ySize = TopologyHelper.calculateSurfaceDimensions(self.Part, self.Surface) -- Corrected to Surface space
89 | local xLimit, yLimit = 0, 0
90 | local xPatchDiv, yPatchDiv = xSize / self.CurrentRadiosityManager.BroadSurfacePatchScale, ySize / self.CurrentRadiosityManager.BroadSurfacePatchScale
91 |
92 | if xPatchDiv >= 1 then
93 | xLimit = xPatchDiv
94 | end
95 | if yPatchDiv >= 1 then
96 | yLimit = yPatchDiv
97 | end
98 |
99 | self.LimitNarrow = vec2(xLimit * self.CurrentRadiosityManager.NarrowSurfacePatchScale, yLimit * self.CurrentRadiosityManager.NarrowSurfacePatchScale)
100 | self.Limit = vec2(xLimit, yLimit)
101 | self.LimitBroad = self.CurrentRadiosityManager.BroadSurfacePatchScale * self.CurrentRadiosityManager.PixelsPerStud
102 | --self.LimitNarrow = vec2(math.floor(self.LimitNarrow.X), math.floor(self.LimitNarrow.Y))
103 |
104 | for xCoord = 0, xLimit, 1 do
105 | for yCoord = 0, yLimit, 1 do
106 | local pixelsPerStud = self.CurrentRadiosityManager.PixelsPerStud
107 | local xWorldPos, yWorldPos = (xCoord * self.CurrentRadiosityManager.BroadSurfacePatchScale), (yCoord * self.CurrentRadiosityManager.BroadSurfacePatchScale)
108 |
109 | if xCoord == xLimit then
110 | if xSize == xWorldPos then
111 | break
112 | end
113 | end
114 | if yCoord == yLimit then
115 | if ySize == yWorldPos then
116 | break
117 | end
118 | end
119 |
120 | --if math.abs(xWorldPos) > self.CurrentRadiosityManager.BroadSurfacePatchScale then
121 | -- break
122 | --end
123 | --if math.abs(yWorldPos) > self.CurrentRadiosityManager.BroadSurfacePatchScale then
124 | -- break
125 | --end
126 |
127 | local xPos = xWorldPos * pixelsPerStud
128 | local yPos = yWorldPos * pixelsPerStud
129 |
130 | local SurfaceImageLabel = Instance.new("ImageLabel")
131 | SurfaceImageLabel.Name = "BroadSurfacePatch"
132 | SurfaceImageLabel.BorderSizePixel = 0
133 | SurfaceImageLabel.BackgroundTransparency = 1
134 | SurfaceImageLabel.Position = udim2(0, xPos, 0, yPos)
135 | SurfaceImageLabel.Size = udim2(0, self.LimitBroad, 0, self.LimitBroad)
136 | SurfaceImageLabel.Parent = self.SurfaceGui
137 | SurfaceImageLabel.ResampleMode = Enum.ResamplerMode.Default
138 |
139 | local EditableImage = Asset:CreateEditableImage({
140 | Size = vec2(self.CurrentRadiosityManager.NarrowSurfacePatchScale, self.CurrentRadiosityManager.NarrowSurfacePatchScale)
141 | })
142 | Canvas.Patches[SurfaceImageLabel] = EditableImage
143 | SurfaceImageLabel.ImageContent = Content.fromObject(EditableImage)
144 |
145 | local worldCF = TopologyHelper.calculateBroadPatchWorldPosition(self.SurfaceGui, SurfaceImageLabel, self.Part, self.Surface, self.PartCornerCF)
146 | SurfaceImageLabel:SetAttribute("WorldCFrame", worldCF)
147 | SurfaceImageLabel:SetAttribute("IsRendering", false)
148 |
149 | self.SurfaceGui:SetAttribute("BroadSurfacePatchScale", self.CurrentRadiosityManager.BroadSurfacePatchScale)
150 | self.SurfaceGui:SetAttribute("NarrowSurfacePatchScale", self.CurrentRadiosityManager.NarrowSurfacePatchScale)
151 | self.SurfaceGui:SetAttribute("NarrowToBroadFactor", self.CurrentRadiosityManager.NarrowToBroadFactor)
152 |
153 | -- DEBUG WORLDCF
154 | --local myPart = Instance.new("Part")
155 | --myPart.Size = vec3(1, 1, 1)
156 | --myPart.BrickColor = BrickColor.new("Really red")
157 | --myPart.Anchored = true
158 | --myPart.CFrame = worldCF
159 | --myPart.CanCollide = false
160 | --myPart.CanQuery = false
161 | --myPart.Parent = workspace
162 |
163 | -- return
164 | table.insert(self.BroadSurfacePatches, SurfaceImageLabel)
165 | end
166 | end
167 | end
168 |
169 | function Canvas:prepareRender()
170 | self.PartCF = self.Part.CFrame
171 | self.PixelsPerStud = self.SurfaceGui.PixelsPerStud
172 | self.WorldSpaceNormal = self.PartCF:VectorToWorldSpace(vec3FromNormalId(self.Surface)).Unit
173 | self:createSurfacePatches()
174 | end
175 |
176 | function Canvas:prepareRenderIndirect()
177 | self.PartCF = self.Part.CFrame
178 | self.PixelsPerStud = self.SurfaceGui.PixelsPerStud
179 | self.WorldSpaceNormal = self.PartCF:VectorToWorldSpace(vec3FromNormalId(self.Surface)).Unit
180 | end
181 |
182 |
183 | --# Finalize
184 | return Canvas
--------------------------------------------------------------------------------
/RadiosityEngine/Rendering.lua:
--------------------------------------------------------------------------------
1 | --# Point
2 | local Rendering = {}
3 |
4 |
5 | --# Include
6 | local Modules = script.Parent
7 | local MathHelper = require(Modules:WaitForChild("MathHelper"))
8 | local TopologyHelper = require(Modules:WaitForChild("TopologyHelper"))
9 |
10 |
11 | --# Quick References
12 | local vec2, cf, vec3, udim2, c3, mr, mp, sqrt, abs, clamp, ceil, pi, vec3FromNormalId = Vector2.new, CFrame.new, Vector3.new, UDim2.new, Color3.new, math.random, math.pow, math.sqrt, math.abs, math.clamp, math.ceil, math.pi, Vector3.FromNormalId
13 | local clamp, max, min, abs = math.clamp, math.max, math.min, math.abs
14 |
15 |
16 | --# Variables
17 | local fullBrightVec3 = vec3(1, 1, 1)
18 |
19 | local reflectionIncAmount = 1.99
20 | local reflectionIncAmountIndirect = 0.8
21 | local reflectionIncAmountColor = 1.99
22 | local reflectionAOColorAccum = vec3(1, 1, 1)
23 | local reflectionIncAmountColorAO = 0.35
24 | local reflectionIncAmountAO = 0.93
25 | local reflectionIncAmountAOVec = vec3(reflectionIncAmountAO, reflectionIncAmountAO, reflectionIncAmountAO)
26 | local reflectionLimit = 2
27 |
28 |
29 | --# Lighting Calculations
30 | function calculateIndirectLightingContribution(sunRayDirection, sunRadius: number, totalLightContribution: number, accumulatedColor: number, worldSpaceNormal: Vector3, worldSpacePixelCoord: CFrame, pixelOffset: number, sampleIndex: number, samplesPerPixel: number, pixelSamplesScale: number, randomSamplingEnabled: boolean, rayDistance: number, initRaycastParams: RaycastParams, sunDirection: Vector3)
31 | local reflectionRayResult = nil
32 | local reflectionAccumColor = vec3(0, 0, 0)
33 |
34 | local finalTotalContribution = 0
35 | local finalAccumColor = vec3(0, 0, 0)
36 |
37 | local rayOrigin = worldSpacePixelCoord.Position + worldSpaceNormal * 0.0003
38 |
39 | -- Initial cosine-weighted sampling
40 | --local reflectionDirection = TopologyHelper.calculateCosineWeightedHemisphereSample(worldSpaceNormal, sampleIndex, samplesPerPixel, randomSamplingEnabled).Unit
41 | local reflectionDirection = (worldSpaceNormal + MathHelper.randomUnitVector()).Unit
42 | local reflectionNormal = worldSpaceNormal
43 | local reflectionCount = 0
44 | local canBounce = true
45 |
46 | while canBounce do
47 | local lastDist: number
48 | if reflectionRayResult then
49 | lastDist = reflectionRayResult.Distance
50 | end
51 |
52 | -- Perform raycasting from the origin along the reflection direction
53 | reflectionRayResult = workspace:Raycast(rayOrigin, reflectionDirection * rayDistance)
54 |
55 | local cosTheta = math.max(0.2, reflectionNormal:Dot(reflectionDirection))
56 | local pdfFactor = cosTheta / math.pi -- Importance sampling PDF factor
57 |
58 | if reflectionRayResult then
59 | local hitColor = MathHelper.col3ToVec3(reflectionRayResult.Instance.Color)
60 |
61 | -- Handle if the ray hits an emissive light source
62 | local isLight = false
63 | local myLight = nil
64 |
65 | for _, items in reflectionRayResult.Instance:GetChildren() do
66 | if items:IsA("Light") then
67 | isLight = true
68 | myLight = items
69 | end
70 | end
71 |
72 | if isLight then
73 | local lightFixedAttenuation = (reflectionRayResult.Distance * reflectionRayResult.Distance)
74 | local attenuation = 1 / lightFixedAttenuation
75 | attenuation = math.clamp(attenuation * (myLight.Range * 8), 0, 0.5)
76 |
77 | finalTotalContribution += 2 * attenuation * pdfFactor
78 | finalAccumColor += hitColor * reflectionIncAmountColor * reflectionAOColorAccum * attenuation * pdfFactor
79 | canBounce = false -- Stop bouncing after hitting a light source
80 | reflectionCount = reflectionLimit -- Ensure reflection limit is reached
81 | else
82 | -- If not a light, bounce the reflection ray for indirect lighting
83 | local reflectionToSun = nil
84 | if sunRayDirection then
85 | local newSunDir = sunRayDirection.Unit
86 | reflectionToSun = workspace:Raycast(reflectionRayResult.Position + reflectionRayResult.Normal * 0.0001, newSunDir * rayDistance)
87 | canBounce = false
88 | end
89 |
90 | -- Apply lighting if the reflection ray doesn't reach the sun
91 | if not reflectionToSun then
92 | finalTotalContribution += reflectionIncAmount * pdfFactor
93 | finalAccumColor += hitColor * reflectionIncAmountColor * pdfFactor
94 | else
95 | finalAccumColor += vec3(hitColor.X, hitColor.Y, hitColor.Z) * reflectionIncAmountColorAO * pdfFactor
96 |
97 | -- Apply ambient occlusion effect for blocked rays
98 | -- I commented this part out because indirect lighting already simulates this. You can uncomment if you want more prominent AO, but it's usually not necessary.
99 | --local attenuation = 1 / (reflectionRayResult.Distance * 1.6)
100 | --attenuation = math.min(0.25, attenuation)
101 | --attenuation = math.max(0.1, attenuation)
102 | --finalTotalContribution -= reflectionIncAmountAO * attenuation
103 | --finalAccumColor -= reflectionIncAmountAOVec * attenuation
104 |
105 | -- Update reflection direction for next bounce
106 | reflectionDirection = TopologyHelper.calculateCosineWeightedHemisphereSample(reflectionRayResult.Normal, sampleIndex, samplesPerPixel, randomSamplingEnabled).Unit
107 | rayOrigin = reflectionRayResult.Position + reflectionRayResult.Normal * 0.0001
108 | reflectionNormal = reflectionRayResult.Normal
109 | end
110 |
111 | -- Increment the reflection bounce count
112 | reflectionCount += 1
113 | end
114 | else
115 | -- For rays that miss objects, add indirect lighting contribution
116 | finalTotalContribution += reflectionIncAmountIndirect * pdfFactor
117 | finalAccumColor += vec3(reflectionIncAmountIndirect, reflectionIncAmountIndirect, reflectionIncAmountIndirect) * pdfFactor
118 | canBounce = false
119 | end
120 |
121 | -- Limit reflection bounces
122 | if reflectionCount > reflectionLimit then
123 | canBounce = false
124 | end
125 | end
126 |
127 | -- Add the final contribution to the total lighting
128 | return finalTotalContribution, finalAccumColor
129 | end
130 |
131 |
132 | function Rendering.calculatePixelCombinedBrightness(initRaycastParams: RaycastParams, worldSpacePixelCoord: CFrame, sunRadius: number, rayDistance: number, surface: Enum.NormalId, pixelBrightness: number, pixelColor: Vector3, partRotationCF: CFrame, partCF: CFrame, sunDirection: Vector3, pixelSamplesScale: number, samplesPerPixel: number, lightsContainer: {}, bakeGlobalLights: boolean, bakeLocalLights: boolean, sampleIndex: number, randomSamplingEnabled: boolean, pixelToWorldFactor: number, worldSpaceNormal: Vector3, pixelOffset: number, indirectLightingEnabled: boolean, directLightingEnabled: boolean, samplesPerAxis: number)
133 | -- Calculate the up vector, tangent, and bitangent
134 | --local rayOrigin = TopologyHelper.calculatePixelSamplePoint(worldSpaceNormal, worldSpacePixelCoord, pixelOffset, sampleIndex, samplesPerPixel, randomSamplingEnabled).Position
135 | local rayOrigin = worldSpacePixelCoord.Position + worldSpaceNormal * 0.0003
136 |
137 | -- Initialize total brightness and color contributions
138 | local totalLightContribution = 0
139 | local accumulatedColor = vec3(0, 0, 0)
140 | local totalLightFactor = 0
141 | local currentGlobalDepth = 0
142 | local canContributeLight = false
143 |
144 | -- Calculate global light contribution
145 | local lightFacingFactor = sunDirection:Dot(worldSpaceNormal)
146 |
147 | local canDoMultipleLightSamples = true
148 | if samplesPerPixel <= 1 or sunRadius <= 0 then
149 | canDoMultipleLightSamples = false
150 | end
151 |
152 | local canRenderGlobalLight = true
153 | local sunRayDirection = nil
154 |
155 | if bakeGlobalLights then
156 | totalLightFactor += 1
157 |
158 | local rayDirection = nil
159 | if canDoMultipleLightSamples then
160 | if randomSamplingEnabled then
161 | rayDirection = sunDirection + MathHelper.randomUnitVector() * sunRadius
162 | else
163 | rayDirection = TopologyHelper.calculateGlobalLightSampleVector(sunDirection, sunRadius, sampleIndex, samplesPerAxis)
164 | end
165 | else
166 | rayDirection = sunDirection
167 | end
168 | sunRayDirection = rayDirection.Unit
169 |
170 | if directLightingEnabled == true then
171 | local worldRaycastResult = workspace:Raycast(rayOrigin, sunRayDirection * rayDistance, initRaycastParams)
172 |
173 | if lightFacingFactor > 0 then
174 | if not worldRaycastResult then
175 | accumulatedColor += (fullBrightVec3 * lightFacingFactor * 1)
176 | totalLightContribution += (lightFacingFactor * 1)
177 | else
178 | canRenderGlobalLight = false
179 | end
180 | else
181 | canRenderGlobalLight = false
182 | end
183 | end
184 |
185 | end
186 |
187 | if indirectLightingEnabled == true then
188 | -- Perform AO instead
189 | local canDoIndirect = false
190 | if directLightingEnabled == false then
191 | canDoIndirect = true
192 | else
193 | if canRenderGlobalLight == false then
194 | canDoIndirect = true
195 | end
196 | end
197 |
198 | if canDoIndirect then
199 | local finalTotalContribution, finalAccumColor = calculateIndirectLightingContribution(sunRayDirection, sunRadius, totalLightContribution, accumulatedColor, worldSpaceNormal, worldSpacePixelCoord, pixelOffset, sampleIndex, samplesPerPixel, pixelSamplesScale, randomSamplingEnabled, rayDistance, initRaycastParams, sunDirection)
200 |
201 | totalLightContribution += finalTotalContribution
202 | accumulatedColor += finalAccumColor
203 | end
204 | end
205 |
206 | -- Calculate local light contributions
207 | if directLightingEnabled == false then bakeLocalLights = false end
208 |
209 | if bakeLocalLights then
210 | for _, light in pairs(lightsContainer) do
211 | totalLightFactor += 1
212 |
213 | local lightPart = light.Parent
214 | local surfaceLightPos = TopologyHelper.calculateLightSamplePoint(light, sampleIndex, samplesPerPixel, samplesPerAxis, randomSamplingEnabled)
215 | local rayDirection = (surfaceLightPos - rayOrigin)
216 | local distance = rayDirection.Magnitude
217 | rayDirection = rayDirection.Unit
218 | local lightSurfaceNormal: Vector3 -- For surface and spot lights only
219 | local lightFixedAttenuation = (distance * distance)
220 | lightFacingFactor = worldSpaceNormal:Dot(rayDirection)
221 | local lightBrightness = light.Brightness
222 |
223 | if lightFacingFactor > 0 then
224 | if distance < lightFixedAttenuation then -- I don't have a better way to calculate light distance atm
225 | local skipLight = false
226 |
227 | -- Make sure that our light is within visible FOV of light
228 | if light:IsA("SurfaceLight") or light:IsA("SpotLight") then
229 | -- Calculate the dot product between the surface normal and the ray direction
230 | lightSurfaceNormal = light:GetAttribute("SurfaceNormal")
231 | local dotProduct = rayDirection:Dot(lightSurfaceNormal)
232 |
233 | if ( dotProduct <= -0.05 ) then
234 | else
235 | skipLight = true
236 | end
237 | end
238 |
239 | -- We can continue lighting the pixel if the light is in FOV
240 | if skipLight == false then
241 | local raycastResult = workspace:Raycast(rayOrigin, rayDirection * distance * 1.01, initRaycastParams)
242 |
243 | if raycastResult then
244 | local hasLight = false
245 | for _, child in raycastResult.Instance:GetChildren() do
246 | if child:IsA("Light") then
247 | hasLight = true
248 | end
249 | end
250 |
251 | if hasLight then
252 | -- FULL: we add light instead of removing it
253 | local attenuation = 1 / lightFixedAttenuation
254 | attenuation = clamp(attenuation * (light.Range * 8), 0, 0.5)
255 |
256 | totalLightContribution += attenuation * lightFacingFactor
257 | accumulatedColor += (MathHelper.col3ToVec3(light.Color) * attenuation) * lightFacingFactor
258 | end
259 | end
260 | end
261 |
262 | end
263 | end
264 |
265 | end
266 | end
267 |
268 | -- Normalize the total light contribution by the total number of samples
269 | local normalizedLightContribution = totalLightContribution * pixelSamplesScale
270 |
271 | -- Adjust pixel brightness and color based on total light contribution
272 | pixelBrightness = clamp(pixelBrightness + normalizedLightContribution, 0, 1)
273 | pixelColor = MathHelper.clampVec3(pixelColor + (accumulatedColor * pixelSamplesScale), 0, 1)
274 |
275 | return pixelBrightness, pixelColor
276 | end
277 |
278 |
279 | --# Finalize
280 | return Rendering
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | 
4 |
5 | ---
6 |
7 |
8 |
9 | > # Video Showcase of Radiosity Engine:
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ---
18 |
19 | > # Notice
20 |
21 | - This is an early WIP experimental lighting framework that takes full advantage of Roblox's Editable Image instance. This means lighting is calculated separately from Roblox's in-house lighting engine by using a light transport simulation. As a result, developers can enjoy the flexibility of high-quality baked lighting at a low performance cost. Additionally, you can use this rendering engine to add to Roblox's existing lighting or render a scene using strictly baked lighting! Changes are still being made to Editable Image, so expect updates as Roblox rolls out the feature!
22 |
23 | - The github repository can be found [here](https://github.com/Razorboot/radiosity_engine_luau/tree/main).
24 |
25 | - Make sure you have the necessary **Studio Beta Settings** enabled! (EditableImage, Parallel Luau). If you receive errors, it may also be that too many threads are being executed at once. This can be modified in the ``Main`` script inside of ``ServerScriptService``. More information about this can be found in the [Baking Lights section](#baking-lights).
26 |
27 | - **If you use the place file, run the game from the "Run" execution.**
28 | This is because EditableImage beta does not support Server to Client replication yet, but will likely be rolled out with the official release of EditableImage!
29 |
30 | 
31 |
32 | - **Rendering will pause your game temporarily.** This means it should only be done in Studio. (Later on I will cache the results to draw on client) This is because the engine is using its full capacity to render lighting in parallel with an optimized number of threads.
33 | ---
34 |
35 | > # Introduction
36 |
37 | A few years ago I released a custom lighting framework that pre-renders the lighting in your experience. Since then, Roblox has implemented changes to Parallel Luau and added support for low-level image manipulation that enables many improvements in rendering times, performance, and most importantly, quality. This post details a complete rewrite of my lighting framework.
38 |
39 | This release is modeled after a rendering technique called Radiosity Lightmapping, which was popular during the early 2000s to bake lights and shadows and global illumination (indirect lighting) in video games.
40 |
41 | Instead of having your GPU calculate lighting for every pixel on the screen in real-time, radiosity is a pre-rendered, world-space technique that isn't limited to performance issues inherent to real-time rendering. As a result, radiosity can afford intensive light calculations such as raytracing, soft shadows, and indirect illumination regardless of hardware limitations.
42 |
43 | Radiosity Engine v2 currently supports:
44 | + Parallel Luau
45 | + Global lights (sun)
46 | + Local lights (spotlights, pointlights, surfacelights)
47 | + Direct Illumination
48 | + Global Illumination
49 | + Hard & Soft shadows
50 |
51 | There are also a few limitations to keep in mind, which I will explain in depth below:
52 | + EditableImages don't transfer between client and server at the moment. The engine is designed to be rendered on the server and lighting data is saved globally. Despite this, I believe Roblox is planning to fix this limitation once Editable Images are released.
53 | + Only parts with their ``Shape`` set to ``Enum.PartType.Block`` or ``Enum.PartType.Wedge`` can have lightmaps (textures with lighting data) applied to them. This means Radiosity Engine cannot accurately render lighting on unions, meshparts, spheres, corner wedges, etc. However, these parts still cast shadows!
54 | + Increasing the resolution of lightmaps too much can create performance issues. (You can only render so much image data at once!)
55 | + Rendering times are affected by the complexity of your scene.
56 |
57 | ---
58 |
59 | > # Getting Started
60 | > Learn how to set up a new experience with Radiosity Engine.
61 |
62 | I highly suggest downloading the sample place file from the [github repository](https://github.com/Razorboot/radiosity_engine_luau/blob/main/radiosity_engine_11-25-24.rbxl).
63 | **If you use the place file, run the game from the "Run" execution**. This is because EditableImage beta does not support Server to Client replication yet, but will likely be rolled out with the official release of EditableImage!
64 |
65 | An example scene is already set up for you inside the ``"Geometry"`` folder in ``Workspace``. Currently, Radiosity Engine is split into two parts, the ``"Modules"`` folder and the ``"Main"`` script.
66 |
67 | The Modules folder contains the Radiosity ``"Manager"`` class, which allows you to create a new container to render a specific part of your scene. For example, if you have an open area in your experience that doesn't have many shadows and another area that has many shadow-casting objects, you can render lighting at a lower resolution for the open area, and use a higher resolution for the closed area. By using Managers, you can split the scene up into two containers with different properties. The Main script communicates directly with Radiosity Managers to bake lighting in your experience.
68 |
69 | The example scene already has an existing Manager. However, if you want to create a Radiosity Manager yourself, you can do so by including the ``"Manager"`` module in a server-sided ``Script`` and instancing a new Manager:
70 | ```lua
71 | local RadiosityEngine = ServerScriptService:WaitForChild("RadiosityEngine")
72 | local RadiosityEngineManager = require(RadiosityEngine:WaitForChild("Manager"))
73 | MyRadiosityManager = RadiosityEngineManager:new( script )
74 | ```
75 |
76 | The Main script already has Radiosity Engine set up and running with a Radiosity Manager! However, you can learn specifics about how to use Radiosity Engine if you continue reading.
77 |
78 | ---
79 |
80 | > # Preparing Lighting Information
81 | > Learn how to add parts to render and lights to influence your scene.
82 |
83 | Before baking anything, you need to include all the parts you want to render. Because Radiosity renders lighting on individual surfaces of parts, you need to apply lightmaps to the specific surfaces of each part you want to render.
84 |
85 | You can apply a lightmap to all surfaces of a part with:
86 | ```lua
87 | MyRadiosityManager:createCanvasOnAllSurfaces( part: BasePart )
88 | ```
89 | You can apply a lightmap to a specific surface of a part with:
90 | ```lua
91 | Manager:createCanvas( part: BasePart, surface: Enum.NormalId )
92 | ```
93 | Optionally, you can toggle local lighting and add local light sources to a Radiosity Manager:
94 | ```lua
95 | MyRadiosityManager.BakeLocalLights = true
96 | MyRadiosityManager:insertLight( light: Light )
97 | ```
98 | You can toggle Global Lighting with:
99 | ```lua
100 | MyRadiosityManager.BakeGlobalLights = false
101 | ```
102 | ❗Keep in mind that lights behave differently than in Roblox's default lighting engine. ``Brightness`` is ignored and light use a physically-accurate quadratic falloff.
103 |
104 | Additionally, lights are treated as volumes rather than points. This means lights must be attached to a part because the properties of the part (size, rotation, etc.) are essential in calculating realistic light emission.
105 |
106 | ---
107 |
108 | 
109 |
110 | ---
111 |
112 | > # Lighting Features
113 | > Learn how to use the different rendering options supported!
114 |
115 | Each Radiosity Manager contains a few core properties that can be modified to achieve different results.
116 | + ``MyRadiosityManager.NarrowSurfacePatchScale = [number]`` sets the pixel resolution for each patch. By default, the pixel resolution is 32, which means each patch contains 32x32 pixels.
117 |
118 | + ``MyRadiosityManager.BroadSurfacePatchScale = [number]`` sets the scale of each patch in studs. By default this value is 25, meaning each patch will have a size of 25x25 studs.
119 |
120 | + ``MyRadiosityManager.BakeGlobalLights = [Boolean]`` toggles whether light and shadows from the sun are rendered.
121 |
122 | + ``MyRadiosityManager.BakeLocalLights = [Boolean]`` toggles whether light and shadows from local light sources (point lights, spot lights, surface lights) are rendered.
123 |
124 | + ``MyRadiosityManager.DirectLightingEnabled = [Boolean]`` toggles whether direct light and shadows are rendered.
125 |
126 | + ``MyRadiosityManager.IndirectLightingEnabled = [Boolean]`` toggles whether global illumination is rendered.
127 |
128 | ❗ Indirect Illumination requires a high number of samples per pixel to minimize noise in the resulting image. This is because indirect illumination needs to sample more lighting information around the current pixel. This also extends script execution time.
129 |
130 | A reasonable optimization to achieve faster global illumination in your experience is to disable ``DirectLightingEnabled``, and simply render indirect lighting at a lower patch resolution (by lowering ``NarrowSurfacePatchScale``). You can then enable shadow map lighting and/or voxel lighting to get real-time direct lighting with baked global illumination!
131 |
132 | Take a look at the comparison below of using this method compared to strictly using Roblox's default shadow map lighting!
133 |
134 | 
135 |
136 | Mixing Direct and Indirect lighting with Voxel Lighting yields the best results:
137 | 
138 |
139 | + ``MyRadiosityManager.SunRadius = [number between 0 - 1]`` toggles how smooth shadows cast by the sun are. A higher value means shadows will appear softer and blurrier, while lower values produce sharper shadows.
140 |
141 | + ``MyRadiosityManager.SamplesPerPixel = [number]`` sets how many sample rays are fired per pixel. This allows Radiosity Engine to gather information about the scene around the pixel. Setting SamplesPerPixel too high can result in lag because more rays are fired per pixel.
142 |
143 | + ``MyRadiosityManager.RandomLightSamplingEnabled = [Boolean]`` Toggles whether random sampling or uniform sampling is used when sampling points on a light source.
144 |
145 | ❗ Both random light sampling and uniform hemisphere sampling come with advantages and drawbacks. Uniform hemisphere sampling eliminates noise, but creates banding artifacts when the ``samplesPerPixel`` value is too low. Random light sampling on the other hand eliminates banding, but creates noise if ``samplesPerPixel`` is too low.
146 |
147 | Here is a table comparing the lighting results between random and uniform light sampling:
148 | 
149 |
150 | ---
151 |
152 | > # Baking Lights
153 | > Learn how to render lighting information into your scene.
154 |
155 | This process can be skipped over if you're using the place file. However, it may be beneficial to understand how the engine works!
156 |
157 | After you've prepared the lighting information for your scene, you're ready to bake! The process I'll describe below is optimized for Parallel Luau and is separated into sections. The example place file includes the full implementation.
158 |
159 | Before baking, lighting information needs to be updated and render workers need to be instantiated. These workers are Lua actors which work on rendering multiple pixels on the lightmap at once. The number of actors is based on the resolution of the lightmap, which I'll cover later.
160 | You can prepare lighting information and render workers using:
161 | ```lua
162 | MyRadiosityManager:prepareLights()
163 | local workers = MyRadiosityManager:prepareRenderWorkers()
164 | ```
165 | You also need to update the current Radiosity Manager before rendering:
166 | ```lua
167 | MyRadiosityManager:updateRenderVars()
168 | ```
169 | Now that the rendering setup is complete, we can begin baking. Radiosity Engine stores lighting information by creating a SurfaceGui for each surface in the Radiosity Manager. These SurfaceGuis are part of a special class called a ``"Canvas"``, which contains essential information about the surface to bake. Each Canvas is then split up into ImageLabels called ``"BroadSurfacePatches"``. The engine then divides each patch into pixels which are stored in an EditableImage called the ``"NarrowSurfacePatch"``. You can assign a render worker to a pixel on each patch to calculate lighting information in parallel.
170 |
171 | ``RadiosityEngineManager:renderPatch(...)`` allows you to render lighting for a specific patch. Because Radiosity Engine is designed for parallel Luau, you need to pass information to workers for rendering. The snippet below scans through each broad surface patch of every canvas, renders that patch with a render worker, and then repeats the process until rendering is complete.
172 | ```lua
173 | for canvasIndex, canvas in pairs(MyRadiosityManager.Canvases) do
174 | canvas:prepareRender() -- Required before rendering.
175 |
176 | task.wait()
177 |
178 | for _, BroadPatch in pairs(canvas.BroadSurfacePatches) do
179 | -- OPTIONAL: task.defer allows multiple patches to be rendered at once, heavy performance impact but viable for simple scenes.
180 |
181 | --task.defer(function()
182 | for xPixel = 0, MyRadiosityManager.NarrowSurfacePatchScale - 1 do
183 | workers[xPixel + 1]:SendMessage(
184 | table.unpack(MyRadiosityManager:getRenderInfo(canvas, BroadPatch, xPixel))
185 | )
186 | end
187 | --end)
188 |
189 | task.wait()
190 | end
191 | end
192 |
193 | radiosityActor:BindToMessageParallel("RenderPatch", function(...)
194 | RadiosityEngineManager:renderPatch(...)
195 | end)
196 | ```
197 |
--------------------------------------------------------------------------------
/RadiosityEngine/Manager.lua:
--------------------------------------------------------------------------------
1 | --# Point
2 | local Manager = {}
3 | Manager.__index = Manager
4 |
5 |
6 | --# Services
7 | local Lighting = game:GetService("Lighting")
8 | local ServerScriptService = game:GetService("ServerScriptService")
9 | local RunService = game:GetService("RunService")
10 |
11 |
12 | --# Include
13 | local RadiosityEngine = script.Parent
14 | local Canvas = require(RadiosityEngine.Canvas)
15 | local Rendering = require(RadiosityEngine.Rendering)
16 | local TopologyHelper = require(RadiosityEngine.TopologyHelper)
17 | local MathHelper = require(RadiosityEngine.MathHelper)
18 |
19 |
20 | --# Variables
21 | local vec2, cf, vec3, vec3FromNormalId, c3, abs, clamp = Vector2.new, CFrame.new, Vector3.new, Vector3.FromNormalId, Color3.new, math.abs, math.clamp
22 | local sunDirection = game.Lighting:GetSunDirection()
23 |
24 |
25 | --# Global Variables
26 | local occlusionCheckBias = -0.0003
27 | local occlusionCheckDistance = 0.12
28 |
29 |
30 | --# Methods
31 | function Manager:new(executionScript)
32 | local newManager = {
33 | Canvases = {},
34 | Lights = {},
35 |
36 | CanvasesRendered = 0,
37 | RenderingComplete = false,
38 |
39 | BroadSurfacePatchScale = 25,
40 | NarrowSurfacePatchScale = 32,
41 | SamplesPerPixel = 50,
42 | PixelSamplesScale = 0.0,
43 | PixelsPerStud = 50,
44 | NarrowToBroadFactor = 0.0,
45 | RayDistance = 300.0,
46 | MaxRayDepth = 8,
47 |
48 | PixelToWorldFactor = 0,
49 | PixelOffset = 0,
50 |
51 | BakeLocalLights = false,
52 | BakeGlobalLights = true,
53 | RandomLightSamplingEnabled = false,
54 | DirectLightingEnabled = true,
55 | IndirectLightingEnabled = true,
56 | RenderType = 0,
57 |
58 | Actor = executionScript:GetActor(),
59 | ExecutionScript = executionScript,
60 |
61 | IsSequential = true,
62 | SunRadius = 0.04,
63 | }
64 |
65 | setmetatable(newManager, Manager)
66 | return newManager
67 | end
68 |
69 | function Manager:transferSettingsToCanvas(myCanvas)
70 | --myCanvas.BroadSurfacePatchScale = self.BroadSurfacePatchScale
71 | --myCanvas.NarrowSurfacePatchScale = self.NarrowSurfacePatchScale
72 | --myCanvas.SamplesPerPixel = self.SamplesPerPixel
73 | --myCanvas.PixelSamplesScale = self.PixelSamplesScale
74 | --myCanvas.PixelsPerStud = self.PixelsPerStud
75 | --myCanvas.NarrowToBroadFactor = self.NarrowToBroadFactor
76 | --myCanvas.RayDistance = self.RayDistance
77 | --myCanvas.MaxRayDepth = self.MaxRayDepth
78 | --myCanvas.BakeLocalLights = self.BakeLocalLights
79 | --myCanvas.BakeGlobalLights = self.BakeGlobalLights
80 | end
81 |
82 | function Manager:insertCanvases(myCanvases: {}, inheritsSettings: boolean)
83 | if not inheritsSettings then
84 | for _, canvas in pairs(myCanvases) do
85 | self:transferSettingsToCanvas(canvas)
86 | end
87 | end
88 | for _, canvas in pairs(myCanvases) do
89 | table.insert(self.Canvases, canvas)
90 | end
91 | end
92 |
93 | function Manager:insertLight(myLight: Light)
94 | table.insert(self.Lights, myLight)
95 | --for _, canvas in self.Canvases do
96 | -- table.insert(canvas.InitRaycastParams.FilterDescendantsInstances, myLight)
97 | --end
98 | end
99 |
100 | function Manager:removeLight(myLight: Light)
101 | for i, light in self.Lights do
102 | if light == myLight then
103 | table.remove(self.Lights, i)
104 | end
105 | end
106 | --for _, canvas in self.Canvases do
107 | -- for i, element in canvas.InitRaycastParams.FilterDescendantsInstances do
108 | -- if element == myLight then
109 | -- table.remove(canvas.InitRaycastParams.FilterDescendantsInstances, i)
110 | -- end
111 | -- end
112 | --end
113 | end
114 |
115 | function Manager:prepareLights()
116 | for _, light in self.Lights do
117 | local lightPart = light.Parent
118 | local lightPartHalfSize = lightPart.Size / 2
119 | lightPart:SetAttribute("HalfSize", lightPartHalfSize)
120 |
121 | if light:IsA("PointLight") then
122 | light:SetAttribute("CornerCFrame", lightPart.CFrame * cf(-lightPartHalfSize.X, -lightPartHalfSize.Y, -lightPartHalfSize.Z))
123 | elseif light:IsA("SurfaceLight") or light:IsA("SpotLight") then
124 | light:SetAttribute("CornerCFrame", lightPart.CFrame * TopologyHelper.calculateLightCornerCF(light, lightPartHalfSize))
125 | --light:SetAttribute("SurfaceNormal", (lightPart.CFrame - lightPart.Position):pointToObjectSpace(Vector3.fromNormalId(lightPart.Light.Face)).Unit)
126 |
127 | -- Work smarter, not harder!
128 | light:SetAttribute("SurfaceNormal", lightPart.CFrame:vectorToWorldSpace(vec3FromNormalId(light.Face)).Unit )
129 | end
130 | end
131 | end
132 |
133 | function Manager:createCanvasOnAllSurfaces(part: BasePart)
134 | local tempTable = {}
135 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Top))
136 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Right))
137 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Left))
138 | if not part:IsA("WedgePart") then
139 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Front))
140 | end
141 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Back))
142 | table.insert(tempTable, self:createCanvas(part, Enum.NormalId.Bottom))
143 | return tempTable
144 | end
145 |
146 | function Manager:quickCreateCanvas(part: BasePart, surface: Enum.NormalId)
147 | local myCanvas = Canvas:new(self)
148 | myCanvas:assignSurface(surface)
149 | if part then
150 | myCanvas:assignPart(part)
151 | else
152 | print("RadiosityEngine - Manager: 79: No BasePart assigned to Canvas.")
153 | end
154 | myCanvas:assignPixelsPerStud(self.PixelsPerStud)
155 |
156 | self:transferSettingsToCanvas(myCanvas)
157 |
158 | table.insert(self.Canvases, myCanvas)
159 | return myCanvas
160 | end
161 |
162 | function Manager:getRenderInfo(canvas, BroadPatch, xPixel)
163 | local MyRadiosityManager = self
164 |
165 | return
166 | {"RenderPatch",
167 | canvas.Part.ClassName,
168 | canvas.InitRaycastParams, canvas.PartCF, xPixel,
169 | MyRadiosityManager.NarrowSurfacePatchScale, MyRadiosityManager.SamplesPerPixel,
170 | canvas.HalfPartSize, MyRadiosityManager.PixelsPerStud,
171 | MyRadiosityManager.PixelSamplesScale, MyRadiosityManager.RayDistance,
172 | canvas.Surface, canvas.PartRotationCF, MyRadiosityManager.BakeGlobalLights,
173 | MyRadiosityManager.BakeLocalLights, MyRadiosityManager.NarrowToBroadFactor,
174 | Canvas.Patches[BroadPatch], BroadPatch:GetAttribute("WorldCFrame"),
175 | MyRadiosityManager.Lights, MyRadiosityManager.RandomLightSamplingEnabled,
176 | MyRadiosityManager.SunRadius, MyRadiosityManager.PixelToWorldFactor,
177 | canvas.WorldSpaceNormal, MyRadiosityManager.PixelOffset,
178 | MyRadiosityManager.IndirectLightingEnabled, MyRadiosityManager.DirectLightingEnabled,
179 | MyRadiosityManager.SamplesPerAxis}
180 | end
181 |
182 | function Manager:createCanvas(part: BasePart, surface: Enum.NormalId)
183 | -- For wedges, we need to instantiate a new box to render on
184 | surface = surface or Enum.NormalId.Top
185 |
186 | if part:IsA("WedgePart") then
187 | if surface == Enum.NormalId.Top then
188 | local newCanvasPart = Instance.new("Part")
189 | newCanvasPart.Anchored = true
190 | newCanvasPart.CanCollide = false
191 | newCanvasPart.CanTouch = false
192 | newCanvasPart.CanQuery = false
193 | newCanvasPart.Transparency = 1
194 | newCanvasPart.CastShadow = false
195 |
196 | newCanvasPart.CFrame, newCanvasPart.Size = TopologyHelper.calculateWedgeTopSurfaceDimensions(part)
197 | newCanvasPart.Parent = part
198 |
199 | local newCanvas = self:quickCreateCanvas(newCanvasPart, surface)
200 | table.insert(newCanvas.InitRaycastParams.FilterDescendantsInstances, part)
201 | return newCanvas
202 | else
203 | return self:quickCreateCanvas(part, surface)
204 | end
205 |
206 | -- Any other part can be rendered normally
207 | else
208 | --local myCanvas = Canvas:new(self)
209 | --myCanvas:assignSurface(surface or Enum.NormalId.Top)
210 | --if part then
211 | -- myCanvas:assignPart(part)
212 | --else
213 | -- print("RadiosityEngine - Manager: 79: No BasePart assigned to Canvas.")
214 | --end
215 | --myCanvas:assignPixelsPerStud(self.PixelsPerStud)
216 |
217 | --self:transferSettingsToCanvas(myCanvas)
218 |
219 | --table.insert(self.Canvases, myCanvas)
220 | --return myCanvas
221 | return self:quickCreateCanvas(part, surface)
222 | end
223 | end
224 |
225 | function Manager:getCanvas(part: BasePart, surface: Enum.NormalId)
226 | for _, myCanvas in pairs(self.Canvases) do
227 | if myCanvas.Part == part and myCanvas.Surface == surface then
228 | return myCanvas
229 | end
230 | end
231 | return nil
232 | end
233 |
234 | function Manager:removeCanvas(part: BasePart, surface: Enum.NormalId)
235 | for i, myCanvas in pairs(self.Canvases) do
236 | if myCanvas.Part == part and myCanvas.Surface == surface then
237 | table.remove(self.Canvases, i)
238 | return true
239 | end
240 | end
241 | return nil
242 | end
243 |
244 | function Manager:countRenderedCanvases()
245 | local canvasesRendered = 0
246 |
247 | for _, canvas in pairs(self.Canvases) do
248 | for _, patch in pairs(canvas.BroadSurfacePatches) do
249 | if patch:GetAttribute("RenderingComplete") then
250 | local renderingComplete = patch:GetAttribute("RenderingComplete")
251 | if renderingComplete == true then
252 | canvasesRendered += 1
253 | end
254 | end
255 | end
256 | end
257 |
258 | return canvasesRendered
259 | end
260 |
261 | function Manager:waitUntilAllCanvasesAreRendered()
262 | local allPatchesRendered = true
263 | repeat
264 | for _, canvas in pairs(self.Canvases) do
265 | for _, patch in pairs(canvas.BroadSurfacePatches) do
266 | if patch:GetAttribute("RenderingComplete") then
267 | local renderingComplete = patch:GetAttribute("RenderingComplete")
268 | if renderingComplete == false then
269 | allPatchesRendered = false
270 | break
271 | end
272 | end
273 | end
274 | end
275 | wait(1)
276 | until allPatchesRendered == true
277 | end
278 |
279 | function Manager:updateRenderVars()
280 | self.PixelSamplesScale = 1.0 / self.SamplesPerPixel
281 | self.NarrowToBroadFactor = (self.BroadSurfacePatchScale * self.PixelsPerStud) / self.NarrowSurfacePatchScale
282 | self.BroadToNarrowFactor = self.BroadSurfacePatchScale / (self.NarrowSurfacePatchScale * self.PixelsPerStud)
283 | self.PixelToWorldFactor = (self.NarrowToBroadFactor / self.PixelsPerStud)
284 | self.PixelOffset = 2 * self.PixelToWorldFactor
285 | self.SamplesPerAxis = math.ceil(math.sqrt(self.SamplesPerPixel))
286 |
287 | for _, canvas in self.Canvases do
288 | canvas.SurfaceGui.PixelsPerStud = self.PixelsPerStud
289 | end
290 | end
291 |
292 | function Manager:updateRenderVarsIndirect()
293 | self:updateRenderVars()
294 | --for _, light in self.Lights do
295 | -- for _, canvas in self.Canvases do
296 | -- table.insert(canvas.InitRaycastParams.FilterDescendantsInstances, light.Parent)
297 | -- end
298 | --end
299 | end
300 |
301 | function Manager:prepareRenderPixelData(myCanvas)
302 | --task.wait()
303 |
304 | local pixelData = SharedTable.new()
305 | for xPixel = 1, self.NarrowSurfacePatchScale do
306 | pixelData[xPixel] = {}
307 | end
308 |
309 | return pixelData
310 | end
311 |
312 | function Manager:prepareRenderWorkers()
313 | -- Set up actors for parallel processing
314 | local workers = {}
315 | local numOfWorkers = math.floor(self.NarrowSurfacePatchScale) * 2
316 | for i = 1, numOfWorkers do
317 | local actor = Instance.new("Actor")
318 | self.ExecutionScript:Clone().Parent = actor
319 | table.insert(workers, actor)
320 | end
321 |
322 | -- Parent all actors under self
323 | for _, actor in workers do
324 | actor.Parent = self.ExecutionScript
325 | end
326 |
327 | return workers
328 | end
329 |
330 |
331 | -- Actor Script (Inside the BindToMessageParallel)
332 | -- Render direct lighting
333 | function castOcclusionRay(pos, worldSpaceNormal, direction)
334 | return workspace:Raycast(pos + (worldSpaceNormal * -occlusionCheckBias) + (direction * occlusionCheckBias), direction * occlusionCheckDistance)
335 | end
336 |
337 | function Manager:renderPatch(partClassName: string, initRaycastParams: RaycastParams, partCF: CFrame, xPixel: number, narrowSurfacePatchScale: number, samplesPerPixel: number, halfPartSize: Vector3, pixelsPerStud: number, pixelSamplesScale: number, rayDistance: number, surface: Enum.NormalId, partRotationCF: CFrame, bakeGlobalLights: boolean, bakeLocalLights: boolean, narrowToBroadFactor: number, narrowSurfacePatch: EditableImage, broadSurfacePatchCF: CFrame, lights: {}, randomSamplingEnabled: boolean, sunRadius: number, pixelToWorldFactor: number, worldSpaceNormal: Vector3, pixelOffset: number, indirectLightingEnabled: boolean, directLightingEnabled: boolean, samplesPerAxis: number)
338 | for yPixel = 0, narrowSurfacePatchScale - 1 do
339 | local pixelCoord = nil
340 | local pixelColor = nil
341 | local pixelBrightness = nil
342 | local pixelIsOutOfBounds = false
343 |
344 | local worldSpacePixelCoord = TopologyHelper.calculateWorldSpacePixelPos(broadSurfacePatchCF, xPixel, yPixel, pixelsPerStud, surface, narrowToBroadFactor)
345 |
346 | -- Bounds check
347 | if TopologyHelper.isPointOutOfBounds(worldSpacePixelCoord, partCF, halfPartSize) == true then
348 | pixelIsOutOfBounds = true
349 | break
350 | end
351 |
352 | -- Coloring
353 | pixelCoord = vec2(xPixel, yPixel)
354 | pixelColor = vec3(0, 0, 0)
355 | pixelBrightness = 0.0
356 |
357 | if pixelIsOutOfBounds == false then
358 | if partClassName == "WedgePart" and surface ~= Enum.NormalId.Top and surface ~= Enum.NormalId.Back and surface ~= Enum.NormalId.Front and surface ~= Enum.NormalId.Bottom then
359 | local is_out = TopologyHelper.isPointOutOfRangeWedge(worldSpacePixelCoord, partCF, halfPartSize)
360 | if is_out then
361 | pixelIsOutOfBounds = true
362 | pixelBrightness = 1
363 | end
364 | end
365 | end
366 |
367 | -- Occluder check
368 | local occlusionWorldNormal = worldSpaceNormal * occlusionCheckBias
369 | local occlusionCast = workspace:Raycast(worldSpacePixelCoord.Position + occlusionWorldNormal, worldSpaceNormal * occlusionCheckDistance, initRaycastParams)
370 |
371 | local pixelBlocked = false
372 | if occlusionCast then
373 | pixelBlocked = true
374 | else
375 | --local tangent, bitangent
376 | --if math.abs(worldSpaceNormal.Y) > 0.999 then
377 | -- tangent = Vector3.xAxis
378 | --else
379 | -- tangent = worldSpaceNormal:Cross(Vector3.yAxis).Unit
380 | --end
381 | --bitangent = tangent:Cross(worldSpaceNormal).Unit
382 |
383 | --if castOcclusionRay(worldSpacePixelCoord.Position, worldSpaceNormal, tangent) then
384 | -- pixelBlocked = true
385 | --else
386 | -- if castOcclusionRay(worldSpacePixelCoord.Position, worldSpaceNormal, -tangent) then
387 | -- pixelBlocked = true
388 | -- else
389 | -- if castOcclusionRay(worldSpacePixelCoord.Position, worldSpaceNormal, bitangent) then
390 | -- pixelBlocked = true
391 | -- else
392 | -- if castOcclusionRay(worldSpacePixelCoord.Position, worldSpaceNormal, -bitangent) then
393 | -- pixelBlocked = true
394 | -- end
395 | -- end
396 | -- end
397 | --end
398 | end
399 |
400 | -- Calculate lighting
401 | if pixelBlocked == false and pixelIsOutOfBounds == false then
402 | -- Perform basic light attenuation for every light in the scene
403 | -- Perform shadow sampling
404 | -- perform indirect lighting (if enabled)
405 | for sampleIndex = 1, samplesPerPixel do
406 | pixelBrightness, pixelColor = Rendering.calculatePixelCombinedBrightness(initRaycastParams, worldSpacePixelCoord, sunRadius, rayDistance, surface, pixelBrightness, pixelColor, partRotationCF, partCF, sunDirection, pixelSamplesScale, samplesPerPixel, lights, bakeGlobalLights, bakeLocalLights, sampleIndex, randomSamplingEnabled, pixelToWorldFactor, worldSpaceNormal, pixelOffset, indirectLightingEnabled, directLightingEnabled, samplesPerAxis)
407 | end
408 | end
409 |
410 | -- Draw to canvas
411 | local pixelColorX = clamp(pixelColor.X, 0, 1)
412 | local pixelColorY = clamp(pixelColor.Y, 0, 1)
413 | local pixelColorZ = clamp(pixelColor.Z, 0, 1)
414 | local pixelBrightnessF = clamp(pixelBrightness, 0, 1)
415 |
416 | if pixelIsOutOfBounds == false and pixelBlocked == false then
417 | pixelColorX = MathHelper.linearToGamma(pixelColorX)
418 | pixelColorY = MathHelper.linearToGamma(pixelColorY)
419 | pixelColorZ = MathHelper.linearToGamma(pixelColorZ)
420 | pixelBrightnessF = MathHelper.linearToGamma(pixelBrightnessF)
421 | end
422 |
423 | task.synchronize()
424 | narrowSurfacePatch:DrawLine(pixelCoord, pixelCoord, c3(pixelColorX, pixelColorY, pixelColorZ), pixelBrightnessF, Enum.ImageCombineType.AlphaBlend)
425 | task.desynchronize()
426 | end
427 | end
428 |
429 |
430 | --# Finalize
431 | return Manager
432 |
--------------------------------------------------------------------------------
/RadiosityEngine/TopologyHelper.lua:
--------------------------------------------------------------------------------
1 | --# Point
2 | local TopologyHelper = {}
3 |
4 |
5 | --# Include
6 | local Modules = script.Parent
7 | local MathHelper = require(Modules:WaitForChild("MathHelper"))
8 |
9 |
10 | --# Quick References
11 | local vec2, cf, vec3, udim2, c3, mr, mp, sqrt, abs, clamp, max, min, sin, cos, ceil, floor, vec3FromNormalId = Vector2.new, CFrame.new, Vector3.new, UDim2.new, Color3.new, math.random, math.pow, math.sqrt, math.abs, math.clamp, math.max, math.min, math.sin, math.cos, math.ceil, math.floor, Vector3.FromNormalId
12 | local sampleScale = 10000
13 | local lightShrinkFactor = 1
14 | local boundsMarginFactor = 0.95
15 |
16 | local DOUBLE_PI = math.pi * 2
17 | local HALF_PI = math.pi / 2
18 | local QUARTER_PI = math.pi / 4
19 |
20 |
21 | --# Functions
22 | @native
23 | function TopologyHelper.calculateLightCornerCF(light, lightPartHalfSize: Vector3)
24 | if light.Face == Enum.NormalId.Top then
25 | return cf(-lightPartHalfSize.X, lightPartHalfSize.Y, -lightPartHalfSize.Z)
26 | elseif light.Face == Enum.NormalId.Bottom then
27 | return cf(-lightPartHalfSize.X, -lightPartHalfSize.Y, -lightPartHalfSize.Z)
28 | elseif light.Face == Enum.NormalId.Right then
29 | return cf(lightPartHalfSize.X, -lightPartHalfSize.Y, -lightPartHalfSize.Z)
30 | elseif light.Face == Enum.NormalId.Left then
31 | return cf(-lightPartHalfSize.X, -lightPartHalfSize.Y, -lightPartHalfSize.Z)
32 | elseif light.Face == Enum.NormalId.Front then
33 | return cf(-lightPartHalfSize.X, -lightPartHalfSize.Y, -lightPartHalfSize.Z)
34 | elseif light.Face == Enum.NormalId.Back then
35 | return cf(-lightPartHalfSize.X, -lightPartHalfSize.Y, lightPartHalfSize.Z)
36 | end
37 | end
38 |
39 | -- we need to calculate a vector to shoot to the sun if: we don't have random sampling enabled
40 | @native
41 | function TopologyHelper.calculateGlobalLightSampleVector(sunDirection: Vector3, sunRadius: number, sampleIndex: number, samplesPerAxis: number)
42 | -- Calculate the up vector, tangent, and bitangent
43 | local upVector = vec3(0, 1, 0)
44 | if abs(sunDirection:Dot(upVector)) > 0.999 then
45 | upVector = vec3(1, 0, 0)
46 | end
47 | local tangent = sunDirection:Cross(upVector).Unit
48 | local bitangent = sunDirection:Cross(tangent).Unit
49 |
50 | -- Calculate indices for the current sample
51 | local indexA = (sampleIndex % samplesPerAxis)
52 | local indexB = floor(sampleIndex / samplesPerAxis)
53 |
54 | -- Map indexA and indexB to a [-1, 1] range
55 | local u1 = (indexA + 0.5) / samplesPerAxis * 2 - 1
56 | local u2 = (indexB + 0.5) / samplesPerAxis * 2 - 1
57 |
58 | -- Concentric disk sampling
59 | local r, theta
60 | if u1 == 0 and u2 == 0 then
61 | r, theta = 0, 0
62 | else
63 | if abs(u1) > abs(u2) then
64 | r = u1
65 | theta = (QUARTER_PI) * (u2 / u1)
66 | else
67 | r = u2
68 | theta = (HALF_PI) - (QUARTER_PI) * (u1 / u2)
69 | end
70 | end
71 |
72 | -- Scale the offset by the sun radius and the distance to the surface
73 | local offsetX = r * cos(theta) * sunRadius
74 | local offsetY = r * sin(theta) * sunRadius
75 |
76 | -- Combine the sun direction with the calculated offset
77 | local offsetVector = (tangent * offsetX) + (bitangent * offsetY)
78 |
79 | -- Calculate the new direction vector
80 | local newSunDirection = (sunDirection + offsetVector)
81 |
82 | return newSunDirection
83 | end
84 |
85 | @native
86 | function TopologyHelper.calculateWedgeTopSurfaceDimensions(Wedge: WedgePart)
87 | -- Calculate the size of the top surface of the Wedge
88 | local width = Wedge.Size.X
89 | local height = Wedge.Size.Y
90 | local length = Wedge.Size.Z
91 |
92 | local height_half = height / 2
93 | local length_half = length / 2
94 |
95 | -- Create a part representing the top surface
96 | local topSurfacePart = Instance.new("Part")
97 | topSurfacePart.Anchored = true
98 | topSurfacePart.CanCollide = false -- No collision needed
99 | topSurfacePart.CanTouch = false
100 | topSurfacePart.CanQuery = false
101 |
102 | -- Convert the normal into world space
103 | local min_edge_pos = Vector3.new(0, -height_half, -length_half)
104 | local max_edge_pos = Vector3.new(0, height_half, length_half)
105 | local forward_vector = (max_edge_pos - min_edge_pos).Unit
106 | local right_vector = Vector3.new(1, 0, 0)
107 | local local_space_normal = forward_vector:Cross(right_vector).Unit
108 | local world_space_normal = Wedge.CFrame:VectorToWorldSpace(local_space_normal)
109 |
110 | -- Apply position and rotation to the part
111 | local surface_cf = CFrame.new(Wedge.Position, Wedge.Position + world_space_normal) * CFrame.new(0, 0, 0.025) * CFrame.Angles(-1.5707963267948966, 0, 0)
112 | local surface_dimensions = Vector3.new(width, 0.1, math.sqrt(length^2 + height^2) ) -- See! Middle school math is actually useful!
113 |
114 | -- Finalize
115 | return surface_cf, surface_dimensions
116 | end
117 |
118 | @native
119 | function TopologyHelper.calculatePixelSamplePoint(worldSpaceNormal: Vector3, worldSpacePixelCoord: CFrame, pixelOffset: number, sampleIndex: number, samplesPerPixel: number, randomSamplingEnabled: boolean)
120 | local upVector = Vector3.yAxis
121 | if abs(worldSpaceNormal:Dot(upVector)) > 0.999 then
122 | upVector = Vector3.xAxis
123 | end
124 | local tangent = worldSpaceNormal:Cross(upVector).Unit
125 | local bitangent = worldSpaceNormal:Cross(tangent).Unit
126 |
127 | -- Determine the sampling method
128 | local randomXOffset, randomZOffset
129 |
130 | if randomSamplingEnabled == true then
131 | -- Randomly sample a point within a circle
132 | randomXOffset, randomZOffset = MathHelper.randomPointInCircle(pixelOffset)
133 | else
134 | -- Uniformly sample points within a circle
135 | local samplesPerAxis = ceil(sqrt(samplesPerPixel))
136 |
137 | -- Calculate indices for the current sample
138 | local indexA = (sampleIndex % samplesPerAxis)
139 | local indexB = floor(sampleIndex / samplesPerAxis)
140 |
141 | -- Map indexA and indexB to a [-1, 1] range for concentric disk sampling
142 | local u1 = (indexA + 0.5) / samplesPerAxis * 2 - 1
143 | local u2 = (indexB + 0.5) / samplesPerAxis * 2 - 1
144 |
145 | -- Concentric disk sampling
146 | local r, theta
147 | if u1 == 0 and u2 == 0 then
148 | r, theta = 0, 0
149 | else
150 | if abs(u1) > abs(u2) then
151 | r = u1
152 | theta = (QUARTER_PI) * (u2 / u1)
153 | else
154 | r = u2
155 | theta = (HALF_PI) - (QUARTER_PI) * (u1 / u2)
156 | end
157 | end
158 |
159 | randomXOffset = r * cos(theta) * pixelOffset
160 | randomZOffset = r * sin(theta) * pixelOffset
161 | end
162 |
163 | return worldSpacePixelCoord
164 | + (worldSpaceNormal * 0.0001)
165 | + (tangent * randomXOffset)
166 | + (bitangent * randomZOffset)
167 | end
168 |
169 | @native
170 | function TopologyHelper.calculateCosineWeightedHemisphereSample(worldSpaceNormal: Vector3, sampleIndex: number, samplesPerPixel: number, randomLightSamplingEnabled: boolean)
171 | local u1Mapped = MathHelper.randomDouble()
172 | local u2Mapped = MathHelper.randomDouble()
173 |
174 | -- Cosine-weighted hemisphere sampling over the polar and azimuthal angles
175 | -- u1Mapped gives us the azimuth (phi), u2Mapped gives us the cosine-weighted elevation (theta)
176 |
177 | -- Azimuthal angle phi (0 to 2π) for the X, Y sampling
178 | local phi = 2 * math.pi * u1Mapped
179 |
180 | -- Cosine-weighted elevation angle theta (0 to π/2 for hemisphere) for the Z (upwards) sampling
181 | local theta = math.acos(sqrt(u2Mapped)) -- Adjusted for cosine-weighted distribution
182 |
183 | -- Convert spherical coordinates (theta, phi) to Cartesian coordinates (x, y, z)
184 | local diskX = math.sin(theta) * math.cos(phi)
185 | local diskY = math.sin(theta) * math.sin(phi)
186 | local diskZ = math.cos(theta) -- Z is the cosine-weighted component
187 |
188 | -- Now construct the sampled direction vector in local space
189 | local sampleDirection = Vector3.new(diskX, diskY, diskZ)
190 |
191 | -- Transform the sample direction to world space using the worldSpaceNormal
192 | -- To do this, we need to construct a local tangent and bitangent to the normal
193 | local tangent, bitangent
194 | if math.abs(worldSpaceNormal.Y) > 0.999 then
195 | tangent = Vector3.xAxis
196 | else
197 | tangent = worldSpaceNormal:Cross(Vector3.yAxis).Unit
198 | end
199 | bitangent = tangent:Cross(worldSpaceNormal).Unit
200 |
201 | -- Transform the sample direction from local space to world space
202 | local worldSampleDirection =
203 | sampleDirection.X * tangent +
204 | sampleDirection.Y * bitangent +
205 | sampleDirection.Z * worldSpaceNormal
206 |
207 | -- Return the cosine-weighted sample direction in world space
208 | return worldSampleDirection.Unit
209 | end
210 |
211 | function TopologyHelper.calculateLightSamplePoint(light: Light, sampleIndex: number, samplesPerPixel: number, samplesPerAxis: number, randomSamplingEnabled: boolean)
212 | local lightPart = light.Parent
213 | local cornerCF = light:GetAttribute("CornerCFrame")
214 | local lightSize = lightPart.Size
215 |
216 | local pointX, pointY, pointZ = 0, 0, 0
217 |
218 | -- Calculate the grid indices for this sampleIndex
219 | local indexA = (sampleIndex % samplesPerAxis)
220 | local indexB = floor(sampleIndex / samplesPerAxis)
221 |
222 | if light:IsA("SurfaceLight") or light:IsA("SpotLight") then
223 | if light.Face == Enum.NormalId.Top or light.Face == Enum.NormalId.Bottom then
224 | if randomSamplingEnabled == false then
225 | -- Sampling over XZ plane
226 | local fractionX = indexA / samplesPerAxis
227 | local fractionZ = indexB / samplesPerAxis
228 | pointX = (lightSize.X * fractionX) * lightShrinkFactor
229 | pointZ = (lightSize.Z * fractionZ) * lightShrinkFactor
230 | else
231 | pointX = ((lightSize.X / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
232 | pointZ = ((lightSize.Z / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
233 | end
234 |
235 | if light.Face == Enum.NormalId.Bottom then
236 | pointY = 0 -- Bottom face (Y is at 0 from corner)
237 | else
238 | pointY = 0 -- Top face (Y is at full height from corner)
239 | end
240 |
241 | elseif light.Face == Enum.NormalId.Right or light.Face == Enum.NormalId.Left then
242 | if randomSamplingEnabled == false then
243 | -- Sampling over YZ plane
244 | local fractionY = indexA / samplesPerAxis
245 | local fractionZ = indexB / samplesPerAxis
246 | pointY = (lightSize.Y * fractionY) * lightShrinkFactor
247 | pointZ = (lightSize.Z * fractionZ) * lightShrinkFactor
248 | else
249 | pointY = ((lightSize.Y / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
250 | pointZ = ((lightSize.Z / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
251 | end
252 |
253 | if light.Face == Enum.NormalId.Left then
254 | pointX = 0 -- Left face (X is at 0 from corner)
255 | else
256 | pointX = 0 -- Right face (X is at full width from corner)
257 | end
258 |
259 | elseif light.Face == Enum.NormalId.Front or light.Face == Enum.NormalId.Back then
260 | if randomSamplingEnabled == false then
261 | -- Sampling over XY plane
262 | local fractionX = indexA / samplesPerAxis
263 | local fractionY = indexB / samplesPerAxis
264 | pointX = (lightSize.X * fractionX) * lightShrinkFactor
265 | pointY = (lightSize.Y * fractionY) * lightShrinkFactor
266 | else
267 | pointX = ((lightSize.X / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
268 | pointY = ((lightSize.Y / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
269 | end
270 |
271 | if light.Face == Enum.NormalId.Back then
272 | pointZ = 0 -- Back face (Z is at 0 from corner)
273 | else
274 | pointZ = 0 -- Front face (Z is at full depth from corner)
275 | end
276 | end
277 | else
278 | if randomSamplingEnabled == false then
279 | -- Handle PointLight or any other light type with 3D sampling (from the previous code)
280 | samplesPerAxis = ceil(samplesPerPixel ^ (1/3))
281 | local indexX = (sampleIndex % samplesPerAxis)
282 | local indexY = floor((sampleIndex / samplesPerAxis) % samplesPerAxis)
283 | local indexZ = floor(sampleIndex / (samplesPerAxis * samplesPerAxis))
284 | local fractionX = indexX / samplesPerAxis
285 | local fractionY = indexY / samplesPerAxis
286 | local fractionZ = indexZ / samplesPerAxis
287 | pointX = (lightSize.X * fractionX) * lightShrinkFactor
288 | pointY = (lightSize.Y * fractionY) * lightShrinkFactor
289 | pointZ = (lightSize.Z * fractionZ) * lightShrinkFactor
290 |
291 | else
292 | pointX = ((lightSize.X / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
293 | pointY = ((lightSize.Y / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
294 | pointZ = ((lightSize.Z / sampleScale) * mr(0, sampleScale)) * lightShrinkFactor
295 | end
296 | end
297 |
298 | -- Offset from the corner of the light part
299 | local samplePoint = cornerCF * CFrame.new(pointX, pointY, pointZ)
300 |
301 | return samplePoint.Position
302 | end
303 |
304 | @native
305 | function TopologyHelper.isPointOutOfBounds(worldPoint: CFrame, partCF: CFrame, halfPartSize: Vector3)
306 | local localWorldSpacePixelCoord = partCF:ToObjectSpace(worldPoint).Position
307 | if abs(localWorldSpacePixelCoord.X*boundsMarginFactor) > halfPartSize.X or abs(localWorldSpacePixelCoord.Y*boundsMarginFactor) > halfPartSize.Y or abs(localWorldSpacePixelCoord.Z*boundsMarginFactor) > halfPartSize.Z then
308 | return true
309 | end
310 | end
311 |
312 | @native
313 | function TopologyHelper.isPointOutOfRangeWedge(worldPoint: CFrame, wedgeCF: CFrame, halfPartSize: Vector3)
314 | -- Calculate the size of the top surface of the wedge
315 | local height_half = halfPartSize.Y / 2
316 | local length_half = halfPartSize.Z / 2
317 |
318 | -- Convert the normal into world space
319 | local min_edge_pos = vec3(0, -height_half, -length_half)
320 | local max_edge_pos = vec3(0, height_half, length_half)
321 |
322 | local slant_vector = (max_edge_pos - min_edge_pos).Unit
323 | local slant_center = (max_edge_pos - min_edge_pos)/2
324 |
325 | local test_local_pos = wedgeCF:PointToObjectSpace(worldPoint.Position)
326 | --local test_to_line = (test_local_pos - slant_center).Unit
327 |
328 | -- Calculate AB and AP vectors
329 | local pointA = min_edge_pos
330 | local pointB = max_edge_pos
331 | local pointP = test_local_pos
332 |
333 | local AB = pointB - pointA
334 | local AP = pointP - pointA
335 | local flippedAB = -AB
336 | local AB_dot_AB = AB:Dot(AB)
337 | local AP_dot_flippedAB = AP:Dot(flippedAB)
338 | local scalar = AP_dot_flippedAB / AB_dot_AB
339 | local projection = pointA + (scalar * flippedAB)
340 |
341 | if projection.Y <= (test_local_pos.Y - 0.5) then
342 | return true
343 | end
344 |
345 | --local to_line_cross = slant_vector:Cross(test_to_line)
346 |
347 | --if to_line_cross.X <= 0 then
348 | -- return true
349 | --end
350 | end
351 |
352 | @native
353 | function TopologyHelper.calculateSurfaceDimensions(partInstance: BasePart, surfaceAssignment: Enum.NormalId)
354 | if surfaceAssignment == Enum.NormalId.Top then
355 | return partInstance.Size.Z, partInstance.Size.X
356 | elseif surfaceAssignment == Enum.NormalId.Bottom then
357 | return partInstance.Size.Z, partInstance.Size.X
358 | elseif surfaceAssignment == Enum.NormalId.Right then
359 | return partInstance.Size.Z, partInstance.Size.Y
360 | elseif surfaceAssignment == Enum.NormalId.Left then
361 | return partInstance.Size.Z, partInstance.Size.Y
362 | elseif surfaceAssignment == Enum.NormalId.Front then
363 | return partInstance.Size.X, partInstance.Size.Y
364 | elseif surfaceAssignment == Enum.NormalId.Back then
365 | return partInstance.Size.X, partInstance.Size.Y
366 | end
367 | end
368 |
369 | @native
370 | function TopologyHelper.calculateCrossVectors(partCornerCF: CFrame, surfaceAssignment: Enum.NormalId, partAssignment: BasePart, pixelsPerStud: number)
371 | if surfaceAssignment == Enum.NormalId.Top then
372 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(1, 0, 0))
373 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, 0, -1))
374 | return rightNormal, downNormal
375 | elseif surfaceAssignment == Enum.NormalId.Bottom then
376 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(-1, 0, 0))
377 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, 0, -1))
378 | return rightNormal, downNormal
379 | elseif surfaceAssignment == Enum.NormalId.Right then
380 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(0, 0, -1))
381 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, -1, 0))
382 | return rightNormal, downNormal
383 | elseif surfaceAssignment == Enum.NormalId.Left then
384 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(0, 0, 1))
385 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, -1, 0))
386 | return rightNormal, downNormal
387 | elseif surfaceAssignment == Enum.NormalId.Back then
388 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(1, 0, 0))
389 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, -1, 0))
390 | return rightNormal, downNormal
391 | elseif surfaceAssignment == Enum.NormalId.Front then
392 | local rightNormal = partCornerCF:VectorToWorldSpace(vec3(-1, 0, 0))
393 | local downNormal = partCornerCF:VectorToWorldSpace(vec3(0, -1, 0))
394 | return rightNormal, downNormal
395 | end
396 | end
397 |
398 | -- Returns WorldCFrame
399 | @native
400 | function TopologyHelper.calculateBroadPatchWorldPosition(patchSurfaceGui: SurfaceGui, patchImageLabel: ImageLabel, partInstance: BasePart, surfaceAssignment: Enum.NormalId, partCornerCF: CFrame)
401 | if surfaceAssignment == Enum.NormalId.Top then
402 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
403 | local patchImageWorldSpacePos = partCornerCF * cf(patchImageLabel.Position.Y.Offset / pixelsPerStud, 0, -patchImageLabel.Position.X.Offset / pixelsPerStud)
404 | return patchImageWorldSpacePos
405 |
406 | elseif surfaceAssignment == Enum.NormalId.Bottom then
407 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
408 | local patchImageWorldSpacePos = partCornerCF * cf(-patchImageLabel.Position.Y.Offset / pixelsPerStud, 0, -patchImageLabel.Position.X.Offset / pixelsPerStud)
409 | return patchImageWorldSpacePos
410 |
411 | elseif surfaceAssignment == Enum.NormalId.Right then
412 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
413 | local patchImageWorldSpacePos = partCornerCF * cf(0, -patchImageLabel.Position.Y.Offset / pixelsPerStud, -patchImageLabel.Position.X.Offset / pixelsPerStud)
414 | return patchImageWorldSpacePos
415 |
416 | elseif surfaceAssignment == Enum.NormalId.Left then
417 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
418 | local patchImageWorldSpacePos = partCornerCF * cf(0, -patchImageLabel.Position.Y.Offset / pixelsPerStud, patchImageLabel.Position.X.Offset / pixelsPerStud)
419 | return patchImageWorldSpacePos
420 |
421 | elseif surfaceAssignment == Enum.NormalId.Back then
422 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
423 | local patchImageWorldSpacePos = partCornerCF * cf(patchImageLabel.Position.X.Offset / pixelsPerStud, -patchImageLabel.Position.Y.Offset / pixelsPerStud, 0)
424 | return patchImageWorldSpacePos
425 |
426 | elseif surfaceAssignment == Enum.NormalId.Front then
427 | local pixelsPerStud = patchSurfaceGui.PixelsPerStud
428 | local patchImageWorldSpacePos = partCornerCF * cf(-patchImageLabel.Position.X.Offset / pixelsPerStud, -patchImageLabel.Position.Y.Offset / pixelsPerStud, 0)
429 | return patchImageWorldSpacePos
430 | end
431 | end
432 |
433 | @native
434 | function TopologyHelper.calculateWorldSpaceOffset(xPixel: number, yPixel: number, pixelsPerStud: number, surface: Enum.NormalId, narrowToBroadFactor: number)
435 | local yPixelOffset = (yPixel * narrowToBroadFactor) / pixelsPerStud
436 | local xPixelOffset = (xPixel * narrowToBroadFactor) / pixelsPerStud
437 |
438 | if surface == Enum.NormalId.Top then
439 | return cf( yPixelOffset, 0, -xPixelOffset )
440 |
441 | elseif surface == Enum.NormalId.Bottom then
442 | return cf( -yPixelOffset, 0, -xPixelOffset )
443 |
444 | elseif surface == Enum.NormalId.Right then
445 | return cf( 0, -yPixelOffset, -xPixelOffset )
446 |
447 | elseif surface == Enum.NormalId.Left then
448 | return cf( 0, -yPixelOffset, xPixelOffset )
449 |
450 | elseif surface == Enum.NormalId.Back then
451 | return cf( xPixelOffset, -yPixelOffset, 0 )
452 |
453 | elseif surface == Enum.NormalId.Front then
454 | return cf( -xPixelOffset, -yPixelOffset, 0 )
455 | end
456 | end
457 |
458 | @native
459 | function TopologyHelper.worldToPixelSpace(xPixel: number, yPixel: number, pixelsPerStud: number, surface: Enum.NormalId, narrowToBroadFactor: number)
460 | local yPixelOffset = (yPixel * narrowToBroadFactor) / pixelsPerStud
461 | local xPixelOffset = (xPixel * narrowToBroadFactor) / pixelsPerStud
462 |
463 | local yPixelOffset = (yPixel / pixelsPerStud) * narrowToBroadFactor
464 |
465 | if surface == Enum.NormalId.Top then
466 | return cf( yPixelOffset, 0, -xPixelOffset )
467 |
468 | elseif surface == Enum.NormalId.Bottom then
469 | return cf( -yPixelOffset, 0, -xPixelOffset )
470 |
471 | elseif surface == Enum.NormalId.Right then
472 | return cf( 0, -yPixelOffset, -xPixelOffset )
473 |
474 | elseif surface == Enum.NormalId.Left then
475 | return cf( 0, -yPixelOffset, xPixelOffset )
476 |
477 | elseif surface == Enum.NormalId.Back then
478 | return cf( xPixelOffset, -yPixelOffset, 0 )
479 |
480 | elseif surface == Enum.NormalId.Front then
481 | return cf( -xPixelOffset, -yPixelOffset, 0 )
482 | end
483 | end
484 |
485 | @native
486 | function TopologyHelper.calculateWorldSpacePixelPos(BroadSurfacePatchCF: CFrame, xPixel: number, yPixel: number, pixelsPerStud: number, surface: Enum.NormalId, narrowToBroadFactor: number)
487 | local worldSpacePixelCoord = BroadSurfacePatchCF * TopologyHelper.calculateWorldSpaceOffset(xPixel, yPixel, pixelsPerStud, surface, narrowToBroadFactor)
488 | return worldSpacePixelCoord
489 | end
490 |
491 | function TopologyHelper.setCornerCF(canvasObject)
492 | if canvasObject.Surface == Enum.NormalId.Top then
493 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
494 | local yOffset = canvasObject.Part.Size.Y/2
495 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(-partSurfaceSizeY/2, yOffset, partSurfaceSizeX/2)
496 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
497 |
498 | elseif canvasObject.Surface == Enum.NormalId.Bottom then
499 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
500 | local yOffset = (canvasObject.Part.Size.Y/2) * -1
501 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(partSurfaceSizeY/2, yOffset, partSurfaceSizeX/2)
502 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
503 |
504 | elseif canvasObject.Surface == Enum.NormalId.Right then
505 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
506 | local xOffset = canvasObject.Part.Size.X / 2
507 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(xOffset, partSurfaceSizeY/2, partSurfaceSizeX/2)
508 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
509 |
510 | elseif canvasObject.Surface == Enum.NormalId.Left then
511 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
512 | local xOffset = (canvasObject.Part.Size.X / 2) * -1
513 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(xOffset, partSurfaceSizeY/2, -partSurfaceSizeX/2)
514 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
515 |
516 | elseif canvasObject.Surface == Enum.NormalId.Back then
517 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
518 | local zOffset = (canvasObject.Part.Size.Z / 2)
519 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(-partSurfaceSizeX/2, partSurfaceSizeY/2, zOffset)
520 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
521 |
522 | elseif canvasObject.Surface == Enum.NormalId.Front then
523 | local partSurfaceSizeX, partSurfaceSizeY = TopologyHelper.calculateSurfaceDimensions(canvasObject.Part, canvasObject.Surface)
524 | local zOffset = (canvasObject.Part.Size.Z / 2) * -1
525 | canvasObject.PartCornerCF = canvasObject.Part.CFrame * cf(partSurfaceSizeX/2, partSurfaceSizeY/2, zOffset)
526 | canvasObject.SurfaceGui:SetAttribute("PartCornerCF", canvasObject.PartCornerCF)
527 | end
528 | end
529 |
530 |
531 | --# Finalize
532 | return TopologyHelper
533 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------