function ProcessSpecularLighting(IntersectPos, OriginalColor) -- OriginalColor is the color of the pixel on the screen
local SunRayOrigin = (CFrame.new(IntersectPos, IntersectPos + SunDirection) * CFrame.new(0, 0, 0.1)).Position
local SunRayDirection = (CFrame.new(IntersectPos, IntersectPos - SunDirection) * CFrame.new(0, 0, 0.1)).Position
local SunLightRay = workspace:Raycast(SunRayOrigin, SunRayDirection, Params)
if SunLightRay then
local ReflectedSunDirection = SunRayDirection - (2 * SunRayDirection:Dot(SunLightRay.Normal) * SunLightRay.Normal) -- Relfect the direction.
local Shininess = nil -- a percentage from 0 - 1 that is used for the colour combining below
return Color3.new(1, 1, 1):Lerp(OriginalColor, Shininess) -- Merge the two colours depending on the shininess of the angle
else
return OriginalColor
end
end
Yes, the dot product of 2 vectors is equal to the product of the length of those vectors times the cos(angle). You can rewrite the formula to get the angle.
In math terms:
This isn’t quite the right approach for this case. We want to get rid of the negatives out the dot product we return from these unit rays cause then we basically get a value from 0 to 1 representing the shadow angle. To add on you need to raise this mixture float to some exponent, usually called k. I coded this up quickly in bkcore just to show what i mean