Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ option(XRAY_USE_ASAN "Use AddressSanitizer" OFF)
option(XRAY_ENABLE_TRACY "Enable tracy profiler" OFF)
option(XRAY_USE_AI_PBR "Enable AI PBR texture converter (requires ONNX Runtime)" OFF)

option(XRAY_USE_DLSS "Enable NVIDIA DLSS / NGX (requires SDK)" OFF)
option(XRAY_USE_NRD "Enable NVIDIA NRD denoise via NRDIntegration+NRI (Linux Vulkan: -DXRAY_USE_NRD=ON)" OFF)

include(XRay.Build)
include(XRay.Windows.Externals)
include(XRay.Packaging)
Expand Down
61 changes: 61 additions & 0 deletions Externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,64 @@ if (NOT TARGET xrLuabind)
"Read the build instructions: https://github.com/OpenXRay/xray-16/wiki"
)
endif()
if (XRAY_USE_NRD)
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/NRD/CMakeLists.txt")
message(FATAL_ERROR "XRAY_USE_NRD=ON but Externals/NRD is missing")
endif()
set(NRD_STATIC_LIBRARY ON CACHE BOOL "Build NRD as static library" FORCE)
set(NRD_NRI ON CACHE BOOL "Pull NRI for NRDIntegration" FORCE)
set(NRD_EMBEDS_SPIRV_SHADERS ON CACHE BOOL "NRD embeds SPIRV shaders" FORCE)
set(NRD_EMBEDS_DXIL_SHADERS OFF CACHE BOOL "NRD: no DXIL on Linux Vulkan" FORCE)
set(NRD_EMBEDS_DXBC_SHADERS OFF CACHE BOOL "NRD: no DXBC on Linux Vulkan" FORCE)
set(NRD_NORMAL_ENCODING "3" CACHE STRING "NRD normal encoding (RGBA16_UNORM)" FORCE)
set(NRD_ROUGHNESS_ENCODING "1" CACHE STRING "NRD roughness encoding (LINEAR)" FORCE)
set(NRI_ENABLE_NVAPI OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_AMDAGS OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_NVTX_SUPPORT OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_NONE_SUPPORT OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_D3D11_SUPPORT OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_D3D12_SUPPORT OFF CACHE BOOL "" FORCE)
set(NRI_ENABLE_VK_SUPPORT ON CACHE BOOL "" FORCE)
add_subdirectory(NRD)

set(_xray_nri_vk_core "${CMAKE_BINARY_DIR}/_deps/vulkan_headers-src/include/vulkan/vulkan_core.h")
set(_xray_nri_vk_ok FALSE)
if (EXISTS "${_xray_nri_vk_core}")
file(STRINGS "${_xray_nri_vk_core}" _xray_nri_vk_ver REGEX "^#define VK_HEADER_VERSION ")
if (_xray_nri_vk_ver MATCHES "VK_HEADER_VERSION ([0-9]+)" AND CMAKE_MATCH_1 GREATER_EQUAL 354)
set(_xray_nri_vk_ok TRUE)
endif()
endif()
if (NOT _xray_nri_vk_ok)
set(_xray_nri_vk_zip "${CMAKE_BINARY_DIR}/_deps/vulkan_headers-v1.4.354.zip")
set(_xray_nri_vk_extract "${CMAKE_BINARY_DIR}/_deps/vulkan_headers-v1.4.354-extract")
message(STATUS "NRD: upgrading Vulkan-Headers for NRI to v1.4.354")
file(DOWNLOAD
"https://github.com/KhronosGroup/Vulkan-Headers/archive/refs/tags/v1.4.354.zip"
"${_xray_nri_vk_zip}"
SHOW_PROGRESS
STATUS _xray_nri_vk_dl
)
list(GET _xray_nri_vk_dl 0 _xray_nri_vk_dl_code)
if (NOT _xray_nri_vk_dl_code EQUAL 0)
message(FATAL_ERROR "NRD: failed to download Vulkan-Headers v1.4.354")
endif()
file(REMOVE_RECURSE "${_xray_nri_vk_extract}")
file(ARCHIVE_EXTRACT INPUT "${_xray_nri_vk_zip}" DESTINATION "${_xray_nri_vk_extract}")
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/_deps/vulkan_headers-src")
file(RENAME "${_xray_nri_vk_extract}/Vulkan-Headers-1.4.354" "${CMAKE_BINARY_DIR}/_deps/vulkan_headers-src")
file(REMOVE_RECURSE "${_xray_nri_vk_extract}")
endif()

