| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // 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 <AnKi/Shaders/QuadVert.hlsl>
- #if ANKI_PIXEL_SHADER
- # include <AnKi/Shaders/Functions.hlsl>
- SamplerState g_nearestAnyClampSampler : register(s0);
- SamplerState g_linearAnyClampSampler : register(s1);
- Texture2D g_depthRt : register(t0);
- Texture3D<Vec4> g_fogVolume : register(t1);
- struct Constants
- {
- F32 m_zSplitCount;
- F32 m_finalZSplit;
- F32 m_near;
- F32 m_far;
- };
- ANKI_FAST_CONSTANTS(Constants, g_consts)
- Vec4 main(VertOut input) : SV_TARGET0
- {
- const Vec2 uv = input.m_uv;
- Vec3 uvw;
- // Compute W coordinate
- const F32 depth = g_depthRt.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r;
- const F32 linearDepth = linearizeDepth(depth, g_consts.m_near, g_consts.m_far);
- uvw.z = linearDepth * (g_consts.m_zSplitCount / (g_consts.m_finalZSplit + 1.0f));
- // Compute UV coordinates
- uvw.xy = uv;
- // Read the volume
- const Vec4 fogVals = g_fogVolume.SampleLevel(g_linearAnyClampSampler, uvw, 0.0);
- const Vec3 inScattering = fogVals.rgb;
- const F32 transmittance = fogVals.a;
- // Apply the fog
- return Vec4(inScattering, transmittance);
- }
- #endif // ANKI_PIXEL_SHADER
|