I am attempting to calculate normals to get proper lighting for the waves but no matter what I try it doesnt work I dont understand is it a roblox bug or am I getting the calculations wrong.
here is my function:
local function gertsnerwave(position, direction, wavelength, steepness, amplitude, speed, timee)
local w = math.sqrt(9.8 * (2 * math_pi / wavelength))
-- direction input is already normalized
--local Q = steepness
local Q = steepness/(w * amplitude)
local A = amplitude
local D = direction
local phase = speed * 2/wavelength
local f = w*direction:Dot(Vector2.new(position.X, position.Z)) + phase * timee
local sine = math_sin(f)
local cosine = math_cos(f)
local Position = Vector3_new(
Q * A * D.X * cosine,
A * sine,
Q * A * D.Y * cosine
)
local WA = w * A
local S0andC0 = w * direction:Dot(Vector2_new(position.X, position.Z) ) + phase * timee
local S0 = math_sin(S0andC0)
local C0 = math_cos(S0andC0)
local B = Vector3_new(
1 - (Q * (direction.X * direction.X) * WA * S0),
direction.X * WA * C0,
-(Q * direction.X * direction.Y * WA * S0)
)
local T = Vector3_new(
- (Q * direction.X * direction.Y * WA * S0),
direction.Y * WA * C0,
1 - (Q * (direction.Y * direction.Y) * WA * S0)
)
local N = Vector3_new(
-(direction.X * WA * C0),
1 - (Q * WA * S0)
-direction.Y * WA * C0
).Unit
return CFrame.fromMatrix(Position, B.Unit,N, T.Unit)
--return CFrame_new(Position)
end
this is the result i get:
its really weird and metallic and isn’t supposed to look like that
this is the source where I am getting the formula from:
Binormal formula:
Tangent formula:
Normal formula:
Keep in mind that in these calculations Y and Z (XZY) are switched places so my function seems a bit different but all the calculations should be on spot?
Edit: Note that the different texture is just a native glass roblox texture and it clearly isn’t supposed to look like that
What I am trying to replicate: Summed Gerstner/Trochoidal waves in roblox! - YouTube