Skip to content

Commit

Permalink
Fix normal decoding in the shader
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Oct 7, 2024
1 parent 028abbd commit c51e491
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion blade-graphics/src/vulkan/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl crate::traits::ResourceDevice for super::Context {
image: texture.raw,
view_type: map_view_dimension(desc.dimension),
format: super::map_texture_format(desc.format),
subresource_range: subresource_range,
subresource_range,
..Default::default()
};

Expand Down
5 changes: 3 additions & 2 deletions blade-render/code/fill-gbuf.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
if ((debug.texture_flags & DebugTextureFlags_NORMAL) != 0u) {
normal_local = vec3<f32>(0.0, 0.0, 1.0); // ignore normal map
} else {
let n_xy = entry.normal_scale * textureSampleLevel(textures[entry.normal_texture], sampler_linear, tex_coords, lod).xy;
let raw_unorm = textureSampleLevel(textures[entry.normal_texture], sampler_linear, tex_coords, lod).xy;
let n_xy = entry.normal_scale * (2.0 * raw_unorm - 1.0);
normal_local = vec3<f32>(n_xy, sqrt(max(0.0, 1.0 - dot(n_xy, n_xy))));
}
var normal = qrot(geo_to_world_rot, tangent_space_geo * normal_local);
Expand Down Expand Up @@ -185,7 +186,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
if (debug.view_mode == DebugMode_NormalTexture) {
textureStore(out_debug, global_id.xy, vec4<f32>(normal_local, 0.0));
}
if (debug.view_mode == DebugMode_NormalFactor) {
if (debug.view_mode == DebugMode_NormalScale) {
textureStore(out_debug, global_id.xy, vec4<f32>(entry.normal_scale));
}
if (debug.view_mode == DebugMode_GeometryNormal) {
Expand Down
3 changes: 2 additions & 1 deletion blade-render/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const META_BASE_COLOR: crate::texture::Meta = crate::texture::Meta {
y_flip: false,
};
const META_NORMAL: crate::texture::Meta = crate::texture::Meta {
format: blade_graphics::TextureFormat::Bc5Snorm,
//Note: "texpresso" doesn't know how to produce signed normalized
format: blade_graphics::TextureFormat::Bc5Unorm,
generate_mips: false,
y_flip: false,
};
Expand Down
2 changes: 1 addition & 1 deletion blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum DebugMode {
DiffuseAlbedoTexture = 2,
DiffuseAlbedoFactor = 3,
NormalTexture = 4,
NormalFactor = 5,
NormalScale = 5,
GeometryNormal = 6,
ShadingNormal = 7,
Motion = 8,
Expand Down

0 comments on commit c51e491

Please sign in to comment.