Skip to content

Commit 6e52731

Browse files
authored
Reduced standard shader variant count from 256 to 32 (#556)
1 parent bb1a613 commit 6e52731

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

Resources/Engine/Shaders/PostProcess/Luminance.ovfx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ out vec4 FRAGMENT_COLOR;
2121
uniform sampler2D _InputTexture;
2222
uniform float _CenterWeightBias;
2323

24-
const float EPSILON = 0.0001f;
24+
const float EPSILON = 0.0001;
2525

2626
float luminance(vec3 v)
2727
{

Resources/Engine/Shaders/PostProcess/Tonemapping.ovfx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ uniform float _Exposure;
2323
uniform int _Mode;
2424
uniform int _GammaCorrection;
2525

26+
const float EPSILON = 0.0001;
27+
2628
float luminance(vec3 v)
2729
{
28-
return dot(v, vec3(0.2126, 0.7152, 0.0722));
30+
return max(dot(v, vec3(0.2126, 0.7152, 0.0722)), EPSILON);
2931
}
3032

3133
vec3 applyGammaCorrection(vec3 color)
@@ -62,18 +64,18 @@ vec3 reinhard(vec3 v)
6264
vec3 reinhard_jodie(vec3 v)
6365
{
6466
float l = luminance(v);
65-
vec3 tv = v / (1.0f + v);
66-
return mix(v / (1.0f + l), tv, tv);
67+
vec3 tv = v / (1.0 + v);
68+
return mix(v / (1.0 + l), tv, tv);
6769
}
6870

6971
vec3 uncharted2_tonemap_partial(vec3 x)
7072
{
71-
const float A = 0.15f;
72-
const float B = 0.50f;
73-
const float C = 0.10f;
74-
const float D = 0.20f;
75-
const float E = 0.02f;
76-
const float F = 0.30f;
73+
const float A = 0.15;
74+
const float B = 0.50;
75+
const float C = 0.10;
76+
const float D = 0.20;
77+
const float E = 0.02;
78+
const float F = 0.30;
7779
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
7880
}
7981

Resources/Engine/Shaders/Standard.ovfx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#pass SHADOW_PASS
22

33
#feature PARALLAX_MAPPING
4-
#feature ALPHA_CLIPPING
5-
#feature ALPHA_DITHERING
64
#feature NORMAL_MAPPING
75
#feature DISTANCE_FADE
86
#feature SPECULAR_WORKFLOW
9-
#feature GAMMA_CORRECTION
107

118
#shader vertex
129
#version 450 core
@@ -96,10 +93,6 @@ uniform int u_MinLayers = 8;
9693
uniform int u_MaxLayers = 64;
9794
#endif
9895

99-
#if defined(ALPHA_CLIPPING)
100-
uniform float u_AlphaClippingThreshold = 0.1;
101-
#endif
102-
10396
#if defined(SHADOW_PASS)
10497
#undef PARALLAX_MAPPING // Disable parallax mapping in shadow pass
10598
uniform float u_ShadowClippingThreshold = 0.5;
@@ -113,6 +106,13 @@ uniform float u_DistanceFadeLength = 10.0;
113106
uniform vec2 u_TextureTiling = vec2(1.0, 1.0);
114107
uniform vec2 u_TextureOffset = vec2(0.0, 0.0);
115108

109+
uniform float u_AlphaClippingThreshold = 0.0;
110+
uniform bool u_AlphaDithering = false;
111+
112+
// Useful when no post-processing is applied.
113+
uniform bool u_BuiltInToneMapping = false;
114+
uniform bool u_BuiltInGammaCorrection = false;
115+
116116
uniform sampler2D _ShadowMap;
117117
uniform mat4 _LightSpaceMatrix;
118118

@@ -149,20 +149,15 @@ void main()
149149
}
150150
#else
151151

152-
#if defined(ALPHA_CLIPPING)
153152
if (albedo.a < u_AlphaClippingThreshold)
154153
{
155154
discard;
156155
}
157-
#endif
158156

159-
#if defined(ALPHA_DITHERING)
160-
const float ditheredAlpha = Dithering(albedo.a, gl_FragCoord.xy);
161-
if (ditheredAlpha < 0)
157+
if (u_AlphaDithering && Dithering(albedo.a, gl_FragCoord.xy) < 0)
162158
{
163159
discard;
164160
}
165-
#endif
166161

167162
#if defined(NORMAL_MAPPING)
168163
const vec3 normal = ComputeNormal(texCoords, fs_in.Normal, u_NormalMap, fs_in.TBN);
@@ -194,9 +189,11 @@ void main()
194189
_LightSpaceMatrix
195190
);
196191

197-
#if defined(GAMMA_CORRECTION)
198-
pbr = pow(pbr, vec3(1.0 / 2.2));
199-
#endif
192+
// Simple built-in tonemapping (Reinhard) and gamma correction for elements
193+
// not affected by post-processing (e.g. debug, UI, etc.), but still aiming
194+
// to approximate the final PBR look.
195+
pbr = mix(pbr, pbr / (pbr + vec3(1.0)), u_BuiltInToneMapping);
196+
pbr = mix(pbr, pow(pbr, vec3(1.0 / 2.2)), u_BuiltInGammaCorrection);
200197

201198
FRAGMENT_COLOR = vec4(pbr, albedo.a);
202199
#endif

Sources/Overload/OvEditor/src/OvEditor/Rendering/DebugSceneRenderer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class DebugCamerasRenderPass : public OvRendering::Core::ARenderPass
121121
m_cameraMaterial.SetProperty("u_Albedo", FVector4{ 0.0f, 0.447f, 1.0f, 1.0f });
122122
m_cameraMaterial.SetProperty("u_Metallic", 0.0f);
123123
m_cameraMaterial.SetProperty("u_Roughness", 0.25f);
124-
m_cameraMaterial.AddFeature("GAMMA_CORRECTION");
124+
m_cameraMaterial.SetProperty("u_BuiltInGammaCorrection", true);
125+
m_cameraMaterial.SetProperty("u_BuiltInToneMapping", true);
125126
}
126127

127128
protected:

0 commit comments

Comments
 (0)