@@ -12,22 +12,16 @@ let pixellizeShader;
12
12
let fresnelShader ;
13
13
let bloomShader ;
14
14
15
-
16
15
function fresnelShaderCallback ( ) {
17
16
const fresnelPower = uniformFloat ( 2 ) ;
18
17
const fresnelBias = uniformFloat ( - 0.1 ) ;
19
18
const fresnelScale = uniformFloat ( 2 ) ;
20
19
getCameraInputs ( ( inputs ) => {
21
- let myValue = [ 1 , 0 , 0 ] ;
22
20
let n = normalize ( inputs . normal ) ;
23
- If ( n == n , ( ) => assign ( myValue , 1 ) ) ;
24
21
let v = normalize ( - inputs . position ) ;
25
22
let base = 1.0 - dot ( n , v ) ;
26
23
let fresnel = fresnelScale * pow ( base , fresnelPower ) + fresnelBias ;
27
-
28
-
29
- let col = mix ( myValue , [ 1 , .5 , .7 ] , fresnel ) ;
30
-
24
+ let col = mix ( [ 0 , 0 , 0 ] , [ 1 , .5 , .7 ] , fresnel ) ;
31
25
inputs . color = [ col , 1 ] ;
32
26
return inputs ;
33
27
} ) ;
@@ -48,7 +42,7 @@ function starShaderCallback() {
48
42
let r = skyRadius ;
49
43
r *= 1.5 * sin ( phi ) ;
50
44
let x = r * sin ( phi ) * cos ( theta ) ;
51
- let y = r * 1.5 * cos ( phi ) ;
45
+ let y = r * 1.5 * cos ( phi ) ;
52
46
let z = r * sin ( phi ) * sin ( theta ) ;
53
47
return [ x , y , z ] ;
54
48
}
@@ -66,7 +60,7 @@ function starShaderCallback() {
66
60
}
67
61
68
62
function pixellizeShaderCallback ( ) {
69
- const pixelSize = uniformFloat ( ( ) => width / 2 ) ;
63
+ const pixelSize = uniformFloat ( ( ) => width * .75 ) ;
70
64
getColor ( ( input , canvasContent ) => {
71
65
let coord = input . texCoord ;
72
66
coord = floor ( coord * pixelSize ) / pixelSize ;
@@ -80,51 +74,51 @@ function bloomShaderCallback() {
80
74
getColor ( ( input , canvasContent ) => {
81
75
const blurredCol = texture ( canvasContent , input . texCoord ) ;
82
76
const originalCol = texture ( preBlur , input . texCoord ) ;
83
- const brightPass = max ( originalCol - 0.3 , 0.7 ) * 1.2 ;
77
+ const brightPass = max ( originalCol , 0.3 ) * 1.5 ;
84
78
const bloom = originalCol + blurredCol * brightPass ;
85
79
return bloom ;
86
80
} ) ;
87
81
}
88
82
89
83
async function setup ( ) {
90
84
createCanvas ( windowWidth , windowHeight , WEBGL ) ;
91
- stars = buildGeometry ( ( ) => sphere ( 20 , 4 , 2 ) )
85
+ stars = buildGeometry ( ( ) => sphere ( 30 , 4 , 2 ) )
92
86
originalFrameBuffer = createFramebuffer ( ) ;
93
87
94
- // starShader = baseMaterialShader().modify(starShaderCallback);
95
- // starStrokeShader = baseStrokeShader().modify(starShaderCallback)
88
+ starShader = baseMaterialShader ( ) . modify ( starShaderCallback ) ;
89
+ starStrokeShader = baseStrokeShader ( ) . modify ( starShaderCallback )
96
90
fresnelShader = baseColorShader ( ) . modify ( fresnelShaderCallback ) ;
97
- // bloomShader = baseFilterShader().modify(bloomShaderCallback);
98
- // pixellizeShader = baseFilterShader().modify(pixellizeShaderCallback);
91
+ bloomShader = baseFilterShader ( ) . modify ( bloomShaderCallback ) ;
92
+ pixellizeShader = baseFilterShader ( ) . modify ( pixellizeShaderCallback ) ;
99
93
}
100
94
101
95
function draw ( ) {
102
96
originalFrameBuffer . begin ( ) ;
103
97
background ( 0 ) ;
104
- orbitControl ( ) ;
98
+ orbitControl ( ) ;
105
99
106
- // push()
107
- // strokeWeight(4)
108
- // stroke(255,0,0)
109
- // rotateX(PI/2 + millis() * 0.0005);
110
- // fill(255,100, 150)
111
- // strokeShader(starStrokeShader)
112
- // shader(starShader);
113
- // model(stars, 5000 );
114
- // pop()
100
+ push ( )
101
+ strokeWeight ( 4 )
102
+ stroke ( 255 , 0 , 0 )
103
+ rotateX ( PI / 2 + millis ( ) * 0.0005 ) ;
104
+ fill ( 255 , 100 , 150 )
105
+ strokeShader ( starStrokeShader )
106
+ shader ( starShader ) ;
107
+ model ( stars , 2000 ) ;
108
+ pop ( )
115
109
116
110
push ( )
117
111
shader ( fresnelShader )
118
112
noStroke ( )
119
113
sphere ( 500 ) ;
120
114
pop ( )
115
+ filter ( pixellizeShader ) ;
121
116
122
- // filter(pixellizeShader);
123
117
originalFrameBuffer . end ( ) ;
124
118
125
119
imageMode ( CENTER )
126
120
image ( originalFrameBuffer , 0 , 0 )
127
121
128
- // filter(BLUR, 20)
129
- // filter(bloomShader);
122
+ filter ( BLUR , 20 )
123
+ filter ( bloomShader ) ;
130
124
}
0 commit comments