ScratchData LogoScratchData
Back to Scratch-Minion's profile

Ray Tracer with Reflections

SCScratch-Minion•Created April 29, 2020
Ray Tracer with Reflections
32
25
393 views
View on Scratch

Instructions

** Use Turbo Mode (<Shift> key + Green Flag) ** The scene is redrawn 3 times in improving resolution. * Reflections in Ray Tracing are difficult for me! How should I combine direct light and reflected light? ** Answers welcome in the project comments! ** * Read on here to see my current algorithm * * Should Green light reflect in a Blue sphere? I haven't got the Xmas decorations out to check this. My algorithm is limited as I have not used coefficients for ambient, diffuse and reflected strengths for each RGB colour component for each object (sphere/plane). My algorithm is in the custom block: "Combine Primary Ray and Reflected Ray Colours". I ignore ambient reflected light, diffuse reflected light intensity decreases with distance, and total RGB components cannot exceed 255. This project adds reflections to my previous project: https://scratch.mit.edu/projects/389235995/ A "Ray Tracer" traces rays from the viewer through each pixel on the screen and calculates which object it hits first in 3D space (ie. which object is closest). The pixel is coloured with the colour of that object. More advanced Ray Tracers add different types of lighting, shadows and reflections of other objects. They also include not just spheres and planes (which have easier math) but other 3D objects. In this project the lighting has 3 components: - Ambient Light - general background reflected light that even gets into dark places such as under a bed - Diffuse Light - sphere lighting that is stronger if the light shines more "straight on" towards the sphere. (Diffuse Light Intensity does not depend where the viewer is) - Specular Reflected Light - the highlight produced when light is reflected off a sphere almost directly towards the viewer. Ray Tracing math at: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection * I haven't written code in my Distance to Plane custom block to check the denominator is not zero.

Description

** Forkphorus is faster to see the best resolution! https://forkphorus.github.io/#390390900 My Ray Tracer studio: https://scratch.mit.edu/studios/26312219/ Ray Tracing math at: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection * I haven't written code in my Distance to Plane custom block to check the denominator is not zero.

Project Details

Project ID390390900
CreatedApril 29, 2020
Last ModifiedMay 3, 2020
SharedMay 3, 2020
Visibilityvisible
CommentsAllowed