From 55b1555df2ded543e623c8b5eb60d3a3fff9e32c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 6 Aug 2020 01:12:15 -0700 Subject: [PATCH] prevent point lights from overflowing shader --- EffectInterfaces/PointLightEffect.cs | 3 ++- Effects/PBREffect.cs | 2 ++ Renderer.cs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/EffectInterfaces/PointLightEffect.cs b/EffectInterfaces/PointLightEffect.cs index bca763a..37d0db0 100644 --- a/EffectInterfaces/PointLightEffect.cs +++ b/EffectInterfaces/PointLightEffect.cs @@ -2,6 +2,7 @@ namespace Kav { public interface PointLightEffect { - PointLightCollection PointLights { get; } // TODO: should be a collection class? + int MaxPointLights { get; } + PointLightCollection PointLights { get; } } } diff --git a/Effects/PBREffect.cs b/Effects/PBREffect.cs index efe9cd2..f7927b4 100644 --- a/Effects/PBREffect.cs +++ b/Effects/PBREffect.cs @@ -117,6 +117,8 @@ namespace Kav } } + public int MaxPointLights { get; } = 4; + public PointLightCollection PointLights { get { return pointLightCollection; } diff --git a/Renderer.cs b/Renderer.cs index dab71d3..4f71cac 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -30,6 +30,7 @@ namespace Kav int i = 0; foreach (var pointLight in pointLights) { + if (i > pointLightEffect.MaxPointLights) { break; } pointLightEffect.PointLights[i] = pointLight; i++; }