Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Jan 12, 2024
2 parents dd9f686 + 1472628 commit 25262e1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion FinalEngine.Rendering/FinalEngine.Rendering.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@
<None Update="Resources\Textures\default_diffuse.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Textures\default_normal.jpg">
<None Update="Resources\Textures\default_emission.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Textures\default_normal.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Textures\default_specular.png">
Expand Down
2 changes: 2 additions & 0 deletions FinalEngine.Rendering/Geometry/IMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IMaterial
{
ITexture2D DiffuseTexture { get; set; }

ITexture2D EmissionTexture { get; set; }

ITexture2D NormalTexture { get; set; }

float Shininess { get; set; }
Expand Down
14 changes: 13 additions & 1 deletion FinalEngine.Rendering/Geometry/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ public sealed class Material : IMaterial
{
private static readonly ITexture2D DefaultDiffuseTexture = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\default_diffuse.png");

private static readonly ITexture2D DefaultNormalTexture = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\default_normal.jpg");
private static readonly ITexture2D DefaultEmissionTexture = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\default_emission.png");

private static readonly ITexture2D DefaultNormalTexture = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\default_normal.png");

private static readonly ITexture2D DefaultSpecularTexture = ResourceManager.Instance.LoadResource<ITexture2D>("Resources\\Textures\\default_specular.png");

private ITexture2D? diffuseTexture;

private ITexture2D? emissionTexture;

private ITexture2D? normalTexture;

private ITexture2D? specularTexture;
Expand All @@ -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; }
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct Material
sampler2D diffuseTexture;
sampler2D specularTexture;
sampler2D normalTexture;
sampler2D emissionTexture;
float shininess;
};

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 25262e1

Please sign in to comment.