Hey all. So I’ve been working on a raytracer, and I a want to implement specular lighting. Which makes reflective objects appear more shiny.
Now this is cool and all, but I have no idea how I am suppose to find the angle between 2 rays that I will need to make this work.
How do I do this?
Help would be greatly appreciated as always
My current code:
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