本文整理匯總了C#中SharpDX.Direct3D9.Texture.GetLevelDescription方法的典型用法代碼示例。如果您正苦於以下問題:C# Texture.GetLevelDescription方法的具體用法?C# Texture.GetLevelDescription怎麽用?C# Texture.GetLevelDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpDX.Direct3D9.Texture
的用法示例。
在下文中一共展示了Texture.GetLevelDescription方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Render
/// <summary>
/// Render method is called directly by renderer. Depending on stage, post process can do various things
/// </summary>
/// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
{
switch (postProcessStage)
{
case PostProcessStage.HDR:
{
MyMinerGame.SetRenderTarget(availableRenderTarget, null);
MyEffectContrast effectContrast = MyRender.GetEffect(MyEffects.Contrast) as MyEffectContrast;
effectContrast.SetDiffuseTexture(source);
effectContrast.SetHalfPixel(MyUtils.GetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height));
effectContrast.SetContrast(Contrast);
effectContrast.SetHue(Hue);
effectContrast.SetSaturation(Saturation);
MyGuiManager.GetFullscreenQuad().Draw(effectContrast);
return availableRenderTarget;
}
break;
}
return source;
}
示例2: Render
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
{
switch (postProcessStage)
{
case PostProcessStage.AlphaBlended:
{
BlendState.Opaque.Apply();
DepthStencilState.None.Apply();
RasterizerState.CullCounterClockwise.Apply();
MyRender.SetRenderTarget(availableRenderTarget, null);
MyEffectChromaticAberration effectChromaAberr = MyRender.GetEffect(MyEffects.ChromaticAberration) as MyEffectChromaticAberration;
effectChromaAberr.SetInputTexture(source);
effectChromaAberr.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height);
effectChromaAberr.SetAspectRatio((float)source.GetLevelDescription(0).Width / (float)source.GetLevelDescription(0).Height);
effectChromaAberr.SetDistortionLens(DistortionLens);
effectChromaAberr.SetDistortionCubic(DistortionCubic);
effectChromaAberr.SetDistortionWeights(ref DistortionWeights);
effectChromaAberr.Enable();
MyRender.GetFullscreenQuad().Draw(effectChromaAberr);
return availableRenderTarget;
}
}
return source;
}
示例3: Render
/// <summary>
/// Render method is called directly by renderer. Depending on stage, post process can do various things
/// </summary>
/// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
{
switch (postProcessStage)
{
case PostProcessStage.AlphaBlended:
{
BlendState.Opaque.Apply();
DepthStencilState.None.Apply();
RasterizerState.CullCounterClockwise.Apply();
MyRender.SetRenderTarget(availableRenderTarget, null);
MyEffectAntiAlias effectAntiAlias = MyRender.GetEffect(MyEffects.AntiAlias) as MyEffectAntiAlias;
effectAntiAlias.SetDiffuseTexture(source);
effectAntiAlias.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height);
if (MyRenderConstants.RenderQualityProfile.EnableFXAA)
effectAntiAlias.ApplyFxaa();
else
return source; // Nothing to do, return source
MyRender.GetFullscreenQuad().Draw(effectAntiAlias);
return availableRenderTarget;
}
break;
}
return source;
}
示例4: DrawCentered
public static void DrawCentered(this Sprite sprite,
Texture texture,
Vector2 position,
Rectangle? rectangle = null)
{
var desc = texture.GetLevelDescription(0);
sprite.Draw(
texture, new ColorBGRA(255, 255, 255, 255), rectangle,
new Vector3(-(position.X - desc.Width / 2f), -(position.Y - desc.Height / 2f), 0));
}
示例5: Render
public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
{
switch (postProcessStage)
{
case PostProcessStage.AlphaBlended:
{
BlendState.Opaque.Apply();
DepthStencilState.None.Apply();
RasterizerState.CullCounterClockwise.Apply();
MyRender.SetRenderTarget(availableRenderTarget, null);
MyEffectColorMapping effect = MyRender.GetEffect(MyEffects.ColorMapping) as MyEffectColorMapping;
effect.SetInputTexture(source);
effect.SetHalfPixel(source.GetLevelDescription(0).Width, source.GetLevelDescription(0).Height);
effect.Enable();
MyRender.GetFullscreenQuad().Draw(effect);
return availableRenderTarget;
}
}
return source;
}
示例6: TextureBase
public TextureBase(DeviceContext context, Texture texture)
: base(context)
{
_texture = texture;
SurfaceDescription desc = _texture.GetLevelDescription(0);
_width = desc.Width;
_height = desc.Height;
_size = new Vector2(_width, _height);
_levelCount = _texture.LevelCount;
_usage = desc.Usage;
_format = desc.Format;
_pool = desc.Pool;
#if DEBUG
Context.PerformanceMonitor.IncreaseLifetimeCounter(LifetimeCounters.TextureCount);
#endif
}
示例7: GenerateDownscale4
/// <summary>
/// Downscales the source to 1/4th size, using mipmaps
/// !! IMPORTANT !! you cannot just switch function call. Also changing RTs is necessary.
/// </summary>
protected void GenerateDownscale4(Texture sourceMod, Texture sourceDiv, Texture destination, MyEffectScale effect)
{
effect.SetTechnique(MyEffectScale.Technique.Downscale4);
MyMinerGame.SetRenderTarget(destination, null);
effect.SetSourceTextureMod(sourceMod);
effect.SetSourceTextureDiv(sourceDiv);
//effect.SetLumTexture(currentFrameAdaptedLuminance);
effect.SetHalfPixel(sourceMod.GetLevelDescription(0).Width, sourceMod.GetLevelDescription(0).Height);
MyGuiManager.GetFullscreenQuad().Draw(effect);
}
示例8: CalculateAverageLuminance
/*
private void CalculateAverageLuminance(RenderTarget2D source, RenderTarget2D destination, MyEffectLuminance luminanceEffect, MyEffectScale scalingEffect, float dt, float tau)
{
// Calculate the initial luminance
luminanceEffect.SetTechniqueLuminance();
PostProcess(source, destination, luminanceEffect);
//// Repeatedly downscale
//scalingEffect.SetTechniqueDownscale();
//for (int i = 1; i < luminanceChain.Length; i++)
//{
// scalingEffect.SetSourceDimensions(luminanceChain[i - 1].Width, luminanceChain[i - 1].Height);
// PostProcess(luminanceChain[i - 1], luminanceChain[i], scalingEffect);
//}
//// Final downscale
//scalingEffect.SetTechniqueDownscaleLuminance();
//scalingEffect.SetSourceDimensions(luminanceChain[luminanceChain.Length - 1].Width, luminanceChain[luminanceChain.Length - 1].Height);
//PostProcess(luminanceChain[luminanceChain.Length - 1], currentFrameLuminance, scalingEffect);
// Final downscale
luminanceEffect.SetTechniqueLuminanceMipmap();
float size = MathHelper.Min(MyCamera.ForwardViewport.Width, MyCamera.ForwardViewport.Height);
// TODO check if mipmap level is correct
int mipLevel = (int)Math.Floor(Math.Log(size / 8.0f, 2));
//int mipLevel = (int)Math.Ceiling(Math.Log(size / 8.0f, 2));
luminanceEffect.SetMipLevel(mipLevel);
PostProcess(destination, currentFrameLuminance, luminanceEffect);
// Adapt the luminance, to simulate slowly adjust exposure
MyMinerGame.Static.GraphicsDevice.SetRenderTarget(currentFrameAdaptedLuminance);
luminanceEffect.SetTechniqueAdaptedLuminance();
luminanceEffect.SetDT(dt);
luminanceEffect.SetTau(tau);
luminanceEffect.SetSourceTexture(currentFrameLuminance);
luminanceEffect.SetSourceTexture2(lastFrameAdaptedLuminance);
luminanceEffect.SetHalfPixel(source.Width, source.Height);
MyGuiManager.GetFullscreenQuad().Draw(luminanceEffect);
}
*/
private void HDR(Texture sourceMod, Texture sourceDiv, Texture bloomSource, MyEffectHDR effect, float middleGrey, float exposure)
{
effect.SetSourceTextureMod(sourceMod);
effect.SetSourceTextureDiv(sourceDiv);
effect.SetBloomTexture(bloomSource);
//effect.SetLumTexture(currentFrameAdaptedLuminance);
//effect.SetLumTexture(currentFrameLuminance);
effect.SetHalfPixel(sourceMod.GetLevelDescription(0).Width, sourceMod.GetLevelDescription(0).Height);
//effect.SetMiddleGrey(middleGrey);
effect.SetExposure(exposure);
MyGuiManager.GetFullscreenQuad().Draw(effect);
}
示例9: Blur
private void Blur(Texture sourceAndDestination, Texture aux, MyEffectGaussianBlur effect, float verticalBlurAmount, float horizontalBlurAmount)
{
effect.SetHalfPixel(sourceAndDestination.GetLevelDescription(0).Width, sourceAndDestination.GetLevelDescription(0).Height);
int numberOfBlurPasses = Convert.ToInt32(Math.Floor(NumberOfBlurPasses));
for (int i = 0; i < numberOfBlurPasses; i++)
{
// Apply vertical gaussian blur
MyMinerGame.SetRenderTarget(aux, null);
effect.BlurAmount = verticalBlurAmount;
effect.SetSourceTexture(sourceAndDestination);
//effect.SetWidthForHorisontalPass(sourceAndDestination.Width);
effect.SetHeightForVerticalPass(sourceAndDestination.GetLevelDescription(0).Height);
MyGuiManager.GetFullscreenQuad().Draw(effect);
// Apply horizontal gaussian blur
MyMinerGame.SetRenderTarget(sourceAndDestination, null);
effect.BlurAmount = horizontalBlurAmount;
effect.SetSourceTexture(aux);
//effect.SetHeightForVerticalPass(sourceAndDestination.Height);
effect.SetWidthForHorisontalPass(aux.GetLevelDescription(0).Width);
MyGuiManager.GetFullscreenQuad().Draw(effect);
}
}
示例10: DrawSpriteBatch
// Draws sprite batch at specified position
// normalizedPosition -> X and Y are within interval <0..1>
// scale -> scale for original texture, it's not in pixel/texels, but multiply of original size. E.g. 1 means unchanged size, 2 means double size. Scale is uniform, preserves aspect ratio.
// rotation -> angle in radians. Rotation is always around "origin" coordinate
// originNormalized -> the origin of the sprite. Specify (0,0) for the upper-left corner.
// RETURN: Method returns rectangle where was sprite/texture drawn in normalized coordinates
internal static void DrawSpriteBatch(Texture texture, Vector2 normalizedCoord, float scale, Color color, MyGuiDrawAlignEnum drawAlign, Vector2 rightVector, Vector2 originNormalized)
{
System.Diagnostics.Debug.Assert(m_spriteBatchUsageCount > 0);
if (texture == null)
return;
if (m_screenshot != null && m_screenshot.IgnoreSprites)
return;
Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord);
// Fix the scale for screen resolution
float fixedScale = scale * m_safeScreenScale;
Vector2 sizeInPixels = new Vector2(texture.GetLevelDescription(0).Width, texture.GetLevelDescription(0).Height);
Vector2 sizeInPixelsScaled = sizeInPixels * fixedScale;
screenCoord = GetAlignedCoordinate(screenCoord, sizeInPixelsScaled, drawAlign);
//m_spriteBatch.Draw(texture, SharpDXHelper.ToSharpDX(screenCoord), null, SharpDXHelper.ToSharpDX(color), rotation, SharpDXHelper.ToSharpDX(originNormalized * sizeInPixels), fixedScale, SpriteEffects.None, 0);
RectangleF rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale, fixedScale);
Vector2 origin = originNormalized * sizeInPixels;
m_spriteBatch.DrawSprite(texture, null, ref rect, true, null, color, rightVector, ref origin, VRageRender.Graphics.SpriteEffects.None, 0);
}
示例11: SetSourceTexture
public void SetSourceTexture(Texture renderTarget2D)
{
m_D3DEffect.SetTexture(m_source, renderTarget2D);
m_D3DEffect.SetValue(m_halfPixel, MyUtils.GetHalfPixel(renderTarget2D.GetLevelDescription(0).Width, renderTarget2D.GetLevelDescription(0).Height));
}
示例12: DrawVertexBuffer
static void DrawVertexBuffer(Texture depthForParticlesRT, List<MyBillboard> billboards)
{
// This is important for optimalization (although I don't know when it can happen to have zero billboards), but
// also that loop below needs it - as it assumes we are rendering at least one billboard.
if (billboards.Count == 0)
return;
Device device = MyRender.GraphicsDevice;
Surface oldTargets = null;
DepthStencilState previousState = null;
if (MyRender.Settings.VisualizeOverdraw)
{
oldTargets = device.GetRenderTarget(0);
//We borrow lod0normals to render stencil
MyRender.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.Auxiliary0), null);
device.Clear(ClearFlags.Target | ClearFlags.Stencil, new ColorBGRA(0), 1.0f, 0);
previousState = MyStateObjects.StencilMask_AlwaysIncrement_DepthStencilState;
MyStateObjects.StencilMask_AlwaysIncrement_DepthStencilState.Apply();
}
else
{
previousState = DepthStencilState.None;
DepthStencilState.None.Apply();
}
// Draw particles without culling. It's because how we calculate left/up vector, we can have problems in back camera. (yes, that can be solved, but why bother...)
// Also I guess that drawing without culling may be faster - as GPU doesn't have to check it
// No it's not, correct culling is faster: http://msdn.microsoft.com/en-us/library/windows/desktop/bb204882(v=vs.85).aspx
RasterizerState.CullNone.Apply();
MyEffectTransparentGeometry effect = MyRender.GetEffect(MyEffects.TransparentGeometry) as MyEffectTransparentGeometry;
effect.SetWorldMatrix(Matrix.Identity);
Matrix viewMatrix = MyRenderCamera.ViewMatrixAtZero;
effect.SetViewMatrix(ref viewMatrix);
effect.SetProjectionMatrix(ref MyRenderCamera.ProjectionMatrix);
Viewport originalViewport = MyRender.GraphicsDevice.Viewport;
effect.SetDepthsRT(depthForParticlesRT);
effect.SetHalfPixel(depthForParticlesRT.GetLevelDescription(0).Width, depthForParticlesRT.GetLevelDescription(0).Height);
effect.SetScale(MyRender.GetScaleForViewport(depthForParticlesRT));
// Later we can interpolate between Main and Aux
effect.SetEnvironmentMap(MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCube));
//For struct size checks
//int stride = MyVertexFormatTransparentGeometry.VertexDeclaration.VertexStride;
//int s = Marshal.SizeOf(new MyVertexFormatTransparentGeometry());
// We iterate over all sorted billboards, and seach for when texture/shader has changed.
// We try to draw as many billboards as possible (using the same texture), but because we are rendering billboards
// sorted by depth, we still need to switch sometimes. Btw: I have observed, that most time consuming when drawing particles
// is device.DrawUserPrimitives(), even if I call it for the whole list of billboards (without this optimization). I think, it's
// because particles are pixel-bound (I do a lot of light calculation + there is blending, which is always slow).
MyTransparentMaterial lastMaterial = MyTransparentMaterials.GetMaterial(billboards[0].Material);
MyBillboard lastBillboard = billboards[0];
MyTransparentMaterial lastBlendMaterial = lastBillboard.BlendMaterial != null ? MyTransparentMaterials.GetMaterial(lastBillboard.BlendMaterial) : null;
bool ignoreDepth = false;
Matrix projectionMatrix = MyRenderCamera.ProjectionMatrix;
Matrix invProjectionMatrix = Matrix.Invert(projectionMatrix);
effect.SetInverseDefaultProjectionMatrix(ref invProjectionMatrix);
if (lastBillboard.CustomViewProjection != -1)
{
SetupCustomViewProjection(effect, ref originalViewport, lastBillboard, ref ignoreDepth, ref projectionMatrix);
}
// 0.05% of billboard is blended
const float softColorizeSize = 0.05f;
device.VertexDeclaration = MyVertexFormatTransparentGeometry.VertexDeclaration;
device.SetStreamSource(0, m_vertexBuffer, 0, MyVertexFormatTransparentGeometry.Stride);
device.Indices = m_indexBuffer;
MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
MyEffectTransparentGeometry effect2 = MyRender.GetEffect(MyEffects.TransparentGeometry) as MyEffectTransparentGeometry;
effect2.SetShadowBias(0.001f);
MyLights.UpdateEffectReflector(effect2.Reflector, false);
MyLights.UpdateEffect(effect2, false);
int geomCount = billboards.Count;
int it = 0;
int cnt = 0;
while (geomCount > 0)
{
if (geomCount > RENDER_BUFFER_SIZE)
{
//.........這裏部分代碼省略.........
示例13: DrawSpriteBatch
// Draws sprite batch at specified position
// normalizedPosition -> X and Y are within interval <0..1>
// scale -> scale for original texture, it's not in pixel/texels, but multiply of original size. E.g. 1 means unchanged size, 2 means double size. Scale is uniform, preserves aspect ratio.
// rotation -> angle in radians. Rotation is always around "origin" coordinate
// originNormalized -> the origin of the sprite. Specify (0,0) for the upper-left corner.
// RETURN: Method returns rectangle where was sprite/texture drawn in normalized coordinates
public static void DrawSpriteBatch(Texture texture, Vector2 normalizedCoord, float scale, Color color, MyGuiDrawAlignEnum drawAlign, float rotation, Vector2 originNormalized)
{
System.Diagnostics.Debug.Assert(m_spriteBatchUsageCount > 0);
if (texture == null)
return;
Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord);
// Fix the scale for screen resolution
float fixedScale = scale * m_safeScreenScale;
Vector2 sizeInPixels = new Vector2(texture.GetLevelDescription(0).Width, texture.GetLevelDescription(0).Height);
Vector2 sizeInPixelsScaled = sizeInPixels * fixedScale;
screenCoord = GetAlignedCoordinate(screenCoord, sizeInPixelsScaled, drawAlign);
m_spriteBatch.Draw(texture, SharpDXHelper.ToSharpDX(screenCoord), null, SharpDXHelper.ToSharpDX(color), rotation, SharpDXHelper.ToSharpDX(originNormalized * sizeInPixels), fixedScale, SpriteEffects.None, 0);
}
示例14: BlitToThumbnail
private void BlitToThumbnail(Device device, Texture renderTarget)
{
MyMinerGame.SetRenderTarget(renderTarget, null);
var screenEffect = MyRender.GetEffect(MyEffects.Scale) as MyEffectScale;
Debug.Assert(screenEffect != null);
screenEffect.SetTechnique(MyEffectScale.Technique.HWScalePrefabPreviews);
screenEffect.SetSourceTextureMod(m_fullSizeRT);
//screenEffect.SetScale(2f * new Vector2(renderTarget.Width / (float)m_fullSizeRT.Width, renderTarget.Height / (float)m_fullSizeRT.Height));
screenEffect.SetScale(2f * new Vector2((renderTarget.GetLevelDescription(0).Width - 1) / (float)m_fullSizeRT.GetLevelDescription(0).Width, (renderTarget.GetLevelDescription(0).Height - 1) / (float)m_fullSizeRT.GetLevelDescription(0).Height));
MyGuiManager.GetFullscreenQuad().Draw(screenEffect);
MyMinerGame.SetRenderTarget(null, null);
}
示例15: CreateTextureCopy
protected static Texture CreateTextureCopy(Texture sourceTexture, out SizeF textureSize)
{
if (sourceTexture == null)
{
textureSize = new SizeF();
return null;
}
SurfaceDescription desc = sourceTexture.GetLevelDescription(0);
textureSize = new SizeF(desc.Width, desc.Height);
DeviceEx device = SkinContext.Device;
Texture result = new Texture(device, desc.Width, desc.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Default);
using(Surface target = result.GetSurfaceLevel(0))
using(Surface source = sourceTexture.GetSurfaceLevel(0))
device.StretchRectangle(source, target, TextureFilter.None);
return result;
}