aurora: Rework normal visualization slightly

This commit is contained in:
Luke Street 2022-03-27 13:41:02 -04:00
parent ce84609b4e
commit 242dff697f
1 changed files with 12 additions and 9 deletions

View File

@ -5,6 +5,8 @@
#include <absl/container/flat_hash_map.h>
constexpr bool EnableNormalVisualization = false;
namespace aurora::gfx::gx {
using namespace fmt::literals;
@ -498,7 +500,7 @@ std::pair<wgpu::ShaderModule, ShaderInfo> build_shader(const ShaderConfig& confi
std::string vtxXfrAttrsPre;
std::string vtxXfrAttrs;
size_t locIdx = 0;
size_t vtxOutIdx = 1;
size_t vtxOutIdx = 0;
size_t uniBindingIdx = 1;
if (config.indexedAttributeCount > 0) {
// Display list attributes
@ -583,9 +585,12 @@ std::pair<wgpu::ShaderModule, ShaderInfo> build_shader(const ShaderConfig& confi
}
vtxXfrAttrsPre += fmt::format(FMT_STRING("\n var mv_pos = ubuf.pos_mtx * vec4<f32>({}, 1.0);"
"\n var mv_nrm = ubuf.nrm_mtx * vec4<f32>({}, 0.0);"
"\n out.pos = ubuf.proj * vec4<f32>(mv_pos, 1.0);"
"\n out.norm = vec4<f32>(mv_nrm, 0.0);"),
"\n out.pos = ubuf.proj * vec4<f32>(mv_pos, 1.0);"),
vtx_attr(config, GX::VA_POS), vtx_attr(config, GX::VA_NRM));
if constexpr (EnableNormalVisualization) {
vtxOutAttrs += fmt::format(FMT_STRING("\n @location({}) nrm: vec3<f32>;"), vtxOutIdx++);
vtxXfrAttrsPre += "\n out.nrm = mv_nrm;";
}
std::string fragmentFnPre;
std::string fragmentFn;
@ -888,9 +893,9 @@ std::pair<wgpu::ShaderModule, ShaderInfo> build_shader(const ShaderConfig& confi
}
}
}
// if (config.alphaDiscard) {
// fragmentFn += fmt::format(FMT_STRING("\n if (prev.a < {}f) {{ discard; }}"), *config.alphaDiscard);
// }
if constexpr (EnableNormalVisualization) {
fragmentFn += "\n prev = vec4<f32>(in.nrm, prev.a);";
}
const auto shaderSource =
fmt::format(FMT_STRING(R"""({uniformPre}
@ -903,8 +908,7 @@ struct Uniform {{
var<uniform> ubuf: Uniform;{uniformBindings}{sampBindings}{texBindings}
struct VertexOutput {{
@builtin(position) pos: vec4<f32>;
@location(0) norm: vec4<f32>;{vtxOutAttrs}
@builtin(position) pos: vec4<f32>;{vtxOutAttrs}
}};
@stage(vertex)
@ -917,7 +921,6 @@ fn vs_main({vtxInAttrs}
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {{
var prev: vec4<f32>;{fragmentFnPre}{fragmentFn}
//prev = vec4<f32>(in.norm.xyz, prev.a);
return prev;
}}
)"""),