Skip to content

Commit

Permalink
Merge pull request #238 from doodlum/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Mar 30, 2024
2 parents 72b2adf + d87ae9c commit 20c72e0
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 198 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21)

project(
CommunityShaders
VERSION 0.8.0
VERSION 0.8.7
LANGUAGES CXX
)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne

float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level);
specularIrradiance = sRGB2Lin(specularIrradiance);

diffuseColor = sRGB2Lin(diffuseColor) * 0.5;

specularIrradiance = lerp(specularIrradiance, diffuseColor, saturate(distance / 1000.0));
diffuseColor = sRGB2Lin(diffuseColor);

float2 specularBRDF = EnvBRDFApprox(roughness, NoV);

Expand All @@ -53,16 +50,13 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne
return specularIrradiance * ((F0 + S) * specularBRDF.x + specularBRDF.y);
}

float3 GetDynamicCubemapFresnel(float2 uv, float3 N, float3 VN, float3 V, float roughness, float level, float distance)
float3 GetDynamicCubemapFresnel(float2 uv, float3 N, float3 VN, float3 V, float roughness, float level, float3 diffuseColor, float distance)
{
float NoV = saturate(dot(N, V));
float2 specularBRDF = EnvBRDFApprox(roughness, NoV);
if (specularBRDF.y > 0.001) {
float3 R = reflect(-V, N);

float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level);
specularIrradiance = sRGB2Lin(specularIrradiance);
specularIrradiance = specularIrradiance * (1.0 - saturate(distance / 1000.0));

// Horizon specular occlusion
// https://marmosetco.tumblr.com/post/81245981087
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ float3 Lin2sRGB(float3 color)
#if defined(REFLECTIONS)
color.rgb = lerp(color.rgb, sRGB2Lin(ReflectionsTexture.SampleLevel(LinearSampler, uv, 0)), saturate(mipLevel * (1.0 / 10.0)));
#else
color.rgb = lerp(color.rgb, color.rgb * sRGB2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0)) * 10.0, saturate(mipLevel * (1.0 / 10.0)));
color.rgb = lerp(color.rgb, color.rgb * sRGB2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0).x) * 10.0, saturate(mipLevel * (1.0 / 10.0)));
#endif

color.rgb = Lin2sRGB(color.rgb);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Info]
Version = 1-0-0
Version = 1-0-3
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Info]
Version = 1-0-0
Version = 1-0-1
36 changes: 13 additions & 23 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
complexMaterial = complexMaterial && complexMaterialColor.y > (4.0 / 255.0) && (complexMaterialColor.y < (1.0 - (4.0 / 255.0)));
shininess = lerp(shininess, shininess * complexMaterialColor.y, complexMaterial);
float3 complexSpecular = lerp(1.0, lerp(1.0, baseColor.xyz, complexMaterialColor.z), complexMaterial);
baseColor.xyz = lerp(baseColor.xyz, lerp(baseColor.xyz, 0.0, complexMaterialColor.z), complexMaterial);
# endif // defined (CPM_AVAILABLE) && defined(ENVMAP)

# if defined(FACEGEN)
Expand Down Expand Up @@ -1372,7 +1373,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif // LOD_LAND_BLEND

# if defined(SNOW)
useSnowSpecular = landSnowMask > 0;
useSnowSpecular = landSnowMask != 0.0;
# endif // SNOW
# endif // LANDSCAPE

Expand Down Expand Up @@ -1444,15 +1445,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
normal.xyz = texProjTmp2.xxx * (finalProjNormal - normal.xyz) + normal.xyz;
baseColor.xyz = texProjTmp2.xxx * (projDiffuse * ProjectedUVParams2.xyz - baseColor.xyz) + baseColor.xyz;