if (SHADERMAKE_PATH AND NOT EXISTS "${SHADERMAKE_PATH}")
get_filename_component(_sm_dir "${SHADERMAKE_PATH}" DIRECTORY)
get_filename_component(_sm_alt "${_sm_dir}/../ShaderMake" ABSOLUTE)
if (EXISTS "${_sm_alt}")
file(MAKE_DIRECTORY "${_sm_dir}")
file(CREATE_LINK "${_sm_alt}" "${SHADERMAKE_PATH}" SYMBOLIC)
message(STATUS "NRD: linked ShaderMake -> ${SHADERMAKE_PATH}")
endif()
endif()

message(STATUS "NRD: enabled (NRI + SPIRV, normalEnc=3 roughnessEnc=1)")
endif()
47 changes: 47 additions & 0 deletions res/gamedata/shaders/r5/atmosphere.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef ATMOSPHERE_H
#define ATMOSPHERE_H

static const float3 ATM_RAYLEIGH = float3(5.8e-3, 1.35e-2, 3.31e-2);
static const float ATM_MIE = 2.1e-2;
static const float ATM_MIE_G = 0.76;

float AtmosphereRayleighPhase(float cosTheta)
{
return 0.0596831 * (1.0 + cosTheta * cosTheta);
}

float AtmosphereMiePhase(float cosTheta, float g)
{
float g2 = g * g;
float denom = 1.0 + g2 - 2.0 * g * cosTheta;
return 0.1193662 * (1.0 - g2) / max(pow(max(denom, 1e-4), 1.5), 1e-4);
}

void AtmosphereAerial(float3 viewDir, float dist, float3 sunDir, float3 sunColor, float3 fogColor, float strength,
out float3 transmittance, out float3 inscatter)
{
float t = max(dist, 0.0);
float height = saturate(viewDir.y * 0.5 + 0.5);
float density = exp(-height * 2.4) * strength;
float3 betaR = ATM_RAYLEIGH * density;
float betaM = ATM_MIE * density;
float3 ext = betaR + betaM;
transmittance = exp(-ext * t);
float cosTheta = saturate(dot(viewDir, sunDir));
float3 ray = betaR * AtmosphereRayleighPhase(cosTheta);
float mie = betaM * AtmosphereMiePhase(cosTheta, ATM_MIE_G);
float3 scatter = (ray + mie) * sunColor + fogColor * betaR * 0.18;
float3 invExt = 1.0 / max(ext, 1e-4);
inscatter = scatter * invExt * (1.0 - transmittance);
}

float3 AtmosphereSkyInscatter(float3 viewDir, float3 sunDir, float3 sunColor, float3 fogColor, float3 skyTint, float strength)
{
float3 T, insc;
AtmosphereAerial(viewDir, 80.0, sunDir, sunColor, fogColor, strength, T, insc);
float horizon = saturate(1.0 - abs(viewDir.y));
float sunGlow = pow(saturate(dot(viewDir, sunDir)), 32.0);
return (insc * skyTint + sunColor * sunGlow * 0.12 * horizon) * strength;
}

#endif
45 changes: 37 additions & 8 deletions res/gamedata/shaders/r5/bindless_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ Texture2D GetBindlessTexture(uint index)

