mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-02-19 10:21:47 +00:00
62 lines
1.9 KiB
HLSL
62 lines
1.9 KiB
HLSL
/*
|
|
===========================================================================
|
|
Copyright (C) 2024 Gian 'myT' Schellenbaum
|
|
|
|
This file is part of Challenge Quake 3 (CNQ3).
|
|
|
|
Challenge Quake 3 is free software; you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
or (at your option) any later version.
|
|
|
|
Challenge Quake 3 is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Challenge Quake 3. If not, see <https://www.gnu.org/licenses/>.
|
|
===========================================================================
|
|
*/
|
|
// volumetric lighting: temporal reprojection
|
|
|
|
|
|
#include "common.hlsli"
|
|
#include "scene_view.h.hlsli"
|
|
|
|
|
|
cbuffer RootConstants
|
|
{
|
|
uint currTextureIndex;
|
|
uint prevTextureIndex;
|
|
uint prevTextureSamplerIndex;
|
|
float alpha;
|
|
}
|
|
|
|
[numthreads(4, 4, 4)]
|
|
void cs(uint3 id : SV_DispatchThreadID)
|
|
{
|
|
RWTexture3D<float> currTexture = ResourceDescriptorHeap[currTextureIndex];
|
|
uint3 textureSize = GetTextureSize(currTexture);
|
|
if(any(id >= textureSize))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SceneView scene = GetSceneView();
|
|
Texture3D<float> prevTexture = ResourceDescriptorHeap[prevTextureIndex];
|
|
SamplerState prevTextureSampler = SamplerDescriptorHeap[prevTextureSamplerIndex];
|
|
|
|
float3 tc = scene.FroxelReproject01(id, float3(textureSize));
|
|
float currValue = currTexture[id];
|
|
float3 halfPixelSize = float3(0.5, 0.5, 0.5) / float3(textureSize);
|
|
if(IsInRange(tc, halfPixelSize, float3(1, 1, 1) - halfPixelSize))
|
|
{
|
|
float prevValue = prevTexture.SampleLevel(prevTextureSampler, tc, 0);
|
|
float finalValue = lerp(currValue, prevValue, alpha);
|
|
if(finalValue != currValue)
|
|
{
|
|
currTexture[id] = finalValue;
|
|
}
|
|
}
|
|
}
|