Texture issues
#2
The error was caused because a BitmapImage was using a relative Uri. The code in DXEngine is reading the bitmapImage.UriSource.LocalPath and I did not expect that the LocalPath getter would throw an exception when the path was not absolute.

I have fixed that with checking for absolute path before getting LocalPath. This fix is available in the pre-release version (v1.4) - if you need it, please send me an email or private message and I will send you a link to pre-release version.

Alternatively you can change the Uri to an absolute uri.


The other problem is related to showing tiled textures. To show tiled textures, please use Viewport property instead of Transform. This is also a standard WPF's way to provide tiled images in 2D graphics - see :https://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.viewport(v=vs.110).aspx

The problem with Transform on the ImageBrush is that it is very hard to implement for all cases (this would require a support in pixel shader that would require a lot of additional shader versions that would support texture transformations).

For example to show 4 x 2 tiles, set TileMode to Tile and then set Viewport to "0 0 0.25 0.5".

<visuals:BoxVisual3D x:Name="Box1" CenterPosition="30 10 30" Size="100 20 100">
<visuals:BoxVisual3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush TileMode="Tile" Viewport="0 0 0.25 0.5"> <!-- 4 x 2 -->
<ImageBrush.ImageSource>
<BitmapImage UriSource="/Resources/PowerToysTexture.png" />
</ImageBrush.ImageSource>
</ImageBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</visuals:BoxVisual3D.Material>
</visuals:BoxVisual3D>


After writing all that I got an idea: when the ImageBrush (or any other TileBrush) has TileMode set to Tile and Viewport set to 0,0,1,1 and it has a single ScaleTransform, it is possible to convert ScaleTransform into Viewport Rect value:

imageBrush.Viewport = new Rect(0, 0, scaleTransform.ScaleX, scaleTransform.ScaleY);
usedTransform = null;

This was also added to the development version of DXEngine and will come with next version. Until then please use Viewport for tiled images.
Andrej Benedik
  


Messages In This Thread
Texture issues - by jesusg - 05-06-2016, 11:02 AM
RE: Texture issues - by abenedik - 05-10-2016, 09:26 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)