struct MaterialData
{
uint diffuseIndex; // Descriptor heap index
uint normalIndex; // Descriptor heap index
uint detailIndex; // Descriptor heap index
uint pbrIndex; // Descriptor heap index
uint diffuseIndex;
uint normalIndex;
uint detailIndex;
uint pbrIndex;
float detailScale;
float alphaRef;
uint flags;
uint shaderVariant;
uint lmapIndex;
float emissiveIntensity;
uint _pad1;
uint _pad2;
};

// Material flags
#define MAT_FLAG_ALPHA_TEST (1 << 0)
#define MAT_FLAG_TWO_SIDED (1 << 1)
#define MAT_FLAG_EMISSIVE (1 << 2)
Expand All @@ -49,6 +52,33 @@ struct MaterialData
#define MAT_FLAG_HAS_PBR_LAYER (1 << 7)
#define MAT_FLAG_ALPHA_BLEND (1 << 8)
#define MAT_FLAG_WATER (1 << 9)
#define MAT_FLAG_FOLIAGE (1 << 10)
#define MAT_FLAG_STEEP_PARALLAX (1 << 11)
#define MAT_FLAG_HAS_LMAP (1 << 12)
#define MAT_FLAG_GLASS (1 << 13)
#define MAT_FLAG_SCOPE (1 << 14)
#define MAT_FLAG_HUD3D (1 << 15)
#define MAT_FLAG_WMARK (1 << 16)

float GlowTexelAlpha(float4 tex)
{
return saturate(tex.a);
}

float GlowTexelMask(float4 tex)
{
return GlowTexelAlpha(tex);
}

float ParticleTexelAlpha(float4 tex)
{
return saturate(tex.a);
}

float3 GlowEmissiveRgb(float4 tex, float intensity)
{
return tex.rgb * intensity * GlowTexelAlpha(tex);
}

// ═══════════════════════════════════════════════════════
// TERRAIN MATERIAL DATA (matches C++ TerrainMaterialData)
Expand Down Expand Up @@ -79,9 +109,8 @@ struct TerrainMaterialData
uint pbrB_Index; // PBR for mask.b channel
uint pbrA_Index; // PBR for mask.a channel

// Properties
float detailScale; // Uniform scale for all 4 detail layers
uint flags; // MAT_FLAG_TERRAIN, MAT_FLAG_HAS_PBR_LAYER
float detailScale;
uint flags;
};

// ═══════════════════════════════════════════════════════
Expand Down
Binary file modified res/gamedata/shaders/r5/bindless_forward.ps
Binary file not shown.
11 changes: 6 additions & 5 deletions res/gamedata/shaders/r5/bindless_forward.vs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct VS_OUTPUT
float3 normal : TEXCOORD2;
float3 tangent : TEXCOORD3;
float3 bitangent: TEXCOORD4;
nointerpolation uint materialID : TEXCOORD5; // Direct material ID (no indirection)
nointerpolation uint materialID : TEXCOORD5;
float hemi : TEXCOORD6;
float2 lmUV : TEXCOORD7;
};

// ═══════════════════════════════════════════════════════
Expand Down Expand Up @@ -91,7 +93,7 @@ VS_OUTPUT main(VS_INPUT input)
float4 worldPos = mul(worldMatrix, float4(input.position.xyz, 1.0));
output.worldPos = worldPos.xyz;
float3 clipPos = worldPos.xyz;
if (g_Materials[materialID].flags & MAT_FLAG_ALPHA_BLEND)
if ((instanceData.flags & 0x1) == 0 && (g_Materials[materialID].flags & MAT_FLAG_ALPHA_BLEND))
clipPos += (eye_position - clipPos) * 0.002;
output.position = mul(m_VP, float4(clipPos, 1.0));

Expand All @@ -101,11 +103,10 @@ VS_OUTPUT main(VS_INPUT input)
output.tangent = normalize(mul(worldMatrix3x3, tangentUnpacked));
output.bitangent = normalize(mul(worldMatrix3x3, binormalUnpacked));

