-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImage.glsl
42 lines (41 loc) · 2.18 KB
/
Image.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Raytracing in one weekend, chapter 7: Diffuse. Created by Reinder Nijhoff 2018
// Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// @reindernijhoff
//
// https://www.shadertoy.com/view/llVcDz
//
// These shaders are my implementation of the raytracer described in the (excellent)
// book "Raytracing in one weekend" [1] by Peter Shirley (@Peter_shirley). I have tried
// to follow the code from his book as much as possible, but I had to make some changes
// to get it running in a fragment shader:
//
// - There are no classes (and methods) in glsl so I use structs and functions instead.
// Inheritance is implemented by adding a type variable to the struct and adding ugly
// if/else statements to the (not so overloaded) functions.
// - The scene description is procedurally implemented in the world_hit function to save
// memory.
// - The color function is implemented using a loop because it is not possible to have a
// recursive function call in glsl.
// - Only one sample per pixel per frame is calculated. Samples of all frames are added
// in Buffer A and averaged in the Image tab.
//
// You can find the raytracer / pathtracer in Buffer A.
//
// = Ray tracing in one week =
// Chapter 7: Diffuse https://www.shadertoy.com/view/llVcDz
// Chapter 9: Dielectrics https://www.shadertoy.com/view/MlVcDz
// Chapter 11: Defocus blur https://www.shadertoy.com/view/XlGcWh
// Chapter 12: Where next? https://www.shadertoy.com/view/XlycWh
//
// = Ray tracing: the next week =
// Chapter 6: Rectangles and lights https://www.shadertoy.com/view/4tGcWD
// Chapter 7: Instances https://www.shadertoy.com/view/XlGcWD
// Chapter 8: Volumes https://www.shadertoy.com/view/XtyyDD
// Chapter 9: A Scene Testing All New Features https://www.shadertoy.com/view/MtycDD
//
// [1] http://in1weekend.blogspot.com/2016/01/ray-tracing-in-one-weekend.html
//
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec4 data = texelFetch(iChannel0, ivec2(fragCoord),0);
fragColor = vec4(sqrt(data.rgb/data.w),1.0);
}