// 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 mutator METHOD 0 1 2 // 0: solid colod, 1: 2D image, 2: generated #pragma anki technique vert pixel #define CUSTOM_DEPTH 1.0 #include #if ANKI_PIXEL_SHADER # include # include # include # include # if METHOD == 0 struct Constants { Vec3 m_solidColor; F32 m_padding; }; ANKI_FAST_CONSTANTS(Constants, g_consts) # elif METHOD == 1 SamplerState g_trilinearAnySampler : register(s0); Texture2D g_envMapTex : register(t0); struct Constants { Mat4 m_invertedViewProjectionJitterMat; Vec3 m_cameraPos; F32 m_padding; Vec3 m_scale; F32 m_padding1; Vec3 m_bias; F32 m_padding2; }; ANKI_FAST_CONSTANTS(Constants, g_consts) # else SamplerState g_linearAnyClampSampler : register(s0); Texture2D g_skyLut : register(t0); ConstantBuffer g_consts : register(b0); # endif Vec4 main(VertOut input) : SV_TARGET0 { const Vec2 uv = input.m_uv; # if METHOD == 0 ANKI_MAYBE_UNUSED(uv); const Vec3 output = g_consts.m_solidColor; # elif METHOD == 1 const F32 depth = 1.0; const Vec2 ndc = uvToNdc(uv); const Vec4 worldPos4 = mul(g_consts.m_invertedViewProjectionJitterMat, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPos); const Vec2 uv3 = equirectangularMapping(eyeToFrag); // When uv is close to the edge of the texture the other quads might be in the oposit coordinate. Then the // derivatives will be huge causing the texture to use the highest mip and thus create a visible seam. To fix this // find when the derivatives are large and do some manual work to fix it const Vec2 dx = abs(ddx_coarse(uv3)); const F32 maxD = max(dx.x, dx.y); const F32 bias = (maxD > 0.9) ? -100.0f : 0.0f; const Vec3 output = g_envMapTex.SampleBias(g_trilinearAnySampler, uv3, bias).rgb * g_consts.m_scale + g_consts.m_bias; # else const F32 depth = 1.0; const Vec2 ndc = uvToNdc(uv); const Vec4 worldPos4 = mul(g_consts.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPosition); const Vec3 output = computeSkyColor(g_skyLut, g_linearAnyClampSampler, eyeToFrag, -g_consts.m_directionalLight.m_direction, g_consts.m_directionalLight.m_power, true); # endif return Vec4(output, 0.0); } #endif // ANKI_PIXEL_SHADER