Skip to content
Merged
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
14 changes: 13 additions & 1 deletion NewVegasReloaded/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ extern "C" {

static void MessageHandler(NVSEMessagingInterface::Message* msg) {
switch (msg->type) {
case NVSEMessagingInterface::kMessage_PostLoad:
if (!GetModuleHandle(L"LODFlickerFix.dll")) {
MessageBox(NULL, L"LOD Flicker Fix not found.\nNew Vegas Reloaded cannot be used without it, please install it.", L"New Vegas Reloaded", MB_OK | MB_ICONERROR);
ExitProcess(0);
}

if (!GetModuleHandle(L"VanillaPlusTerrain.dll")) {
MessageBox(NULL, L"Vanilla Plus Terrain not found.\nNew Vegas Reloaded cannot be used without it, please install it.", L"New Vegas Reloaded", MB_OK | MB_ICONERROR);
ExitProcess(0);
}

break;
case NVSEMessagingInterface::kMessage_PreLoadGame:
TheSettingManager->GameLoading = true;
break;
Expand Down Expand Up @@ -52,7 +64,7 @@ extern "C" {

Info->InfoVersion = PluginInfo::kInfoVersion;
Info->Name = "NewVegasReloaded";
Info->Version = 421;
Info->Version = 430;
return true;

}
Expand Down
10 changes: 5 additions & 5 deletions NewVegasReloaded/NewVegasReloaded.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,2,1,0
PRODUCTVERSION 4,2,1,0
FILEVERSION 4,3,0,0
PRODUCTVERSION 4,3,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "New Vegas Reloaded"
VALUE "FileVersion", "4.2.1"
VALUE "FileVersion", "4.3.0"
VALUE "InternalName", "NewVegasReloaded.dll"
VALUE "LegalCopyright", "Copyright (C) 2024"
VALUE "LegalCopyright", "Copyright (C) 2025"
VALUE "OriginalFilename", "NewVegasReloaded.dll"
VALUE "ProductName", "New Vegas Reloaded"
VALUE "ProductVersion", "4.2.1"
VALUE "ProductVersion", "4.3.0"
END
END
BLOCK "VarFileInfo"
Expand Down
10 changes: 5 additions & 5 deletions resource/NewVegasReloaded.dll.defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,13 @@ Enabled = true # Volumetric fog shader tinted by the sun. R

[_Shaders.Water.Default]
causticsStrength = 3.0 # Caustic strength underwater. Caustics seen from above water not currently supported
causticsStrengthS = 0.2 # Not used.
causticsStrengthS = 0.2 # Godrays intensity underwater.
choppiness = 0.7 # Exponent for the waves normals. A higher value will create more defined wave crests.
depthDarkness = 1.0 # How much light reaches the bottom of the water.
inExtCoeff_B = 1.0 # Not used.
inExtCoeff_G = 1.0 # Not used.
inExtCoeff_R = 1.0 # Not used.
inScattCoeff = 1.0 # Not used.
inExtCoeff_B = 1.0 # Underwater fog color tint (blue component).
inExtCoeff_G = 1.0 # Underwater fog color tint (green component).
inExtCoeff_R = 1.0 # Underwater fog color tint (red component).
inScattCoeff = 1.0 # Underwater scattering modifier, higher values lead to less brightness.
reflectivity = 1.0 # Multiplier for the strength of reflections on the surface.
shoreFactor = 6.0 # Size of the shore fading area on shallow slope areas.
shoreMovement = 0.3 # Speed of wave movement in the shore.
Expand Down
4 changes: 0 additions & 4 deletions src/core/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ void RenderManager::Initialize() {
Logger::Log("ERROR: Cannot initialize the render manager. Graphics device not supported.");
if (TheSettingManager->SettingsMain.Main.AnisotropicFilter >= 2) device->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, TheSettingManager->SettingsMain.Main.AnisotropicFilter);
BackBuffer = CreateHDRRenderTarget();

ILS = GetModuleHandle(L"ImprovedLightingShaders.dll");
if (ILS)
Logger::Log("ILS detected.");
}

void RenderManager::ResolveDepthBuffer(IDirect3DTexture9* Buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ ShaderCollection* ShaderManager::GetShaderCollection(const char* Name) {
if (!memcmp(Name, "PAR", 3)) return Shaders.POM;
//if (!memcmp(Name, "SKIN", 4)) return Shaders.Skin; // temporarily disabled, the shaders are half broken
if (!memcmp(Name, "SKY", 3)) return Shaders.Sky;
if (strstr(TerrainShadersNames, Name)) return Shaders.Terrain;
if (strstr(BloodShaders, Name)) return Shaders.Blood;

if (Shaders.PBR->GetTemplate(Name).Name != NULL) return Shaders.PBR;
if (Shaders.Terrain->GetTemplate(Name).Name != NULL) return Shaders.Terrain;

return NULL;
}
Expand Down
80 changes: 46 additions & 34 deletions src/core/ShaderRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,33 @@ bool ShaderProgram::FileExists(const char* path) {
bool ShaderProgram::CheckPreprocessResult(const char* CachedPreprocessPath, ID3DXBuffer* ShaderSource) {
void* CurrentContent = ShaderSource->GetBufferPointer();

ID3DXBuffer* CachedSource;
void* CachedContent;
ID3DXBuffer* CachedSource = nullptr;
void* CachedContent = nullptr;

std::ifstream File(CachedPreprocessPath, std::ios::in | std::ios::ate);
if (File.is_open()) {
std::streamoff Size = File.tellg();
D3DXCreateBuffer(Size, &CachedSource);
File.seekg(0, std::ios::beg);
CachedContent = CachedSource->GetBufferPointer();
File.read((char*)CachedContent, Size);
File.close();
if (Size > 0 && SUCCEEDED(D3DXCreateBuffer(Size, &CachedSource))) {
File.seekg(0, std::ios::beg);
CachedContent = CachedSource->GetBufferPointer();
File.read((char*)CachedContent, Size);
File.close();
}
else {
File.close();
return false;
}
}
else {
return false;
}

bool match;
bool match = false;

if (!CachedContent) {
match = false;
}
else if (ShaderSource->GetBufferSize() != CachedSource->GetBufferSize()) {
match = false;
}
else {
match = !memcmp(CurrentContent, CachedContent, ShaderSource->GetBufferSize());
if (CachedContent && CachedSource) {
if (ShaderSource->GetBufferSize() == CachedSource->GetBufferSize()) {
match = !memcmp(CurrentContent, CachedContent, ShaderSource->GetBufferSize());
}
}

if (CachedSource) CachedSource->Release();
Expand Down Expand Up @@ -132,21 +133,15 @@ ShaderRecord* ShaderRecord::LoadShader(const char* Name, const char* SubPath, Sh
strcat(ShaderCompiledPath, Name);

D3DXMACRO* Macros = &(Template.Defines[0]);
if (TheRenderManager->ILS || TheRenderManager->IsReversedDepth()) {
if (TheRenderManager->IsReversedDepth()) {
int i = 0;
bool nullFound = false;
while (!nullFound && i < 28) {
nullFound = Template.Defines[i].Name == NULL;
if (!nullFound) i++;
}
if (TheRenderManager->ILS) {
Template.Defines[i] = { "ILS", "" };
i++;
}
if (TheRenderManager->IsReversedDepth()) {
Template.Defines[i] = { "REVERSED_DEPTH", "" };
i++;
}
Template.Defines[i] = { "REVERSED_DEPTH", "" };
Template.Defines[i + 1] = { NULL, NULL }; // Ensure null termination
}

HRESULT prepass = D3DXPreprocessShaderFromFileA(ShaderSourcePath, Macros, NULL, &ShaderSource, &Errors);
Expand All @@ -162,11 +157,16 @@ ShaderRecord* ShaderRecord::LoadShader(const char* Name, const char* SubPath, Sh
std::ifstream FileBinary(ShaderCompiledPath, std::ios::in | std::ios::binary | std::ios::ate);
if (FileBinary.is_open()) {
std::streamoff Size = FileBinary.tellg();
D3DXCreateBuffer(Size, &Shader);
FileBinary.seekg(0, std::ios::beg);
Function = Shader->GetBufferPointer();
FileBinary.read((char*)Function, Size);
FileBinary.close();
if (Size > 0 && SUCCEEDED(D3DXCreateBuffer(Size, &Shader))) {
FileBinary.seekg(0, std::ios::beg);
Function = Shader->GetBufferPointer();
FileBinary.read((char*)Function, Size);
FileBinary.close();
}
else {
FileBinary.close();
Logger::Log("ERROR: Failed to create buffer for shader binary %s", ShaderCompiledPath);
}
}
else {
Logger::Log("ERROR: Shader binary %s not found.", ShaderCompiledPath);
Expand Down Expand Up @@ -222,16 +222,26 @@ ShaderRecord* ShaderRecord::LoadShader(const char* Name, const char* SubPath, Sh
Logger::Log("Issues getting constants descriptions for %s", Name);
}
else if (Shader) {
HRESULT createResult = E_FAIL;
if (ShaderProfile[0] == 'v') {
ShaderProg = new ShaderRecordVertex(Name);
TheRenderManager->device->CreateVertexShader((const DWORD*)Function, &((ShaderRecordVertex*)ShaderProg)->ShaderHandle);
createResult = TheRenderManager->device->CreateVertexShader((const DWORD*)Function, &((ShaderRecordVertex*)ShaderProg)->ShaderHandle);
}
else {
ShaderProg = new ShaderRecordPixel(Name);
TheRenderManager->device->CreatePixelShader((const DWORD*)Function, &((ShaderRecordPixel*)ShaderProg)->ShaderHandle);
createResult = TheRenderManager->device->CreatePixelShader((const DWORD*)Function, &((ShaderRecordPixel*)ShaderProg)->ShaderHandle);
}

if (SUCCEEDED(createResult)) {
ShaderProg->CreateCT(ShaderSource, ConstantTable);
Logger::Log("Shader loaded: %s", ShaderCompiledPath);
}
else {
Logger::Log("ERROR: Failed to create DirectX shader for %s", Name);
ReportError(createResult);
delete ShaderProg;
ShaderProg = nullptr;
}
ShaderProg->CreateCT(ShaderSource, ConstantTable);
Logger::Log("Shader loaded: %s", ShaderCompiledPath);
}
}
}
Expand Down Expand Up @@ -571,6 +581,7 @@ ShaderRecordVertex::ShaderRecordVertex(const char* shaderName) {

Name = shaderName;
ShaderHandle = NULL;
ClearSamplers = false;

}

Expand All @@ -583,6 +594,7 @@ ShaderRecordVertex::~ShaderRecordVertex() {
ShaderRecordPixel::ShaderRecordPixel(const char* shaderName) {
Name = shaderName;
ShaderHandle = NULL;
ClearSamplers = true;

}

Expand Down
32 changes: 25 additions & 7 deletions src/effects/Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,37 @@ class TerrainShaders : public ShaderCollection
return std::map<std::string_view, ShaderTemplate>{
{ "SLS2100.vso", ShaderTemplate{ "TerrainTemplate", {{"VS", ""}} } },
{ "SLS2092.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "1"}}} },
{ "SLS2096.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "1"}, {"POINTLIGHT", ""}}} },
{ "SLS2094.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "1"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2096.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "1"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2098.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "1"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2100.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "2"}}} },
{ "SLS2104.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "2"}, {"POINTLIGHT", ""}}} },
{ "SLS2102.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "2"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2104.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "2"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2106.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "2"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2108.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "3"}}} },
{ "SLS2112.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "3"}, {"POINTLIGHT", ""}}} },
{ "SLS2110.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "3"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2112.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "3"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2114.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "3"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2116.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "4"}}} },
{ "SLS2120.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "4"}, {"POINTLIGHT", ""}}} },
{ "SLS2118.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "4"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2120.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "4"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2122.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "4"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2124.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "5"}}} },
{ "SLS2128.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "5"}, {"POINTLIGHT", ""}}} },
{ "SLS2126.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "5"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2128.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "5"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2130.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "5"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2132.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "6"}}} },
{ "SLS2136.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "6"}, {"POINTLIGHT", ""}}} },
{ "SLS2134.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "6"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2136.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "6"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2138.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "6"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2140.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "7"}}} },
{ "SLS2144.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "7"}, {"POINTLIGHT", ""}}} }
{ "SLS2142.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "7"}, {"NUM_PT_LIGHTS", "6"}}} },
{ "SLS2144.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "7"}, {"NUM_PT_LIGHTS", "12"}}} },
{ "SLS2146.pso", ShaderTemplate{"TerrainTemplate", {{"PS", ""}, {"TEX_COUNT", "7"}, {"NUM_PT_LIGHTS", "24"}}} },
{ "SLS2002.vso", ShaderTemplate{"TerrainLODTemplate", {{"VS", ""}}} },
{ "SLS2003.pso", ShaderTemplate{"TerrainLODTemplate", {{"PS", ""}}} },
{ "SLS2080.vso", ShaderTemplate{"TerrainFadeTemplate", {{"VS", ""}}} },
{ "SLS2082.pso", ShaderTemplate{"TerrainFadeTemplate", {{"PS", ""}}} },
};
};

Expand Down
43 changes: 16 additions & 27 deletions src/hlsl/NewVegas/Effects/CombineDepth.fx.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ float4 TESR_CameraData;

float4x4 TESR_InvProjectionTransform;

sampler2D TESR_DepthBufferWorld : register(s0) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };
sampler2D TESR_DepthBufferViewModel : register(s1) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; };
sampler2D TESR_DepthBufferWorld : register(s0) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = POINT; MINFILTER = POINT; MIPFILTER = NONE; };
sampler2D TESR_DepthBufferViewModel : register(s1) = sampler_state { ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = POINT; MINFILTER = POINT; MIPFILTER = NONE; };

static const float viewModelNearZ = TESR_DepthConstants.x;
static const float invertedDepth = TESR_DepthConstants.z;
static const float nearZ = TESR_CameraData.x;
static const float farZ = TESR_CameraData.y;
Expand All @@ -30,41 +31,29 @@ VSOUT FrameVS(VSIN IN)
return OUT;
}

// linearize depth
float readDepth(float depth, float nearZ, float farZ)
{
float Q = farZ/(farZ - nearZ);
float ViewZ = (-nearZ *Q) / (depth - Q);
return ViewZ;
// Convert depth to view space Z.
float ToVS(float depth, float nearZ, float farZ) {
return nearZ * farZ / (nearZ + depth * (farZ - nearZ));
}

// convert back to usual depth buffer format for easier reconstruction
float packDepth(float viewZ, float nearZ, float farZ){
float Q = farZ/(farZ - nearZ);
return (Q* (viewZ - nearZ ))/ viewZ;
// Convert view space Z to depth.
float ToPS(float viewZ, float nearZ, float farZ){
return nearZ * (farZ - viewZ) / (viewZ * (farZ - nearZ));
}


float4 CombineDepth(VSOUT IN) : COLOR0
{

float4 CombineDepth(VSOUT IN) : COLOR0 {
float worldDepth = tex2D(TESR_DepthBufferWorld, IN.UVCoord).x;
float viewModelDepth = tex2D(TESR_DepthBufferViewModel, IN.UVCoord).x;

float combinedDepth = min(worldDepth, viewModelDepth);
if (invertedDepth){
combinedDepth = max(worldDepth, viewModelDepth);
}

float x = IN.UVCoord.x * 2 - 1;
float y = (1 - IN.UVCoord.y) * 2 - 1;
float4 clipSpace = float4(x, y, combinedDepth, 1.0f);

float4 viewSpace = mul(clipSpace, TESR_InvProjectionTransform);
float worldViewZ = ToVS(worldDepth, nearZ, farZ);
float viewModelViewZ = ToVS(viewModelDepth, viewModelNearZ, farZ);

viewSpace /= viewSpace.w;
float combinedViewZ = worldViewZ;
if (viewModelDepth > 0.0)
combinedViewZ = viewModelViewZ;

return float4(viewSpace.z / farZ, combinedDepth, 1.0, 1.0); // scale values back to 0 - 1 to avoid overflow
return float4(combinedViewZ / farZ, ToPS(combinedViewZ, nearZ, farZ), 1.0, 1.0);
}

technique
Expand Down
2 changes: 1 addition & 1 deletion src/hlsl/NewVegas/Effects/VolumetricFog.fx.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ float4 VolumetricFog(VSOUT IN) : COLOR0
float3 heightFog = mixHeightFog(finalColor.rgb, heightFogColor.rgb, extinction, inScattering, fogDepth, strength * HeightFogDensity, 1.5 / (fogPower * HeightFogFalloff), worldPos, HeightFogHeight);
finalColor = lerp(finalColor, float4(heightFog, 1), saturate(HeightFogBlend));

finalColor = lerp(color, finalColor, FogAmount);
finalColor = max(lerp(color, finalColor, FogAmount), 0.0f);

return delinearize(finalColor);
}
Expand Down
Loading
Loading