// UVs are pre-unpacked in UnifiedVertex format - pass through directly
output.texcoord = input.texcoord;

// Pass material ID to pixel shader
output.lmUV = input.texcoord1;
output.materialID = materialID;
output.hemi = input.normal.a;

return output;
}
Binary file added res/gamedata/shaders/r5/bindless_lightplanes.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_particle.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_particle_distort.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_skinned.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_skinned_hud.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_skinned_mdi.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_terrain.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_wallmark.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/r5/bindless_wallmark_mult.ps
Binary file not shown.
Binary file added res/gamedata/shaders/r5/bindless_wallmark_set.ps
Binary file not shown.
38 changes: 38 additions & 0 deletions res/gamedata/shaders/r5/bloom_blur.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cbuffer BloomParams : register(b5)
{
float2 g_SrcSize;
float2 g_DstSize;
float g_Threshold;
float g_Intensity;
float2 g_Dir;
};

Texture2D<float4> t_In : register(t0);
RWTexture2D<float4> u_Out : register(u0);

[numthreads(8, 8, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
uint2 pixel = id.xy;
if (pixel.x >= (uint)g_DstSize.x || pixel.y >= (uint)g_DstSize.y)
return;

const float w[8] = {
0.1346, 0.1273, 0.1078, 0.0816,
0.0553, 0.0335, 0.0182, 0.0088
};

float step = max(g_Intensity, 0.5);
int2 maxP = int2(g_DstSize) - 1;
float4 c = t_In.Load(int3(pixel, 0)) * w[0];
[unroll]
for (int i = 1; i < 8; ++i) {
int2 o = int2(g_Dir * (float(i) * step) + 0.5);
o = max(o, int2(g_Dir));
int2 p0 = clamp(int2(pixel) + o, int2(0, 0), maxP);
int2 p1 = clamp(int2(pixel) - o, int2(0, 0), maxP);
c += t_In.Load(int3(p0, 0)) * w[i];
c += t_In.Load(int3(p1, 0)) * w[i];
}
u_Out[pixel] = c;
}
84 changes: 84 additions & 0 deletions res/gamedata/shaders/r5/bloom_extract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cbuffer BloomParams : register(b5)
{
float2 g_SrcSize;
float2 g_DstSize;
float g_Threshold;
float g_Intensity;
float2 g_Pad;
};

Texture2D<float4> t_Hdr : register(t0);
Texture2D<float> t_exposure : register(t1);
Texture2D<float> t_depth : register(t2);
Texture2D<float4> t_WorldPos : register(t3);
RWTexture2D<float4> u_Bloom : register(u0);

#include "shared/surface_marks.h"

float3 HighTap(float3 rgb, float depth, float scale)
{
float3 lin = rgb * scale;
float defHdr = 9.0;
if (depth <= 1e-7)
{
lin *= 2.0;
defHdr = 3.0;
}
return lin / defHdr;
}

[numthreads(8, 8, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
uint2 dst = id.xy;
if (dst.x >= (uint)g_DstSize.x || dst.y >= (uint)g_DstSize.y)
return;

int2 src = int2((float2(dst) + 0.5) * g_SrcSize / g_DstSize);
int2 maxS = int2(g_SrcSize) - 1;

uint dw, dh;
t_depth.GetDimensions(dw, dh);
float2 depthScale = float2(dw, dh) / max(g_SrcSize, float2(1.0, 1.0));

float scale = t_exposure.Load(int3(0, 0, 0));
scale = clamp(scale, 1.0 / 128.0, 20.0);

int2 o0 = clamp(src + int2(-1, -1), int2(0, 0), maxS);
int2 o1 = clamp(src + int2( 1, -1), int2(0, 0), maxS);
int2 o2 = clamp(src + int2(-1, 1), int2(0, 0), maxS);
int2 o3 = clamp(src + int2( 1, 1), int2(0, 0), maxS);

float3 c0 = t_Hdr.Load(int3(o0, 0)).rgb;
float3 c1 = t_Hdr.Load(int3(o1, 0)).rgb;
float3 c2 = t_Hdr.Load(int3(o2, 0)).rgb;
float3 c3 = t_Hdr.Load(int3(o3, 0)).rgb;

int2 d0 = clamp(int2(float2(o0) * depthScale), int2(0, 0), int2(dw, dh) - 1);
int2 d1 = clamp(int2(float2(o1) * depthScale), int2(0, 0), int2(dw, dh) - 1);
int2 d2 = clamp(int2(float2(o2) * depthScale), int2(0, 0), int2(dw, dh) - 1);
int2 d3 = clamp(int2(float2(o3) * depthScale), int2(0, 0), int2(dw, dh) - 1);

uint ww, wh;
t_WorldPos.GetDimensions(ww, wh);
float2 wpScale = float2(ww, wh) / max(g_SrcSize, float2(1.0, 1.0));
int2 w0 = clamp(int2(float2(o0) * wpScale), int2(0, 0), int2(ww, wh) - 1);
int2 w1 = clamp(int2(float2(o1) * wpScale), int2(0, 0), int2(ww, wh) - 1);
int2 w2 = clamp(int2(float2(o2) * wpScale), int2(0, 0), int2(ww, wh) - 1);
int2 w3 = clamp(int2(float2(o3) * wpScale), int2(0, 0), int2(ww, wh) - 1);
float hud0 = IsHudSurfMark(t_WorldPos.Load(int3(w0, 0)).w) ? 0.0 : 1.0;
float hud1 = IsHudSurfMark(t_WorldPos.Load(int3(w1, 0)).w) ? 0.0 : 1.0;
float hud2 = IsHudSurfMark(t_WorldPos.Load(int3(w2, 0)).w) ? 0.0 : 1.0;
float hud3 = IsHudSurfMark(t_WorldPos.Load(int3(w3, 0)).w) ? 0.0 : 1.0;
float hudW = hud0 + hud1 + hud2 + hud3;

float3 s0 = HighTap(c0, t_depth.Load(int3(d0, 0)), scale) * hud0;
float3 s1 = HighTap(c1, t_depth.Load(int3(d1, 0)), scale) * hud1;
float3 s2 = HighTap(c2, t_depth.Load(int3(d2, 0)), scale) * hud2;
float3 s3 = HighTap(c3, t_depth.Load(int3(d3, 0)), scale) * hud3;

float3 avg = (hudW > 0.5) ? ((s0 + s1) + (s2 + s3)) * (2.0 / hudW) : 0.0;
float hi = max(dot(avg, float3(1.0, 1.0, 1.0)) - g_Threshold, 0.0);
hi *= max(g_Intensity, 0.5);
u_Bloom[dst] = float4(avg, hi);
}
Binary file added res/gamedata/shaders/r5/clouds.ps
Binary file not shown.
30 changes: 30 additions & 0 deletions res/gamedata/shaders/r5/clouds.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "shared/common.h"
#include "shared/cloudconfig.h"

struct VS_INPUT
{
float3 p : POSITION;
float4 dir : COLOR0;
float4 color : COLOR1;
};

struct VS_OUTPUT
{
float4 hpos : SV_Position;
float4 color : COLOR0;
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
};

VS_OUTPUT main(VS_INPUT v)
{
VS_OUTPUT o;
o.hpos = mul(m_WVP, float4(v.p, 1.0));
float2 d0 = v.dir.xy * 2.0 - 1.0;
float2 d1 = v.dir.wz * 2.0 - 1.0;
o.tc0 = v.p.xz * CLOUD_TILE0 + d0 * timers.z * CLOUD_SPEED0;
o.tc1 = v.p.xz * CLOUD_TILE1 + d1 * timers.z * CLOUD_SPEED1;
o.color = v.color;
o.color.w *= pow(max(v.p.y, 0.0), 25.0);
return o;
}
Loading
Loading