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