// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma anki technique vert pixel #include #include #include #include SamplerState g_nearestAnyClampSampler : register(s0); Texture2D g_inTex : register(t0); Texture2D g_inTex2 : register(t1); Texture2D g_integerTex : register(t2); struct Consts { U32 m_drawStyle; U32 m_padding0; U32 m_padding1; U32 m_padding2; }; ANKI_FAST_CONSTANTS(Consts, g_consts) #if ANKI_PIXEL_SHADER Vec3 uintToColor(U32 v) { // simple integer hash → 0..1 const F32 h = frac(sin(v * 12.9898) * 43758.5453); const F32 s = 0.6; // moderate saturation const F32 val = 0.9; // bright // HSV → RGB const Vec3 k = Vec3(1.0, 2.0 / 3.0, 1.0 / 3.0); const Vec3 p = abs(frac(h + k) * 6.0 - 3.0); const Vec3 rgb = val * lerp(1.0, saturate(p - 1.0), s); return rgb; // 0..1 } Vec3 main(VertOut input) : SV_TARGET0 { Vec4 rgba = g_inTex.SampleLevel(g_nearestAnyClampSampler, input.m_uv, 0.0); switch((DebugRenderTargetDrawStyle)g_consts.m_drawStyle) { case DebugRenderTargetDrawStyle::kTonemap: rgba.xyz = reinhardTonemap(rgba.xyz); break; case DebugRenderTargetDrawStyle::kGBufferNormal: rgba.xyz = unpackNormalFromGBuffer(rgba) / 2.0f + 0.5f; break; case DebugRenderTargetDrawStyle::kGBufferRoughness: rgba.xyz = unpackRoughnessFromGBuffer(rgba, 0.0).xxx; break; case DebugRenderTargetDrawStyle::kGBufferMetallic: rgba.xyz = unpackSubsurfaceAndMetallicFromGBuffer(rgba).yyy; break; case DebugRenderTargetDrawStyle::kGBufferSubsurface: rgba.xyz = unpackSubsurfaceAndMetallicFromGBuffer(rgba).xxx; break; case DebugRenderTargetDrawStyle::kGBufferEmission: { const Vec4 rt2 = g_inTex2.SampleLevel(g_nearestAnyClampSampler, input.m_uv, 0.0); const Vec4 rt1 = rgba; rgba.xyz = invertReinhardTonemap(Vec3(rt1.z, rt2.x, rt1.w)); break; } case DebugRenderTargetDrawStyle::kAlphaOnly: rgba.xyz = rgba.www; break; case DebugRenderTargetDrawStyle::kRedOnly: rgba.xyz = rgba.rrr; break; case DebugRenderTargetDrawStyle::kIntegerTexture: { const UVec4 val = g_integerTex.SampleLevel(g_nearestAnyClampSampler, input.m_uv, 0.0); rgba = Vec4(uintToColor(val.x), 1.0); } default: break; } return rgba.xyz; } #endif