Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit c472db4

Browse files
committed
Keep lens dirt aspect ratio
1 parent 7f1301a commit c472db4

7 files changed

Lines changed: 60 additions & 6 deletions

File tree

PostProcessing/Runtime/Effects/Bloom.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,32 @@ public override void Render(PostProcessRenderContext context)
145145
iterations
146146
);
147147

148+
// Lens dirtiness
149+
// Keep the aspect ratio correct & center the dirt texture, we don't want it to be
150+
// stretched or squashed
148151
var dirtTexture = settings.lensTexture.value == null
149152
? RuntimeUtilities.blackTexture
150153
: settings.lensTexture.value;
151154

155+
var dirtRatio = (float)dirtTexture.width / (float)dirtTexture.height;
156+
var screenRatio = (float)context.width / (float)context.height;
157+
var dirtTileOffset = new Vector4(1f, 1f, 0f, 0f);
158+
159+
if (dirtRatio > screenRatio)
160+
{
161+
dirtTileOffset.x = screenRatio / dirtRatio;
162+
dirtTileOffset.z = (1f - dirtTileOffset.x) * 0.5f;
163+
}
164+
else if (screenRatio > dirtRatio)
165+
{
166+
dirtTileOffset.y = dirtRatio / screenRatio;
167+
dirtTileOffset.w = (1f - dirtTileOffset.y) * 0.5f;
168+
}
169+
170+
// Shader properties
152171
var uberSheet = context.uberSheet;
153172
uberSheet.EnableKeyword("BLOOM");
173+
uberSheet.properties.SetVector(ShaderIDs.Bloom_DirtTileOffset, dirtTileOffset);
154174
uberSheet.properties.SetVector(ShaderIDs.Bloom_Settings, shaderSettings);
155175
uberSheet.properties.SetColor(ShaderIDs.Bloom_Color, settings.color.value.linear);
156176
uberSheet.properties.SetTexture(ShaderIDs.Bloom_DirtTex, dirtTexture);

PostProcessing/Runtime/Utils/ShaderIDs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static class ShaderIDs
6060
internal static readonly int Bloom_Settings = Shader.PropertyToID("_Bloom_Settings");
6161
internal static readonly int Bloom_Color = Shader.PropertyToID("_Bloom_Color");
6262
internal static readonly int Bloom_Threshold = Shader.PropertyToID("_Bloom_Threshold");
63+
internal static readonly int Bloom_DirtTileOffset = Shader.PropertyToID("_Bloom_DirtTileOffset");
6364

6465
internal static readonly int ChromaticAberration_Amount = Shader.PropertyToID("_ChromaticAberration_Amount");
6566
internal static readonly int ChromaticAberration_SpectralLut = Shader.PropertyToID("_ChromaticAberration_SpectralLut");

PostProcessing/Shaders/Builtins/Uber.shader

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Shader "Hidden/PostProcessing/Uber"
2929
TEXTURE2D_SAMPLER2D(_BloomTex, sampler_BloomTex);
3030
TEXTURE2D_SAMPLER2D(_Bloom_DirtTex, sampler_Bloom_DirtTex);
3131
float4 _BloomTex_TexelSize;
32-
half3 _Bloom_Settings; // x: sampleScale, y: intensity, z: lens intensity
32+
float4 _Bloom_DirtTileOffset; // xy: tiling, zw: offset
33+
half3 _Bloom_Settings; // x: sampleScale, y: intensity, z: lens dirt intensity
3334
half3 _Bloom_Color;
3435

3536
// Chromatic aberration
@@ -142,7 +143,7 @@ Shader "Hidden/PostProcessing/Uber"
142143
#if BLOOM
143144
{
144145
half4 bloom = UpsampleTent(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), uvSPR, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
145-
half4 dirt = half4(SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord).rgb, 0.0);
146+
half4 dirt = half4(SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw).rgb, 0.0);
146147

147148
// Additive bloom (artist friendly)
148149
bloom *= _Bloom_Settings.y;

PostProcessing/Textures/Lens Dirt/LensDirt00.png.meta

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostProcessing/Textures/Lens Dirt/LensDirt01.png.meta

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostProcessing/Textures/Lens Dirt/LensDirt02.png.meta

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostProcessing/Textures/Lens Dirt/LensDirt03.png.meta

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)