@@ -71,7 +71,7 @@ fn sun_intensity(zenith_angle_cos: f32) -> f32 {
71
71
)
72
72
}
73
73
74
- fn sky ( dir : Vec3 , sun_position : Vec3 ) -> Vec3 {
74
+ fn sky ( dir : Vec3 , sun_position : Vec3 , sun_intensity_extra_spec_const_factor : u32 ) -> Vec3 {
75
75
let up = vec3 ( 0.0 , 1.0 , 0.0 ) ;
76
76
let sunfade = 1.0 - ( 1.0 - saturate ( sun_position. y / 450000.0 ) . exp ( ) ) ;
77
77
let rayleigh_coefficient = RAYLEIGH - ( 1.0 * ( 1.0 - sunfade) ) ;
@@ -96,7 +96,12 @@ fn sky(dir: Vec3, sun_position: Vec3) -> Vec3 {
96
96
let beta_r_theta = beta_r * rayleigh_phase ( cos_theta * 0.5 + 0.5 ) ;
97
97
98
98
let beta_m_theta = beta_m * henyey_greenstein_phase ( cos_theta, MIE_DIRECTIONAL_G ) ;
99
- let sun_e = sun_intensity ( sun_direction. dot ( up) ) ;
99
+ let sun_e = sun_intensity ( sun_direction. dot ( up) )
100
+
101
+ // HACK(eddyb) this acts like an integration test for specialization constants,
102
+ // but the correct value is only obtained when this is a noop (multiplies by `1`).
103
+ * ( sun_intensity_extra_spec_const_factor as f32 / 100.0 ) ;
104
+
100
105
let mut lin = pow (
101
106
sun_e * ( ( beta_r_theta + beta_m_theta) / ( beta_r + beta_m) ) * ( Vec3 :: splat ( 1.0 ) - fex) ,
102
107
1.5 ,
@@ -130,7 +135,11 @@ fn get_ray_dir(uv: Vec2, pos: Vec3, look_at_pos: Vec3) -> Vec3 {
130
135
( forward + uv. x * right + uv. y * up) . normalize ( )
131
136
}
132
137
133
- pub fn fs ( constants : & ShaderConstants , frag_coord : Vec2 ) -> Vec4 {
138
+ pub fn fs (
139
+ constants : & ShaderConstants ,
140
+ frag_coord : Vec2 ,
141
+ sun_intensity_extra_spec_const_factor : u32 ,
142
+ ) -> Vec4 {
134
143
let mut uv = ( frag_coord - 0.5 * vec2 ( constants. width as f32 , constants. height as f32 ) )
135
144
/ constants. height as f32 ;
136
145
uv. y = -uv. y ;
@@ -141,7 +150,7 @@ pub fn fs(constants: &ShaderConstants, frag_coord: Vec2) -> Vec4 {
141
150
let dir = get_ray_dir ( uv, eye_pos, sun_pos) ;
142
151
143
152
// evaluate Preetham sky model
144
- let color = sky ( dir, sun_pos) ;
153
+ let color = sky ( dir, sun_pos, sun_intensity_extra_spec_const_factor ) ;
145
154
146
155
// Tonemapping
147
156
let color = color. max ( Vec3 :: splat ( 0.0 ) ) . min ( Vec3 :: splat ( 1024.0 ) ) ;
@@ -154,9 +163,12 @@ pub fn main_fs(
154
163
#[ spirv( frag_coord) ] in_frag_coord : Vec4 ,
155
164
#[ spirv( push_constant) ] constants : & ShaderConstants ,
156
165
output : & mut Vec4 ,
166
+
167
+ // NOTE(eddyb) this acts like an integration test for specialization constants.
168
+ #[ spirv( spec_constant( id = 0x5007 , default = 100 ) ) ] sun_intensity_extra_spec_const_factor : u32 ,
157
169
) {
158
170
let frag_coord = vec2 ( in_frag_coord. x , in_frag_coord. y ) ;
159
- * output = fs ( constants, frag_coord) ;
171
+ * output = fs ( constants, frag_coord, sun_intensity_extra_spec_const_factor ) ;
160
172
}
161
173
162
174
#[ spirv( vertex) ]
0 commit comments