Shader
A Shader is an object that is used to modify the behavior of a ray. It is applied to the ray when it is traced. Each shader is applied to a ray in the order they are in the ray's shader table. Because a shader is applied to each ray individually, they cannot be used to modify the adjacent pixels.
Creating a Shader
Shader Shader.new(function shaderFunction , table attributes? )
Creates a new Shader.
Properties
function Function
The function to call when the shader is applied.
Note
The shader function is expected to return an Out dictionary. If the shader function returns nothing, the ray will keep its current output.
For backwards compatibility, the shader can also return a Color3. Note that TracedRay.Color is deprecated and will be removed in a future version.
table Attributes
Optional user-defined attributes to pass to the shader.
Methods
dict Process(TracedRay tracedRay , RaycastResult raycastResult , ... )
Process the shader on the ray.
Warning
Ray.Out should never contain values for non-existent buffers.
TracedRay Continue(TracedRay tracedRay , RaycastResult raycastResult )
Continues the ray after it has been processed by the shader.
Note
This method will continue the ray in the same direction as the ray's previous direction. For more fine control over how the ray is continued, create a new TracedRay manually in a shader.
TracedRay Reflect(TracedRay tracedRay , RaycastResult raycastResult , Vector3 normal )
Reflects the ray.
TracedRay Refract(TracedRay tracedRay , RaycastResult raycastResult , Vector3 normal , number indexOfRefraction )])
Refracts the ray.
Vector3, float SimpleIntersect(Vector3 origin , Vector3 direction , Instance object )
Calculates the intersection end point and length of a ray through an object based on its outermost geometry.
Vector3, float ComplexIntersect(Vector3 origin , Vector3 direction , Instance object )
Calculates the first intersection end point and length of a ray through an object based on its true geometry.
Vector3 Color3ToVector3(Color3 color )
Converts a Color3 to a Vector3 to make math operations easier.
Important
Shaders are expected to return a Color3. If you convert a Color3 to a Vector3, remember to convert it back to a Color3 when returning a value.
Color3 Vector3ToColor3(Vector3 vector , boolean clamp? [=false] )
Converts a Vector3 to a Color3. If
Color3 NumberToColor3(number number )
Converts a number to a greyscale Color3.