diff --git a/FinalEngine.Rendering/FinalEngine.Rendering.csproj b/FinalEngine.Rendering/FinalEngine.Rendering.csproj index 3771bdf7..e0599692 100644 --- a/FinalEngine.Rendering/FinalEngine.Rendering.csproj +++ b/FinalEngine.Rendering/FinalEngine.Rendering.csproj @@ -109,7 +109,10 @@ PreserveNewest - + + PreserveNewest + + PreserveNewest diff --git a/FinalEngine.Rendering/Geometry/IMaterial.cs b/FinalEngine.Rendering/Geometry/IMaterial.cs index 53f6a02c..f768dc66 100644 --- a/FinalEngine.Rendering/Geometry/IMaterial.cs +++ b/FinalEngine.Rendering/Geometry/IMaterial.cs @@ -10,6 +10,8 @@ public interface IMaterial { ITexture2D DiffuseTexture { get; set; } + ITexture2D EmissionTexture { get; set; } + ITexture2D NormalTexture { get; set; } float Shininess { get; set; } diff --git a/FinalEngine.Rendering/Geometry/Material.cs b/FinalEngine.Rendering/Geometry/Material.cs index e0d8cb80..fe34b03f 100644 --- a/FinalEngine.Rendering/Geometry/Material.cs +++ b/FinalEngine.Rendering/Geometry/Material.cs @@ -12,12 +12,16 @@ public sealed class Material : IMaterial { private static readonly ITexture2D DefaultDiffuseTexture = ResourceManager.Instance.LoadResource("Resources\\Textures\\default_diffuse.png"); - private static readonly ITexture2D DefaultNormalTexture = ResourceManager.Instance.LoadResource("Resources\\Textures\\default_normal.jpg"); + private static readonly ITexture2D DefaultEmissionTexture = ResourceManager.Instance.LoadResource("Resources\\Textures\\default_emission.png"); + + private static readonly ITexture2D DefaultNormalTexture = ResourceManager.Instance.LoadResource("Resources\\Textures\\default_normal.png"); private static readonly ITexture2D DefaultSpecularTexture = ResourceManager.Instance.LoadResource("Resources\\Textures\\default_specular.png"); private ITexture2D? diffuseTexture; + private ITexture2D? emissionTexture; + private ITexture2D? normalTexture; private ITexture2D? specularTexture; @@ -33,6 +37,12 @@ public ITexture2D DiffuseTexture set { this.diffuseTexture = value; } } + public ITexture2D EmissionTexture + { + get { return this.emissionTexture ??= DefaultEmissionTexture; } + set { this.emissionTexture = value; } + } + public ITexture2D NormalTexture { get { return this.normalTexture ??= DefaultNormalTexture; } @@ -54,10 +64,12 @@ public void Bind(IPipeline pipeline) pipeline.SetUniform("u_material.diffuseTexture", 0); pipeline.SetUniform("u_material.specularTexture", 1); pipeline.SetUniform("u_material.normalTexture", 2); + pipeline.SetUniform("u_material.emissionTexture", 3); pipeline.SetUniform("u_material.shininess", this.Shininess); pipeline.SetTexture(this.DiffuseTexture, 0); pipeline.SetTexture(this.SpecularTexture, 1); pipeline.SetTexture(this.NormalTexture, 2); + pipeline.SetTexture(this.EmissionTexture, 3); } } diff --git a/FinalEngine.Rendering/Resources/Shaders/Includes/lighting.glsl b/FinalEngine.Rendering/Resources/Shaders/Includes/lighting.glsl index ca0ed4da..cd362352 100644 --- a/FinalEngine.Rendering/Resources/Shaders/Includes/lighting.glsl +++ b/FinalEngine.Rendering/Resources/Shaders/Includes/lighting.glsl @@ -44,6 +44,8 @@ struct SpotLight float outerRadius; }; +uniform bool u_test; + vec3 CalculateLight(LightBase light, Material material, vec3 direction, vec3 normal, vec3 viewPosition, vec3 fragPosition, vec2 texCoord) { normal = normalize(normal); @@ -62,9 +64,14 @@ vec3 CalculateLight(LightBase light, Material material, vec3 direction, vec3 nor float specularShading = pow(max(dot(normal, halfWayDirection), 0.0), material.shininess); vec3 specularColor = specularShading * light.color * light.intensity * texture(material.specularTexture, texCoord).rgb; - return diffuseColor + specularColor; + // Calculate emission map here as it's a lighting effect. + vec3 emissionColor = texture(material.emissionTexture, texCoord).rgb; + + return diffuseColor + specularColor + emissionColor; } + + vec3 CalculateDirectionalLight(DirectionalLight light, Material material, vec3 normal, vec3 viewPosition, vec3 fragPosition, vec2 texCoord) { return CalculateLight(light.base, material, -light.direction, normal, viewPosition, fragPosition, texCoord); diff --git a/FinalEngine.Rendering/Resources/Shaders/Includes/material.glsl b/FinalEngine.Rendering/Resources/Shaders/Includes/material.glsl index 096274af..f8ee2f12 100644 --- a/FinalEngine.Rendering/Resources/Shaders/Includes/material.glsl +++ b/FinalEngine.Rendering/Resources/Shaders/Includes/material.glsl @@ -6,6 +6,7 @@ struct Material sampler2D diffuseTexture; sampler2D specularTexture; sampler2D normalTexture; + sampler2D emissionTexture; float shininess; }; diff --git a/FinalEngine.Rendering/Resources/Textures/default_emission.png b/FinalEngine.Rendering/Resources/Textures/default_emission.png new file mode 100644 index 00000000..a41fce27 Binary files /dev/null and b/FinalEngine.Rendering/Resources/Textures/default_emission.png differ diff --git a/FinalEngine.Rendering/Resources/Textures/default_normal.jpg b/FinalEngine.Rendering/Resources/Textures/default_normal.jpg deleted file mode 100644 index cfdeddd8..00000000 Binary files a/FinalEngine.Rendering/Resources/Textures/default_normal.jpg and /dev/null differ diff --git a/FinalEngine.Rendering/Resources/Textures/default_normal.png b/FinalEngine.Rendering/Resources/Textures/default_normal.png new file mode 100644 index 00000000..62a60cb1 Binary files /dev/null and b/FinalEngine.Rendering/Resources/Textures/default_normal.png differ