From 242dff697f9966d301f7016e459c121a8198e3e9 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 27 Mar 2022 13:41:02 -0400 Subject: [PATCH] aurora: Rework normal visualization slightly --- aurora/lib/gfx/gx_shader.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/aurora/lib/gfx/gx_shader.cpp b/aurora/lib/gfx/gx_shader.cpp index 66e357c55..f6b0f5f87 100644 --- a/aurora/lib/gfx/gx_shader.cpp +++ b/aurora/lib/gfx/gx_shader.cpp @@ -5,6 +5,8 @@ #include +constexpr bool EnableNormalVisualization = false; + namespace aurora::gfx::gx { using namespace fmt::literals; @@ -498,7 +500,7 @@ std::pair 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 build_shader(const ShaderConfig& confi } vtxXfrAttrsPre += fmt::format(FMT_STRING("\n var mv_pos = ubuf.pos_mtx * vec4({}, 1.0);" "\n var mv_nrm = ubuf.nrm_mtx * vec4({}, 0.0);" - "\n out.pos = ubuf.proj * vec4(mv_pos, 1.0);" - "\n out.norm = vec4(mv_nrm, 0.0);"), + "\n out.pos = ubuf.proj * vec4(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;"), vtxOutIdx++); + vtxXfrAttrsPre += "\n out.nrm = mv_nrm;"; + } std::string fragmentFnPre; std::string fragmentFn; @@ -888,9 +893,9 @@ std::pair 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(in.nrm, prev.a);"; + } const auto shaderSource = fmt::format(FMT_STRING(R"""({uniformPre} @@ -903,8 +908,7 @@ struct Uniform {{ var ubuf: Uniform;{uniformBindings}{sampBindings}{texBindings} struct VertexOutput {{ - @builtin(position) pos: vec4; - @location(0) norm: vec4;{vtxOutAttrs} + @builtin(position) pos: vec4;{vtxOutAttrs} }}; @stage(vertex) @@ -917,7 +921,6 @@ fn vs_main({vtxInAttrs} @stage(fragment) fn fs_main(in: VertexOutput) -> @location(0) vec4 {{ var prev: vec4;{fragmentFnPre}{fragmentFn} - //prev = vec4(in.norm.xyz, prev.a); return prev; }} )"""),