Avoid texture dummy in directional light
@@ -107,10 +107,10 @@ impl DirectionalLight {
impl Light for DirectionalLight {
fn shader_source(&self, i: u32) -> String {
+ if self.shadow_texture.is_some() {
format!(
"
uniform sampler2D shadowMap{};
- uniform float shadowEnabled{};
uniform mat4 shadowMVP{};
uniform vec3 color{};
@@ -118,25 +118,30 @@ impl Light for DirectionalLight {
vec3 calculate_lighting{}(vec3 surface_color, vec3 position, vec3 normal, vec3 view_direction, float metallic, float roughness, float occlusion)
{{
- vec3 result = calculate_light(color{}, -direction{}, surface_color, view_direction, normal, metallic, roughness);
- if(shadowEnabled{} > 0.5) {{
- result *= calculate_shadow(shadowMap{}, shadowMVP{}, position);
+ return calculate_light(color{}, -direction{}, surface_color, view_direction, normal, metallic, roughness)
+ * calculate_shadow(shadowMap{}, shadowMVP{}, position);
}}
- return result;
+
+ ", i, i, i, i, i, i, i, i, i)
+ } else {
+ format!(
+ "
+ uniform vec3 color{};
+ uniform vec3 direction{};
+
+ vec3 calculate_lighting{}(vec3 surface_color, vec3 position, vec3 normal, vec3 view_direction, float metallic, float roughness, float occlusion)
+ {{
+ return calculate_light(color{}, -direction{}, surface_color, view_direction, normal, metallic, roughness);
}}
- ", i, i, i, i, i, i, i, i, i, i, i)
+ ", i, i, i, i, i)
+ }
}
fn use_uniforms(&self, program: &Program, i: u32) -> ThreeDResult<()> {
if let Some(tex) = self.shadow_map() {
program.use_texture(&format!("shadowMap{}", i), tex)?;
program.use_uniform_float(&format!("shadowEnabled{}", i), &1.0)?;
program.use_uniform_mat4(&format!("shadowMVP{}", i), &self.shadow_matrix)?;
- } else {
- self.context
- .use_texture_dummy(&program, &format!("shadowMap{}", i))?;
- program.use_uniform_float(&format!("shadowEnabled{}", i), &0.0)?;
- program.use_uniform_mat4(&format!("shadowMVP{}", i), &self.shadow_matrix)?;
}
program.use_uniform_vec3(
&format!("color{}", i),
