[wgsl-in] support textureSampleCompareLevel

This commit is contained in:
Dzmitry Malyshau
2021-05-28 22:32:35 -04:00
committed by Dzmitry Malyshau
parent 1366546645
commit 8a1d883ba5
2 changed files with 33 additions and 1 deletions

View File

@@ -880,6 +880,38 @@ impl Parser {
}
}
"textureSampleCompare" => {
lexer.open_arguments()?;
let (image_name, image_span) = lexer.next_ident_with_span()?;
lexer.expect(Token::Separator(','))?;
let (sampler_name, sampler_span) = lexer.next_ident_with_span()?;
lexer.expect(Token::Separator(','))?;
let coordinate = self.parse_general_expression(lexer, ctx.reborrow())?;
let sc = ctx.prepare_sampling(image_name, image_span)?;
let array_index = if sc.arrayed {
lexer.expect(Token::Separator(','))?;
Some(self.parse_general_expression(lexer, ctx.reborrow())?)
} else {
None
};
lexer.expect(Token::Separator(','))?;
let reference = self.parse_general_expression(lexer, ctx.reborrow())?;
let offset = if lexer.skip(Token::Separator(',')) {
Some(self.parse_const_expression(lexer, ctx.types, ctx.constants)?)
} else {
None
};
lexer.close_arguments()?;
crate::Expression::ImageSample {
image: sc.image,
sampler: ctx.lookup_ident.lookup(sampler_name, sampler_span)?,
coordinate,
array_index,
offset,
level: crate::SampleLevel::Auto,
depth_ref: Some(reference),
}
}
"textureSampleCompareLevel" => {
lexer.open_arguments()?;
let (image_name, image_span) = lexer.next_ident_with_span()?;
lexer.expect(Token::Separator(','))?;

View File

@@ -30,7 +30,7 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
}
let flip_correction = vec2<f32>(0.5, -0.5);
let light_local = homogeneous_coords.xy * flip_correction / homogeneous_coords.w + vec2<f32>(0.5, 0.5);
return textureSampleCompare(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z / homogeneous_coords.w);
return textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z / homogeneous_coords.w);
}
let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);