gpt4 book ai didi

wpf - wpf 中的 Mipmapping

转载 作者:行者123 更新时间:2023-12-04 12:55:35 29 4
gpt4 key购买 nike

我是 'wpf' 的新手,我遇到了以下问题:在我的项目中,我尝试使用小分辨率 .png 作为模型的纹理。当我在 Blender(我构建立方体的地方)中禁用 mipmapping 时,结果正是我想要的:

no mipmapping

但是在 wpf 项目中,模糊效果永远不会关闭:

wpf result

这是我的代码:

<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>

我在互联网上做了很多搜索并尝试了很多方法:强制软件渲染,使用DrawingBrush而不是ImageBrush但结果是一样的。有没有办法克服这种渲染?

最佳答案

使用 VisualBrush 尝试以下方法 - 它会产生清晰的锯齿状纹理:

Screenshot



        <DiffuseMaterial x:Key="Material">
<DiffuseMaterial.Brush>
<VisualBrush RenderOptions.CachingHint="Cache">
<VisualBrush.Visual>
<Image Source="char.png" RenderOptions.BitmapScalingMode="NearestNeighbor" />
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</Grid.Resources>


<Viewport3D Name="myViewport">
<Viewport3D.Camera>
<PerspectiveCamera Position="0 0.5 1.5" LookDirection="0 0 -1"
UpDirection="0 1 0" FieldOfView="120" />
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D Material="{StaticResource Material}">

<GeometryModel3D.Geometry>
<MeshGeometry3D
Positions="0 0 0, 0 1 0, 1 0 0, 1 1 0"
TriangleIndices="0 2 3, 0 3 1"
TextureCoordinates="0 1, 0 0, 1 1, 1 0" />
</GeometryModel3D.Geometry>

</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>

<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="#ffffff"/>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D.Children>
</Viewport3D>
</Grid>

关于wpf - wpf 中的 Mipmapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12367928/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com