From abd6b1af91c6ad9949c986ecae30e3ed699b3438 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 26 Aug 2020 17:02:45 -0700 Subject: [PATCH] add directional light + rename GBufferEffect for clarity --- Effects/DeferredPBREffect.cs | 24 +++++++++ ...Effect.cs => DeferredPBR_GBufferEffect.cs} | 8 +-- Effects/DirectionalLightCollection.cs | 47 ++++++++++++++++++ Effects/FXB/DeferredPBREffect.fxb | Bin 50536 -> 53400 bytes Effects/FXB/DeferredPBR_GBufferEffect.fxb | Bin 0 -> 7476 bytes Effects/HLSL/DeferredPBREffect.fx | 24 +++++---- ...Effect.fx => DeferredPBR_GBufferEffect.fx} | 0 Effects/PBREffect.cs | 42 ---------------- Kav.Core.csproj | 4 +- Kav.Framework.csproj | 4 +- Loaders/ModelLoader.cs | 2 +- Renderer.cs | 8 +++ Resources.cs | 4 +- 13 files changed, 104 insertions(+), 63 deletions(-) rename Effects/{GBufferEffect.cs => DeferredPBR_GBufferEffect.cs} (95%) create mode 100644 Effects/DirectionalLightCollection.cs create mode 100644 Effects/FXB/DeferredPBR_GBufferEffect.fxb rename Effects/HLSL/{GBufferEffect.fx => DeferredPBR_GBufferEffect.fx} (100%) diff --git a/Effects/DeferredPBREffect.cs b/Effects/DeferredPBREffect.cs index 04af0e8..97c8615 100644 --- a/Effects/DeferredPBREffect.cs +++ b/Effects/DeferredPBREffect.cs @@ -12,6 +12,7 @@ namespace Kav EffectParameter eyePositionParam; PointLightCollection pointLightCollection; + DirectionalLightCollection directionalLightCollection; public Texture2D GPosition { get; set; } public Texture2D GAlbedo { get; set; } @@ -28,6 +29,14 @@ namespace Kav private set { pointLightCollection = value; } } + public int MaxDirectionalLights { get; } = 4; + + public DirectionalLightCollection DirectionalLights + { + get { return directionalLightCollection; } + private set { directionalLightCollection = value; } + } + public DeferredPBREffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.DeferredPBREffect) { CacheEffectParameters(); @@ -37,6 +46,11 @@ namespace Kav Parameters["PointLightColors"], MaxPointLights ); + + DirectionalLights = new DirectionalLightCollection( + Parameters["DirectionalLightDirections"], + Parameters["DirectionalLightColors"] + ); } protected DeferredPBREffect(DeferredPBREffect cloneSource) : base(cloneSource) @@ -58,6 +72,16 @@ namespace Kav { PointLights[i] = cloneSource.PointLights[i]; } + + DirectionalLights = new DirectionalLightCollection( + Parameters["DirectionalLightDirections"], + Parameters["DirectionalLightColors"] + ); + + for (int i = 0; i < MaxDirectionalLights; i++) + { + DirectionalLights[i] = cloneSource.DirectionalLights[i]; + } } public override Effect Clone() diff --git a/Effects/GBufferEffect.cs b/Effects/DeferredPBR_GBufferEffect.cs similarity index 95% rename from Effects/GBufferEffect.cs rename to Effects/DeferredPBR_GBufferEffect.cs index ff8769d..26a9c8f 100644 --- a/Effects/GBufferEffect.cs +++ b/Effects/DeferredPBR_GBufferEffect.cs @@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics; namespace Kav { - public class GBufferEffect : Effect, TransformEffect + public class DeferredPBR_GBufferEffect : Effect, TransformEffect { EffectParameter worldParam; EffectParameter worldViewProjectionParam; @@ -126,12 +126,12 @@ namespace Kav } } - public GBufferEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.GBufferEffect) + public DeferredPBR_GBufferEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.DeferredPBR_GBufferEffect) { CacheEffectParameters(); } - protected GBufferEffect(GBufferEffect cloneSource) : base(cloneSource) + protected DeferredPBR_GBufferEffect(DeferredPBR_GBufferEffect cloneSource) : base(cloneSource) { CacheEffectParameters(); @@ -150,7 +150,7 @@ namespace Kav public override Effect Clone() { - return new GBufferEffect(this); + return new DeferredPBR_GBufferEffect(this); } protected override void OnApply() diff --git a/Effects/DirectionalLightCollection.cs b/Effects/DirectionalLightCollection.cs new file mode 100644 index 0000000..10bcbda --- /dev/null +++ b/Effects/DirectionalLightCollection.cs @@ -0,0 +1,47 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Kav +{ + public class DirectionalLightCollection + { + private readonly Vector3[] directions = new Vector3[4]; + private readonly Vector3[] colors = new Vector3[4]; + private readonly float[] intensities = new float[4]; + + readonly EffectParameter lightDirectionsParam; + readonly EffectParameter lightColorsParam; + + public DirectionalLightCollection(EffectParameter lightDirectionsParam, EffectParameter lightColorsParam) + { + this.lightDirectionsParam = lightDirectionsParam; + this.lightColorsParam = lightColorsParam; + } + + public DirectionalLight this[int i] + { + get + { + var color = colors[i] / intensities[i]; + return new DirectionalLight( + directions[i], + new Color( + color.X, + color.Y, + color.Z, + 1f + ), + intensities[i] + ); + } + set + { + directions[i] = value.Direction; + colors[i] = value.Color.ToVector3() * value.Intensity; + intensities[i] = value.Intensity; + lightDirectionsParam.SetValue(directions); + lightColorsParam.SetValue(colors); + } + } + } +} diff --git a/Effects/FXB/DeferredPBREffect.fxb b/Effects/FXB/DeferredPBREffect.fxb index b3cda6cd261cc0d33aa2276683b75ccdc06dbee7..10298d5149531440477ff239977961028697e518 100644 GIT binary patch literal 53400 zcmeI0L2R5y702iMc5SbnHcpe!mbOsS8fYQ32@OynO`XIoEhHgLvS6T)I`PI{*m#ZY zKm!HVq=h<;ge5LLaM++oRQ8nvs*0$PkT~{$1QJ&t!i@t+t%SP#|1Gq&ZiguQ#W?OuYt*JUJ>d zUfTH0@t1vN6yGB#cc2vZj*Xw0Y1C%XRE+->1^<-rT|t@L*Em_5Xxdol`-<=97v<~u zehWHpq70&VTZLyCyPd)Mrw8BG@8Ra`nej&9_k}>G7dkRl#_>Cx^WzY9qgcPr)&{>9 z1DmwB4Q29BZGODbsGmC8JUclxU7MS8>%h6L1^SHfdNI5S{okS7b4|NNIEJ~V=^b25 z|45t2{Jst4sdKf02+B+Gy}J42DW43N1FBN`GfVzsd?ElbH)C+$PJ8V z1V#4@GojC|o&nwux_jn8v(cQz>DS#K|MYu?XW{?4XYR$=(fVxd6z??S4ZAxF8Q#S1 z^ZsshGrsP+hA){F>+R`{5%;JkQ$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cW%zO zxr2xA-2ZkTyL&v%xh>(WlrVmbIWP|63hwqY+LU+o^N@5ywz>zA2V>KRwy{+Dw$7J+ zBe^fk&Diwivx2fn)zp#*{;V7!{)S}Nhi!^-N2JTSI-g>nz~7EnGHa3`MgpC+FCpF* za$((!{#Tk(L>DJovLeq?e g1?!i7|8({v{umm4>q1+K>z>% diff --git a/Effects/FXB/DeferredPBR_GBufferEffect.fxb b/Effects/FXB/DeferredPBR_GBufferEffect.fxb new file mode 100644 index 0000000000000000000000000000000000000000..9b2d6844f486894e8a28f804c05221fee8d81938 GIT binary patch literal 7476 zcmds6O=w(I6u$4hX)BVR!9iS95J^!%L}{9Y+Q3v}lh%NRCMHuGnP!HWq(*S@ zgf3iUF{q0!x_Dqf>9{E9BDkpw5er?E;-VD65oh5-(3J?5jNfR%7Pd%%bDZ{?;7W4VR7`BD!0E--zIU?CrZ z)FC!LS;vwUj^a54ei+VEu1Crj*?)FC!L z-G1DFejUtywA9(AA5XKOr5$)a20oUXo6P5Drj8fp-#$B=E0>#Hisxq0Dc6NE8}(@# z{uAKLI`vEUI3KM37Jn>>O>{ncz-FFLPUh!xdLC&{6D&)tLaN~$%h*f_Gxv0TX^k?y zco)xuEyTXi{R^iIaUuU(;#|H_DCMW|ly>$}u(Va}Jc9akJHxZ*bER@_tTZ`WE*8p+ ze`$Ad8`|9`?Vg;;y*pAWypx-nn<>mH&NIh$%eI+@%$VYHCzxw;H<*||04A1vH!^y- zRGNHG;{jD=EC_t(Vo#ZHv3j~N)+KIP_sHn*?DWi3t_)dV9kF%6)KVAwFnV@!I#)uO z+=A}=Uf3LW7E!dxxU|9kNIbHSuMEteIfK+dKiWC22f?iCQLs=Sgj1s6xd@INeHn7y z(f6UU1JV%eS;z~Heg*P%NBr$Us+mg2VuqIyN&^DwGRn<}wG4Kb1L}9nEG;z-0yt=ZZ7fOEL%ho;j$h)z>lnK=nqZ z>F|(r;c*NP^AciaDn|A~4>Dp7Q$e|2A!FV!4Icbd2>-xKcWc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IJ~jID+=_2bD|_$}*$*-H8t$P2+)UKCSA!#?`&!3$ zv(-~t$G2^S_{MjySL5AhD%O3i?}+u3*1K$ZM29Y)j&)Q2&R93~?~3)b_TLR1xcKZR p+O9B47%P$k6o|NO^!GTH!Cb|}GTbj)_8aK*bK^k#TE1)G_YchewfX=6 literal 0 HcmV?d00001 diff --git a/Effects/HLSL/DeferredPBREffect.fx b/Effects/HLSL/DeferredPBREffect.fx index 9f4e74e..a49f27a 100644 --- a/Effects/HLSL/DeferredPBREffect.fx +++ b/Effects/HLSL/DeferredPBREffect.fx @@ -2,6 +2,7 @@ static const float PI = 3.141592653589793; static const int MAX_POINT_LIGHTS = 64; +static const int MAX_DIRECTIONAL_LIGHTS = 4; DECLARE_TEXTURE(gPosition, 0); DECLARE_TEXTURE(gAlbedo, 1); @@ -10,10 +11,13 @@ DECLARE_TEXTURE(gMetallicRoughness, 3); BEGIN_CONSTANTS - float3 EyePosition _ps(c0) _cb(c0); + float3 EyePosition _ps(c0) _cb(c0); - float3 PointLightPositions[MAX_POINT_LIGHTS] _ps(c1) _cb(c1); - float3 PointLightColors[MAX_POINT_LIGHTS] _ps(c65) _cb(c65); + float3 PointLightPositions[MAX_POINT_LIGHTS] _ps(c1) _cb(c1); + float3 PointLightColors[MAX_POINT_LIGHTS] _ps(c65) _cb(c65); + + float3 DirectionalLightDirections[MAX_DIRECTIONAL_LIGHTS] _ps(c129) _cb(c129); + float3 DirectionalLightColors[MAX_DIRECTIONAL_LIGHTS] _ps(c133) _cb(c133); MATRIX_CONSTANTS @@ -123,14 +127,14 @@ float4 ComputeColor( Lo += ComputeLight(lightDir, radiance, F0, V, N, albedo, metallic, roughness); } - // // directional light - // for (int i = 0; i < 4; i++) - // { - // float3 lightDir = LightDirections[i]; - // float3 radiance = DirectionLightColors[i]; + // directional light + for (int i = 0; i < MAX_DIRECTIONAL_LIGHTS; i++) + { + float3 lightDir = DirectionalLightDirections[i]; + float3 radiance = DirectionalLightColors[i]; - // Lo += ComputeLight(lightDir, radiance, F0, V, N, albedo, metallic, roughness); - // } + Lo += ComputeLight(lightDir, radiance, F0, V, N, albedo, metallic, roughness); + } float3 ambient = float3(0.03, 0.03, 0.03) * albedo; // * AO; float3 color = ambient + Lo; diff --git a/Effects/HLSL/GBufferEffect.fx b/Effects/HLSL/DeferredPBR_GBufferEffect.fx similarity index 100% rename from Effects/HLSL/GBufferEffect.fx rename to Effects/HLSL/DeferredPBR_GBufferEffect.fx diff --git a/Effects/PBREffect.cs b/Effects/PBREffect.cs index 9efe2fe..db04a25 100644 --- a/Effects/PBREffect.cs +++ b/Effects/PBREffect.cs @@ -3,48 +3,6 @@ using Microsoft.Xna.Framework.Graphics; namespace Kav { - public class DirectionalLightCollection - { - private readonly Vector3[] directions = new Vector3[4]; - private readonly Vector3[] colors = new Vector3[4]; - private readonly float[] intensities = new float[4]; - - readonly EffectParameter lightPositionsParam; - readonly EffectParameter lightColorsParam; - - public DirectionalLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam) - { - this.lightPositionsParam = lightPositionsParam; - this.lightColorsParam = lightColorsParam; - } - - public DirectionalLight this[int i] - { - get - { - var color = colors[i] / intensities[i]; - return new DirectionalLight( - directions[i], - new Color( - color.X, - color.Y, - color.Z, - 1f - ), - intensities[i] - ); - } - set - { - directions[i] = value.Direction; - colors[i] = value.Color.ToVector3() * value.Intensity; - intensities[i] = value.Intensity; - lightPositionsParam.SetValue(directions); - lightColorsParam.SetValue(colors); - } - } - } - public class PBREffect : Effect, TransformEffect, PointLightEffect, DirectionalLightEffect { EffectParameter worldParam; diff --git a/Kav.Core.csproj b/Kav.Core.csproj index 615ab97..7957739 100644 --- a/Kav.Core.csproj +++ b/Kav.Core.csproj @@ -15,8 +15,8 @@ - - Kav.Resources.GBufferEffect.fxb + + Kav.Resources.DeferredPBR_GBufferEffect.fxb Kav.Resources.DeferredPBREffect.fxb diff --git a/Kav.Framework.csproj b/Kav.Framework.csproj index c0f517d..0557675 100644 --- a/Kav.Framework.csproj +++ b/Kav.Framework.csproj @@ -15,8 +15,8 @@ - - Kav.Resources.GBufferEffect.fxb + + Kav.Resources.DeferredPBR_GBufferEffect.fxb Kav.Resources.DeferredPBREffect.fxb diff --git a/Loaders/ModelLoader.cs b/Loaders/ModelLoader.cs index 2655368..4e908a0 100644 --- a/Loaders/ModelLoader.cs +++ b/Loaders/ModelLoader.cs @@ -15,7 +15,7 @@ namespace Kav foreach (var meshPartData in meshData.MeshParts) { - var effect = new Kav.GBufferEffect( + var effect = new Kav.DeferredPBR_GBufferEffect( graphicsDevice ) { diff --git a/Renderer.cs b/Renderer.cs index 0a77640..c53f855 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -160,6 +160,14 @@ namespace Kav i++; } + i = 0; + foreach (var directionalLight in directionalLights) + { + if (i > DeferredPBREffect.MaxDirectionalLights) { break; } + DeferredPBREffect.DirectionalLights[i] = directionalLight; + i++; + } + SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, DeferredPBREffect); SpriteBatch.Draw(deferredRenderTarget, Vector2.Zero, Color.White); SpriteBatch.End(); diff --git a/Resources.cs b/Resources.cs index 5c50646..83d4b04 100644 --- a/Resources.cs +++ b/Resources.cs @@ -4,13 +4,13 @@ namespace Kav { internal class Resources { - public static byte[] GBufferEffect + public static byte[] DeferredPBR_GBufferEffect { get { if (gBufferEffect == null) { - gBufferEffect = GetResource("GBufferEffect"); + gBufferEffect = GetResource("DeferredPBR_GBufferEffect"); } return gBufferEffect; }