Comments (3)
I can say that I had similar issues with some DDS files, where Luminance-type DDS files (I think that's similar to your BC4_linear_grayscale) which should have the luminance in the alpha channel ended up having it in the red channel. I'm not sure if it's an ambiguity of the DDS format, or the parser not interpreting all header fields properly (especially the R/G/B/A bit mask fields), but in any case the culprit is probably in the code from SharpDX's DDS utilities, which HelixToolkit just uses for DDS reading.
I ended up changing the shader to user a different channel, but you may be easier off if you can get your exporter to save the DDS in a compatible format...
from helix-toolkit.
That's looks about right, maybe it's sharpdx. But modifying the shader is not in my capabilities and I can't change the Dds format since they are needed like this somewhere else,
I could do a work around so that instead of loading the Dds to texture model I could convert it to color4[] first, then use it for the texture model
but this would increase the time needed for rendering the image and my conversion creates a memory overhead {from 800mb to 2GB in 15-30s}
public static TextureModel DDsToTextureModel(string filepath)
{
using (var image = Pfimage.FromFile(filepath))
{
if (image.Compressed)
image.Decompress();
var carray = ConvertIImageToColor4Array(image);
return new TextureModel(carray, image.Width, image.Height);
}
}
public static Color4[] ConvertIImageToColor4Array(IImage image)
{
byte[] imageData = image.Data;
int width = image.Width;
int height = image.Height;
// Number of pixels
int pixelCount = width * height;
Color4[] colors = new Color4[pixelCount];
for (int i = 0; i < pixelCount; i++)
{
// Calculate pixel byte offset in imageData
int row = i / width;
int col = i % width;
int offset = row * image.Stride + col * (image.BitsPerPixel / 8);
// Extract Color4 based on image format
colors[i] = ExtractColorFromPixel(imageData, offset, image.Format);
}
return colors;
}
private static Color4 ExtractColorFromPixel(byte[] imageData, int offset, ImageFormat format)
{
Color4 color = new Color4();
switch (format)
{
case ImageFormat.Rgb8:
// Assuming it might be grayscale where R=G=B with 8 bits.
byte gray = imageData[offset];
color.Red = color.Green = color.Blue = gray / 255f;
color.Alpha = 1f;
break;
case ImageFormat.R5g5b5:
// Assuming data is little-endian; adjust if big-endian.
ushort pixelValue = BitConverter.ToUInt16(imageData, offset);
color.Red = ((pixelValue >> 10) & 0x1F) / 31f;
color.Green = ((pixelValue >> 5) & 0x1F) / 31f;
color.Blue = (pixelValue & 0x1F) / 31f;
color.Alpha = 1f;
break;
case ImageFormat.R5g6b5:
pixelValue = BitConverter.ToUInt16(imageData, offset);
color.Red = ((pixelValue >> 11) & 0x1F) / 31f;
color.Green = ((pixelValue >> 5) & 0x3F) / 63f;
color.Blue = (pixelValue & 0x1F) / 31f;
color.Alpha = 1f;
break;
case ImageFormat.R5g5b5a1:
pixelValue = BitConverter.ToUInt16(imageData, offset);
color.Red = ((pixelValue >> 11) & 0x1F) / 31f;
color.Green = ((pixelValue >> 6) & 0x1F) / 31f;
color.Blue = ((pixelValue >> 1) & 0x1F) / 31f;
color.Alpha = (pixelValue & 0x1) != 0 ? 1f : 0f;
break;
case ImageFormat.Rgba16:
// 4 bits for each channel
ushort rgbaValue = BitConverter.ToUInt16(imageData, offset);
color.Red = ((rgbaValue >> 12) & 0xF) / 15f;
color.Green = ((rgbaValue >> 8) & 0xF) / 15f;
color.Blue = ((rgbaValue >> 4) & 0xF) / 15f;
color.Alpha = (rgbaValue & 0xF) / 15f;
break;
case ImageFormat.Rgb24:
color.Red = imageData[offset + 2] / 255f;
color.Green = imageData[offset + 1] / 255f;
color.Blue = imageData[offset] / 255f;
color.Alpha = 1f;
break;
case ImageFormat.Rgba32:
color.Red = imageData[offset + 2] / 255f;
color.Green = imageData[offset + 1] / 255f;
color.Blue = imageData[offset + 0] / 255f;
color.Alpha = imageData[offset + 3] / 255f;
break;
default:
throw new ArgumentOutOfRangeException(nameof(format), "Unsupported image format.");
}
return color;
}
from helix-toolkit.
If you are interested in debugging the issue, the source is in https://github.com/helix-toolkit/helix-toolkit/blob/develop/Source/HelixToolkit.SharpDX.Shared/SharpDX.Toolkit/Graphics/DDSHelper.cs
from helix-toolkit.
Related Issues (20)
- [V3] Missing TriangleIndices setting in Converter.ToMeshGeometry3D
- MyGet nightly packages HOT 1
- [V3, SharpDX] The ToMeshGeometry3D method makes extra copies HOT 1
- [V3] Assign the wrong value in `BoundingBoxExtensions` at Maths. HOT 4
- Get Angles and Vectors of Axes After Rotating them in Helix wpf mouse.RotateGesture
- Is it possible to render the content of a Viewport3DX to a bitmap without the parent WPF window containing the Viewport3DX being open or visible? HOT 3
- Unexpected rendering with OITRenderMode = SinglePassWeighted for semi-transparent models with alpha=1 HOT 2
- Unexpected rendering with OITRenderMode = DepthPeeling with alpha=0 or alpha=1 HOT 2
- SharpDX.SharpDXException [0x80070057] when creating a DiffuseMap from an image HOT 8
- PostEffect Mesh BorderHighlight disappears if cull mode is set to front
- Additive Rendering HOT 2
- Textures on PointGeometry3D object HOT 3
- Strange behavior for ParticleStormNode with multiple rows/columns HOT 1
- V3 HelixToolkit.Geometry namespace is not consistency HOT 4
- Remove obsolete members in V3 HOT 4
- some questions aboat sharpdx HOT 1
- Anti-aliasing introducing additional colours into Viewport Renders. HOT 3
- Helixtoolkit.WPF V3, Panning does not working well when zoom-in in Viewport3D HOT 8
- helixtoolkit.wpf is missing NuGet package README file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helix-toolkit.