useSnowDecalSpecular = true;
# if defined(SNOW)
useSnowDecalSpecular = true;
psout.SnowParameters.y = GetSnowParameterY(texProjTmp2, baseColor.w);
# endif // SNOW
} else {
if (texProjTmp > 0) {
baseColor.xyz = ProjectedUVParams2.xyz;
useSnowDecalSpecular = true;
# if defined(SNOW)
useSnowDecalSpecular = true;
psout.SnowParameters.y = GetSnowParameterY(texProjTmp, baseColor.w);
# endif // SNOW
} else {
Expand Down Expand Up @@ -1704,7 +1705,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
if (shaderDescriptors[0].PixelShaderDescriptor & _DefShadow) {
if (lightIndex < numShadowLights) {
lightColor *= shadowColor[ShadowLightMaskSelect[lightIndex]];
;
}
}

Expand Down Expand Up @@ -1821,15 +1821,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif

# if defined(RIM_LIGHTING)
lightDiffuseColor += nsLightColor * GetRimLightMultiplier(normalizedLightDirection, viewDirection, worldSpaceNormal.xyz) * rimSoftLightColor.xyz;
lightDiffuseColor += nsLightColor * GetRimLightMultiplier(normalizedLightDirection, worldSpaceViewDirection, worldSpaceNormal.xyz) * rimSoftLightColor.xyz;
# endif

# if defined(BACK_LIGHTING)
lightDiffuseColor += (saturate(-lightAngle) * backLightColor.xyz) * nsLightColor;
# endif

# if defined(SPECULAR) || (defined(SPARKLE) && !defined(SNOW))
lightsSpecularColor += GetLightSpecularInput(input, normalizedLightDirection, viewDirection, worldSpaceNormal.xyz, lightColor, shininess, uv);
lightsSpecularColor += GetLightSpecularInput(input, normalizedLightDirection, worldSpaceViewDirection, worldSpaceNormal.xyz, lightColor, shininess, uv);
# endif

lightsDiffuseColor += lightDiffuseColor;
Expand Down Expand Up @@ -1914,6 +1914,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
if (dynamicCubemap) {
# if defined(CPM_AVAILABLE)
envRoughness = lerp(envRoughness, 1.0 - complexMaterialColor.y, (float)complexMaterial);
envRoughness *= envRoughness;
F0 = lerp(F0, sRGB2Lin(complexSpecular), (float)complexMaterial);
# endif

Expand Down Expand Up @@ -1965,13 +1966,19 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif // MULTI_LAYER_PARALLAX

# if defined(SPECULAR)
# if defined(CPM_AVAILABLE) && defined(ENVMAP)
specularColor = (specularColor * glossiness * MaterialData.yyy) * lerp(SpecularColor.xyz, complexSpecular, complexMaterial);
# else
specularColor = (specularColor * glossiness * MaterialData.yyy) * SpecularColor.xyz;
# endif
# elif defined(SPARKLE)
specularColor *= glossiness;
# endif // SPECULAR

# if defined(SNOW)
if (useSnowSpecular)
specularColor = 0;
# endif

# if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE))
# if defined(DYNAMIC_CUBEMAPS)
Expand Down Expand Up @@ -2003,30 +2010,14 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
color.xyz = tmpColor.xyz + ColourOutputClamp.xxx;
color.xyz = min(vertexColor.xyz, color.xyz);

# if defined(CPM_AVAILABLE) && defined(ENVMAP)
color.xyz += specularColor * complexSpecular;
# else
color.xyz += specularColor;
# endif // defined (CPM_AVAILABLE) && defined(ENVMAP)

color.xyz = sRGB2Lin(color.xyz);

# if defined(WETNESS_EFFECTS)
color.xyz += wetnessSpecular * wetnessGlossinessSpecular;
# endif

# if defined(DYNAMIC_CUBEMAPS)
# if defined(EYE)
color.xyz += GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 0.5, 2, viewPosition.z) * input.Color.xyz * envMask;
# elif defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX)
color.xyz += GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 0.5 - (saturate(envMask) * 0.5), 2 - saturate(envMask), viewPosition.z) * (1.0 - ((float)dynamicCubemap * saturate(envMask))) * input.Color.xyz;
# elif defined(HAIR)
color.xyz += GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 0.5, 2, viewPosition.z);
# else
color.xyz += GetDynamicCubemapFresnel(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 0.5, 2, viewPosition.z) * input.Color.xyz;
# endif
# endif

# if defined(EYE)
color.xyz *= saturate(normalize(input.EyeNormal2.xyz).y); // Occlusion
# endif
Expand Down Expand Up @@ -2131,7 +2122,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
tmp = saturate(tmp1 * tmp2);
tmp *= tmp * (3 + -2 * tmp);
psout.ScreenSpaceNormals.w = tmp * SSRParams.w;
psout.ScreenSpaceNormals.w = 0.0;

# if defined(WATER_BLENDING)
if (perPassWaterBlending[0].EnableWaterBlendingSSR) {
Expand Down
20 changes: 6 additions & 14 deletions src/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Features/WaterCaustics.h"
#include "Features/WaterParallax.h"
#include "Features/WetnessEffects.h"
#include "State.h"

void Feature::Load(json&)
{
Expand Down Expand Up @@ -118,18 +119,9 @@ const std::vector<Feature*>& Feature::GetFeatureList()
SubsurfaceScattering::GetSingleton()
};

static std::vector<Feature*> featuresVR = {
DynamicCubemaps::GetSingleton(),
GrassLighting::GetSingleton(),
GrassCollision::GetSingleton(),
ScreenSpaceShadows::GetSingleton(),
ExtendedMaterials::GetSingleton(),
WetnessEffects::GetSingleton(),
LightLimitFix::GetSingleton(),
TerrainBlending::GetSingleton(),
WaterCaustics::GetSingleton(),
SubsurfaceScattering::GetSingleton()
};

return REL::Module::IsVR() ? featuresVR : features;
static std::vector<Feature*> featuresVR(features);
std::erase_if(featuresVR, [](Feature* a) {
return !a->SupportsVR();
});
return (REL::Module::IsVR() && !State::GetSingleton()->IsDeveloperMode()) ? featuresVR : features;
}
7 changes: 6 additions & 1 deletion src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ struct Feature
virtual std::string_view GetShaderDefineName() { return ""; }

virtual bool HasShaderDefine(RE::BSShader::Type) { return false; }
/**
* Whether the feature supports VR.
*
* \return true if VR supported; else false
*/
virtual bool SupportsVR() { return false; }

virtual void SetupResources() = 0;
virtual void Reset() = 0;
Expand All @@ -32,6 +38,5 @@ struct Feature
virtual void WriteDiskCacheInfo(CSimpleIniA& a_ini);
virtual void ClearShaderCache() {}

// Cat: add all the features in here
static const std::vector<Feature*>& GetFeatureList();
};
8 changes: 4 additions & 4 deletions src/Features/DynamicCubemaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,6 @@ void DynamicCubemaps::SetupResources()
envCaptureRawTexture->CreateSRV(srvDesc);
envCaptureRawTexture->CreateUAV(uavDesc);

envInferredTexture = new Texture2D(texDesc);
envInferredTexture->CreateSRV(srvDesc);
envInferredTexture->CreateUAV(uavDesc);

envCapturePositionTexture = new Texture2D(texDesc);
envCapturePositionTexture->CreateSRV(srvDesc);
envCapturePositionTexture->CreateUAV(uavDesc);
Expand All @@ -496,6 +492,10 @@ void DynamicCubemaps::SetupResources()
envTexture->CreateSRV(srvDesc);
envTexture->CreateUAV(uavDesc);

envInferredTexture = new Texture2D(texDesc);
envInferredTexture->CreateSRV(srvDesc);
envInferredTexture->CreateUAV(uavDesc);

updateCubemapCB = new ConstantBuffer(ConstantBufferDesc<UpdateCubemapCB>());
}

Expand Down
2 changes: 2 additions & 0 deletions src/Features/DynamicCubemaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ struct DynamicCubemaps : Feature
void UpdateCubemapCapture();

virtual void DrawDeferred();

bool SupportsVR() override { return true; };
};
2 changes: 2 additions & 0 deletions src/Features/ExtendedMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ struct ExtendedMaterials : Feature
virtual void Save(json& o_json);

virtual void RestoreDefaultSettings();

bool SupportsVR() override { return true; };
};
2 changes: 2 additions & 0 deletions src/Features/GrassCollision.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ struct GrassCollision : Feature
virtual void Save(json& o_json);

virtual void RestoreDefaultSettings();

bool SupportsVR() override { return true; };
};
2 changes: 2 additions & 0 deletions src/Features/GrassLighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ struct GrassLighting : Feature
virtual void Save(json& o_json);

virtual void RestoreDefaultSettings();

bool SupportsVR() override { return true; };
};
39 changes: 18 additions & 21 deletions src/Features/LightLimitFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
EnableParticleLightsDetection,
ParticleLightsSaturation,
EnableParticleLightsOptimization,
ParticleLightsOptimisationClusterRadius)
ParticleLightsOptimisationClusterRadius,
ParticleBrightness,
ParticleRadius,
BillboardBrightness,
BillboardRadius)

void LightLimitFix::DrawSettings()
{
Expand Down Expand Up @@ -54,11 +58,15 @@ void LightLimitFix::DrawSettings()
ImGui::Spacing();
ImGui::Spacing();

ImGui::TextWrapped("Particle Lights Color");
ImGui::TextWrapped("Particle Lights Customisation");
ImGui::SliderFloat("Saturation", &settings.ParticleLightsSaturation, 1.0, 2.0, "%.2f");
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Particle light saturation.");
}
ImGui::SliderFloat("Particle Brightness", &settings.ParticleBrightness, 0.0, 10.0, "%.2f");
ImGui::SliderFloat("Particle Radius", &settings.ParticleRadius, 0.0, 10.0, "%.2f");
ImGui::SliderFloat("Billboard Brightness", &settings.BillboardBrightness, 0.0, 10.0, "%.2f");
ImGui::SliderFloat("Billboard Radius", &settings.BillboardRadius, 0.0, 10.0, "%.2f");

ImGui::Spacing();
ImGui::Spacing();
Expand Down Expand Up @@ -550,8 +558,6 @@ bool LightLimitFix::AddParticleLight(RE::BSRenderPass* a_pass, LightLimitFix::Co
color.blue *= emittance->blue;
}

float radius = 0;

if (auto rendererData = a_pass->geometry->GetGeometryRuntimeData().rendererData) {
if (auto triShape = a_pass->geometry->AsTriShape()) {
uint32_t vertexSize = rendererData->vertexDesc.GetSize();
Expand Down Expand Up @@ -585,15 +591,6 @@ bool LightLimitFix::AddParticleLight(RE::BSRenderPass* a_pass, LightLimitFix::Co
color.alpha *= vertexColor->data[3] / 255.f;
}
}

uint32_t offset = rendererData->vertexDesc.GetAttributeOffset(RE::BSGraphics::Vertex::Attribute::VA_POSITION);
for (int v = 0; v < triShape->GetTrishapeRuntimeData().vertexCount; v++) {
if (VertexPosition* vertex = reinterpret_cast<VertexPosition*>(&rendererData->rawVertexData[vertexSize * v + offset])) {
RE::NiPoint3 position{ (float)vertex->data[0], (float)vertex->data[1], (float)vertex->data[2] };
radius = std::max(radius, position.Length());
}
}
radius /= 255.f;
}
}

Expand All @@ -608,7 +605,7 @@ bool LightLimitFix::AddParticleLight(RE::BSRenderPass* a_pass, LightLimitFix::Co
color.blue *= config->colorMult.blue;
}

queuedParticleLights.insert({ a_pass->geometry, { color, radius, *config } });
queuedParticleLights.insert({ a_pass->geometry, { color, *config } });
return true;
}

Expand Down Expand Up @@ -649,8 +646,8 @@ float LightLimitFix::CalculateLightDistance(float3 a_lightPosition, float a_radi

void LightLimitFix::AddCachedParticleLights(eastl::vector<LightData>& lightsData, LightLimitFix::LightData& light, ParticleLights::Config* a_config, RE::BSGeometry* a_geometry, double a_timer)
{
static float& lightFadeStart = (*(float*)RELOCATION_ID(527668, 414582).address());
static float& lightFadeEnd = (*(float*)RELOCATION_ID(527669, 414583).address());
static float& lightFadeStart = (*(float*)REL::RelocationID(527668, 414582).address());
static float& lightFadeEnd = (*(float*)REL::RelocationID(527669, 414583).address());

float distance = CalculateLightDistance(light.positionWS[0].data, light.radius);

Expand Down Expand Up @@ -746,6 +743,7 @@ void LightLimitFix::UpdateLights()
viewMatrixCached[eyeIndex] = eyeCount == 1 ?
state->GetRuntimeData().cameraData.getEye(eyeIndex).viewMat :
state->GetVRRuntimeData().cameraData.getEye(eyeIndex).viewMat;
viewMatrixCached[eyeIndex].Invert(viewMatrixInverseCached[eyeIndex]);
}

RE::NiLight* refLight = nullptr;
Expand Down Expand Up @@ -880,9 +878,9 @@ void LightLimitFix::UpdateLights()
color.x = particleLight.second.color.red * particleData->GetParticlesRuntimeData().color[p].red;
color.y = particleLight.second.color.green * particleData->GetParticlesRuntimeData().color[p].green;
color.z = particleLight.second.color.blue * particleData->GetParticlesRuntimeData().color[p].blue;
clusteredLight.color += Saturation(color, settings.ParticleLightsSaturation) * alpha;
clusteredLight.color += Saturation(color, settings.ParticleLightsSaturation) * alpha * settings.ParticleBrightness;

clusteredLight.radius += radius * particleLight.second.config.radiusMult;
clusteredLight.radius += radius * settings.ParticleRadius * particleLight.second.config.radiusMult;
clusteredLight.positionWS[0].data.x += positionWS.x;
clusteredLight.positionWS[0].data.y += positionWS.y;
clusteredLight.positionWS[0].data.z += positionWS.z;
Expand All @@ -900,9 +898,8 @@ void LightLimitFix::UpdateLights()

light.color = Saturation(light.color, settings.ParticleLightsSaturation);

light.color *= particleLight.second.color.alpha;

light.radius = particleLight.second.radius * 70.0f * 0.5f;
light.color *= particleLight.second.color.alpha * settings.BillboardBrightness;
light.radius = particleLight.first->worldBound.radius * settings.BillboardRadius * particleLight.second.config.radiusMult;

auto position = particleLight.first->world.translate;

Expand Down
Loading

0 comments on commit 20c72e0

Please sign in to comment.