Skip to content

Commit

Permalink
Fixed MaterialMapType
Browse files Browse the repository at this point in the history
  • Loading branch information
MrScautHD committed Dec 23, 2024
1 parent 553c609 commit ea967b2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/Bliss/CSharp/Audio/AudioDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Bliss.CSharp.Audio;

public class AudioDevice : Disposable {

// TODO: Change Audio Lib (This is not supporting MacOS!!!)

public AudioDevice(uint sampleRate, uint channels) {
AudioContext.Initialize(sampleRate, channels);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bliss/CSharp/Effects/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ public virtual void Apply() { }

protected override void Dispose(bool disposing) {
if (disposing) {
this.Shader.Item1.Dispose();
this.Shader.Item2.Dispose();

foreach (SimplePipeline pipeline in this._cachedPipelines.Values) {
pipeline.Dispose();
}

this.Shader.Item1.Dispose();
this.Shader.Item2.Dispose();
}
}
}
6 changes: 3 additions & 3 deletions src/Bliss/CSharp/Geometry/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public void Draw(CommandList commandList, OutputDescription output, Transform tr
}

// Set optional color.
Color cachedColor = this.Material.GetMapColor(MaterialMapType.Albedo.ToString()) ?? Color.White;
this.Material.SetMapColor(MaterialMapType.Albedo.ToString(), color ?? cachedColor);
Color cachedColor = this.Material.GetMapColor(MaterialMapType.Albedo) ?? Color.White;
this.Material.SetMapColor(MaterialMapType.Albedo, color ?? cachedColor);

// Update matrix buffer.
this._modelMatrixBuffer.SetValue(0, cam3D.GetProjection());
Expand Down Expand Up @@ -263,7 +263,7 @@ public void Draw(CommandList commandList, OutputDescription output, Transform tr
}

// Reset albedo material color.
this.Material.SetMapColor(MaterialMapType.Albedo.ToString(), cachedColor);
this.Material.SetMapColor(MaterialMapType.Albedo, cachedColor);
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions src/Bliss/CSharp/Geometry/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,52 +181,52 @@ public static Model Load(GraphicsDevice graphicsDevice, string path, bool loadMa
AMaterial aMaterial = scene.Materials[mesh.MaterialIndex];

if (aMaterial.HasTextureDiffuse) {
material.AddMaterialMap(MaterialMapType.Albedo.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Albedo, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Diffuse),
Color = ModelConversion.FromColor4D(aMaterial.ColorDiffuse)
});
}

if (aMaterial.PBR.HasTextureMetalness) {
material.AddMaterialMap(MaterialMapType.Metallic.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Metallic, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Metalness),
Color = ModelConversion.FromColor4D(aMaterial.ColorSpecular)
});
}

if (aMaterial.HasTextureNormal) {
material.AddMaterialMap(MaterialMapType.Normal.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Normal, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Normals)
});
}

if (aMaterial.PBR.HasTextureRoughness) {
material.AddMaterialMap(MaterialMapType.Roughness.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Roughness, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Roughness)
});
}

if (aMaterial.HasTextureAmbientOcclusion) {
material.AddMaterialMap(MaterialMapType.Occlusion.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Occlusion, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.AmbientOcclusion)
});
}

if (aMaterial.HasTextureEmissive) {
material.AddMaterialMap(MaterialMapType.Emission.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Emission, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Emissive),
Color = ModelConversion.FromColor4D(aMaterial.ColorEmissive)
});
}

if (aMaterial.HasTextureHeight) {
material.AddMaterialMap(MaterialMapType.Height.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Height, new MaterialMap() {
Texture = LoadMaterialTexture(graphicsDevice, scene, aMaterial, path, TextureType.Height)
});
}
}
else {
material.AddMaterialMap(MaterialMapType.Albedo.ToString(), new MaterialMap() {
material.AddMaterialMap(MaterialMapType.Albedo, new MaterialMap() {
Texture = GlobalResource.DefaultModelTexture,
Color = Color.White
});
Expand Down Expand Up @@ -269,7 +269,7 @@ public static Model Load(GraphicsDevice graphicsDevice, string path, bool loadMa
vertices[j].Tangent = mesh.HasTangentBasis ? ModelConversion.FromVector3D(mesh.Tangents[j]) : Vector3.Zero;

// Set Color.
vertices[j].Color = material.GetMapColor(MaterialMapType.Albedo.ToString())?.ToRgbaFloat().ToVector4() ?? Vector4.Zero;
vertices[j].Color = material.GetMapColor(MaterialMapType.Albedo)?.ToRgbaFloat().ToVector4() ?? Vector4.Zero;
}

// Setup indices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SimpleTextureLayout : Disposable {
public SimpleTextureLayout(GraphicsDevice graphicsDevice, string name) {
this.GraphicsDevice = graphicsDevice;
this.Name = name;

this.Layout = this.GraphicsDevice.ResourceFactory.CreateResourceLayout(new ResourceLayoutDescription() {
Elements = [
new ResourceLayoutElementDescription(name, ResourceKind.TextureReadOnly, ShaderStages.Fragment),
Expand Down
54 changes: 21 additions & 33 deletions src/Bliss/CSharp/Materials/MaterialMapType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,42 @@
* https://github.com/MrScautHD/Bliss/blob/main/LICENSE
*/

using System.Runtime.Serialization;

namespace Bliss.CSharp.Materials;

/// <summary>
/// An undefined or uninitialized material map type.
/// </summary>
public enum MaterialMapType {
public static class MaterialMapType {

/// <summary>
/// The base color map.
/// The name of the albedo map, representing base color and opacity.
/// </summary>
[EnumMember(Value = "fAlbedo")]
Albedo,

public const string Albedo = "fAlbedo";

/// <summary>
/// The metallic map.
/// The name of the metallic map, representing the metallic property of a material.
/// </summary>
[EnumMember(Value = "fMetallic")]
Metallic,

public const string Metallic = "fMetallic";

/// <summary>
/// The normal map.
/// The name of the normal map, used for simulating surface details without additional geometry.
/// </summary>
[EnumMember(Value = "fNormal")]
Normal,

public const string Normal = "fNormal";

/// <summary>
/// The roughness map.
/// The name of the roughness map, representing the roughness property of a material.
/// </summary>
[EnumMember(Value = "fRoughness")]
Roughness,

public const string Roughness = "fRoughness";

/// <summary>
/// The occlusion map.
/// The name of the occlusion map, representing ambient occlusion for the material.
/// </summary>
[EnumMember(Value = "fOcclusion")]
Occlusion,

public const string Occlusion = "fOcclusion";

/// <summary>
/// The emission map.
/// The name of the emission map, used for materials that emit light.
/// </summary>
[EnumMember(Value = "fEmissive")]
Emission,

public const string Emission = "fEmissive";

/// <summary>
/// The height map.
/// The name of the height map, used for simulating displacement and depth.
/// </summary>
[EnumMember(Value = "fHeight")]
Height
public const string Height = "fHeight";
}

0 comments on commit ea967b2

Please sign in to comment.