Skip to content

Commit 2d14322

Browse files
committed
feature (extended translucency): ScatteringVolume material
Adding a new material model to the feature: ScatteringVolume This material is modeled after a ball of smoke, which scattering light exponentially through it. It is unique because its the first material model that "fade out" the mesh, instead of strengthening its edges. This material was originally designed for `Ghost`, or `SetActorAlpha`. But it does not work out of the box yet: 1. The EffectShader of a regular ghost is way too strong, making it hard to see difference in the mesh's rendering. 2. We disabled this effect in SKIN shader to avoid rendering issue with makeup and face details.
1 parent 87a8408 commit 2d14322

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

features/Extended Translucency/Shaders/ExtendedTranslucency/ExtendedTranslucency.hlsli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace ExtendedTranslucency
66
static const uint RimLight = 1;
77
static const uint IsotropicFabric = 2;
88
static const uint AnisotropicFabric = 3;
9-
static const uint Disabled = 4; // Any value >= 4
9+
static const uint ScatteringVolume = 4;
10+
static const uint Disabled = 5; // Any value >= 5
1011
}
1112

1213
bool IsValidMaterial(uint Material)
@@ -41,6 +42,11 @@ namespace ExtendedTranslucency
4142
return a0 * (length(cross(v, t)) + length(cross(v, b))) / (abs(dot(v, n)) + 0.001) - a0 * a0;
4243
}
4344

45+
float GetViewDependentAlphaScatteringVolume(float alpha, float3 view, float3 normal)
46+
{
47+
return 1.0 - pow(1.0 - alpha, dot(view, normal));
48+
}
49+
4450
float SoftClamp(float alpha, float limit)
4551
{
4652
// soft clamp [alpha,1] and remap the transparency

package/Shaders/Lighting.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3205,7 +3205,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace)
32053205

32063206
[branch] if (ExtendedTranslucency::IsValidMaterial(AlphaMaterialModel))
32073207
{
3208-
if (alpha >= 0.0156862754 && alpha < 1.0) {
3208+
if (alpha >= 0.0156862754 && alpha <= 1.0 - 0.0156862754) {
32093209
float originalAlpha = alpha;
32103210
alpha = alpha * (1.0 - AlphaMaterialReduction);
32113211
[branch] if (AlphaMaterialModel == ExtendedTranslucency::MaterialModel::AnisotropicFabric)
@@ -3220,6 +3220,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace : SV_IsFrontFace)
32203220
{
32213221
alpha = ExtendedTranslucency::GetViewDependentAlphaFabric1D(alpha, viewDirection, worldNormal.xyz);
32223222
}
3223+
else if (AlphaMaterialModel == ExtendedTranslucency::MaterialModel::ScatteringVolume)
3224+
{
3225+
alpha = ExtendedTranslucency::GetViewDependentAlphaScatteringVolume(alpha, viewDirection, worldNormal.xyz);
3226+
}
32233227
else
32243228
{
32253229
alpha = ExtendedTranslucency::GetViewDependentAlphaNaive(alpha, viewDirection, worldNormal.xyz);

src/Features/ExtendedTranslucency.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void ExtendedTranslucency::DrawSettings()
9090
"1 - Rim Edge",
9191
"2 - Isotropic Fabric, Glass, ...",
9292
"3 - Anisotropic Fabric",
93+
"4 - Scattering Volume",
9394
};
9495

9596
static constexpr int AlphaModeSize = static_cast<int>(std::size(AlphaModeNames));
@@ -104,7 +105,8 @@ void ExtendedTranslucency::DrawSettings()
104105
" - Disabled: No anisotropic transluency, flat alpha.\n"
105106
" - Rim Edge: Naive rim light effect with no physics model, the edge of the geometry is always opaque even its full transparent.\n"
106107
" - Isotropic Fabric: Imaginary fabric weaved from threads in one direction, respect normal map, also works well for layer of glass panels.\n"
107-
" - Anisotropic Fabric: Common fabric weaved from tangent and birnormal direction, ignores normal map.\n");
108+
" - Anisotropic Fabric: Common fabric weaved from tangent and birnormal direction, ignores normal map.\n"
109+
" - Scattering Volume: A **volumn** (instead of a layer) of light scattering or absoring material, it fade the geometry out at its edge instead of strength them like other material.\n");
108110
}
109111
if (ImGui::Checkbox("Skinned Mesh Only", &settings.SkinnedOnly)) {
110112
changed = true;
@@ -160,7 +162,7 @@ std::pair<std::string, std::vector<std::string>> ExtendedTranslucency::GetFeatur
160162
return {
161163
"Extended Translucency provides realistic rendering of thin fabric and other translucent materials.\n"
162164
"This feature supports multiple material models for different types of translucent surfaces.",
163-
{ "Multiple translucency material models (rim edge, isotropic/anisotropic fabric)",
165+
{ "Multiple translucency material models (rim edge, isotropic/anisotropic fabric, scattering volume)",
164166
"Realistic fabric translucency with directional light transmission",
165167
"Per-material override support via NIF extra data",
166168
"Configurable transparency and softness controls",

src/Features/ExtendedTranslucency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ExtendedTranslucency final : Feature
3232
RimLight = 1, // Similar effect like rim light
3333
IsotropicFabric = 2, // 1D fabric model, respect normal map
3434
AnisotropicFabric = 3, // 2D fabric model alone tangent and binormal, ignores normal map
35+
ScatteringVolume = 4, // Fade out at the edge, models a ball of fog (light decays in exponential on distance)
3536

3637
DescriptorUseDefault = 0, // In ExtraFeatureDescriptor, 0 means 'UseDefault' instead of 'Disabled'
3738
DescriptorDisabled = 7, // In ExtraFeatureDescriptor, value >= 5 means 'Disabled'

0 commit comments

Comments
 (0)