Created
April 26, 2025 18:07
-
-
Save phosphoer/12d739b46880ccabbd6270f6afd3ef47 to your computer and use it in GitHub Desktop.
Replicube - Boat and Ocean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- params for the scene | |
waterBaseColor = 13 | |
boatColor = 15 | |
boatLength = 14 | |
boatWidthBase = 4 | |
mastHeight = 10 | |
timeOffset = 2 | |
-- define the water shape and color with sin waves | |
waterY = -5 | |
height = sin((x + t + timeOffset) * 0.3) * 1.7 | |
height = height + sin((z * 0.5) * 0.2) * 1 | |
water = y < height + waterY and 1 or 0 | |
waterColor = waterBaseColor + clamp(height, -1, 1) | |
if abs(x) == extent or abs(y) == extent or abs(z) == extent then | |
waterColor = waterBaseColor | |
end | |
-- start defining the extents and position of the boat | |
PI = 3.141 | |
boatX =1 | |
boatY = sin((boatX + t + timeOffset) * 0.3) * 1.7 + waterY + 1 | |
boatFront = boatX + boatLength / 2 | |
boatBack = boatX - boatLength / 2 | |
-- useful to have a t value along the length of the boat | |
boatT = clamp((x - boatBack) / (boatLength), 0, 1) | |
boatInvT = 1 - boatT | |
-- taper the hull along the length of the boat | |
boatTaperStartT = 0.6 | |
boatWidth = boatWidthBase - clamp((boatT - boatTaperStartT) / (1 - boatTaperStartT), 0, 1) * boatWidthBase | |
if x == boatBack then boatWidth = boatWidth - 1 end | |
boatBottom = boatY - 2 + max(0, (boatT - 0.6) / 0.4) * 3 | |
boatBottom = boatBottom + max(0, (boatInvT - 0.75) / 0.25) * 2 | |
boatBottom = boatBottom + abs(z * 0.5) | |
-- add some vertical variation to the deck | |
boatTop = boatY + 3 | |
if boatT > 0.2 and boatT < boatTaperStartT then boatTop = boatTop - 1 end | |
if boatT < 0.3 then boatTop = boatTop + 1 end | |
-- define the sail using a similar technique | |
sailBottom = boatTop + 1 | |
sailTop = boatTop + mastHeight - 2 | |
sailT = clamp((y - sailBottom) / (sailTop - sailBottom), 0, 1) | |
sailCurve = clamp(1 - (abs(sailT - 0.5) / 0.5), 0, 1) * 6 | |
boatSail = abs(x - (boatX + 1 + sailCurve * 0.5)) < 1 and abs(z) < boatWidthBase and y > sailBottom and y < sailTop and 1 or 0 | |
-- inset the deck into the top of the hull | |
-- important to do after the sail so it doesn't affect it | |
if abs(z) < boatWidth - 1 and boatT > 0 then boatTop = boatTop - 1 end | |
-- define the boat and mast as a volume within the bounds we setup | |
boat = x >= boatBack and x <= boatFront and y > boatBottom and y < boatTop and abs(z) < boatWidth and 1 or 0 | |
boatMast = x == boatX and z == 0 and y > boatBottom and y < boatTop + mastHeight and 1 or 0 | |
-- sum everything up into a final color | |
return water * waterColor + min(1, boat + boatMast) * boatColor + boatSail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment