Skip to content

Commit 878f8de

Browse files
committed
Load Textures with the right format
1 parent b875d0b commit 878f8de

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/EngineKit/Graphics/Material.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public record Material(string Name) : IDisposable
3030
public SamplerInformation? MetalnessRoughnessTextureSamplerInformation;
3131
public SamplerInformation? OcclusionTextureSamplerInformation;
3232
public SamplerInformation? EmissiveTextureSamplerInformation;
33-
33+
3434
private bool _isDirty;
3535
public string Name { get; set; } = Name;
3636

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

241-
BaseColorTexture = CreateTextureFromImage(BaseColorImage, BaseColorTextureSamplerInformation, logger,
241+
BaseColorTexture = CreateTextureFromImage(BaseColorImage, Format.R8G8B8A8Srgb, BaseColorTextureSamplerInformation, logger,
242242
graphicsContext, samplerLibrary, textures, makeResident);
243-
NormalTexture = CreateTextureFromImage(NormalImage, NormalTextureSamplerInformation, logger, graphicsContext,
243+
NormalTexture = CreateTextureFromImage(NormalImage, Format.R8G8B8A8UNorm, NormalTextureSamplerInformation, logger, graphicsContext,
244244
samplerLibrary, textures, makeResident);
245-
MetalnessRoughnessTexture = CreateTextureFromImage(MetalnessRoughnessImage,
245+
MetalnessRoughnessTexture = CreateTextureFromImage(MetalnessRoughnessImage, Format.R8G8B8A8UNorm,
246246
MetalnessRoughnessTextureSamplerInformation, logger, graphicsContext, samplerLibrary, textures,
247247
makeResident);
248-
SpecularTexture = CreateTextureFromImage(SpecularImage, SpecularTextureSamplerInformation, logger,
248+
SpecularTexture = CreateTextureFromImage(SpecularImage, Format.R8G8B8A8UNorm, SpecularTextureSamplerInformation, logger,
249249
graphicsContext, samplerLibrary, textures, makeResident);
250-
OcclusionTexture = CreateTextureFromImage(OcclusionImage, OcclusionTextureSamplerInformation, logger,
250+
OcclusionTexture = CreateTextureFromImage(OcclusionImage, Format.R8G8B8A8UNorm, OcclusionTextureSamplerInformation, logger,
251251
graphicsContext, samplerLibrary, textures, makeResident);
252-
EmissiveTexture = CreateTextureFromImage(EmissiveImage, EmissiveTextureSamplerInformation, logger,
252+
EmissiveTexture = CreateTextureFromImage(EmissiveImage, Format.R8G8B8A8Srgb, EmissiveTextureSamplerInformation, logger,
253253
graphicsContext, samplerLibrary, textures, makeResident);
254254

255255
TexturesLoaded = true;
256256
}
257257

258258
private static ITexture? CreateTextureFromImage(
259259
ImageInformation? image,
260+
Format format,
260261
SamplerInformation? sampler,
261262
ILogger logger,
262263
IGraphicsContext graphicsContext,
@@ -272,10 +273,10 @@ public void LoadTextures(
272273

273274
var sw = Stopwatch.StartNew();
274275
texture = image.ImageData.HasValue
275-
? graphicsContext.CreateTextureFromMemory(image, Format.R8G8B8A8Srgb, image.Name, generateMipmaps: true, flipVertical: false, flipHorizontal: false)
276+
? graphicsContext.CreateTextureFromMemory(image, format, image.Name, generateMipmaps: true, flipVertical: false, flipHorizontal: false)
276277
: string.IsNullOrEmpty(image.FileName)
277278
? null
278-
: graphicsContext.CreateTextureFromFile(image.FileName, Format.R8G8B8A8Srgb, true, false, false);
279+
: graphicsContext.CreateTextureFromFile(image.FileName, format, true, false, false);
279280

280281
sw.Stop();
281282

0 commit comments

Comments
 (0)