SharpDX - Transparency from image

Mar 7, 2014 at 10:05 AM
Hi,

how can i enable transparency from image for textures ??

In WPF3D, all i need to do is to create the diffuse material with image brush and use it. In SharpDX fork, I had created PhongMaterial and set its DiffuseMap to the same image i used in WPF3D, but here the transparent region are rendered as Black.

Thanks
Mar 8, 2014 at 4:05 PM
I used PNG textures. Also read this about how you need to order transparent parts :

http://www.ericsink.com/wpf3d/2_Transparency.html


I still have problems with layered transparency though, when one part of the model overlaps the other it does not look right.
Mar 8, 2014 at 5:48 PM
Thank you Rogad for your reply.

I would like to know have you used PNG textures to attained transparency in "SharpDX fork of Helix Toolkit" ?? because the link you have provided is about transparency in WPF3D but I need transparency in SharpDX.

P.S. I already got the transparency using image texture in WPF3D but I require same functionality in SharpDX fork using that same image.
Mar 8, 2014 at 5:56 PM
Edited Mar 8, 2014 at 5:57 PM
Sorry I did not realise you were asking about SharpDX. I have not tried it, because I couldn't see how to get support, so gave up on it.
Mar 12, 2014 at 7:04 PM
After debugging the code, I had resolved this issue. Following are the changes I needed to make in Helix SharpDx.


In the pixel shader "PShaderPhong" method, alpha value is taken explicitly from the diffuse material.

Current Code "Default.fx"
/// set diffuse alpha
I.a = vMaterialDiffuse.a;
Fix "Default.fx"
I.a = vMaterialDiffuse.a * vMaterialTexture[3];
Also the conversion of texture map is done through BMP encoder, however apparantly it looks like BMP encoder doesn't support alpha in texture map. Changing bmp encoder to png encoder will resolve this issue.

Current Code "RenderUtil.cs"
public static byte[] ToByteArray(this System.Windows.Media.Imaging.BitmapSource bitmapSource)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
                encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource));
                encoder.Save(ms);
                return ms.ToArray();
            }
        }
Fix "RenderUtil.cs"
public static byte[] ToByteArray(this System.Windows.Media.Imaging.BitmapSource bitmapSource)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var encoder = new System.Windows.Media.Imaging.PngBitmapEncoder();
                encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSource));
                encoder.Save(ms);
                return ms.ToArray();
            }
        }
Coordinator
Apr 29, 2014 at 9:57 AM
I have forwarded this to the guys working on the sharpdx fork.
May 24, 2014 at 5:16 PM
Is there a similar fix for Helix ?

For my project this is the main area where Helix does not seem to work right.

Despite following various tutorials/guides on transparency, such as putting the transparent textures last I still end up with this :

Image

Some of the transparency is working, but as you can see not all.

Would really like to fix this :)
May 30, 2014 at 3:46 PM
Anyone ? Objo ? Are you still with us ? :)
Coordinator
May 30, 2014 at 9:56 PM
hi Rogad, yes I am following the discussion, but don´t know how to solve this. How are you rendering the hair? Are you using SharpDX or WPF? Can you create a demo application we can include with the library?
May 30, 2014 at 10:08 PM
Hi :)

I'm using WPF and Helix. I have not used SharpDX for anything yet, I was trying to find some documentation for it or support, but haven't found much yet.

Unfortunately I cannot turn this into something distributable. The models I had to buy from Daz3D and I cannot redistribute them like that.