mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-02-19 10:21:47 +00:00
206 lines
5.1 KiB
HLSL
206 lines
5.1 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: shared data structures and functions
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include "typedefs.h.hlsli"
|
|
#if !defined(__cplusplus)
|
|
#include "common.hlsli"
|
|
#include "simplex_noise.hlsli"
|
|
#endif
|
|
|
|
#if defined(__cplusplus)
|
|
#pragma pack(push, 1)
|
|
#endif
|
|
|
|
struct FogVolume
|
|
{
|
|
float3 scatter;
|
|
float absorption;
|
|
float3 emissive;
|
|
float anisotropy;
|
|
float3 boxMin;
|
|
float noiseMin;
|
|
float3 boxMax;
|
|
float noiseMax;
|
|
float noiseScale;
|
|
float noiseTimeScale;
|
|
uint isHeightFog;
|
|
|
|
#if !defined(__cplusplus)
|
|
bool IsPointInside(float3 position)
|
|
{
|
|
return IsInRange(position, boxMin, boxMax);
|
|
}
|
|
|
|
float DensityAt(float3 position, float time)
|
|
{
|
|
float4 positionTime = float4(position * noiseScale, time * noiseTimeScale);
|
|
float density = noiseMin + (noiseMax - noiseMin) * SimplexNoise4D(positionTime);
|
|
if(isHeightFog)
|
|
{
|
|
float maxHeight = boxMax.z - boxMin.z;
|
|
float height = position.z - boxMin.z;
|
|
density *= 1.0 - EaseOutCubic(height / maxHeight);
|
|
}
|
|
|
|
return density;
|
|
}
|
|
#endif
|
|
};
|
|
|
|
#if defined(__cplusplus)
|
|
#pragma pack(pop)
|
|
#endif
|
|
|
|
#if !defined(__cplusplus)
|
|
|
|
// defines voxel sampling offsets for super-sampled fog injection
|
|
|
|
#if defined(VOXEL_SUPERSAMPLING_1X)
|
|
static const int VoxelSampleCount = 1;
|
|
static const float3 VoxelSamples[1] =
|
|
{
|
|
float3(0, 0, 0)
|
|
};
|
|
#elif defined(VOXEL_SUPERSAMPLING_2X)
|
|
static const float Offset = 0.1666666666666666666666666666666;
|
|
static const int VoxelSampleCount = 9;
|
|
static const float3 VoxelSamples[9] =
|
|
{
|
|
float3(0, 0, 0),
|
|
float3(-Offset, -Offset, -Offset),
|
|
float3(-Offset, -Offset, +Offset),
|
|
float3(-Offset, +Offset, -Offset),
|
|
float3(-Offset, +Offset, +Offset),
|
|
float3(+Offset, -Offset, -Offset),
|
|
float3(+Offset, -Offset, +Offset),
|
|
float3(+Offset, +Offset, -Offset),
|
|
float3(+Offset, +Offset, +Offset)
|
|
};
|
|
#elif defined(VOXEL_SUPERSAMPLING_3X)
|
|
static const int VoxelSampleCount = 27;
|
|
static const float3 VoxelSamples[27] =
|
|
{
|
|
float3(-0.25, -0.25, -0.25),
|
|
float3(-0.25, -0.25, 0),
|
|
float3(-0.25, -0.25, 0.25),
|
|
float3(-0.25, 0, -0.25),
|
|
float3(-0.25, 0, 0),
|
|
float3(-0.25, 0, 0.25),
|
|
float3(-0.25, 0.25, -0.25),
|
|
float3(-0.25, 0.25, 0),
|
|
float3(-0.25, 0.25, 0.25),
|
|
float3(0, -0.25, -0.25),
|
|
float3(0, -0.25, 0),
|
|
float3(0, -0.25, 0.25),
|
|
float3(0, 0, -0.25),
|
|
float3(0, 0, 0),
|
|
float3(0, 0, 0.25),
|
|
float3(0, 0.25, -0.25),
|
|
float3(0, 0.25, 0),
|
|
float3(0, 0.25, 0.25),
|
|
float3(0.25, -0.25, -0.25),
|
|
float3(0.25, -0.25, 0),
|
|
float3(0.25, -0.25, 0.25),
|
|
float3(0.25, 0, -0.25),
|
|
float3(0.25, 0, 0),
|
|
float3(0.25, 0, 0.25),
|
|
float3(0.25, 0.25, -0.25),
|
|
float3(0.25, 0.25, 0),
|
|
float3(0.25, 0.25, 0.25)
|
|
};
|
|
#elif defined(VOXEL_SUPERSAMPLING_4X)
|
|
static const int VoxelSampleCount = 65;
|
|
static const float3 VoxelSamples[65] =
|
|
{
|
|
float3(0, 0, 0),
|
|
float3(-0.3, -0.3, -0.3),
|
|
float3(-0.3, -0.3, -0.1),
|
|
float3(-0.3, -0.3, 0.1),
|
|
float3(-0.3, -0.3, 0.3),
|
|
float3(-0.3, -0.1, -0.3),
|
|
float3(-0.3, -0.1, -0.1),
|
|
float3(-0.3, -0.1, 0.1),
|
|
float3(-0.3, -0.1, 0.3),
|
|
float3(-0.3, 0.1, -0.3),
|
|
float3(-0.3, 0.1, -0.1),
|
|
float3(-0.3, 0.1, 0.1),
|
|
float3(-0.3, 0.1, 0.3),
|
|
float3(-0.3, 0.3, -0.3),
|
|
float3(-0.3, 0.3, -0.1),
|
|
float3(-0.3, 0.3, 0.1),
|
|
float3(-0.3, 0.3, 0.3),
|
|
float3(-0.1, -0.3, -0.3),
|
|
float3(-0.1, -0.3, -0.1),
|
|
float3(-0.1, -0.3, 0.1),
|
|
float3(-0.1, -0.3, 0.3),
|
|
float3(-0.1, -0.1, -0.3),
|
|
float3(-0.1, -0.1, -0.1),
|
|
float3(-0.1, -0.1, 0.1),
|
|
float3(-0.1, -0.1, 0.3),
|
|
float3(-0.1, 0.1, -0.3),
|
|
float3(-0.1, 0.1, -0.1),
|
|
float3(-0.1, 0.1, 0.1),
|
|
float3(-0.1, 0.1, 0.3),
|
|
float3(-0.1, 0.3, -0.3),
|
|
float3(-0.1, 0.3, -0.1),
|
|
float3(-0.1, 0.3, 0.1),
|
|
float3(-0.1, 0.3, 0.3),
|
|
float3(0.1, -0.3, -0.3),
|
|
float3(0.1, -0.3, -0.1),
|
|
float3(0.1, -0.3, 0.1),
|
|
float3(0.1, -0.3, 0.3),
|
|
float3(0.1, -0.1, -0.3),
|
|
float3(0.1, -0.1, -0.1),
|
|
float3(0.1, -0.1, 0.1),
|
|
float3(0.1, -0.1, 0.3),
|
|
float3(0.1, 0.1, -0.3),
|
|
float3(0.1, 0.1, -0.1),
|
|
float3(0.1, 0.1, 0.1),
|
|
float3(0.1, 0.1, 0.3),
|
|
float3(0.1, 0.3, -0.3),
|
|
float3(0.1, 0.3, -0.1),
|
|
float3(0.1, 0.3, 0.1),
|
|
float3(0.1, 0.3, 0.3),
|
|
float3(0.3, -0.3, -0.3),
|
|
float3(0.3, -0.3, -0.1),
|
|
float3(0.3, -0.3, 0.1),
|
|
float3(0.3, -0.3, 0.3),
|
|
float3(0.3, -0.1, -0.3),
|
|
float3(0.3, -0.1, -0.1),
|
|
float3(0.3, -0.1, 0.1),
|
|
float3(0.3, -0.1, 0.3),
|
|
float3(0.3, 0.1, -0.3),
|
|
float3(0.3, 0.1, -0.1),
|
|
float3(0.3, 0.1, 0.1),
|
|
float3(0.3, 0.1, 0.3),
|
|
float3(0.3, 0.3, -0.3),
|
|
float3(0.3, 0.3, -0.1),
|
|
float3(0.3, 0.3, 0.1),
|
|
float3(0.3, 0.3, 0.3),
|
|
};
|
|
#endif
|
|
|
|
#endif
|