I'm here with another question about direct 3d 11 (sharpdx). My terrain engine is working good, but theres a problem with texture mip maps or filter which I can't figure out :/
The problem is basic. Near, the textures look OK:
Far away they're kinda ugly?
Loading it:
internal Texture2D CreateTexture2DFromBitmap(BitmapSource bitmapSource)
{
int Byte = bitmapSource.Size.Width * 4;
using (var buffer = new DataStream(bitmapSource.Size.Height * Byte, true, true))
{
bitmapSource.CopyPixels(Byte, buffer);
var tex = new Texture2D(device, new Texture2DDescription()
{
Width = bitmapSource.Size.Width,
Height = bitmapSource.Size.Height,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Usage = ResourceUsage.Default,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb,
MipLevels = 1,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.Shared,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0)
},
new DataRectangle(buffer.DataPointer, Byte));
return tex;
}
}
Rendering it:
public override void Create(long assetID, Importeur content, DeviceContext context)
{
try
{
_diffuseTexture = content.LoadTexture(assetID, TextureType.DiffuseMap);
context.GenerateMips(_diffuseTexture.MapView);
context.PixelShader.SetShaderResource(0, _diffuseTexture.MapView);
}
catch (Exception e)
{
throw e;
}
}
Filter:
var samplerStateDescription = new SamplerStateDescription
{
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
Filter = Filter.Anisotropic,
MaximumLod = float.MaxValue,
MinimumLod = 0
};
Finally got it working, the problem was a thread block code line from my engine.
Thanks for helping!