I'm new to 'wpf' and I've come over the following problem: In my project I try to use small resolution .png as texture for a model. When I disable mipmapping in Blender (where I built the cube) the result is just what I want:
But in the wpf project the blurred effect never turns off:
Here is my code:
<Window x:Class="GCS.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="504" Width="525" ShowInTaskbar="True">
<Grid>
<Viewport3D Name="myViewport"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewport3D.Resources>
<MaterialGroup x:Key="Material">
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush RenderOptions.BitmapScalingMode="NearestNeighbor" ViewportUnits="Absolute" ImageSource="char.png"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</Viewport3D.Resources>
<Viewport3D.Camera>
<PerspectiveCamera Position="7.8,-11,-0.8" NearPlaneDistance="1" FarPlaneDistance="50" LookDirection="-0.4,0.9,-0.3" UpDirection="0,0,1" FieldOfView="15"/>
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<GeometryModel3D Material="{StaticResource Material}">
<GeometryModel3D.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetZ="0" OffsetX="0" OffsetY="-7"/>
<ScaleTransform3D ScaleZ="1" ScaleY="1" ScaleX="1"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="92"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetZ="0" OffsetX="0" OffsetY="7"/>
<TranslateTransform3D OffsetZ="-6.622" OffsetX="0" OffsetY="-0.023"/>
</Transform3DGroup>
</GeometryModel3D.Transform>
<GeometryModel3D.Geometry>
<MeshGeometry3D
Normals="-1,0,0 -1,0,0 -1,0,0 -1,0,0 0,0,-1 0,0,-1 0,0,-1 0,0,-1 1,0,0 1,0,0 1,0,0 1,0,0 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 0,1,0 0,1,0 0,1,0 0,1,0"
Positions="-1,6,-1 -1,6,1 -1,8,1 -1,8,-1 -1,8,-1 1,8,-1 1,6,-1 -1,6,-1 1,8,-1 1,8,1 1,6,1 1,6,-1 -1,6,1 1,6,1 1,8,1 -1,8,1 -1,6,1 -1,6,-1 1,6,-1 1,6,1 1,8,1 1,8,-1 -1,8,-1 -1,8,1"
TextureCoordinates="0,0.5 0.125,0.5 0.125,0.25 0,0.25 0.5,0.25 0.375,0.25 0.375,0.5 0.5,0.5 0.375,0.25 0.25,0.25 0.25,0.5 0.375,0.5 0.125,0.5 0.25,0.5 0.25,0.25 0.125,0.25 0.375,0.25 0.375,0 0.25,0 0.25,0.25 0.25,0.25 0.25,0 0.125,0 0.125,0.25"
TriangleIndices="0 1 2 0 2 3 4 5 6 4 6 7 8 9 10 8 10 11 12 13 14 12 14 15 16 17 18 16 18 19 20 21 22 20 22 23"/>
</GeometryModel3D.Geometry>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="#ffffff"/>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D.Children>
</Viewport3D>
</Grid>
I've done a lot of search on the Internet and tried many approaches: enforced software rendering, used DrawingBrush instead of ImageBrush but the result is the same. Is there any way to overcome such rendering?
RenderOptions.BitmapScalingMode
on theImgaeBrush
. I don't know whether this is the solution (hence a comment rather than an answer), but you can also set it on theGeometryModel3D
,ModelVisual3D
andViewPort3D
, as well as theWindow
and theGrid
. Have you tried any / all of these options to see if it makes a difference? It seems possible to me that the ImageBrush itself doesn't actually do the scaling in a 3D scenario and therefore setting RenderOptions on the brush object won't have the desired effect. – Noble