Skip to content

Commit

Permalink
Load Textures with the right format
Browse files Browse the repository at this point in the history
  • Loading branch information
deccer committed Jul 16, 2023
1 parent b875d0b commit 878f8de
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/EngineKit/Graphics/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public record Material(string Name) : IDisposable
public SamplerInformation? MetalnessRoughnessTextureSamplerInformation;
public SamplerInformation? OcclusionTextureSamplerInformation;
public SamplerInformation? EmissiveTextureSamplerInformation;

private bool _isDirty;
public string Name { get; set; } = Name;

Expand Down Expand Up @@ -238,25 +238,26 @@ public void LoadTextures(
//TODO(deccer) TextureLoader should be called and pass in material, to set its Texture objects perhaps
//TODO(deccer) this needs to be inverted, ie someone else needs to load the stuff per material, not the material itself

BaseColorTexture = CreateTextureFromImage(BaseColorImage, BaseColorTextureSamplerInformation, logger,
BaseColorTexture = CreateTextureFromImage(BaseColorImage, Format.R8G8B8A8Srgb, BaseColorTextureSamplerInformation, logger,
graphicsContext, samplerLibrary, textures, makeResident);
NormalTexture = CreateTextureFromImage(NormalImage, NormalTextureSamplerInformation, logger, graphicsContext,
NormalTexture = CreateTextureFromImage(NormalImage, Format.R8G8B8A8UNorm, NormalTextureSamplerInformation, logger, graphicsContext,
samplerLibrary, textures, makeResident);
MetalnessRoughnessTexture = CreateTextureFromImage(MetalnessRoughnessImage,
MetalnessRoughnessTexture = CreateTextureFromImage(MetalnessRoughnessImage, Format.R8G8B8A8UNorm,
MetalnessRoughnessTextureSamplerInformation, logger, graphicsContext, samplerLibrary, textures,
makeResident);
SpecularTexture = CreateTextureFromImage(SpecularImage, SpecularTextureSamplerInformation, logger,
SpecularTexture = CreateTextureFromImage(SpecularImage, Format.R8G8B8A8UNorm, SpecularTextureSamplerInformation, logger,
graphicsContext, samplerLibrary, textures, makeResident);
OcclusionTexture = CreateTextureFromImage(OcclusionImage, OcclusionTextureSamplerInformation, logger,
OcclusionTexture = CreateTextureFromImage(OcclusionImage, Format.R8G8B8A8UNorm, OcclusionTextureSamplerInformation, logger,
graphicsContext, samplerLibrary, textures, makeResident);
EmissiveTexture = CreateTextureFromImage(EmissiveImage, EmissiveTextureSamplerInformation, logger,
EmissiveTexture = CreateTextureFromImage(EmissiveImage, Format.R8G8B8A8Srgb, EmissiveTextureSamplerInformation, logger,
graphicsContext, samplerLibrary, textures, makeResident);

TexturesLoaded = true;
}

private static ITexture? CreateTextureFromImage(
ImageInformation? image,
Format format,
SamplerInformation? sampler,
ILogger logger,
IGraphicsContext graphicsContext,
Expand All @@ -272,10 +273,10 @@ public void LoadTextures(

var sw = Stopwatch.StartNew();
texture = image.ImageData.HasValue
? graphicsContext.CreateTextureFromMemory(image, Format.R8G8B8A8Srgb, image.Name, generateMipmaps: true, flipVertical: false, flipHorizontal: false)
? graphicsContext.CreateTextureFromMemory(image, format, image.Name, generateMipmaps: true, flipVertical: false, flipHorizontal: false)
: string.IsNullOrEmpty(image.FileName)
? null
: graphicsContext.CreateTextureFromFile(image.FileName, Format.R8G8B8A8Srgb, true, false, false);
: graphicsContext.CreateTextureFromFile(image.FileName, format, true, false, false);

sw.Stop();

Expand Down

0 comments on commit 878f8de

Please sign in to comment.